aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/render/OpenGL.cpp
diff options
context:
space:
mode:
authorvaxerski <[email protected]>2023-08-06 20:33:36 +0200
committervaxerski <[email protected]>2023-08-06 20:33:36 +0200
commit6c10c384813890ed137f73ee79452cbe8c6f1dca (patch)
tree061cb212d594397c4c812fb1c479e0a2a1523fb2 /src/render/OpenGL.cpp
parenta077b7a92e87a3edd1cebb9bdd4c4fa3ec3d7bb7 (diff)
downloadHyprland-6c10c384813890ed137f73ee79452cbe8c6f1dca.tar.gz
Hyprland-6c10c384813890ed137f73ee79452cbe8c6f1dca.zip
renderer: fully switch to premultiplied alpha
Diffstat (limited to 'src/render/OpenGL.cpp')
-rw-r--r--src/render/OpenGL.cpp31
1 files changed, 10 insertions, 21 deletions
diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp
index 1040aa86..b56c876b 100644
--- a/src/render/OpenGL.cpp
+++ b/src/render/OpenGL.cpp
@@ -118,8 +118,6 @@ void CHyprOpenGLImpl::begin(CMonitor* pMonitor, CRegion* pDamage, bool fake) {
m_RenderData.pCurrentMonData = &m_mMonitorRenderResources[pMonitor];
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_iCurrentOutputFb);
m_iWLROutputFb = m_iCurrentOutputFb;
@@ -421,9 +419,10 @@ void CHyprOpenGLImpl::clear(const CColor& color) {
}
void CHyprOpenGLImpl::blend(bool enabled) {
- if (enabled)
+ if (enabled) {
glEnable(GL_BLEND);
- else
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // everything is premultiplied
+ } else
glDisable(GL_BLEND);
m_bBlend = enabled;
@@ -494,8 +493,6 @@ void CHyprOpenGLImpl::renderRectWithDamage(wlr_box* box, const CColor& col, CReg
float glMatrix[9];
wlr_matrix_multiply(glMatrix, m_RenderData.projection, matrix);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
glUseProgram(m_RenderData.pCurrentMonData->m_shQUAD.program);
#ifndef GLES2
@@ -504,7 +501,9 @@ void CHyprOpenGLImpl::renderRectWithDamage(wlr_box* box, const CColor& col, CReg
wlr_matrix_transpose(glMatrix, glMatrix);
glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shQUAD.proj, 1, GL_FALSE, glMatrix);
#endif
- glUniform4f(m_RenderData.pCurrentMonData->m_shQUAD.color, col.r, col.g, col.b, col.a);
+
+ // premultiply the color as well as we don't work with straight alpha
+ glUniform4f(m_RenderData.pCurrentMonData->m_shQUAD.color, col.r * col.a, col.g * col.a, col.b * col.a, col.a);
wlr_box transformedBox;
wlr_box_transform(&transformedBox, box, wlr_output_transform_invert(m_RenderData.pMonitor->transform), m_RenderData.pMonitor->vecTransformedSize.x,
@@ -543,8 +542,6 @@ void CHyprOpenGLImpl::renderRectWithDamage(wlr_box* box, const CColor& col, CReg
}
glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shQUAD.posAttrib);
-
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
void CHyprOpenGLImpl::renderTexture(wlr_texture* tex, wlr_box* pBox, float alpha, int round, bool allowCustomUV) {
@@ -588,9 +585,7 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, wlr_b
float glMatrix[9];
wlr_matrix_multiply(glMatrix, m_RenderData.projection, matrix);
- CShader* shader = nullptr;
-
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ CShader* shader = nullptr;
bool usingFinalShader = false;
@@ -955,9 +950,6 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, wlr_box* p
}
// finish
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-
glBindTexture(PMIRRORFB->m_cTex.m_iTarget, 0);
blend(BLENDBEFORE);
@@ -1227,8 +1219,8 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CGradientValueData& grad,
float glMatrix[9];
wlr_matrix_multiply(glMatrix, m_RenderData.projection, matrix);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ const auto BLEND = m_bBlend;
+ blend(true);
glUseProgram(m_RenderData.pCurrentMonData->m_shBORDER1.program);
@@ -1286,7 +1278,7 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CGradientValueData& grad,
glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.posAttrib);
glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.texAttrib);
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ blend(BLEND);
}
void CHyprOpenGLImpl::makeRawWindowSnapshot(CWindow* pWindow, CFramebuffer* pFramebuffer) {
@@ -1561,7 +1553,6 @@ void CHyprOpenGLImpl::renderRoundedShadow(wlr_box* box, int round, int range, fl
wlr_matrix_multiply(glMatrix, m_RenderData.projection, matrix);
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glUseProgram(m_RenderData.pCurrentMonData->m_shSHADOW.program);
@@ -1610,8 +1601,6 @@ void CHyprOpenGLImpl::renderRoundedShadow(wlr_box* box, int round, int range, fl
glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shSHADOW.posAttrib);
glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shSHADOW.texAttrib);
-
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
void CHyprOpenGLImpl::saveBufferForMirror() {