/* +------------------------------------------------------+ ____/ \____ /| - Open source game framework licensed to freely use, | \ / / | copy, modify and sell without restriction | +--\ ^__^ /--+ | | | ~/ \~ | | - created for | | ~~~~~~~~~~~~ | +------------------------------------------------------+ | SPACE ~~~~~ | / | ~~~~~~~ BOX |/ +--------------+ 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 for the derivative class to implement. 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. A VAO class and a general Buffer class are also defined here. The VAO class just fills in the abstract methods of the GLObject class and doesn't have any further SPACE BOX specific implementation. The buffer class is probably most useful being inherited by a derived class that implements a more specific type of buffer that passes its target to the base class, like the VBO class. */ #pragma once #include #include #include #include #include #include "gl.h" #include "Log.hpp" namespace sb { /* Calls to the stream operator from within this namespace will search the global namespace as well as the current */ using std::operator<<; class GLObject; std::ostream& operator<<(std::ostream&, const GLObject&); class GLObject { private: /* function types */ typedef std::function generator_function; typedef std::function deleter_function; std::shared_ptr 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; friend std::ostream& operator<<(std::ostream&, const GLObject&); }; class VAO : public GLObject { public: VAO(); void generate(); void bind() const; }; void vao_deleter(GLuint*); class Buffer : public GLObject { private: GLenum buffer_target = GL_INVALID_ENUM; protected: GLenum target() const; public: Buffer(); Buffer(GLenum); void target(GLenum); void generate(); void bind() const; void bind(GLenum); }; void buffer_deleter(GLuint*); }