diff --git a/libkwineffects/kwinglcolorcorrection.cpp b/libkwineffects/kwinglcolorcorrection.cpp index c0dcabd911..e0ea2dd84b 100644 --- a/libkwineffects/kwinglcolorcorrection.cpp +++ b/libkwineffects/kwinglcolorcorrection.cpp @@ -214,7 +214,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 / min(gl_FragColor.a, 1.0)).rgb;\n"; /* @@ -298,9 +298,6 @@ void ColorCorrection::setupForOutput(int screen) { Q_D(ColorCorrection); - if (!d->m_enabled) - return; - GLShader *shader = ShaderManager::instance()->getBoundShader(); if (!shader) { kError(1212) << "no bound shader for color correction setup"; @@ -308,6 +305,9 @@ void ColorCorrection::setupForOutput(int screen) } if (!shader->setUniform("u_ccLookupTexture", d->m_ccTextureUnit)) { + // This means the color correction shaders are probably not loaded + if (!d->m_enabled) + return; kError(1212) << "unable to set uniform for the color correction lookup texture"; } @@ -318,7 +318,7 @@ void ColorCorrection::setupForOutput(int screen) glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTexture); glActiveTexture(GL_TEXTURE0 + d->m_ccTextureUnit); - if (screen < 0 || screen >= d->m_outputCCTextures.count()) { + if (d->m_outputCCTextures.isEmpty() || screen < 0 || screen >= d->m_outputCCTextures.count()) { // Configure with a dummy texture in case something is wrong Q_ASSERT(d->m_dummyCCTexture != 0); glBindTexture(GL_TEXTURE_3D, d->m_dummyCCTexture); @@ -332,6 +332,8 @@ void ColorCorrection::setupForOutput(int screen) Q_UNUSED(screen); #endif // KWIN_HAVE_OPENGLES + checkGLError("setupForOutput"); + d->m_lastOutput = screen; } @@ -542,6 +544,7 @@ void ColorCorrectionPrivate::setupCCTextures() } // TODO Handle errors (what if a texture isn't generated?) + checkGLError("setupCCTextures"); } void ColorCorrectionPrivate::deleteCCTextures() @@ -557,6 +560,8 @@ void ColorCorrectionPrivate::deleteCCTextures() glDeleteTextures(m_outputCCTextures.size(), m_outputCCTextures.data()); m_outputCCTextures.clear(); } + + checkGLError("deleteCCTextures"); } void ColorCorrectionPrivate::setupCCTexture(GLuint texture, const Clut& clut) diff --git a/scene_opengl.cpp b/scene_opengl.cpp index 8f63d6867c..48537cfd05 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -131,9 +131,25 @@ ColorCorrection* SceneOpenGL::colorCorrection() void SceneOpenGL::initColorCorrection() { kDebug(1212) << "Color correction:" << options->isColorCorrected(); + m_colorCorrection = new ColorCorrection(this); m_colorCorrection->setEnabled(options->isColorCorrected()); connect(m_colorCorrection, SIGNAL(changed()), Compositor::self(), SLOT(addRepaintFull())); - connect(options, SIGNAL(colorCorrectedChanged()), Compositor::self(), SLOT(slotReinitialize())); + connect(options, SIGNAL(colorCorrectedChanged()), this, SLOT(slotColorCorrectedChanged())); +} + +void SceneOpenGL::slotColorCorrectedChanged() +{ + m_colorCorrection->setEnabled(options->isColorCorrected()); + + // Reload all shaders + ShaderManager::cleanup(); + ShaderManager::instance(); +} + +void SceneOpenGL::uninitColorCorrection() +{ + kDebug(1212); + disconnect(options, SIGNAL(colorCorrectedChanged()), Compositor::self(), SLOT(slotReinitialize())); } bool SceneOpenGL::selectMode() @@ -881,15 +897,15 @@ void SceneOpenGL::Window::prepareShaderRenderStates(TextureType type, double opa opaque = false; if (!opaque) { glEnable(GL_BLEND); - if (!options->isColorCorrected()) { +// if (!options->isColorCorrected()) { if (alpha) { - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } else { glBlendColor((float)opacity, (float)opacity, (float)opacity, (float)opacity); - glBlendFunc(GL_ONE, GL_ONE_MINUS_CONSTANT_ALPHA); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA); } - } else - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +// } else +// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } const float rgb = brightness * opacity; diff --git a/scene_opengl.h b/scene_opengl.h index b3fce2c219..13bf2a5f68 100644 --- a/scene_opengl.h +++ b/scene_opengl.h @@ -68,6 +68,8 @@ public Q_SLOTS: virtual void windowOpacityChanged(KWin::Toplevel* c); virtual void windowGeometryShapeChanged(KWin::Toplevel* c); virtual void windowClosed(KWin::Toplevel* c, KWin::Deleted* deleted); +private Q_SLOTS: + void slotColorCorrectedChanged(); private: bool selectMode(); bool initTfp(); @@ -76,6 +78,7 @@ private: bool initBufferConfigs(); bool initDrawableConfigs(); void initColorCorrection(); + void uninitColorCorrection(); void waitSync(); #ifndef KWIN_HAVE_OPENGLES void setupModelViewProjectionMatrix(); diff --git a/scene_opengl_egl.cpp b/scene_opengl_egl.cpp index d11c59cd62..c82a76189f 100644 --- a/scene_opengl_egl.cpp +++ b/scene_opengl_egl.cpp @@ -31,7 +31,7 @@ int surfaceHasSubPost; SceneOpenGL::SceneOpenGL(Workspace* ws) : Scene(ws) , init_ok(false) - , m_colorCorrection(new ColorCorrection(this)) + , m_colorCorrection(NULL) { if (!initRenderingContext()) return; @@ -97,6 +97,7 @@ SceneOpenGL::~SceneOpenGL() eglTerminate(dpy); eglReleaseThread(); SceneOpenGL::EffectFrame::cleanup(); + uninitColorCorrection(); checkGLError("Cleanup"); if (m_overlayWindow->window()) { m_overlayWindow->destroy(); diff --git a/scene_opengl_glx.cpp b/scene_opengl_glx.cpp index 9f2ef0794b..36747cc44e 100644 --- a/scene_opengl_glx.cpp +++ b/scene_opengl_glx.cpp @@ -39,7 +39,7 @@ SceneOpenGL::SceneOpenGL(Workspace* ws) : Scene(ws) , m_resetModelViewProjectionMatrix(true) , init_ok(false) - , m_colorCorrection(new ColorCorrection(this)) + , m_colorCorrection(NULL) { initGLX(); // check for FBConfig support @@ -155,6 +155,7 @@ SceneOpenGL::~SceneOpenGL() XFreePixmap(display(), buffer); } SceneOpenGL::EffectFrame::cleanup(); + uninitColorCorrection(); checkGLError("Cleanup"); }