rendered paste bodycommit 973e51615b9abc1dccd72d9f0b0059d311a37d8b
Author: Martin Grlin <ubuntu@martin-graesslin.com>
Date: Tue Apr 21 00:01:05 2009 +0200
Shadow sets the textureWidth and Height uniform, so that shaders can calculate the correct tex coords. The uniform values have to be reset therefore they are stored in the GLShader class
diff --git a/effects/shadow/shadow.cpp b/effects/shadow/shadow.cpp
index 3577ddc..edc9a97 100644
--- a/effects/shadow/shadow.cpp
+++ b/effects/shadow/shadow.cpp
@@ -662,8 +662,18 @@ void ShadowEffect::drawShadowQuadOpenGL( GLTexture *texture, QVector<float> vert
glColor4f( 1.0, 1.0, 1.0, 1.0 );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
prepareRenderStates( texture, opacity, brightness, saturation ); // Usually overrides the above
+ float texw = 0.0f;
+ float texh = 0.0f;
if( shader )
{
+ // the attached window shaders expect unnormalized tex coords
+ // the shadow uses normalized tex coords
+ // set the texture width and height to 1.0 so the shader will calculate correct tex coords
+ texw = shader->getUniformFloatValue("textureWidth");
+ texh = shader->getUniformFloatValue("textureHeight");
+ shader->setUniform("textureWidth", 1.0f);
+ shader->setUniform("textureHeight", 1.0f);
+ // set shadow opacity, saturation and brightness
shader->setUniform("opacity", opacity);
shader->setUniform("saturation", saturation);
shader->setUniform("brightness", brightness);
@@ -676,6 +686,12 @@ void ShadowEffect::drawShadowQuadOpenGL( GLTexture *texture, QVector<float> vert
texture->disableNormalizedTexCoords();
texture->unbind();
restoreRenderStates( texture, opacity, brightness, saturation );
+ if( shader )
+ {
+ // restore texture width and height
+ shader->setUniform("textureWidth", texw);
+ shader->setUniform("textureHeight", texh);
+ }
#endif
}
diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp
index 97ed83f..3778630 100644
--- a/lib/kwinglutils.cpp
+++ b/lib/kwinglutils.cpp
@@ -733,6 +733,8 @@ GLShader::GLShader(const QString& vertexfile, const QString& fragmentfile)
{
mValid = false;
mVariableLocations = 0;
+ mUniformFloatValues = 0;
+ mUniformIntValues = 0;
mProgram = 0;
loadFromFiles(vertexfile, fragmentfile);
@@ -746,6 +748,18 @@ GLShader::~GLShader()
delete mVariableLocations;
}
+ if(mUniformIntValues)
+ {
+ mUniformIntValues->clear();
+ delete mUniformIntValues;
+ }
+
+ if(mUniformFloatValues)
+ {
+ mUniformFloatValues->clear();
+ delete mUniformFloatValues;
+ }
+
if(mProgram)
{
glDeleteProgram(mProgram);
@@ -877,6 +891,8 @@ bool GLShader::load(const QString& vertexsource, const QString& fragmentsource)
delete[] log;
mVariableLocations = new QHash<QString, int>;
+ mUniformIntValues = new QHash<QString, int>;
+ mUniformFloatValues = new QHash<QString, float>;
mValid = true;
return true;
@@ -912,6 +928,7 @@ bool GLShader::setUniform(const QString& name, float value)
if(location >= 0)
{
glUniform1f(location, value);
+ mUniformFloatValues->insert(name, value);
}
return (location >= 0);
}
@@ -922,10 +939,21 @@ bool GLShader::setUniform(const QString& name, int value)
if(location >= 0)
{
glUniform1i(location, value);
+ mUniformIntValues->insert(name, value);
}
return (location >= 0);
}
+float GLShader::getUniformFloatValue(const QString& name)
+ {
+ return mUniformFloatValues->value(name);
+ }
+
+int GLShader::getUniformIntValue(const QString& name)
+ {
+ return mUniformIntValues->value(name);
+ }
+
int GLShader::attributeLocation(const QString& name)
{
if(!mVariableLocations)
diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h
index 82d09e9..c07b897 100644
--- a/lib/kwinglutils.h
+++ b/lib/kwinglutils.h
@@ -218,6 +218,8 @@ class KWIN_EXPORT GLShader
bool setUniform(const QString& name, int value);
int attributeLocation(const QString& name);
bool setAttribute(const QString& name, float value);
+ int getUniformIntValue(const QString& name);
+ float getUniformFloatValue(const QString& name);
static void initStatic();
@@ -234,6 +236,8 @@ class KWIN_EXPORT GLShader
unsigned int mProgram;
bool mValid;
QHash< QString, int >* mVariableLocations;
+ QHash< QString, int >* mUniformIntValues;
+ QHash< QString, float >* mUniformFloatValues;
static bool mFragmentShaderSupported;
static bool mVertexShaderSupported;
};