summaryrefslogtreecommitdiff
path: root/src/render/Framebuffer.cpp
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-04-05 20:49:15 +0200
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-04-05 20:49:15 +0200
commita49bbf450881581e27696405ebaefef63f7bde7a (patch)
tree2c5cd3ecc24b9138f5f8f087350fe9e71a6b6e90 /src/render/Framebuffer.cpp
parentf8e0b0b448b8b68f65ee1c3eebdd4eb3e3382138 (diff)
fadeout done 🎉
Diffstat (limited to 'src/render/Framebuffer.cpp')
-rw-r--r--src/render/Framebuffer.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/render/Framebuffer.cpp b/src/render/Framebuffer.cpp
new file mode 100644
index 00000000..8ab03776
--- /dev/null
+++ b/src/render/Framebuffer.cpp
@@ -0,0 +1,62 @@
+#include "Framebuffer.hpp"
+#include "OpenGL.hpp"
+
+bool CFramebuffer::alloc(int w, int h) {
+ bool firstAlloc = false;
+ if (m_iFb == (uint32_t)-1)
+ {
+ firstAlloc = true;
+ glGenFramebuffers(1, &m_iFb);
+ }
+
+ if (m_cTex.m_iTexID == 0)
+ {
+ firstAlloc = true;
+ glGenTextures(1, &m_cTex.m_iTexID);
+ glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ }
+
+ if (firstAlloc)
+ {
+ glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+
+ glBindFramebuffer(GL_FRAMEBUFFER, m_iFb);
+ glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_cTex.m_iTexID, 0);
+
+ auto status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ RASSERT((status == GL_FRAMEBUFFER_COMPLETE), "Framebuffer incomplete, couldn't create! (FB status: %i)", status);
+
+ Debug::log(LOG, "Framebuffer created, status %i", status);
+ }
+
+ glBindTexture(GL_TEXTURE_2D, 0);
+ glBindFramebuffer(GL_FRAMEBUFFER, g_pHyprOpenGL->m_iCurrentOutputFb);
+
+ m_Size = Vector2D(w, h);
+
+ return true;
+}
+
+void CFramebuffer::bind() {
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_iFb);
+ glViewport(0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecSize.y);
+}
+
+void CFramebuffer::release() {
+ if (m_iFb != (uint32_t)-1 && m_iFb) {
+ glDeleteFramebuffers(1, &m_iFb);
+ }
+
+ if (m_cTex.m_iTexID) {
+ glDeleteTextures(1, &m_cTex.m_iTexID);
+ }
+
+ m_cTex.m_iTexID = 0;
+ m_iFb = -1;
+}