>From 947c9c54f233508a595279b260c25d4500094164 Mon Sep 17 00:00:00 2001
From: Frederic Plourde <[email protected]>
Date: Thu, 29 Sep 2011 15:58:07 -0400
Subject: [PATCH gles] Get rid of irrelevant GLVertexBuffer operations
when using custom shaders

The actual GLVertexBuffer implementation assumes we're using the "main"
opengl
shaders for drawing... Specifying the shader's projection and modelview
matrices, as well as paintAttribs in an hard-coded manner in the ::render
private function. Since we now have user plugins ported to gles, this
assumption isn't true anymore.
---
 plugins/opengl/include/opengl/vertexbuffer.h |    4 ++
 plugins/opengl/src/privatevertexbuffer.h     |    2 +
 plugins/opengl/src/vertexbuffer.cpp          |   47
++++++++++++++++++-------
 3 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/plugins/opengl/include/opengl/vertexbuffer.h
b/plugins/opengl/include/opengl/vertexbuffer.h
index 57ad79d..9801649 100644
--- a/plugins/opengl/include/opengl/vertexbuffer.h
+++ b/plugins/opengl/include/opengl/vertexbuffer.h
@@ -79,6 +79,10 @@ class GLVertexBuffer
 
     void setProgram (GLProgram *program);
 
+    // this 0-argument render function is useful for user plugins that
define
+    // their own projection/modelview/attribs through uniforms
+    int render ();
+
     int render (const GLMatrix &modelview);
 
     int render (const GLMatrix            &modelview,
diff --git a/plugins/opengl/src/privatevertexbuffer.h
b/plugins/opengl/src/privatevertexbuffer.h
index b91253a..59d21e6 100644
--- a/plugins/opengl/src/privatevertexbuffer.h
+++ b/plugins/opengl/src/privatevertexbuffer.h
@@ -130,6 +130,8 @@ class PrivateVertexBuffer
     GLuint colorBuffer;
     GLuint textureBuffers[4];
     std::vector<AbstractUniform*> uniforms;
+
+    bool renderForMainShader;
 };
 
 #endif //_VERTEXBUFFER_PRIVATE_H
diff --git a/plugins/opengl/src/vertexbuffer.cpp
b/plugins/opengl/src/vertexbuffer.cpp
index c7bb38b..5e5a90e 100644
--- a/plugins/opengl/src/vertexbuffer.cpp
+++ b/plugins/opengl/src/vertexbuffer.cpp
@@ -269,6 +269,16 @@ void GLVertexBuffer::setProgram (GLProgram *program)
     priv->program = program;
 }
 
+int GLVertexBuffer::render ()
+{
+    GLScreen *gScreen = GLScreen::get (screen);
+    const GLWindowPaintAttrib dummyAttrib = { 0, 0, 0, 0, 0, 0, 0 };
+    
+    priv->renderForMainShader = false;
+    GLMatrix *dummyMatrix = gScreen->projectionMatrix ();
+    return render (*dummyMatrix, *dummyMatrix, dummyAttrib);
+}
+
 int GLVertexBuffer::render (const GLMatrix &modelview)
 {
     const GLWindowPaintAttrib attrib = { OPAQUE, BRIGHT, COLOR, 0, 0,
0, 0 };
@@ -300,6 +310,9 @@ int GLVertexBuffer::render (const
GLMatrix            &projection,
     return priv->legacyRender (projection, modelview, attrib);
 
     glDisable (GL_BLEND);
+
+    // maybe we're going to be using this VBO with the main open
shaders next.
+    priv->renderForMainShader = true;
 }
 
 PrivateVertexBuffer::PrivateVertexBuffer () :
@@ -348,8 +361,11 @@ int PrivateVertexBuffer::render (const
GLMatrix            &projection,
     return -1;
     }
 
-    program->setUniform ("projection", projection);
-    program->setUniform ("modelview", modelview);
+    if (renderForMainShader)
+    {
+    program->setUniform ("projection", projection);
+    program->setUniform ("modelview", modelview);
+    }
 
     positionIndex = program->attributeLocation ("position");
     (*GL::enableVertexAttribArray) (positionIndex);
@@ -359,7 +375,8 @@ int PrivateVertexBuffer::render (const
GLMatrix            &projection,
     //use default normal
     if (normalData.size () == 0)
     {
-    program->setUniform3f ("singleNormal", 0.0f, 0.0f, -1.0f);
+    if (renderForMainShader)
+        program->setUniform3f ("singleNormal", 0.0f, 0.0f, -1.0f);
     }
     // special case a single normal and apply it to the entire operation
     else if (normalData.size () == 3)
@@ -391,9 +408,6 @@ int PrivateVertexBuffer::render (const
GLMatrix            &projection,
     params[1] = 1.0;
     }
 
-    //divide number of textures by 4 to get 0-1 range
-    params[2] = textureData.size () / 4.0f;
-
     for (int i = textureData.size () - 1; i >= 0; i--)
     {
     char name[10];
@@ -415,13 +429,20 @@ int PrivateVertexBuffer::render (const
GLMatrix            &projection,
     uniforms[i]->set (program);
     }
 
-    //convert paint attribs to 0-1 range
-    attribs[0] = attrib.opacity  / 65535.0f;
-    attribs[1] = attrib.brightness / 65535.0f;
-    attribs[2] = attrib.saturation / 65535.0f;
-    program->setUniform3f ("paintAttrib", attribs[0], attribs[1],
attribs[2]);
-
-    program->setUniform4f ("params", params[0], params[1], params[2],
params[3]);
+    if (renderForMainShader)
+    {
+        // divide number of textures by 4 to get 0-1 range
+        params[2] = textureData.size () / 4.0f;
+        
+    // convert paint attribs to 0-1 range
+    attribs[0] = attrib.opacity  / 65535.0f;
+    attribs[1] = attrib.brightness / 65535.0f;
+    attribs[2] = attrib.saturation / 65535.0f;
+    program->setUniform3f ("paintAttrib", attribs[0], attribs[1],
attribs[2]);
+
+    program->setUniform4f ("params", params[0], params[1], params[2],
params[3]);
+    }
+    
     glDrawArrays (primitiveType, 0, vertexData.size () / 3);
 
     for (int i = 0; i < 4; ++i)
-- 
1.7.4.1
_______________________________________________
dev mailing list
[email protected]
http://lists.compiz.org/mailman/listinfo/dev

Reply via email to