summaryrefslogtreecommitdiff
path: root/src/render/gl/GLFramebuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/gl/GLFramebuffer.cpp')
-rw-r--r--src/render/gl/GLFramebuffer.cpp49
1 files changed, 28 insertions, 21 deletions
diff --git a/src/render/gl/GLFramebuffer.cpp b/src/render/gl/GLFramebuffer.cpp
index 27ad4a1b..0ad84e62 100644
--- a/src/render/gl/GLFramebuffer.cpp
+++ b/src/render/gl/GLFramebuffer.cpp
@@ -4,14 +4,14 @@
#include "macros.hpp"
#include "../Framebuffer.hpp"
+using namespace Render::GL;
+
CGLFramebuffer::CGLFramebuffer() : IFramebuffer() {}
CGLFramebuffer::CGLFramebuffer(const std::string& name) : IFramebuffer(name) {}
bool CGLFramebuffer::internalAlloc(int w, int h, uint32_t drmFormat) {
g_pHyprOpenGL->makeEGLCurrent();
- bool firstAlloc = false;
-
if (!m_tex) {
m_tex = g_pHyprRenderer->createTexture();
m_tex->allocate({w, h});
@@ -20,39 +20,44 @@ bool CGLFramebuffer::internalAlloc(int w, int h, uint32_t drmFormat) {
m_tex->setTexParameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
m_tex->setTexParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
m_tex->setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- firstAlloc = true;
}
if (!m_fbAllocated) {
glGenFramebuffers(1, &m_fb);
m_fbAllocated = true;
- firstAlloc = true;
}
- if (firstAlloc) {
- const auto format = NFormatUtils::getPixelFormatFromDRM(drmFormat);
- m_tex->bind();
+ const auto format = NFormatUtils::getPixelFormatFromDRM(drmFormat);
+ m_tex->bind();
+ glTexImage2D(GL_TEXTURE_2D, 0, format->glInternalFormat ? format->glInternalFormat : format->glFormat, w, h, 0, format->glFormat, format->glType, nullptr);
+ glBindFramebuffer(GL_FRAMEBUFFER, m_fb);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_tex->m_texID, 0);
+
+ if (m_mirrorTex) {
+ const auto format = NFormatUtils::getPixelFormatFromDRM(m_mirrorTex->m_drmFormat);
+ m_mirrorTex->bind();
glTexImage2D(GL_TEXTURE_2D, 0, format->glInternalFormat ? format->glInternalFormat : format->glFormat, w, h, 0, format->glFormat, format->glType, nullptr);
glBindFramebuffer(GL_FRAMEBUFFER, m_fb);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_tex->m_texID, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, m_mirrorTex->m_texID, 0);
+ } else
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
- if (m_stencilTex && m_stencilTex->ok()) {
- m_stencilTex->bind();
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_stencilTex->m_texID, 0);
+ if (m_stencilTex && m_stencilTex->ok()) {
+ m_stencilTex->bind();
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_stencilTex->m_texID, 0);
- glDisable(GL_DEPTH_TEST);
- glDepthMask(GL_FALSE);
- }
+ glDisable(GL_DEPTH_TEST);
+ glDepthMask(GL_FALSE);
+ }
- auto status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- RASSERT((status == GL_FRAMEBUFFER_COMPLETE), "Framebuffer incomplete, couldn't create! (FB status: {}, GL Error: 0x{:x})", status, sc<int>(glGetError()));
+ auto status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ RASSERT((status == GL_FRAMEBUFFER_COMPLETE), "Framebuffer incomplete, couldn't create! (FB status: {}, GL Error: 0x{:x})", status, sc<int>(glGetError()));
- if (m_stencilTex && m_stencilTex->ok())
- m_stencilTex->unbind();
+ if (m_stencilTex && m_stencilTex->ok())
+ m_stencilTex->unbind();
- Log::logger->log(Log::DEBUG, "Framebuffer created, status {}", status);
- }
+ Log::logger->log(Log::DEBUG, "Framebuffer \"{}\" created, status {}", m_name, status);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
@@ -86,6 +91,8 @@ void CGLFramebuffer::release() {
if (m_fbAllocated) {
glBindFramebuffer(GL_FRAMEBUFFER, m_fb);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
+ if (m_mirrorTex)
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteFramebuffers(1, &m_fb);