diff options
Separate headers into compilation units
Diffstat (limited to 'src/buffer/vertex/particle_vertex_buffer.cc')
-rw-r--r-- | src/buffer/vertex/particle_vertex_buffer.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/buffer/vertex/particle_vertex_buffer.cc b/src/buffer/vertex/particle_vertex_buffer.cc new file mode 100644 index 0000000..fc61cc5 --- /dev/null +++ b/src/buffer/vertex/particle_vertex_buffer.cc @@ -0,0 +1,33 @@ +#include "particle_vertex_buffer.h" + +ParticleVertexBuffer::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::~ParticleVertexBuffer() { + glDeleteBuffers(1, &_buffer); + glDeleteVertexArrays(1, &_array); +} + +GLuint ParticleVertexBuffer::getBuffer() const { + return _buffer; +} + +void ParticleVertexBuffer::draw() const { + glBindVertexArray(_array); + glDrawArrays(GL_POINTS, 0, 3*_data.size()); +} |