Changed the OpenGL part and the GLSL shaders to use UBO and
[demo] / src / opengl / uniforms-gl.cc
diff --git a/src/opengl/uniforms-gl.cc b/src/opengl/uniforms-gl.cc
new file mode 100644 (file)
index 0000000..c4d82d2
--- /dev/null
@@ -0,0 +1,39 @@
+#include <GL/glew.h>
+
+#include "uniforms-gl.h"
+
+UniformBufferGL::UniformBufferGL()
+{
+       ubo = 0;
+}
+
+UniformBufferGL::~UniformBufferGL()
+{
+       destroy();
+}
+
+bool UniformBufferGL::create(int size)
+{
+       glGenBuffers(1, &ubo);
+       glBindBuffer(GL_UNIFORM_BUFFER, ubo);
+       glBufferData(GL_UNIFORM_BUFFER, size, 0, GL_STREAM_DRAW);
+
+       return UniformBuffer::create(size);
+}
+
+void UniformBufferGL::destroy()
+{
+       glDeleteBuffers(1, &ubo);
+}
+
+void UniformBufferGL::bind(int binding) const
+{
+       //glBindBuffer(GL_UNIFORM_BUFFER, ubo);
+       glBindBufferBase(GL_UNIFORM_BUFFER, binding, ubo);
+}
+
+void UniformBufferGL::update(void *data)
+{
+       glBindBuffer(GL_UNIFORM_BUFFER, ubo);
+       glBufferSubData(GL_UNIFORM_BUFFER, 0, size, data);
+}