From c00d468f0fad1430b496e596826ec276b13fcef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 21 May 2013 10:33:02 +0200 Subject: [PATCH] GLSL 1.40 shader for CoverSwitch Reflection Shader moved to 1.10 subdirectory and a new version for 1.40 added. At the same time call to glPolygonMode removed as it caused errors with core context (and seems to not be needed). REVIEW: 110572 --- effects/coverswitch/CMakeLists.txt | 7 +++++-- effects/coverswitch/coverswitch.cpp | 11 +++++++---- .../{ => shaders/1.10}/coverswitch-reflection.glsl | 0 .../shaders/1.40/coverswitch-reflection.glsl | 12 ++++++++++++ 4 files changed, 24 insertions(+), 6 deletions(-) rename effects/coverswitch/{ => shaders/1.10}/coverswitch-reflection.glsl (100%) create mode 100644 effects/coverswitch/shaders/1.40/coverswitch-reflection.glsl diff --git a/effects/coverswitch/CMakeLists.txt b/effects/coverswitch/CMakeLists.txt index e4a0233779..15606d99db 100644 --- a/effects/coverswitch/CMakeLists.txt +++ b/effects/coverswitch/CMakeLists.txt @@ -14,8 +14,11 @@ install( FILES DESTINATION ${SERVICES_INSTALL_DIR}/kwin ) install( FILES - coverswitch/coverswitch-reflection.glsl - DESTINATION ${DATA_INSTALL_DIR}/kwin ) + coverswitch/shaders/1.10/coverswitch-reflection.glsl + DESTINATION ${DATA_INSTALL_DIR}/kwin/shaders/1.10 ) +install( FILES + coverswitch/shaders/1.40/coverswitch-reflection.glsl + DESTINATION ${DATA_INSTALL_DIR}/kwin/shaders/1.40 ) ####################################### diff --git a/effects/coverswitch/coverswitch.cpp b/effects/coverswitch/coverswitch.cpp index dc44973216..dcc6c80597 100644 --- a/effects/coverswitch/coverswitch.cpp +++ b/effects/coverswitch/coverswitch.cpp @@ -33,6 +33,7 @@ along with this program. If not, see . #include #include +#include #include @@ -66,7 +67,12 @@ CoverSwitchEffect::CoverSwitchEffect() captionFont.setBold(true); captionFont.setPointSize(captionFont.pointSize() * 2); - const QString fragmentshader = KGlobal::dirs()->findResource("data", "kwin/coverswitch-reflection.glsl"); + QString shadersDir = "kwin/shaders/1.10/"; +#ifndef KWIN_HAVE_OPENGLES + if (GLPlatform::instance()->glslVersion() >= kVersionNumber(1, 40)) + shadersDir = "kwin/shaders/1.40/"; +#endif + const QString fragmentshader = KGlobal::dirs()->findResource("data", shadersDir + "coverswitch-reflection.glsl"); m_reflectionShader = ShaderManager::instance()->loadFragmentShader(ShaderManager::GenericShader, fragmentshader); connect(effects, SIGNAL(windowClosed(KWin::EffectWindow*)), this, SLOT(slotWindowClosed(KWin::EffectWindow*))); connect(effects, SIGNAL(tabBoxAdded(int)), this, SLOT(slotTabBoxAdded(int))); @@ -264,9 +270,6 @@ void CoverSwitchEffect::paintScreen(int mask, QRegion region, ScreenPaintData& d paintScene(frontWindow, leftWindows, rightWindows, true); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -#ifndef KWIN_HAVE_OPENGLES - glPolygonMode(GL_FRONT, GL_FILL); -#endif // we can use a huge scale factor (needed to calculate the rearground vertices) // as we restrict with a PaintClipper painting on the current screen float reflectionScaleFactor = 100000 * tan(60.0 * M_PI / 360.0f) / area.width(); diff --git a/effects/coverswitch/coverswitch-reflection.glsl b/effects/coverswitch/shaders/1.10/coverswitch-reflection.glsl similarity index 100% rename from effects/coverswitch/coverswitch-reflection.glsl rename to effects/coverswitch/shaders/1.10/coverswitch-reflection.glsl diff --git a/effects/coverswitch/shaders/1.40/coverswitch-reflection.glsl b/effects/coverswitch/shaders/1.40/coverswitch-reflection.glsl new file mode 100644 index 0000000000..7b45a4fac8 --- /dev/null +++ b/effects/coverswitch/shaders/1.40/coverswitch-reflection.glsl @@ -0,0 +1,12 @@ +#version 140 +uniform vec4 u_frontColor; +uniform vec4 u_backColor; + +in vec2 varyingTexCoords; + +out vec4 fragColor; + +void main() +{ + fragColor = u_frontColor*(1.0-varyingTexCoords.s) + u_backColor*varyingTexCoords.s; +}