Contrary to the comment in vertexbuffer.h, the default primitive mode in
GLVertexBuffer is GL_TRIANGLES.

PrivateGLScreen::paintBackground () attempted to render several
rectangles in one call, using GL_TRIANGLE_STRIP. This renders unwanted
extra triangles.

Convert it to assemble each rectangle from two separate triangles.
Explicitly use the GL_TRIANGLES primitive type to avoid confusion.

This fixes background rendering artifacts that were rarely visible.

Signed-off-by: Pekka Paalanen <[email protected]>
---
 plugins/opengl/include/opengl/vertexbuffer.h |    2 +-
 plugins/opengl/src/paint.cpp                 |   72 +++++++++++++++++++------
 2 files changed, 55 insertions(+), 19 deletions(-)

diff --git a/plugins/opengl/include/opengl/vertexbuffer.h 
b/plugins/opengl/include/opengl/vertexbuffer.h
index f819685..f791a04 100644
--- a/plugins/opengl/include/opengl/vertexbuffer.h
+++ b/plugins/opengl/include/opengl/vertexbuffer.h
@@ -48,7 +48,7 @@ class GLVertexBuffer
        static GLVertexBuffer *streamingBuffer ();
 
        void begin (GLenum primitiveType);
-       // default primitiveType is GL_TRIANGLE_STRIP
+       // default primitiveType is GL_TRIANGLES
        void begin ();
        int end ();
 
diff --git a/plugins/opengl/src/paint.cpp b/plugins/opengl/src/paint.cpp
index 01e433e..cfd4342 100644
--- a/plugins/opengl/src/paint.cpp
+++ b/plugins/opengl/src/paint.cpp
@@ -70,7 +70,7 @@ PrivateGLScreen::paintBackground (const GLMatrix   &transform,
                                   bool             transformed)
 {
     GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
-    GLfloat         vertexData[12];
+    GLfloat         vertexData[18];
     GLushort        colorData[4];
 
     BoxPtr    pBox = const_cast <Region> (region.handle ())->rects;
@@ -102,24 +102,35 @@ PrivateGLScreen::paintBackground (const GLMatrix   
&transform,
 
     if (backgroundTextures.empty ())
     {
-       streamingBuffer->begin (GL_TRIANGLE_STRIP);
+       streamingBuffer->begin (GL_TRIANGLES);
 
        while (n--)
        {
            vertexData[0]  = pBox->x1;
            vertexData[1]  = pBox->y1;
            vertexData[2]  = 0.0f;
+
            vertexData[3]  = pBox->x1;
            vertexData[4]  = pBox->y2;
            vertexData[5]  = 0.0f;
+
            vertexData[6]  = pBox->x2;
            vertexData[7]  = pBox->y1;
            vertexData[8]  = 0.0f;
-           vertexData[9]  = pBox->x2;
+
+           vertexData[9]  = pBox->x1;
            vertexData[10] = pBox->y2;
            vertexData[11] = 0.0f;
 
-           streamingBuffer->addVertices (4, vertexData);
+           vertexData[12] = pBox->x2;
+           vertexData[13] = pBox->y2;
+           vertexData[14] = 0.0f;
+
+           vertexData[15] = pBox->x2;
+           vertexData[16] = pBox->y1;
+           vertexData[17] = 0.0f;
+
+           streamingBuffer->addVertices (6, vertexData);
 
            pBox++;
        }
@@ -135,7 +146,7 @@ PrivateGLScreen::paintBackground (const GLMatrix   
&transform,
     {
        for (unsigned int i = 0; i < backgroundTextures.size (); i++)
        {
-           GLfloat textureData[8];
+           GLfloat textureData[12];
            GLTexture *bg = backgroundTextures[i];
            CompRegion r = region & *bg;
 
@@ -143,34 +154,59 @@ PrivateGLScreen::paintBackground (const GLMatrix   
&transform,
            nBox = const_cast <Region> (r.handle ())->numRects;
            n = nBox;
 
-           streamingBuffer->begin (GL_TRIANGLE_STRIP);
+           streamingBuffer->begin (GL_TRIANGLES);
 
            while (n--)
            {
+               GLfloat tx1 = COMP_TEX_COORD_X (bg->matrix (), pBox->x1);
+               GLfloat tx2 = COMP_TEX_COORD_X (bg->matrix (), pBox->x2);
+               GLfloat ty1 = COMP_TEX_COORD_Y (bg->matrix (), pBox->y1);
+               GLfloat ty2 = COMP_TEX_COORD_Y (bg->matrix (), pBox->y2);
+
                vertexData[0]  = pBox->x1;
                vertexData[1]  = pBox->y1;
                vertexData[2]  = 0.0f;
+
                vertexData[3]  = pBox->x1;
                vertexData[4]  = pBox->y2;
                vertexData[5]  = 0.0f;
+
                vertexData[6]  = pBox->x2;
                vertexData[7]  = pBox->y1;
                vertexData[8]  = 0.0f;
-               vertexData[9]  = pBox->x2;
+
+               vertexData[9]  = pBox->x1;
                vertexData[10] = pBox->y2;
                vertexData[11] = 0.0f;
 
-               textureData[0] = COMP_TEX_COORD_X (bg->matrix (), pBox->x1);
-               textureData[1] = COMP_TEX_COORD_Y (bg->matrix (), pBox->y1);
-               textureData[2] = COMP_TEX_COORD_X (bg->matrix (), pBox->x1);
-               textureData[3] = COMP_TEX_COORD_Y (bg->matrix (), pBox->y2);
-               textureData[4] = COMP_TEX_COORD_X (bg->matrix (), pBox->x2);
-               textureData[5] = COMP_TEX_COORD_Y (bg->matrix (), pBox->y1);
-               textureData[6] = COMP_TEX_COORD_X (bg->matrix (), pBox->x2);
-               textureData[7] = COMP_TEX_COORD_Y (bg->matrix (), pBox->y2);
-
-               streamingBuffer->addVertices (4, vertexData);
-               streamingBuffer->addTexCoords (0, 4, textureData);
+               vertexData[12] = pBox->x2;
+               vertexData[13] = pBox->y2;
+               vertexData[14] = 0.0f;
+
+               vertexData[15] = pBox->x2;
+               vertexData[16] = pBox->y1;
+               vertexData[17] = 0.0f;
+
+               textureData[0]  = tx1;
+               textureData[1]  = ty1;
+
+               textureData[2]  = tx1;
+               textureData[3]  = ty2;
+
+               textureData[4]  = tx2;
+               textureData[5]  = ty1;
+
+               textureData[6]  = tx1;
+               textureData[7]  = ty2;
+
+               textureData[8]  = tx2;
+               textureData[9]  = ty2;
+
+               textureData[10] = tx2;
+               textureData[11] = ty1;
+
+               streamingBuffer->addVertices (6, vertexData);
+               streamingBuffer->addTexCoords (0, 6, textureData);
 
                pBox++;
            }
-- 
1.7.3.4

_______________________________________________
dev mailing list
[email protected]
http://lists.compiz.org/mailman/listinfo/dev

Reply via email to