spacebox/src/GLObject.hpp

64 lines
1.7 KiB
C++

/* /\ +--------------------------------------------------------------+
____/ \____ /| - zlib/MIT/Unlicenced game framework licensed to freely use, |
\ / / | copy, modify and sell without restriction |
+--\ ^__^ /--+ | |
| ~/ \~ | | - originally created at [http://nugget.fun] |
| ~~~~~~~~~~~~ | +--------------------------------------------------------------+
| SPACE ~~~~~ | /
| ~~~~~~~ BOX |/
+--------------+
[GLObject.hpp]
The abstract GLObject class is meant to be inherited and implemented by more specific
types of OpenGL objects, for example Textures or Buffer objects. It stores the object's
ID and declares virtual functions for generating, binding, and destroying the object.
An appropriate deleter function must be passed in to the constructor from the derived
class. It can be a custom function, or it can be one of the GL deleter functions like
glDeleteTextures.
*/
#ifndef GLObject_h_
#define GLObject_h_
#include <iostream>
#include <memory>
#include <functional>
/* include Open GL */
#if defined(__EMSCRIPTEN__)
#include <GL/glew.h>
#else
#include "glew/glew.h"
#endif
class GLObject
{
private:
typedef std::function<void(GLsizei, GLuint*)> generator_function;
typedef std::function<void(GLuint*)> deleter_function;
std::shared_ptr<GLuint> object_id = nullptr;
deleter_function deleter = nullptr;
protected:
GLObject(deleter_function);
virtual void bind() const = 0;
void generate(generator_function);
public:
virtual void id(GLuint);
virtual GLuint id() const;
virtual bool generated() const;
virtual ~GLObject() = default;
};
#endif