diff options
Diffstat (limited to 'src/buffer/vertex')
-rw-r--r-- | src/buffer/vertex/particle_vertex_buffer.cc | 33 | ||||
-rw-r--r-- | src/buffer/vertex/particle_vertex_buffer.h | 35 | ||||
-rw-r--r-- | src/buffer/vertex/texture_display_vertex_buffer.cc | 46 | ||||
-rw-r--r-- | src/buffer/vertex/texture_display_vertex_buffer.h | 48 |
4 files changed, 91 insertions, 71 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()); +} diff --git a/src/buffer/vertex/particle_vertex_buffer.h b/src/buffer/vertex/particle_vertex_buffer.h index 25855a2..8fb96a4 100644 --- a/src/buffer/vertex/particle_vertex_buffer.h +++ b/src/buffer/vertex/particle_vertex_buffer.h @@ -2,6 +2,8 @@ #include <vector> +#include <GL/glew.h> + class ParticleVertexBuffer { private: std::vector<GLfloat> _data; @@ -10,35 +12,10 @@ private: 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); - } + ParticleVertexBuffer(std::vector<GLfloat>&& data); + ~ParticleVertexBuffer(); - void draw() const { - glBindVertexArray(_array); - glDrawArrays(GL_POINTS, 0, 3*_data.size()); - } + GLuint getBuffer() const; - GLuint getBuffer() const { - return _buffer; - } + void draw() const; }; diff --git a/src/buffer/vertex/texture_display_vertex_buffer.cc b/src/buffer/vertex/texture_display_vertex_buffer.cc new file mode 100644 index 0000000..005ea76 --- /dev/null +++ b/src/buffer/vertex/texture_display_vertex_buffer.cc @@ -0,0 +1,46 @@ +#include "texture_display_vertex_buffer.h" + +TextureDisplayVertexBuffer::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::~TextureDisplayVertexBuffer() { + glDeleteBuffers(1, &_buffer); + glDeleteVertexArrays(1, &_array); +} + +GLuint TextureDisplayVertexBuffer::getBuffer() const { + return _buffer; +} + +void TextureDisplayVertexBuffer::draw(const std::vector<GLuint>& textures) const { + glBindVertexArray(_array); + glBindTextures(textures[0], textures.size(), textures.data()); + glDrawArrays(GL_TRIANGLES, 0, 6); +} diff --git a/src/buffer/vertex/texture_display_vertex_buffer.h b/src/buffer/vertex/texture_display_vertex_buffer.h index 6d4eec2..6febb1e 100644 --- a/src/buffer/vertex/texture_display_vertex_buffer.h +++ b/src/buffer/vertex/texture_display_vertex_buffer.h @@ -2,6 +2,8 @@ #include <vector> +#include <GL/glew.h> + class TextureDisplayVertexBuffer { private: const std::vector<GLfloat> _data; @@ -10,48 +12,10 @@ private: 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); - } + TextureDisplayVertexBuffer(); + ~TextureDisplayVertexBuffer(); - 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; - GLuint getBuffer() const { - return _buffer; - } + void draw(const std::vector<GLuint>& textures) const; }; |