From f13622a9144d4ed478b6431f9519be36aba48432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 27 Nov 2015 16:50:21 +0100 Subject: [PATCH] [effects] Use shader traits generated shader for invert effect Source code needs minor adjustment to be compatible with the shader traits variable naming. --- effects/invert/data/1.10/invert.frag | 4 ++-- effects/invert/data/1.40/invert.frag | 4 ++-- effects/invert/invert.cpp | 21 ++++++++------------- effects/invert/invert.h | 3 --- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/effects/invert/data/1.10/invert.frag b/effects/invert/data/1.10/invert.frag index 9fe602b654..49d7861e15 100644 --- a/effects/invert/data/1.10/invert.frag +++ b/effects/invert/data/1.10/invert.frag @@ -2,11 +2,11 @@ uniform sampler2D sampler; uniform vec4 modulation; uniform float saturation; -varying vec2 varyingTexCoords; +varying vec2 texcoord0; void main() { - vec4 tex = texture2D(sampler, varyingTexCoords); + vec4 tex = texture2D(sampler, texcoord0); if (saturation != 1.0) { vec3 desaturated = tex.rgb * vec3( 0.30, 0.59, 0.11 ); diff --git a/effects/invert/data/1.40/invert.frag b/effects/invert/data/1.40/invert.frag index 6dee1e60ad..632f0a3d88 100644 --- a/effects/invert/data/1.40/invert.frag +++ b/effects/invert/data/1.40/invert.frag @@ -3,13 +3,13 @@ uniform sampler2D sampler; uniform vec4 modulation; uniform float saturation; -in vec2 varyingTexCoords; +in vec2 texcoord0; out vec4 fragColor; void main() { - vec4 tex = texture(sampler, varyingTexCoords); + vec4 tex = texture(sampler, texcoord0); if (saturation != 1.0) { vec3 desaturated = tex.rgb * vec3( 0.30, 0.59, 0.11 ); diff --git a/effects/invert/invert.cpp b/effects/invert/invert.cpp index 2ecad094ca..4243f6bf21 100644 --- a/effects/invert/invert.cpp +++ b/effects/invert/invert.cpp @@ -22,6 +22,7 @@ along with this program. If not, see . #include "invert.h" #include +#include #include #include #include @@ -56,7 +57,6 @@ InvertEffect::InvertEffect() connect(b, SIGNAL(triggered(bool)), this, SLOT(toggleWindow())); connect(effects, SIGNAL(windowClosed(KWin::EffectWindow*)), this, SLOT(slotWindowClosed(KWin::EffectWindow*))); - connect(effects, SIGNAL(screenGeometryChanged(const QSize&)), this, SLOT(resetShader())); } InvertEffect::~InvertEffect() @@ -79,7 +79,13 @@ bool InvertEffect::loadData() shadersDir = QStringLiteral("kwin/shaders/1.40/"); const QString fragmentshader = QStandardPaths::locate(QStandardPaths::GenericDataLocation, shadersDir + QStringLiteral("invert.frag")); - m_shader = ShaderManager::instance()->loadFragmentShader(ShaderManager::GenericShader, fragmentshader); + QFile ff(fragmentshader); + if (!ff.open(QIODevice::ReadOnly)) { + qCCritical(KWINEFFECTS) << "Couldn't open" << fragmentshader << "for reading!"; + return false; + } + + m_shader = ShaderManager::instance()->generateCustomShader(ShaderTrait::MapTexture, QByteArray(), ff.readAll()); if (!m_shader->isValid()) { qCCritical(KWINEFFECTS) << "The shader failed to load!"; return false; @@ -110,11 +116,7 @@ void InvertEffect::drawWindow(EffectWindow* w, int mask, QRegion region, WindowP bool useShader = m_valid && (m_allWindows != m_windows.contains(w)); if (useShader) { ShaderManager *shaderManager = ShaderManager::instance(); - GLShader *genericShader = shaderManager->pushShader(ShaderManager::GenericShader); - QMatrix4x4 screenTransformation = genericShader->getUniformMatrix4x4("screenTransformation"); - shaderManager->popShader(); shaderManager->pushShader(m_shader); - m_shader->setUniform("screenTransformation", screenTransformation); data.shader = m_shader; } @@ -131,8 +133,6 @@ void InvertEffect::paintEffectFrame(KWin::EffectFrame* frame, QRegion region, do if (m_valid && m_allWindows) { frame->setShader(m_shader); ShaderBinder binder(m_shader); - m_shader->setUniform("screenTransformation", QMatrix4x4()); - m_shader->setUniform("windowTransformation", QMatrix4x4()); effects->paintEffectFrame(frame, region, opacity, frameOpacity); } else { effects->paintEffectFrame(frame, region, opacity, frameOpacity); @@ -172,11 +172,6 @@ bool InvertEffect::provides(Feature f) return f == ScreenInversion; } -void InvertEffect::resetShader() -{ - ShaderManager::instance()->resetShader(m_shader, ShaderManager::GenericShader); -} - } // namespace #include "invert.moc" diff --git a/effects/invert/invert.h b/effects/invert/invert.h index 229c206fce..1f946f6c45 100644 --- a/effects/invert/invert.h +++ b/effects/invert/invert.h @@ -54,9 +54,6 @@ public Q_SLOTS: void toggleWindow(); void slotWindowClosed(KWin::EffectWindow *w); -private Q_SLOTS: - void resetShader(); - protected: bool loadData();