KlassischeKeplerKriege/game/glclasses.hpp

90 lines
2 KiB
C++
Raw Normal View History

2016-09-15 15:23:02 +00:00
#pragma once
#include <epoxy/gl.h>
#include <epoxy/glx.h>
2016-09-27 15:57:41 +00:00
#include <string>
2016-09-25 20:24:04 +00:00
namespace endofthejedi {
2016-09-15 15:23:02 +00:00
template <GLenum T> class BufferObject {
2016-09-27 18:56:17 +00:00
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();
2016-09-15 15:23:02 +00:00
};
typedef BufferObject<GL_ARRAY_BUFFER> VBO;
typedef BufferObject<GL_ELEMENT_ARRAY_BUFFER> IBO;
class VAO {
2016-09-27 18:56:17 +00:00
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);
2016-09-25 20:24:04 +00:00
};
2016-09-27 18:56:17 +00:00
class Shader {
private:
GLuint m_program;
2016-09-28 01:33:01 +00:00
bool check();
bool checkShader(GLuint shader);
2016-09-27 18:56:17 +00:00
protected:
public:
Shader();
~Shader();
void bind();
void unbind();
void load(std::string data, GLenum shadertype);
2016-09-28 01:33:01 +00:00
GLuint location(std::string name);
2016-09-27 18:56:17 +00:00
};
2016-09-15 15:23:02 +00:00
}
2016-09-27 15:57:41 +00:00
2016-09-27 18:56:17 +00:00
#define TBufferObject_(pre, post) \
template <GLenum T> pre endofthejedi::BufferObject<T>::post
2016-09-27 15:57:41 +00:00
#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) {
2016-09-27 18:56:17 +00:00
// todo
2016-09-27 15:57:41 +00:00
}
TBufferObject(void, fill)(GLenum usage, GLsizei size, GLvoid *data) {
2016-09-27 18:56:17 +00:00
glBufferData(T, size, data, usage);
2016-09-27 15:57:41 +00:00
}
TBufferObject(void, subfill)(GLintptr offset, GLsizei size,
const GLvoid *data) {
2016-09-27 18:56:17 +00:00
glBufferSubData(T, offset, size, data);
2016-09-27 15:57:41 +00:00
}
TBufferObject(void, map)(GLenum access) {
2016-09-27 18:56:17 +00:00
// todo
2016-09-27 15:57:41 +00:00
}
TBufferObject(void, unmap)() {
2016-09-27 18:56:17 +00:00
// todo
2016-09-27 15:57:41 +00:00
}