diff options
author | Adrian Kummerlaender | 2018-05-21 14:35:43 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2018-05-21 14:35:43 +0200 |
commit | a8feed9d7951c9a947562ed687c704851a31ea9b (patch) | |
tree | 77fc9debb4e72ec9f72ba2cb992b164ae4e63b08 /src/particle_vertex_buffer.h | |
parent | ffa662ec5acdaae36f0ffeaf0cee78a4200d897b (diff) | |
download | computicle-a8feed9d7951c9a947562ed687c704851a31ea9b.tar computicle-a8feed9d7951c9a947562ed687c704851a31ea9b.tar.gz computicle-a8feed9d7951c9a947562ed687c704851a31ea9b.tar.bz2 computicle-a8feed9d7951c9a947562ed687c704851a31ea9b.tar.lz computicle-a8feed9d7951c9a947562ed687c704851a31ea9b.tar.xz computicle-a8feed9d7951c9a947562ed687c704851a31ea9b.tar.zst computicle-a8feed9d7951c9a947562ed687c704851a31ea9b.zip |
Fix VAO, VBO setup, compute shader coupling
Diffstat (limited to 'src/particle_vertex_buffer.h')
-rw-r--r-- | src/particle_vertex_buffer.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/particle_vertex_buffer.h b/src/particle_vertex_buffer.h new file mode 100644 index 0000000..58daf38 --- /dev/null +++ b/src/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, &_buffer); + } + + void draw() { + glBindVertexArray(_array); + glDrawArrays(GL_POINTS, 0, 3*_data.size()); + } + + GLuint getBuffer() const { + return _buffer; + } +}; |