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
This commit is contained in:
parent
7991f3e99d
commit
d7665af4f0
4 changed files with 38 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 ***/
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 )
|
||||
|
|
Loading…
Reference in a new issue