aboutsummaryrefslogtreecommitdiff
path: root/src/buffer/frame
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-05-26 13:20:47 +0200
committerAdrian Kummerlaender2018-05-26 13:21:40 +0200
commit34052b51e00c939a35294d7085cadb5111484dd3 (patch)
tree03a5b1e350e47e2aa8551393ef67b2124ad50ddb /src/buffer/frame
parentf728e4c8d202de241673a13ce61570b6acb4bba7 (diff)
downloadcomputicle-34052b51e00c939a35294d7085cadb5111484dd3.tar
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.gz
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.bz2
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.lz
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.xz
computicle-34052b51e00c939a35294d7085cadb5111484dd3.tar.zst
computicle-34052b51e00c939a35294d7085cadb5111484dd3.zip
Separate headers into compilation units
Diffstat (limited to 'src/buffer/frame')
-rw-r--r--src/buffer/frame/texture_framebuffer.cc51
-rw-r--r--src/buffer/frame/texture_framebuffer.h54
2 files changed, 63 insertions, 42 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;
};