From c6e73ad94d9200efd569d092d5ceac3fc73bc2e2 Mon Sep 17 00:00:00 2001 From: Matias Date: Mon, 14 Jul 2025 11:21:25 +0200 Subject: [PATCH] feat: render window texture entirely via OpenGL calls --- src/main.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5114374..1a42e63 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,8 +30,10 @@ class CBindOwnFramebufferPassElement final: public IPassElement { void draw(const CRegion& damage) override { m_pFramebuffer->bind(); - g_pHyprOpenGL->clear(CHyprColor(0, 0, 0, 0)); g_pHyprOpenGL->m_renderData.currentFB = m_pFramebuffer; + + // TODO: this is not working + g_pHyprOpenGL->clear(CHyprColor(0, 0, 0, 0)); } bool needsLiveBlur() override { @@ -62,20 +64,57 @@ class CRenderWobblyWindowPassElement final: public IPassElement { void draw(const CRegion& damage) override { auto* const pWindowFB = g_pHyprOpenGL->m_renderData.currentFB; - pWindowFB->getTexture()->bind(); m_pOldFramebuffer->bind(); g_pHyprOpenGL->m_renderData.currentFB = m_pOldFramebuffer; const auto windowBox = m_pWindow->getFullWindowBoundingBox(); - g_pHyprOpenGL->m_renderData.primarySurfaceUVTopLeft = - Vector2D {windowBox.x, windowBox.y} / pWindowFB->m_size; - g_pHyprOpenGL->m_renderData.primarySurfaceUVBottomRight = + CBox newBox = windowBox; + g_pHyprOpenGL->m_renderData.renderModif.applyToBox(newBox); + + // get transform + const auto TRANSFORM = + wlTransformToHyprutils(invertTransform(g_pHyprOpenGL->m_renderData.pMonitor->m_transform + )); + + Mat3x3 matrix = + g_pHyprOpenGL->m_renderData.monitorProjection.projectBox(newBox, TRANSFORM, newBox.rot); + Mat3x3 glMatrix = g_pHyprOpenGL->m_renderData.projection.copy().multiply(matrix); + + SShader* shader = &g_pHyprOpenGL->m_shaders->m_shRGBA; + + glActiveTexture(GL_TEXTURE0); + pWindowFB->getTexture()->bind(); + + g_pHyprOpenGL->useProgram(shader->program); + shader->setUniformMatrix3fv(SHADER_PROJ, 1, GL_TRUE, glMatrix.getMatrix()); + shader->setUniformInt(SHADER_TEX, 0); + glBindVertexArray(shader->uniformLocations[SHADER_SHADER_VAO]); + + const Vector2D UVTopLeft = Vector2D {windowBox.x, windowBox.y} / pWindowFB->m_size; + const Vector2D UVBottomRight = Vector2D {windowBox.x + windowBox.width, windowBox.y + windowBox.height} / pWindowFB->m_size; - g_pHyprOpenGL->renderTexture(pWindowFB->getTexture(), windowBox, 1.0f, 0, 0.f, false, true); + const float UVs[] = { + (float)UVBottomRight.x, + (float)UVTopLeft.y, + (float)UVTopLeft.x, + (float)UVTopLeft.y, + (float)UVBottomRight.x, + (float)UVBottomRight.y, + (float)UVTopLeft.x, + (float)UVBottomRight.y, + }; + + glBindBuffer(GL_ARRAY_BUFFER, shader->uniformLocations[SHADER_SHADER_VBO_UV]); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(UVs), UVs); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + glBindVertexArray(0); + pWindowFB->getTexture()->unbind(); } bool needsLiveBlur() override {