diff options
author | vaxerski <[email protected]> | 2023-08-28 18:29:41 +0200 |
---|---|---|
committer | vaxerski <[email protected]> | 2023-08-28 18:29:44 +0200 |
commit | df691859fbe0b1acee9fa5c97440b5953b8edb32 (patch) | |
tree | 71a37287f4ba1e67de91cbc54995a42a2245cdfd /src/render/OpenGL.cpp | |
parent | aed1f66becbaa3002cc1ecbdad6c1ac0f3d59ea6 (diff) | |
download | Hyprland-df691859fbe0b1acee9fa5c97440b5953b8edb32.tar.gz Hyprland-df691859fbe0b1acee9fa5c97440b5953b8edb32.zip |
renderer: make contrast and brightness adjustments before rendering
Diffstat (limited to 'src/render/OpenGL.cpp')
-rw-r--r-- | src/render/OpenGL.cpp | 60 |
1 files changed, 51 insertions, 9 deletions
diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 11c92525..ba2e490b 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -867,7 +867,53 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, CRegion* o const auto PMIRRORFB = &m_RenderData.pCurrentMonData->mirrorFB; const auto PMIRRORSWAPFB = &m_RenderData.pCurrentMonData->mirrorSwapFB; - CFramebuffer* currentRenderToFB = &m_RenderData.pCurrentMonData->primaryFB; + CFramebuffer* currentRenderToFB = PMIRRORFB; + + // begin with color adjustments + // TODO: make this a part of the first pass maybe to save on a drawcall? + { + static auto* const PBLURCONTRAST = &g_pConfigManager->getConfigValuePtr("decoration:blur:contrast")->floatValue; + static auto* const PBLURBRIGHTNESS = &g_pConfigManager->getConfigValuePtr("decoration:blur:brightness")->floatValue; + + PMIRRORSWAPFB->bind(); + + glActiveTexture(GL_TEXTURE0); + + glBindTexture(m_RenderData.pCurrentMonData->primaryFB.m_cTex.m_iTarget, m_RenderData.pCurrentMonData->primaryFB.m_cTex.m_iTexID); + + glTexParameteri(m_RenderData.pCurrentMonData->primaryFB.m_cTex.m_iTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glUseProgram(m_RenderData.pCurrentMonData->m_shBLURFINISH.program); + +#ifndef GLES2 + glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shBLURFINISH.proj, 1, GL_TRUE, glMatrix); +#else + wlr_matrix_transpose(glMatrix, glMatrix); + glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shBLURFINISH.proj, 1, GL_FALSE, glMatrix); +#endif + glUniform1f(m_RenderData.pCurrentMonData->m_shBLURFINISH.contrast, *PBLURCONTRAST); + glUniform1f(m_RenderData.pCurrentMonData->m_shBLURFINISH.brightness, *PBLURBRIGHTNESS); + + glUniform1i(m_RenderData.pCurrentMonData->m_shBLURFINISH.tex, 0); + + glVertexAttribPointer(m_RenderData.pCurrentMonData->m_shBLURFINISH.posAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts); + glVertexAttribPointer(m_RenderData.pCurrentMonData->m_shBLURFINISH.texAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts); + + glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBLURFINISH.posAttrib); + glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBLURFINISH.texAttrib); + + if (!damage.empty()) { + for (auto& RECT : damage.getRects()) { + scissor(&RECT, false /* this region is already transformed */); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } + } + + glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBLURFINISH.posAttrib); + glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBLURFINISH.texAttrib); + + currentRenderToFB = PMIRRORSWAPFB; + } // declare the draw func auto drawPass = [&](CShader* pShader, CRegion* pDamage) { @@ -923,9 +969,9 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, CRegion* o }; // draw the things. - // first draw is prim -> mirr + // first draw is swap -> mirr PMIRRORFB->bind(); - glBindTexture(m_RenderData.pCurrentMonData->primaryFB.m_cTex.m_iTarget, m_RenderData.pCurrentMonData->primaryFB.m_cTex.m_iTexID); + glBindTexture(PMIRRORSWAPFB->m_cTex.m_iTarget, PMIRRORSWAPFB->m_cTex.m_iTexID); // damage region will be scaled, make a temp CRegion tempDamage{damage}; @@ -944,11 +990,9 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, CRegion* o drawPass(&m_RenderData.pCurrentMonData->m_shBLUR2, &tempDamage); // up } - // finalize with effects + // finalize with noise { - static auto* const PBLURCONTRAST = &g_pConfigManager->getConfigValuePtr("decoration:blur:contrast")->floatValue; - static auto* const PBLURNOISE = &g_pConfigManager->getConfigValuePtr("decoration:blur:noise")->floatValue; - static auto* const PBLURBRIGHTNESS = &g_pConfigManager->getConfigValuePtr("decoration:blur:brightness")->floatValue; + static auto* const PBLURNOISE = &g_pConfigManager->getConfigValuePtr("decoration:blur:noise")->floatValue; if (currentRenderToFB == PMIRRORFB) PMIRRORSWAPFB->bind(); @@ -969,9 +1013,7 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, CRegion* o wlr_matrix_transpose(glMatrix, glMatrix); glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shBLURFINISH.proj, 1, GL_FALSE, glMatrix); #endif - glUniform1f(m_RenderData.pCurrentMonData->m_shBLURFINISH.contrast, *PBLURCONTRAST); glUniform1f(m_RenderData.pCurrentMonData->m_shBLURFINISH.noise, *PBLURNOISE); - glUniform1f(m_RenderData.pCurrentMonData->m_shBLURFINISH.brightness, *PBLURBRIGHTNESS); glUniform1i(m_RenderData.pCurrentMonData->m_shBLURFINISH.tex, 0); |