aboutsummaryrefslogtreecommitdiff
path: root/src/buffer/frame
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-05-25 23:47:27 +0200
committerAdrian Kummerlaender2018-05-25 23:48:59 +0200
commitf728e4c8d202de241673a13ce61570b6acb4bba7 (patch)
treea7e29c4319f0e6d667b98f359ddf089c0565c15a /src/buffer/frame
parent5157658ec0cc07d2c56c978ca010cbb78236439f (diff)
downloadcomputicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.gz
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.bz2
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.lz
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.xz
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.tar.zst
computicle-f728e4c8d202de241673a13ce61570b6acb4bba7.zip
Restructure source directory
Diffstat (limited to 'src/buffer/frame')
-rw-r--r--src/buffer/frame/texture_framebuffer.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/buffer/frame/texture_framebuffer.h b/src/buffer/frame/texture_framebuffer.h
new file mode 100644
index 0000000..31153ff
--- /dev/null
+++ b/src/buffer/frame/texture_framebuffer.h
@@ -0,0 +1,62 @@
+#pragma once
+
+class TextureFramebuffer {
+private:
+ GLuint _id;
+ GLuint _texture;
+
+ bool _good = false;
+
+public:
+ struct Guard {
+ const GLuint _id;
+
+ Guard(GLuint id): _id(id) {
+ glBindFramebuffer(GL_FRAMEBUFFER, _id);
+ }
+ ~Guard() {
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ }
+ };
+
+ 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);
+ }
+
+ bool isGood() const {
+ return _good;
+ }
+
+ void 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 getTexture() const {
+ return _texture;
+ }
+};