[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/kwin_composite
From:       Luboš Luňák <l.lunak () kde ! org>
Date:       2007-04-21 16:02:21
Message-ID: 1177171341.249198.28974.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 656516 by lunakl:

Shared implementation of rendering gl geometry.



 M  +7 -19     effects/boxswitch.cpp  
 M  +3 -9      effects/demo_showpicture.cpp  
 M  +3 -9      effects/presentwindows.cpp  
 M  +3 -17     effects/shadow.cpp  
 M  +3 -9      effects/trackmouse.cpp  
 M  +47 -0     lib/kwinglutils.cpp  
 M  +10 -0     lib/kwinglutils.h  
 M  +3 -34     scene_opengl.cpp  
 M  +0 -1      scene_opengl.h  


--- branches/work/kwin_composite/effects/boxswitch.cpp #656515:656516
@@ -429,17 +429,14 @@
         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 @@
         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 @@
         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();
         }
--- branches/work/kwin_composite/effects/demo_showpicture.cpp #656515:656516
@@ -44,31 +44,25 @@
         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();
         }
--- branches/work/kwin_composite/effects/presentwindows.cpp #656515:656516
@@ -127,31 +127,25 @@
         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();
         }
--- branches/work/kwin_composite/effects/shadow.cpp #656515:656516
@@ -64,29 +64,15 @@
     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();
     }
--- branches/work/kwin_composite/effects/trackmouse.cpp #656515:656516
@@ -67,27 +67,21 @@
              ++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();
--- branches/work/kwin_composite/lib/kwinglutils.cpp #656515:656516
@@ -11,6 +11,7 @@
 #include "kwinglutils.h"
 
 #include "kwinglobals.h"
+#include "kwineffects.h"
 
 #include "kdebug.h"
 
@@ -113,6 +114,52 @@
     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
 
 //****************************************
--- branches/work/kwin_composite/lib/kwinglutils.h #656515:656516
@@ -59,6 +59,16 @@
 
 #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:
--- branches/work/kwin_composite/scene_opengl.cpp #656515:656516
@@ -1213,7 +1213,9 @@
     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::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 );
--- branches/work/kwin_composite/scene_opengl.h #656515:656516
@@ -143,7 +143,6 @@
 
         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 );
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic