diff --git a/effects/invert/invert.cpp b/effects/invert/invert.cpp index c90ec4eba3..c8aa4828e0 100644 --- a/effects/invert/invert.cpp +++ b/effects/invert/invert.cpp @@ -106,8 +106,8 @@ void InvertEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Windo texw = nearestPowerOfTwo(texw); texh = nearestPowerOfTwo(texh); } - m_shader->setUniform("textureWidth", (float)texw); - m_shader->setUniform("textureHeight", (float)texh); + m_shader->setTextureWidth( (float)texw ); + m_shader->setTextureHeight( (float)texh ); data.shader = m_shader; } diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index 97ed83fafe..8a52a4ba07 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -734,6 +734,8 @@ GLShader::GLShader(const QString& vertexfile, const QString& fragmentfile) mValid = false; mVariableLocations = 0; mProgram = 0; + mTextureWidth = -1.0f; + mTextureHeight = -1.0f; loadFromFiles(vertexfile, fragmentfile); } @@ -950,6 +952,25 @@ bool GLShader::setAttribute(const QString& name, float value) return (location >= 0); } +void GLShader::setTextureHeight(float height) + { + mTextureHeight = height; + } + +void GLShader::setTextureWidth(float width) + { + mTextureWidth = width; + } + +float GLShader::textureHeight() + { + return mTextureHeight; + } + +float GLShader::textureWidth() + { + return mTextureWidth; + } /*** GLRenderTarget ***/ diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index 82d09e904e..b4c70ac7f6 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -219,6 +219,10 @@ class KWIN_EXPORT GLShader int attributeLocation(const QString& name); bool setAttribute(const QString& name, float value); + void setTextureWidth( float width ); + void setTextureHeight( float height ); + float textureWidth(); + float textureHeight(); static void initStatic(); static bool fragmentShaderSupported() { return mFragmentShaderSupported; } @@ -236,6 +240,8 @@ class KWIN_EXPORT GLShader QHash< QString, int >* mVariableLocations; static bool mFragmentShaderSupported; static bool mVertexShaderSupported; + float mTextureWidth; + float mTextureHeight; }; /** diff --git a/scene_opengl.cpp b/scene_opengl.cpp index 6bd9c2b5b9..3240ff3f0f 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -1650,6 +1650,15 @@ void SceneOpenGL::Window::prepareShaderRenderStates( TextureType type, double op shader->setUniform("opacity", (float)opacity); shader->setUniform("saturation", (float)saturation); shader->setUniform("brightness", (float)brightness); + + // setting texture width and heiht stored in shader + // only set if it is set by an effect that is not negative + float texw = shader->textureWidth(); + if( texw >= 0.0f ) + shader->setUniform("textureWidth", texw); + float texh = shader->textureHeight(); + if( texh >= 0.0f ) + shader->setUniform("textureHeight", texh); } void SceneOpenGL::Window::prepareRenderStates( TextureType type, double opacity, double brightness, double saturation )