aboutsummaryrefslogtreecommitdiff
path: root/src/buffer/vertex
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-05-25 23:47:27 +0200
committerAdrian Kummerlaender2018-05-25 23:48:59 +0200
commitf728e4c8d202de241673a13ce61570b6acb4bba7 (patch)
treea7e29c4319f0e6d667b98f359ddf089c0565c15a /src/buffer/vertex
parent5157658ec0cc07d2c56c978ca010cbb78236439f (diff)
downloadcomputicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.gz
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.bz2
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.lz
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.xz
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.zst
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.zip
Restructure source directory
Diffstat (limited to 'src/buffer/vertex')
-rw-r--r--src/buffer/vertex/particle_vertex_buffer.h44
-rw-r--r--src/buffer/vertex/texture_display_vertex_buffer.h57
2 files changed, 101 insertions, 0 deletions
diff --git a/src/buffer/vertex/particle_vertex_buffer.h b/src/buffer/vertex/particle_vertex_buffer.h
new file mode 100644
index 0000000..25855a2
--- /dev/null
+++ b/src/buffer/vertex/particle_vertex_buffer.h
@@ -0,0 +1,44 @@
+#pragma once
+
+#include <vector>
+
+class ParticleVertexBuffer {
+private:
+ std::vector<GLfloat> _data;
+
+ GLuint _array;
+ GLuint _buffer;
+
+public:
+ ParticleVertexBuffer(std::vector<GLfloat>&& data):
+ _data{ std::move(data) } {
+ glGenVertexArrays(1, &_array);
+ glGenBuffers(1, &_buffer);
+
+ glBindVertexArray(_array);
+ glBindBuffer(GL_ARRAY_BUFFER, _buffer);
+ glBufferData(
+ GL_ARRAY_BUFFER,
+ _data.size() * sizeof(GLfloat),
+ _data.data(),
+ GL_STATIC_DRAW
+ );
+
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
+ }
+
+ ~ParticleVertexBuffer() {
+ glDeleteBuffers(1, &_buffer);
+ glDeleteVertexArrays(1, &_array);
+ }
+
+ void draw() const {
+ glBindVertexArray(_array);
+ glDrawArrays(GL_POINTS, 0, 3*_data.size());
+ }
+
+ GLuint getBuffer() const {
+ return _buffer;
+ }
+};
diff --git a/src/buffer/vertex/texture_display_vertex_buffer.h b/src/buffer/vertex/texture_display_vertex_buffer.h
new file mode 100644
index 0000000..6d4eec2
--- /dev/null
+++ b/src/buffer/vertex/texture_display_vertex_buffer.h
@@ -0,0 +1,57 @@
+#pragma once
+
+#include <vector>
+
+class TextureDisplayVertexBuffer {
+private:
+ const std::vector<GLfloat> _data;
+
+ GLuint _array;
+ GLuint _buffer;
+
+public:
+ TextureDisplayVertexBuffer():
+ _data{
+ -1.f, 1.f, 0.f, 1.f,
+ -1.f, -1.f, 0.f, 0.f,
+ 1.f, -1.f, 1.f, 0.f,
+
+ -1.f, 1.f, 0.f, 1.f,
+ 1.f, -1.f, 1.f, 0.f,
+ 1.f, 1.f, 1.f, 1.f
+ } {
+ glGenVertexArrays(1, &_array);
+ glGenBuffers(1, &_buffer);
+
+ glBindVertexArray(_array);
+ glBindBuffer(GL_ARRAY_BUFFER, _buffer);
+ glBufferData(
+ GL_ARRAY_BUFFER,
+ _data.size() * sizeof(GLfloat),
+ _data.data(),
+ GL_STATIC_DRAW
+ );
+
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(
+ 0, 2, GL_FLOAT, GL_FALSE, 4*sizeof(GLfloat), (void*)0);
+ glEnableVertexAttribArray(1);
+ glVertexAttribPointer(
+ 1, 2, GL_FLOAT, GL_FALSE, 4*sizeof(GLfloat), (void*)(2*sizeof(GLfloat)));
+ }
+
+ ~TextureDisplayVertexBuffer() {
+ glDeleteBuffers(1, &_buffer);
+ glDeleteVertexArrays(1, &_array);
+ }
+
+ void draw(const std::vector<GLuint>& textures) const {
+ glBindVertexArray(_array);
+ glBindTextures(textures[0], textures.size(), textures.data());
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+ }
+
+ GLuint getBuffer() const {
+ return _buffer;
+ }
+};