aboutsummaryrefslogtreecommitdiff
path: root/src/buffer/vertex/particle_vertex_buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer/vertex/particle_vertex_buffer.h')
-rw-r--r--src/buffer/vertex/particle_vertex_buffer.h44
1 files changed, 44 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;
+ }
+};