feat: render window texture entirely via OpenGL calls

This commit is contained in:
Matias 2025-07-14 11:21:25 +02:00
parent 3cb4b0aa3f
commit c6e73ad94d
No known key found for this signature in database
GPG Key ID: ED35A6AC65A06B69

View File

@ -30,8 +30,10 @@ class CBindOwnFramebufferPassElement final: public IPassElement {
void draw(const CRegion& damage) override { void draw(const CRegion& damage) override {
m_pFramebuffer->bind(); m_pFramebuffer->bind();
g_pHyprOpenGL->clear(CHyprColor(0, 0, 0, 0));
g_pHyprOpenGL->m_renderData.currentFB = m_pFramebuffer; g_pHyprOpenGL->m_renderData.currentFB = m_pFramebuffer;
// TODO: this is not working
g_pHyprOpenGL->clear(CHyprColor(0, 0, 0, 0));
} }
bool needsLiveBlur() override { bool needsLiveBlur() override {
@ -62,20 +64,57 @@ class CRenderWobblyWindowPassElement final: public IPassElement {
void draw(const CRegion& damage) override { void draw(const CRegion& damage) override {
auto* const pWindowFB = g_pHyprOpenGL->m_renderData.currentFB; auto* const pWindowFB = g_pHyprOpenGL->m_renderData.currentFB;
pWindowFB->getTexture()->bind();
m_pOldFramebuffer->bind(); m_pOldFramebuffer->bind();
g_pHyprOpenGL->m_renderData.currentFB = m_pOldFramebuffer; g_pHyprOpenGL->m_renderData.currentFB = m_pOldFramebuffer;
const auto windowBox = m_pWindow->getFullWindowBoundingBox(); const auto windowBox = m_pWindow->getFullWindowBoundingBox();
g_pHyprOpenGL->m_renderData.primarySurfaceUVTopLeft = CBox newBox = windowBox;
Vector2D {windowBox.x, windowBox.y} / pWindowFB->m_size; g_pHyprOpenGL->m_renderData.renderModif.applyToBox(newBox);
g_pHyprOpenGL->m_renderData.primarySurfaceUVBottomRight =
// 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} Vector2D {windowBox.x + windowBox.width, windowBox.y + windowBox.height}
/ pWindowFB->m_size; / 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 { bool needsLiveBlur() override {