Add shader support.

Effects can use setShader() method to set a custom shader for window rendering.

svn path=/branches/work/kwin_composite/; revision=643131
This commit is contained in:
Rivo Laks 2007-03-16 13:00:01 +00:00
parent d4fbab83d1
commit 19e7ebe1d8
2 changed files with 42 additions and 2 deletions

View file

@ -811,6 +811,9 @@ void SceneOpenGL::Window::prepareVertices()
// Reset requests for the next painting // Reset requests for the next painting
requestedXResolution = 0; requestedXResolution = 0;
requestedYResolution = 0; requestedYResolution = 0;
// Reset shader. If effect wants to use shader, it has to set it in paint pass
shader = 0;
} }
void SceneOpenGL::Window::prepareForPainting() void SceneOpenGL::Window::prepareForPainting()
@ -1177,6 +1180,9 @@ void SceneOpenGL::Window::performPaint( int mask, QRegion region, WindowPaintDat
if(( mask & PAINT_WINDOW_TRANSFORMED ) && ( data.xScale != 1 || data.yScale != 1 )) if(( mask & PAINT_WINDOW_TRANSFORMED ) && ( data.xScale != 1 || data.yScale != 1 ))
glScalef( data.xScale, data.yScale, 1 ); glScalef( data.xScale, data.yScale, 1 );
if(shader)
prepareShaderRenderStates( mask, data );
else
prepareRenderStates( mask, data ); prepareRenderStates( mask, data );
enableTexture(); enableTexture();
@ -1202,12 +1208,32 @@ void SceneOpenGL::Window::performPaint( int mask, QRegion region, WindowPaintDat
glMatrixMode( GL_MODELVIEW ); glMatrixMode( GL_MODELVIEW );
glPopMatrix(); glPopMatrix();
if(shader)
restoreShaderRenderStates( mask, data );
else
restoreRenderStates( mask, data ); restoreRenderStates( mask, data );
disableTexture(); disableTexture();
} }
void SceneOpenGL::Window::prepareShaderRenderStates( int mask, WindowPaintData data )
{
Q_UNUSED( mask );
// setup blending of transparent windows
glPushAttrib( GL_ENABLE_BIT );
bool opaque = isOpaque() && data.opacity == 1.0;
if( !opaque )
{
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
}
shader->setUniform("opacity", (float)data.opacity);
shader->setUniform("saturation", (float)data.saturation);
shader->setUniform("brightness", (float)data.brightness);
}
void SceneOpenGL::Window::prepareRenderStates( int mask, WindowPaintData data ) void SceneOpenGL::Window::prepareRenderStates( int mask, WindowPaintData data )
{ {
Q_UNUSED( mask );
// setup blending of transparent windows // setup blending of transparent windows
glPushAttrib( GL_ENABLE_BIT ); glPushAttrib( GL_ENABLE_BIT );
bool opaque = isOpaque() && data.opacity == 1.0; bool opaque = isOpaque() && data.opacity == 1.0;
@ -1364,8 +1390,16 @@ void SceneOpenGL::Window::renderGeometry( int mask, QRegion region )
glDisableClientState( GL_TEXTURE_COORD_ARRAY ); glDisableClientState( GL_TEXTURE_COORD_ARRAY );
} }
void SceneOpenGL::Window::restoreShaderRenderStates( int mask, WindowPaintData data )
{
Q_UNUSED( mask );
Q_UNUSED( data );
glPopAttrib(); // ENABLE_BIT
}
void SceneOpenGL::Window::restoreRenderStates( int mask, WindowPaintData data ) void SceneOpenGL::Window::restoreRenderStates( int mask, WindowPaintData data )
{ {
Q_UNUSED( mask );
if( data.opacity != 1.0 || data.saturation != 1.0 || data.brightness != 1.0f ) if( data.opacity != 1.0 || data.saturation != 1.0 || data.brightness != 1.0f )
{ {
if( data.saturation != 1.0 && supports_saturation ) if( data.saturation != 1.0 && supports_saturation )

View file

@ -130,6 +130,9 @@ class SceneOpenGL::Window
// Marks vertices of the window as dirty. Call this if you change // Marks vertices of the window as dirty. Call this if you change
// position of the vertices // position of the vertices
void markVerticesDirty() { verticesDirty = true; } void markVerticesDirty() { verticesDirty = true; }
void setShader( GLShader* s ) { shader = s; }
protected: protected:
// Makes sure that vertex grid requests are fulfilled and that vertices // Makes sure that vertex grid requests are fulfilled and that vertices
// aren't dirty. Call this before paint pass // aren't dirty. Call this before paint pass
@ -138,8 +141,10 @@ class SceneOpenGL::Window
void resetVertices(); // Resets positions of vertices void resetVertices(); // Resets positions of vertices
void prepareRenderStates( int mask, WindowPaintData data ); void prepareRenderStates( int mask, WindowPaintData data );
void prepareShaderRenderStates( int mask, WindowPaintData data );
void renderGeometry( int mask, QRegion region ); void renderGeometry( int mask, QRegion region );
void restoreRenderStates( int mask, WindowPaintData data ); void restoreRenderStates( int mask, WindowPaintData data );
void restoreShaderRenderStates( int mask, WindowPaintData data );
private: private:
QRegion optimizeBindDamage( const QRegion& reg, int limit ); QRegion optimizeBindDamage( const QRegion& reg, int limit );
@ -161,6 +166,7 @@ class SceneOpenGL::Window
int requestedXResolution; int requestedXResolution;
int requestedYResolution; int requestedYResolution;
bool verticesDirty; // vertices have been modified in some way bool verticesDirty; // vertices have been modified in some way
GLShader* shader; // shader to be used for rendering, if any
}; };
} // namespace } // namespace