aboutsummaryrefslogtreecommitdiff
path: root/src/buffer
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer')
-rw-r--r--src/buffer/frame/texture_framebuffer.cc51
-rw-r--r--src/buffer/frame/texture_framebuffer.h54
-rw-r--r--src/buffer/vertex/particle_vertex_buffer.cc33
-rw-r--r--src/buffer/vertex/particle_vertex_buffer.h35
-rw-r--r--src/buffer/vertex/texture_display_vertex_buffer.cc46
-rw-r--r--src/buffer/vertex/texture_display_vertex_buffer.h48
6 files changed, 154 insertions, 113 deletions
diff --git a/src/buffer/frame/texture_framebuffer.cc b/src/buffer/frame/texture_framebuffer.cc
new file mode 100644
index 0000000..b585985
--- /dev/null
+++ b/src/buffer/frame/texture_framebuffer.cc
@@ -0,0 +1,51 @@
+#include "texture_framebuffer.h"
+
+TextureFramebuffer::Guard::Guard(GLuint id):
+ _id(id) {
+ glBindFramebuffer(GL_FRAMEBUFFER, _id);
+}
+
+TextureFramebuffer::Guard::~Guard() {
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+}
+
+TextureFramebuffer::Guard TextureFramebuffer::use() const {
+ return Guard(_id);
+}
+
+TextureFramebuffer::TextureFramebuffer(std::size_t width, std::size_t height) {
+ glGenFramebuffers(1, &_id);
+
+ auto guard = use();
+
+ glGenTextures(1, &_texture);
+ glBindTexture(GL_TEXTURE_2D, _texture);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, (void*)0);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture, 0);
+
+ if ( glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE ) {
+ _good = true;
+ }
+}
+
+TextureFramebuffer::~TextureFramebuffer() {
+ glDeleteFramebuffers(1, &_id);
+}
+
+bool TextureFramebuffer::isGood() const {
+ return _good;
+}
+
+void TextureFramebuffer::resize(std::size_t width, std::size_t height) const {
+ auto guard = use();
+
+ glViewport(0, 0, width, height);
+ glBindTexture(GL_TEXTURE_2D, _texture);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, (void*)0);
+}
+
+GLuint TextureFramebuffer::getTexture() const {
+ return _texture;
+}
diff --git a/src/buffer/frame/texture_framebuffer.h b/src/buffer/frame/texture_framebuffer.h
index 31153ff..f6b20e6 100644
--- a/src/buffer/frame/texture_framebuffer.h
+++ b/src/buffer/frame/texture_framebuffer.h
@@ -1,5 +1,9 @@
#pragma once
+#include <cstdint>
+
+#include <GL/glew.h>
+
class TextureFramebuffer {
private:
GLuint _id;
@@ -11,52 +15,18 @@ public:
struct Guard {
const GLuint _id;
- Guard(GLuint id): _id(id) {
- glBindFramebuffer(GL_FRAMEBUFFER, _id);
- }
- ~Guard() {
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
- }
+ Guard(GLuint id);
+ ~Guard();
};
- Guard use() const {
- return Guard(_id);
- }
-
- TextureFramebuffer(std::size_t width, std::size_t height) {
- glGenFramebuffers(1, &_id);
-
- auto guard = use();
-
- glGenTextures(1, &_texture);
- glBindTexture(GL_TEXTURE_2D, _texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, (void*)0);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture, 0);
-
- if ( glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE ) {
- _good = true;
- }
- }
-
- ~TextureFramebuffer() {
- glDeleteFramebuffers(1, &_id);
- }
+ Guard use() const;
- bool isGood() const {
- return _good;
- }
+ TextureFramebuffer(std::size_t width, std::size_t height);
+ ~TextureFramebuffer();
- void resize(std::size_t width, std::size_t height) const {
- auto guard = use();
+ bool isGood() const;
- glViewport(0, 0, width, height);
- glBindTexture(GL_TEXTURE_2D, _texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, (void*)0);
- }
+ void resize(std::size_t width, std::size_t height) const;
- GLuint getTexture() const {
- return _texture;
- }
+ GLuint getTexture() const;
};
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;
};