Commit d467fc1b authored by Martin Flöser's avatar Martin Flöser

Adding new uniform to enforce that alpha becomes 1.0

When rendering opaque (RGB-only) windows the alpha ends up to be 0
with blending disabled. This breaks subsequent rendering steps which
require blenden (e.g. Lanczos). Therefore a uniform is used to ensure
that the alpha channel is set to 1.
parent 3bee002d
......@@ -1377,6 +1377,7 @@ void ShaderManager::resetShader(ShaderType type)
shader->setUniform("opacity", 1.0f);
shader->setUniform("brightness", 1.0f);
shader->setUniform("saturation", 1.0f);
shader->setUniform("u_forceAlpha", 0);
break;
}
case GenericShader: {
......@@ -1408,6 +1409,7 @@ void ShaderManager::resetShader(ShaderType type)
shader->setUniform("opacity", 1.0f);
shader->setUniform("brightness", 1.0f);
shader->setUniform("saturation", 1.0f);
shader->setUniform("u_forceAlpha", 0);
break;
}
case ColorShader: {
......
......@@ -346,6 +346,9 @@ class KWIN_EXPORT ShaderManager
* normalized texture coordinates. Defaults to @c (1.0/1.0). And expects a @c vec3
* uniform @c colorManiuplation, with @c x being opacity, @c y being brightness and
* @c z being saturation. All three values default to @c 1.0.
* The fragment shader takes a uniform @c u_forceAlpha to force the alpha component
* to @c 1.0 if it is set to a value not @c 0. This uniform is useful when rendering
* a RGB-only window and the alpha channel is required in a later step.
* The sampler uniform is @c sample and defaults to @c 0.
* The shader uses two vertex attributes @c vertex and @c texCoord.
**/
......
......@@ -5,6 +5,7 @@ uniform float opacity;
uniform float brightness;
uniform float saturation;
uniform int debug;
uniform int u_forceAlpha;
varying vec2 varyingTexCoords;
......@@ -25,6 +26,9 @@ void main() {
}
tex.rgb = tex.rgb * opacity * brightness;
tex.a = tex.a * opacity;
if (u_forceAlpha > 0) {
tex.a = 1.0;
}
/*if (debug != 0) {
tex.g += 0.5;
}*/
......
......@@ -836,6 +836,7 @@ void SceneOpenGL::Window::prepareShaderRenderStates( TextureType type, double op
shader->setUniform("opacity", (float)opacity);
shader->setUniform("saturation", (float)saturation);
shader->setUniform("brightness", (float)brightness);
shader->setUniform("u_forceAlpha", opaque ? 1 : 0);
// setting texture width and heiht stored in shader
// only set if it is set by an effect that is not negative
......@@ -1043,6 +1044,7 @@ void SceneOpenGL::Window::restoreShaderRenderStates( TextureType type, double op
{
glDisable( GL_BLEND );
}
ShaderManager::instance()->getBoundShader()->setUniform("u_forceAlpha", 0);
#ifndef KWIN_HAVE_OPENGLES
glPopAttrib(); // ENABLE_BIT
#endif
......@@ -1210,6 +1212,7 @@ void SceneOpenGL::EffectFrame::render( QRegion region, double opacity, double fr
shader->setUniform("offset", QVector2D(0, 0));
shader->setUniform("saturation", 1.0f);
shader->setUniform("brightness", 1.0f);
shader->setUniform("u_forceAlpha", 0);
shader->setUniform("textureWidth", 1.0f);
shader->setUniform("textureHeight", 1.0f);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment