diff --git a/src/render/Framebuffer.cpp b/src/render/Framebuffer.cpp index 8ab03776..85e1f7ca 100644 --- a/src/render/Framebuffer.cpp +++ b/src/render/Framebuffer.cpp @@ -20,7 +20,7 @@ bool CFramebuffer::alloc(int w, int h) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } - if (firstAlloc) + if (firstAlloc || m_Size != Vector2D(w, h)) { glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index f46302ab..5f5818fb 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -108,10 +108,32 @@ void CHyprOpenGLImpl::begin(SMonitor* pMonitor) { glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_iCurrentOutputFb); + m_iWLROutputFb = m_iCurrentOutputFb; + + // ensure a framebuffer for the monitor exists + if (m_mMonitorFramebuffers.find(pMonitor) == m_mMonitorFramebuffers.end() || m_mMonitorFramebuffers[pMonitor].m_Size != pMonitor->vecSize) + m_mMonitorFramebuffers[pMonitor].alloc(pMonitor->vecSize.x, pMonitor->vecSize.y); + + // bind the Hypr Framebuffer + m_mMonitorFramebuffers[pMonitor].bind(); + clear(CColor(11, 11, 11, 255)); } void CHyprOpenGLImpl::end() { + // end the render, copy the data to the WLR framebuffer + glBindFramebuffer(GL_FRAMEBUFFER, m_iWLROutputFb); + const auto TRANSFORM = wlr_output_transform_invert(WL_OUTPUT_TRANSFORM_NORMAL); + float matrix[9]; + wlr_box windowBox = {0, 0, m_RenderData.pMonitor->vecSize.x, m_RenderData.pMonitor->vecSize.y}; + wlr_matrix_project_box(matrix, &windowBox, TRANSFORM, 0, m_RenderData.pMonitor->output->transform_matrix); + + clear(CColor(11, 11, 11, 255)); + + renderTexture(m_mMonitorFramebuffers[m_RenderData.pMonitor].m_cTex, matrix, 255.f, 0); + + // reset our data m_RenderData.pMonitor = nullptr; + m_iWLROutputFb = 0; } void CHyprOpenGLImpl::clear(const CColor& color) { diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index 7d938c15..7792a1fc 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -51,8 +51,10 @@ public: SCurrentRenderData m_RenderData; GLint m_iCurrentOutputFb = 0; + GLint m_iWLROutputFb = 0; std::unordered_map m_mWindowFramebuffers; + std::unordered_map m_mMonitorFramebuffers; private: std::list m_lBuffers;