From 7a6e48ef3b73e89ffb929c075c33ae9e688d83c9 Mon Sep 17 00:00:00 2001 From: Casian Andrei Date: Sat, 5 Jan 2013 05:39:02 +0200 Subject: [PATCH] Fix premultiplied alpha issue with color correction When correcting a color that was with premultiplied alpha, the alpha value was not multiplied back again as a final step. This was breaking color correction when the blend function was GL_ONE, GL_ONE_MINUS_SRC_ALPHA. The blend function was changed for normal windows (a workaround), but not for effect frames, i.e. the effect frames were broken with color correction enabled. Removes the blend function workaround. Removes a useless setupForOutput. BUG: 311319 REVIEW: 108189 --- libkwineffects/kwinglcolorcorrection.cpp | 2 +- scene_opengl.cpp | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/libkwineffects/kwinglcolorcorrection.cpp b/libkwineffects/kwinglcolorcorrection.cpp index 4b43de5ae0..0f46189e0c 100644 --- a/libkwineffects/kwinglcolorcorrection.cpp +++ b/libkwineffects/kwinglcolorcorrection.cpp @@ -235,7 +235,7 @@ void ColorServerInterface::callFinishedSlot(QDBusPendingCallWatcher *watcher) static const char s_ccVars[] = "uniform sampler3D u_ccLookupTexture;\n"; static const char s_ccAlteration[] = - "gl_FragColor.rgb = texture3D(u_ccLookupTexture, gl_FragColor.rgb / gl_FragColor.a).rgb;\n"; + "gl_FragColor.rgb = texture3D(u_ccLookupTexture, gl_FragColor.rgb / gl_FragColor.a).rgb * gl_FragColor.a;\n"; /* diff --git a/scene_opengl.cpp b/scene_opengl.cpp index d463631672..b73e606817 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -1240,8 +1240,6 @@ void SceneOpenGL2Window::beginRenderWindow(int mask, const WindowPaintData &data } shader->setUniform(GLShader::WindowTransformation, transformation(mask, data)); - - static_cast(m_scene)->colorCorrection()->setupForOutput(data.screen()); } void SceneOpenGL2Window::endRenderWindow(const WindowPaintData &data) @@ -1270,15 +1268,11 @@ void SceneOpenGL2Window::prepareStates(TextureType type, qreal opacity, qreal br } if (!opaque) { glEnable(GL_BLEND); - if (static_cast(m_scene)->colorCorrection()->isEnabled()) { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (alpha) { + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); } else { - if (alpha) { - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - } else { - glBlendColor((float)opacity, (float)opacity, (float)opacity, (float)opacity); - glBlendFunc(GL_ONE, GL_ONE_MINUS_CONSTANT_ALPHA); - } + glBlendColor((float)opacity, (float)opacity, (float)opacity, (float)opacity); + glBlendFunc(GL_ONE, GL_ONE_MINUS_CONSTANT_ALPHA); } } m_blendingEnabled = !opaque;