From 5c59f4261bded3f9f809376338d892b0d7ecbdf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 30 Nov 2015 11:51:02 +0100 Subject: [PATCH] [effects] Use shader traits API for reflection shader --- effects/cube/cube.cpp | 10 ++++++---- effects/cube/data/1.10/cube-reflection.glsl | 4 ++-- effects/cube/data/1.40/cube-reflection.glsl | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/effects/cube/cube.cpp b/effects/cube/cube.cpp index 1715c65e4c..4bf0e3d179 100644 --- a/effects/cube/cube.cpp +++ b/effects/cube/cube.cpp @@ -102,7 +102,10 @@ CubeEffect::CubeEffect() if (effects->compositingType() == OpenGL2Compositing) { const QString fragmentshader = QStandardPaths::locate(QStandardPaths::GenericDataLocation, m_shadersDir + QStringLiteral("cube-reflection.glsl")); - m_reflectionShader = ShaderManager::instance()->loadFragmentShader(ShaderManager::GenericShader, fragmentshader); + QFile ffr(fragmentshader); + if (ffr.open(QIODevice::ReadOnly)) { + m_reflectionShader = ShaderManager::instance()->generateCustomShader(ShaderTrait::MapTexture, QByteArray(), ffr.readAll()); + } const QString capshader = QStandardPaths::locate(QStandardPaths::GenericDataLocation, m_shadersDir + QStringLiteral("cube-cap.glsl")); QFile ff(capshader); if (ff.open(QIODevice::ReadOnly)) { @@ -295,7 +298,6 @@ void CubeEffect::slotWallPaperLoaded() void CubeEffect::slotResetShaders() { - ShaderManager::instance()->resetShader(m_reflectionShader, ShaderManager::GenericShader); ShaderManager::instance()->resetShader(cylinderShader, ShaderManager::GenericShader); ShaderManager::instance()->resetShader(sphereShader, ShaderManager::GenericShader); } @@ -486,9 +488,9 @@ void CubeEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data) if (m_reflectionShader && m_reflectionShader->isValid()) { // ensure blending is enabled - no attribute stack ShaderBinder binder(m_reflectionShader); - QMatrix4x4 windowTransformation; + QMatrix4x4 windowTransformation = data.projectionMatrix(); windowTransformation.translate(rect.x() + rect.width() * 0.5f, 0.0, 0.0); - m_reflectionShader->setUniform("windowTransformation", windowTransformation); + m_reflectionShader->setUniform(GLShader::ModelViewProjectionMatrix, windowTransformation); m_reflectionShader->setUniform("u_alpha", alpha); QVector verts; QVector texcoords; diff --git a/effects/cube/data/1.10/cube-reflection.glsl b/effects/cube/data/1.10/cube-reflection.glsl index 5d42db53a0..d9335a2ce9 100644 --- a/effects/cube/data/1.10/cube-reflection.glsl +++ b/effects/cube/data/1.10/cube-reflection.glsl @@ -1,8 +1,8 @@ uniform float u_alpha; -varying vec2 varyingTexCoords; +varying vec2 texcoord0; void main() { - gl_FragColor = vec4(0.0, 0.0, 0.0, u_alpha*varyingTexCoords.s); + gl_FragColor = vec4(0.0, 0.0, 0.0, u_alpha*texcoord0.s); } diff --git a/effects/cube/data/1.40/cube-reflection.glsl b/effects/cube/data/1.40/cube-reflection.glsl index f314483fa1..b70e98d923 100644 --- a/effects/cube/data/1.40/cube-reflection.glsl +++ b/effects/cube/data/1.40/cube-reflection.glsl @@ -1,11 +1,11 @@ #version 140 uniform float u_alpha; -in vec2 varyingTexCoords; +in vec2 texcoord0; out vec4 fragColor; void main() { - fragColor = vec4(0.0, 0.0, 0.0, u_alpha*varyingTexCoords.s); + fragColor = vec4(0.0, 0.0, 0.0, u_alpha*texcoord0.s); }