* fixed template magic
This commit is contained in:
parent
a4557a2762
commit
f77e1b779d
4 changed files with 76 additions and 46 deletions
|
@ -3,6 +3,8 @@
|
|||
#include <epoxy/gl.h>
|
||||
#include <epoxy/glx.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace endofthejedi {
|
||||
|
||||
template <GLenum T> class BufferObject {
|
||||
|
@ -37,10 +39,45 @@ class VAO {
|
|||
|
||||
class Shader {
|
||||
private:
|
||||
GLuint m_program;
|
||||
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
|
||||
}
|
||||
|
|
|
@ -5,10 +5,15 @@
|
|||
#include <epoxy/gl.h>
|
||||
#include <epoxy/glx.h>
|
||||
|
||||
#include <include/glclasses.h>
|
||||
|
||||
namespace endofthejedi {
|
||||
|
||||
class Renderer {
|
||||
private:
|
||||
VBO m_vbo;
|
||||
VAO m_vao;
|
||||
Shader m_shader;
|
||||
protected:
|
||||
public:
|
||||
Renderer();
|
||||
|
|
|
@ -1,53 +1,39 @@
|
|||
#include <include/glclasses.h>
|
||||
|
||||
#define TBufferObject_(pre, post) template <GLenum T> pre endofthejedi::BufferObject<T>::post
|
||||
#define TBufferObject(...) TBufferObject_(__VA_ARGS__)
|
||||
endofthejedi::VAO::VAO() { glGenVertexArrays(1, &m_name); }
|
||||
|
||||
TBufferObject(, BufferObject)() {
|
||||
glGenBuffers(1, &m_name);
|
||||
}
|
||||
endofthejedi::VAO::~VAO() { glDeleteVertexArrays(1, &m_name); }
|
||||
|
||||
TBufferObject(, ~BufferObject)() {
|
||||
glDeleteBuffers(1, m_name);
|
||||
}
|
||||
void endofthejedi::VAO::bind() { glBindVertexArray(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
|
||||
}
|
||||
|
||||
endofthejedi::VAO::VAO() {
|
||||
glGenVertexArrays(1, &m_name);
|
||||
}
|
||||
|
||||
endofthejedi::VAO::~VAO() {
|
||||
glDeleteVertexArrays(1, &m_name);
|
||||
}
|
||||
|
||||
void endofthejedi::VAO::bind() {
|
||||
glBindVertexArray(m_name);
|
||||
}
|
||||
|
||||
void endofthejedi::VAO::fill(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer) {
|
||||
void endofthejedi::VAO::fill(GLuint index, GLint size, GLenum type,
|
||||
GLboolean normalized, GLsizei stride,
|
||||
const GLvoid *pointer) {
|
||||
glEnableVertexAttribArray(index);
|
||||
glVertexAttribPointer(index, size, GL_FLOAT, normalized, stride, pointer);
|
||||
}
|
||||
|
||||
endofthejedi::Shader::Shader() {
|
||||
m_program = glCreateProgram();
|
||||
}
|
||||
|
||||
endofthejedi::Shader::~Shader() {}
|
||||
|
||||
void endofthejedi::Shader::bind() {
|
||||
glUseProgram(m_program);
|
||||
}
|
||||
|
||||
void endofthejedi::Shader::unbind() {
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void endofthejedi::Shader::load(std::string path, GLenum shadertype) {
|
||||
GLuint cheddar = glCreateShader(shadertype);
|
||||
const char* cheddardata = path.c_str();
|
||||
glShaderSource(cheddar, 1, &cheddardata, NULL);
|
||||
glCompileShader(cheddar);
|
||||
glAttachShader(m_program, cheddar);
|
||||
glLinkProgram(m_program);
|
||||
glDeleteShader(cheddar);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <include/renderer.h>
|
||||
|
||||
endofthejedi::Renderer::Renderer() {}
|
||||
endofthejedi::Renderer::Renderer() {
|
||||
|
||||
}
|
||||
|
||||
endofthejedi::Renderer::~Renderer() {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue