diff --git a/effects/boxswitch.cpp b/effects/boxswitch.cpp index 0cfccb0191..36d33416f9 100644 --- a/effects/boxswitch.cpp +++ b/effects/boxswitch.cpp @@ -429,17 +429,14 @@ void BoxSwitchEffect::paintFrame() glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glColor4f( 0, 0, 0, alpha ); - glEnableClientState( GL_VERTEX_ARRAY ); - int verts[ 4 * 2 ] = + const float verts[ 4 * 2 ] = { frame_area.x(), frame_area.y(), frame_area.x(), frame_area.y() + frame_area.height(), frame_area.x() + frame_area.width(), frame_area.y() + frame_area.height(), frame_area.x() + frame_area.width(), frame_area.y() }; - glVertexPointer( 2, GL_INT, 0, verts ); - glDrawArrays( GL_QUADS, 0, 4 ); - glDisableClientState( GL_VERTEX_ARRAY ); + renderGLGeometry( verts, NULL, 4 ); glPopAttrib(); } #endif @@ -475,17 +472,14 @@ void BoxSwitchEffect::paintHighlight( QRect area, QString text ) glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glColor4f( 1, 1, 1, alpha ); - glEnableClientState( GL_VERTEX_ARRAY ); - int verts[ 4 * 2 ] = + const float verts[ 4 * 2 ] = { area.x(), area.y(), area.x(), area.y() + area.height(), area.x() + area.width(), area.y() + area.height(), area.x() + area.width(), area.y() }; - glVertexPointer( 2, GL_INT, 0, verts ); - glDrawArrays( GL_QUADS, 0, 4 ); - glDisableClientState( GL_VERTEX_ARRAY ); + renderGLGeometry( verts, NULL, 4 ); glPopAttrib(); } #endif @@ -589,27 +583,21 @@ void BoxSwitchEffect::paintWindowIcon( EffectWindow* w ) glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); windows[ w ]->iconTexture.bind(); - glEnableClientState( GL_VERTEX_ARRAY ); - int verts[ 4 * 2 ] = + const float verts[ 4 * 2 ] = { x, y, x, y + height, x + width, y + height, x + width, y }; - glVertexPointer( 2, GL_INT, 0, verts ); - glEnableClientState( GL_TEXTURE_COORD_ARRAY ); - int texcoords[ 4 * 2 ] = + const float texcoords[ 4 * 2 ] = { 0, 1, 0, 0, 1, 0, 1, 1 }; - glTexCoordPointer( 2, GL_INT, 0, texcoords ); - glDrawArrays( GL_QUADS, 0, 4 ); - glDisableClientState( GL_TEXTURE_COORD_ARRAY ); - glDisableClientState( GL_VERTEX_ARRAY ); + renderGLGeometry( verts, texcoords, 4 ); windows[ w ]->iconTexture.unbind(); glPopAttrib(); } diff --git a/effects/demo_showpicture.cpp b/effects/demo_showpicture.cpp index 86fffa5ec7..b630e75767 100644 --- a/effects/demo_showpicture.cpp +++ b/effects/demo_showpicture.cpp @@ -44,31 +44,25 @@ void ShowPictureEffect::paintScreen( int mask, QRegion region, ScreenPaintData& picture->bind(); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - glEnableClientState( GL_VERTEX_ARRAY ); int x = pictureRect.x(); int y = pictureRect.y(); int width = pictureRect.width(); int height = pictureRect.height(); - int verts[ 4 * 2 ] = + const float verts[ 4 * 2 ] = { x, y, x, y + height, x + width, y + height, x + width, y }; - glVertexPointer( 2, GL_INT, 0, verts ); - glEnableClientState( GL_TEXTURE_COORD_ARRAY ); - int texcoords[ 4 * 2 ] = + const float texcoords[ 4 * 2 ] = { 0, 1, 0, 0, 1, 0, 1, 1 }; - glTexCoordPointer( 2, GL_INT, 0, texcoords ); - glDrawArrays( GL_QUADS, 0, 4 ); - glDisableClientState( GL_TEXTURE_COORD_ARRAY ); - glDisableClientState( GL_VERTEX_ARRAY ); + renderGLGeometry( mask, region, verts, texcoords, 4 ); picture->unbind(); glPopAttrib(); } diff --git a/effects/presentwindows.cpp b/effects/presentwindows.cpp index 3493707bce..29dd361279 100644 --- a/effects/presentwindows.cpp +++ b/effects/presentwindows.cpp @@ -127,31 +127,25 @@ void PresentWindowsEffect::paintScreen( int mask, QRegion region, ScreenPaintDat filterTexture->bind(); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - glEnableClientState( GL_VERTEX_ARRAY ); int x = filterTextureRect.x(); int y = filterTextureRect.y(); int width = filterTextureRect.width(); int height = filterTextureRect.height(); - int verts[ 4 * 2 ] = + const float verts[ 4 * 2 ] = { x, y, x, y + height, x + width, y + height, x + width, y }; - glVertexPointer( 2, GL_INT, 0, verts ); - glEnableClientState( GL_TEXTURE_COORD_ARRAY ); - int texcoords[ 4 * 2 ] = + const float texcoords[ 4 * 2 ] = { 0, 1, 0, 0, 1, 0, 1, 1 }; - glTexCoordPointer( 2, GL_INT, 0, texcoords ); - glDrawArrays( GL_QUADS, 0, 4 ); - glDisableClientState( GL_TEXTURE_COORD_ARRAY ); - glDisableClientState( GL_VERTEX_ARRAY ); + renderGLGeometry( mask, region, verts, texcoords, 4 ); filterTexture->unbind(); glPopAttrib(); } diff --git a/effects/shadow.cpp b/effects/shadow.cpp index f450aac810..13adf82a4a 100644 --- a/effects/shadow.cpp +++ b/effects/shadow.cpp @@ -64,29 +64,15 @@ void ShadowEffect::drawShadow( EffectWindow* w, int mask, QRegion region, Window if(( mask & PAINT_WINDOW_TRANSFORMED ) && ( data.xScale != 1 || data.yScale != 1 )) glScalef( data.xScale, data.yScale, 1 ); - glEnableClientState( GL_VERTEX_ARRAY ); - int verts[ 4 * 2 ] = + const float verts[ 4 * 2 ] = { 0, 0, 0, w->height(), w->width(), w->height(), w->width(), 0 }; - glVertexPointer( 2, GL_INT, 0, verts ); - if( mask & ( PAINT_WINDOW_TRANSFORMED | PAINT_SCREEN_TRANSFORMED )) - glDrawArrays( GL_QUADS, 0, 4 ); - else - { // clip by region - glEnable( GL_SCISSOR_TEST ); - int dh = displayHeight(); - foreach( QRect r, region.rects()) - { - // Scissor rect has to be given in OpenGL coords - glScissor(r.x(), dh - r.y() - r.height(), r.width(), r.height()); - glDrawArrays( GL_QUADS, 0, 4 ); - } - } - glDisableClientState( GL_VERTEX_ARRAY ); + renderGLGeometry( mask, region, verts, NULL, 4 ); + glPopMatrix(); glPopAttrib(); } diff --git a/effects/trackmouse.cpp b/effects/trackmouse.cpp index fc6bdff168..7a8cada15d 100644 --- a/effects/trackmouse.cpp +++ b/effects/trackmouse.cpp @@ -67,27 +67,21 @@ void TrackMouseEffect::paintScreen( int mask, QRegion region, ScreenPaintData& d ++i ) { QRect r = starRect( i ); - glEnableClientState( GL_VERTEX_ARRAY ); - int verts[ 4 * 2 ] = + const float verts[ 4 * 2 ] = { r.x(), r.y(), r.x(), r.y() + r.height(), r.x() + r.width(), r.y() + r.height(), r.x() + r.width(), r.y() }; - glVertexPointer( 2, GL_INT, 0, verts ); - glEnableClientState( GL_TEXTURE_COORD_ARRAY ); - int texcoords[ 4 * 2 ] = + const float texcoords[ 4 * 2 ] = { 0, 1, 0, 0, 1, 0, 1, 1 }; - glTexCoordPointer( 2, GL_INT, 0, texcoords ); - glDrawArrays( GL_QUADS, 0, 4 ); - glDisableClientState( GL_TEXTURE_COORD_ARRAY ); - glDisableClientState( GL_VERTEX_ARRAY ); + renderGLGeometry( mask, region, verts, texcoords, 4 ); } texture->unbind(); glPopAttrib(); diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index 178fb2b1d4..bbdabc70f0 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -11,6 +11,7 @@ License. See the file "COPYING" for the exact licensing terms. #include "kwinglutils.h" #include "kwinglobals.h" +#include "kwineffects.h" #include "kdebug.h" @@ -113,6 +114,52 @@ int nearestPowerOfTwo( int x ) return 1 << last; } +void renderGLGeometry( const float* vertices, const float* texture, int count, int dim, int stride ) + { + return renderGLGeometry( false, QRegion(), vertices, texture, count, dim, stride ); + } + +void renderGLGeometry( int mask, QRegion region, const float* vertices, const float* texture, int count, + int dim, int stride ) + { + return renderGLGeometry( !( mask & ( Effect::PAINT_WINDOW_TRANSFORMED | Effect::PAINT_SCREEN_TRANSFORMED )), + region, vertices, texture, count, dim, stride ); + } + +void renderGLGeometry( bool clip, QRegion region, const float* vertices, const float* texture, int count, + int dim, int stride ) + { + glPushAttrib( GL_ENABLE_BIT ); + glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); + // Enable arrays + glEnableClientState( GL_VERTEX_ARRAY ); + glVertexPointer( dim, GL_FLOAT, stride, vertices ); + if( texture != NULL ) + { + glEnableClientState( GL_TEXTURE_COORD_ARRAY ); + glTexCoordPointer( 2, GL_FLOAT, stride, texture ); + } + // Render + if( !clip ) + // Just draw the entire window, no clipping + glDrawArrays( GL_QUADS, 0, count ); + else + { + // Make sure there's only a single quad (no transformed vertices) + // Clip using scissoring + glEnable( GL_SCISSOR_TEST ); + int dh = displayHeight(); + foreach( QRect r, region.rects()) + { + // Scissor rect has to be given in OpenGL coords + glScissor(r.x(), dh - r.y() - r.height(), r.width(), r.height()); + glDrawArrays( GL_QUADS, 0, count ); + } + } + glPopClientAttrib(); + glPopAttrib(); + } + #ifdef HAVE_OPENGL //**************************************** diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index bef11250e5..8531b2f621 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -59,6 +59,16 @@ int KWIN_EXPORT nearestPowerOfTwo( int x ); #ifdef HAVE_OPENGL +// renders quads using the given vertices +KWIN_EXPORT void renderGLGeometry( bool clip, QRegion region, const float* vertices, const float* texture, int count, + int dim = 2, int stride = 0 ); +// sets clip according to mask +KWIN_EXPORT void renderGLGeometry( int mask, QRegion region, const float* vertices, const float* texture, int count, + int dim = 2, int stride = 0 ); +// clip = false +KWIN_EXPORT void renderGLGeometry( const float* vertices, const float* texture, int count, + int dim = 2, int stride = 0 ); + class KWIN_EXPORT GLTexture { public: diff --git a/scene_opengl.cpp b/scene_opengl.cpp index 4d5ddddbb9..fb8c9baaf9 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -1213,7 +1213,9 @@ void SceneOpenGL::Window::performPaint( int mask, QRegion region, WindowPaintDat texture.enableUnnormalizedTexCoords(); // Render geometry - renderGeometry( mask, region ); + region.translate( toplevel->x(), toplevel->y() ); // Back to screen coords + renderGLGeometry( mask, region, verticeslist[ 0 ].pos, verticeslist[ 0 ].texcoord, + verticeslist.count(), 3, sizeof( Vertex )); texture.disableUnnormalizedTexCoords(); glPopMatrix(); @@ -1367,39 +1369,6 @@ void SceneOpenGL::Window::prepareRenderStates( int mask, WindowPaintData data ) } } -void SceneOpenGL::Window::renderGeometry( int mask, QRegion region ) - { - // Enable arrays - glEnableClientState( GL_VERTEX_ARRAY ); - glVertexPointer(3, GL_FLOAT, sizeof(Vertex), verticeslist[0].pos); - glEnableClientState( GL_TEXTURE_COORD_ARRAY ); - glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), verticeslist[0].texcoord); - - // Render - if( mask & ( PAINT_WINDOW_TRANSFORMED | PAINT_SCREEN_TRANSFORMED )) - // Just draw the entire window, no clipping - glDrawArrays( GL_QUADS, 0, verticeslist.count() ); - else - { - // Make sure there's only a single quad (no transformed vertices) - // Clip using scissoring - glEnable( GL_SCISSOR_TEST ); - region.translate( toplevel->x(), toplevel->y() ); // Back to screen coords - int dh = displayHeight(); - foreach( QRect r, region.rects()) - { - // Scissor rect has to be given in OpenGL coords - glScissor(r.x(), dh - r.y() - r.height(), r.width(), r.height()); - glDrawArrays( GL_QUADS, 0, verticeslist.count() ); - } - glDisable( GL_SCISSOR_TEST ); - } - - // Disable arrays - glDisableClientState( GL_VERTEX_ARRAY ); - glDisableClientState( GL_TEXTURE_COORD_ARRAY ); - } - void SceneOpenGL::Window::restoreShaderRenderStates( int mask, WindowPaintData data ) { Q_UNUSED( mask ); diff --git a/scene_opengl.h b/scene_opengl.h index 235095b207..cb93b5cb58 100644 --- a/scene_opengl.h +++ b/scene_opengl.h @@ -143,7 +143,6 @@ class SceneOpenGL::Window void prepareRenderStates( int mask, WindowPaintData data ); void prepareShaderRenderStates( int mask, WindowPaintData data ); - void renderGeometry( int mask, QRegion region ); void restoreRenderStates( int mask, WindowPaintData data ); void restoreShaderRenderStates( int mask, WindowPaintData data );