Move repeated code into a helper function.

svn path=/trunk/KDE/kdebase/workspace/; revision=889733
This commit is contained in:
Lucas Murray 2008-11-27 13:38:35 +00:00
parent e4d54bd4de
commit 117cb5719f
2 changed files with 39 additions and 112 deletions

View file

@ -612,6 +612,25 @@ void ShadowEffect::restoreRenderStates( GLTexture *texture, double opacity, doub
#endif #endif
} }
void ShadowEffect::drawShadowQuadOpenGL( GLTexture *texture, QVector<float> verts, QVector<float> texCoords,
QColor color, QRegion region, float opacity, float brightness, float saturation )
{
if( color.isValid() )
glColor4f( color.redF(), color.greenF(), color.blueF(), opacity );
else
glColor4f( 1.0, 1.0, 1.0, opacity );
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
prepareRenderStates( texture, opacity, brightness, saturation );
texture->bind();
texture->enableNormalizedTexCoords();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
renderGLGeometry( region, 4, verts.data(), texCoords.data() );
texture->disableNormalizedTexCoords();
texture->unbind();
restoreRenderStates( texture, opacity, brightness, saturation );
}
void ShadowEffect::drawShadowQuadXRender( XRenderPicture *picture, QRect rect, float xScale, float yScale, void ShadowEffect::drawShadowQuadXRender( XRenderPicture *picture, QRect rect, float xScale, float yScale,
QColor color, float opacity, float brightness, float saturation ) QColor color, float opacity, float brightness, float saturation )
{ {
@ -744,125 +763,47 @@ void ShadowEffect::drawShadow( EffectWindow* window, int mask, QRegion region, c
effects->shadowTextureList( ShadowBorderedActive ) == texture ) effects->shadowTextureList( ShadowBorderedActive ) == texture )
{ // Decorated windows { // Decorated windows
// Active shadow // Active shadow
glColor4f( 1.0, 1.0, 1.0, 1.0 ); drawShadowQuadOpenGL( mShadowTextures.at( texture ).at( quad.id() ),
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); verts, texcoords, QColor(), region,
prepareRenderStates(
mShadowTextures.at( texture ).at( quad.id() ),
data.opacity * window->shadowOpacity( ShadowBorderedActive ), data.opacity * window->shadowOpacity( ShadowBorderedActive ),
data.brightness * window->shadowBrightness( ShadowBorderedActive ), data.brightness * window->shadowBrightness( ShadowBorderedActive ),
data.saturation * window->shadowSaturation( ShadowBorderedActive ) data.saturation * window->shadowSaturation( ShadowBorderedActive ));
);
mShadowTextures.at( texture ).at( quad.id() )->bind();
mShadowTextures.at( texture ).at( quad.id() )->enableNormalizedTexCoords();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
renderGLGeometry( region, 4, verts.data(), texcoords.data() );
mShadowTextures.at( texture ).at( quad.id() )->disableNormalizedTexCoords();
mShadowTextures.at( texture ).at( quad.id() )->unbind();
restoreRenderStates(
mShadowTextures.at( texture ).at( quad.id() ),
data.opacity * window->shadowOpacity( ShadowBorderedActive ),
data.brightness * window->shadowBrightness( ShadowBorderedActive ),
data.saturation * window->shadowSaturation( ShadowBorderedActive )
);
// Inactive shadow // Inactive shadow
texture = effects->shadowTextureList( ShadowBorderedInactive ); texture = effects->shadowTextureList( ShadowBorderedInactive );
drawShadowQuadOpenGL( mShadowTextures.at( texture ).at( quad.id() ),
glColor4f( 1.0, 1.0, 1.0, 1.0 ); verts, texcoords, QColor(), region,
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
prepareRenderStates(
mShadowTextures.at( texture ).at( quad.id() ),
data.opacity * window->shadowOpacity( ShadowBorderedInactive ), data.opacity * window->shadowOpacity( ShadowBorderedInactive ),
data.brightness * window->shadowBrightness( ShadowBorderedInactive ), data.brightness * window->shadowBrightness( ShadowBorderedInactive ),
data.saturation * window->shadowSaturation( ShadowBorderedInactive ) data.saturation * window->shadowSaturation( ShadowBorderedInactive ));
);
mShadowTextures.at( texture ).at( quad.id() )->bind();
mShadowTextures.at( texture ).at( quad.id() )->enableNormalizedTexCoords();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
renderGLGeometry( region, 4, verts.data(), texcoords.data() );
mShadowTextures.at( texture ).at( quad.id() )->disableNormalizedTexCoords();
mShadowTextures.at( texture ).at( quad.id() )->unbind();
restoreRenderStates(
mShadowTextures.at( texture ).at( quad.id() ),
data.opacity * window->shadowOpacity( ShadowBorderedInactive ),
data.brightness * window->shadowBrightness( ShadowBorderedInactive ),
data.saturation * window->shadowSaturation( ShadowBorderedInactive )
);
} }
else if( effects->shadowTextureList( ShadowBorderlessActive ) == texture ) else if( effects->shadowTextureList( ShadowBorderlessActive ) == texture )
{ // Decoration-less normal windows { // Decoration-less normal windows
glColor4f( 1.0, 1.0, 1.0, 1.0 );
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
if( effects->activeWindow() == window ) if( effects->activeWindow() == window )
{ {
prepareRenderStates( drawShadowQuadOpenGL( mShadowTextures.at( texture ).at( quad.id() ),
mShadowTextures.at( texture ).at( quad.id() ), verts, texcoords, QColor(), region,
data.opacity * window->shadowOpacity( ShadowBorderlessActive ), data.opacity * window->shadowOpacity( ShadowBorderlessActive ),
data.brightness * window->shadowBrightness( ShadowBorderlessActive ), data.brightness * window->shadowBrightness( ShadowBorderlessActive ),
data.saturation * window->shadowSaturation( ShadowBorderlessActive ) data.saturation * window->shadowSaturation( ShadowBorderlessActive ));
);
} }
else else
{ {
texture = effects->shadowTextureList( ShadowBorderlessInactive ); texture = effects->shadowTextureList( ShadowBorderlessInactive );
prepareRenderStates( drawShadowQuadOpenGL( mShadowTextures.at( texture ).at( quad.id() ),
mShadowTextures.at( texture ).at( quad.id() ), verts, texcoords, QColor(), region,
data.opacity * window->shadowOpacity( ShadowBorderlessInactive ), data.opacity * window->shadowOpacity( ShadowBorderlessInactive ),
data.brightness * window->shadowBrightness( ShadowBorderlessInactive ), data.brightness * window->shadowBrightness( ShadowBorderlessInactive ),
data.saturation * window->shadowSaturation( ShadowBorderlessInactive ) data.saturation * window->shadowSaturation( ShadowBorderlessInactive ));
);
}
mShadowTextures.at( texture ).at( quad.id() )->bind();
mShadowTextures.at( texture ).at( quad.id() )->enableNormalizedTexCoords();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
renderGLGeometry( region, 4, verts.data(), texcoords.data() );
mShadowTextures.at( texture ).at( quad.id() )->disableNormalizedTexCoords();
mShadowTextures.at( texture ).at( quad.id() )->unbind();
if( effects->activeWindow() == window )
{
restoreRenderStates(
mShadowTextures.at( texture ).at( quad.id() ),
data.opacity * window->shadowOpacity( ShadowBorderlessActive ),
data.brightness * window->shadowBrightness( ShadowBorderlessActive ),
data.saturation * window->shadowSaturation( ShadowBorderlessActive )
);
}
else
{
restoreRenderStates(
mShadowTextures.at( texture ).at( quad.id() ),
data.opacity * window->shadowOpacity( ShadowBorderlessInactive ),
data.brightness * window->shadowBrightness( ShadowBorderlessInactive ),
data.saturation * window->shadowSaturation( ShadowBorderlessInactive )
);
} }
} }
else else
{ // Other windows { // Other windows
glColor4f( 1.0, 1.0, 1.0, 1.0 ); drawShadowQuadOpenGL( mShadowTextures.at( texture ).at( quad.id() ),
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); verts, texcoords, QColor(), region,
prepareRenderStates(
mShadowTextures.at( texture ).at( quad.id() ),
data.opacity * window->shadowOpacity( ShadowOther ), data.opacity * window->shadowOpacity( ShadowOther ),
data.brightness * window->shadowBrightness( ShadowOther ), data.brightness * window->shadowBrightness( ShadowOther ),
data.saturation * window->shadowSaturation( ShadowOther ) data.saturation * window->shadowSaturation( ShadowOther ));
);
mShadowTextures.at( texture ).at( quad.id() )->bind();
mShadowTextures.at( texture ).at( quad.id() )->enableNormalizedTexCoords();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
renderGLGeometry( region, 4, verts.data(), texcoords.data() );
mShadowTextures.at( texture ).at( quad.id() )->disableNormalizedTexCoords();
mShadowTextures.at( texture ).at( quad.id() )->unbind();
restoreRenderStates(
mShadowTextures.at( texture ).at( quad.id() ),
data.opacity * window->shadowOpacity( ShadowOther ),
data.brightness * window->shadowBrightness( ShadowOther ),
data.saturation * window->shadowSaturation( ShadowOther )
);
} }
} }
} }
@ -872,27 +813,11 @@ void ShadowEffect::drawShadow( EffectWindow* window, int mask, QRegion region, c
if( intensifyActiveShadow && window == effects->activeWindow() ) if( intensifyActiveShadow && window == effects->activeWindow() )
opacity = 1 - ( 1 - shadowOpacity ) * ( 1 - shadowOpacity ); opacity = 1 - ( 1 - shadowOpacity ) * ( 1 - shadowOpacity );
glColor4f( shadowColor.redF(), shadowColor.greenF(), shadowColor.blueF(), opacity * data.opacity ); drawShadowQuadOpenGL( mDefaultShadowTextures.at( quad.id() ),
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); verts, texcoords, shadowColor, region,
prepareRenderStates(
mDefaultShadowTextures.at( quad.id() ),
data.opacity * opacity, data.opacity * opacity,
data.brightness, data.brightness,
data.saturation data.saturation );
);
mDefaultShadowTextures.at( quad.id() )->bind();
mDefaultShadowTextures.at( quad.id() )->enableNormalizedTexCoords();
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
renderGLGeometry( region, 4, verts.data(), texcoords.data() );
mDefaultShadowTextures.at( quad.id() )->disableNormalizedTexCoords();
mDefaultShadowTextures.at( quad.id() )->unbind();
restoreRenderStates(
mDefaultShadowTextures.at( quad.id() ),
data.opacity * opacity,
data.brightness,
data.saturation
);
} }
glPopMatrix(); glPopMatrix();

View file

@ -53,6 +53,8 @@ class ShadowEffect
void prepareRenderStates( GLTexture *texture, double opacity, double brightness, double saturation ); void prepareRenderStates( GLTexture *texture, double opacity, double brightness, double saturation );
void restoreRenderStates( GLTexture *texture, double opacity, double brightness, double saturation ); void restoreRenderStates( GLTexture *texture, double opacity, double brightness, double saturation );
void drawShadowQuadOpenGL( GLTexture *texture, QVector<float> verts, QVector<float> texCoords,
QColor color, QRegion region, float opacity, float brightness, float saturation );
void drawShadowQuadXRender( XRenderPicture *picture, QRect rect, float xScale, float yScale, void drawShadowQuadXRender( XRenderPicture *picture, QRect rect, float xScale, float yScale,
QColor color, float opacity, float brightness, float saturation ); QColor color, float opacity, float brightness, float saturation );