KlassischeKeplerKriege/game/glclasses.hpp

148 lines
3.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();
2016-09-29 02:24:14 +00:00
void unbind();
2016-09-27 18:56:17 +00:00
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 init(); // call to init when opengl context exists
2016-09-27 18:56:17 +00:00
void bind();
void unbind();
void load(const std::string &data, GLenum shadertype);
void loadFile(const std::string &data, GLenum shadertype);
GLuint location(const std::string &name);
2016-09-28 22:50:14 +00:00
GLuint program();
2016-09-27 18:56:17 +00:00
};
class Texture {
private:
GLuint m_name;
protected:
public:
Texture();
~Texture();
void bind();
void unbind();
void fill(GLenum target, GLint level, GLint internalFormat, GLsizei width,
GLsizei height, GLint border, GLenum format, GLenum type,
const GLvoid *data);
GLuint getName();
};
class Framebuffer {
private:
GLuint m_name;
protected:
public:
Framebuffer();
~Framebuffer();
void bind();
void unbind();
void attachRenderbuffer(GLenum attachment, GLuint rbo);
void attachTexture(GLenum attachment, GLuint tex);
};
class Renderbuffer {
private:
GLuint m_name;
protected:
public:
Renderbuffer();
~Renderbuffer();
void bind();
void unbind();
void create(GLenum internalformat, GLsizei width, GLsizei height);
};
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
}
void discardLastGlError(bool print = false);
// return false if there's an error
bool checkAndPrintGlError();
void printGlError(GLenum err);
const char *stringFromGlError(GLenum err);