KlassischeKeplerKriege/game/glclasses.hpp
2016-09-27 20:56:17 +02:00

87 lines
1.9 KiB
C++

#pragma once
#include <epoxy/gl.h>
#include <epoxy/glx.h>
#include <string>
namespace endofthejedi {
template <GLenum T> class BufferObject {
private:
GLuint m_name;
GLvoid *m_mappointer;
protected:
public:
BufferObject();
~BufferObject();
void bind();
void bind(GLuint index, GLintptr offset = 0, GLsizeiptr size = 0);
void fill(GLenum usage, GLsizei size = 0, GLvoid *data = NULL);
void subfill(GLintptr offset, GLsizei size, const GLvoid *data);
void map(GLenum access);
void unmap();
};
typedef BufferObject<GL_ARRAY_BUFFER> VBO;
typedef BufferObject<GL_ELEMENT_ARRAY_BUFFER> IBO;
class VAO {
private:
GLuint m_name;
protected:
public:
VAO();
~VAO();
void bind();
void fill(GLuint index, GLint size, GLenum type, GLboolean normalized,
GLsizei stride = 0, const GLvoid *pointer = NULL);
};
class Shader {
private:
GLuint m_program;
bool check();
bool checkShader();
protected:
public:
Shader();
~Shader();
void bind();
void unbind();
void load(std::string data, GLenum shadertype);
};
}
#define TBufferObject_(pre, post) \
template <GLenum T> pre endofthejedi::BufferObject<T>::post
#define TBufferObject(...) TBufferObject_(__VA_ARGS__)
TBufferObject(, BufferObject)() { glGenBuffers(1, &m_name); }
TBufferObject(, ~BufferObject)() { glDeleteBuffers(1, &m_name); }
TBufferObject(void, bind)() { glBindBuffer(T, m_name); }
TBufferObject(void, bind)(GLuint index, GLintptr offset, GLsizeiptr size) {
// todo
}
TBufferObject(void, fill)(GLenum usage, GLsizei size, GLvoid *data) {
glBufferData(T, size, data, usage);
}
TBufferObject(void, subfill)(GLintptr offset, GLsizei size,
const GLvoid *data) {
glBufferSubData(T, offset, size, data);
}
TBufferObject(void, map)(GLenum access) {
// todo
}
TBufferObject(void, unmap)() {
// todo
}