116 lines
3.0 KiB
C++
116 lines
3.0 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.
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
#ifndef SB_GLOBJECT_H_
|
|
#define SB_GLOBJECT_H_
|
|
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <memory>
|
|
#include <functional>
|
|
#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<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;
|
|
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*);
|
|
|
|
}
|
|
|
|
#endif
|