From d7665af4f071b8b8da4c65d28a2069dad7aacbe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 27 Apr 2009 11:07:15 +0000 Subject: [PATCH] Texture width and height is stored in GLShader and the uniform value is set during prepareShaderRenderStates in scene_opengl. So the effects do not have to set the uniform manually. This is useful as other effects can still set this uniform if something different is rendered with a different texture width/height (e.g. shadows or thumbnails). When the window is finally rendered the original value set by the effect is definatelly used. First effect to use this new way to set texture width and height is invert effect. svn path=/trunk/KDE/kdebase/workspace/; revision=959835 --- effects/invert/invert.cpp | 4 ++-- lib/kwinglutils.cpp | 21 +++++++++++++++++++++ lib/kwinglutils.h | 6 ++++++ scene_opengl.cpp | 9 +++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) 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 )