Before this, the GLProgram attached to the singleton streamingBuffer was
created in GLWindow::glDrawTexture () from whatever shaders happened to
be in priv->shaders, with the shaders.h shaders on top. This
initialisation is too late for the first call to
PrivateGLScreen::paintBackground (), hence the program is still NULL,
and no wallpaper is rendered on compiz startup.

This patch creates a static GLShaderData object
PrivateGLScreen::mainShaders for containing the main shaders from
shaders.h (names changed accordingly).

GLScreen constructor takes care of initialising streamingBuffer and
its GLProgram. This makes sure the initialisation happens before first
use of streamingBuffer.

The ugly part, which is why mainShaders is static, is that mainShaders
is also needed in GLWindow::glDrawTexture (). The memory leaking
behaviour of PrivateGLWindow::shaders is retained.

This patch fixes the background painting bug on compiz startup.

Signed-off-by: Pekka Paalanen <[email protected]>
---
 plugins/opengl/src/paint.cpp  |    4 +---
 plugins/opengl/src/privates.h |    1 +
 plugins/opengl/src/screen.cpp |    9 +++++++++
 plugins/opengl/src/shaders.h  |    4 ++--
 4 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/plugins/opengl/src/paint.cpp b/plugins/opengl/src/paint.cpp
index df0845e..01e433e 100644
--- a/plugins/opengl/src/paint.cpp
+++ b/plugins/opengl/src/paint.cpp
@@ -36,7 +36,6 @@
 #include <opengl/opengl.h>
 
 #include "privates.h"
-#include "shaders.h"
 
 
 GLScreenPaintAttrib defaultScreenPaintAttrib = {
@@ -1019,10 +1018,9 @@ GLWindow::glDrawTexture (GLTexture                 
*texture,
        filter = priv->gScreen->filter (NOTHING_TRANS_FILTER);
 
     // add the opengl functions (main) to the shader list, use it, then clear 
it
-    addShaders ("opengl", vertex_shader, fragment_shader);
+    priv->shaders.push_back (new GLShaderData (PrivateGLScreen::mainShaders));
     program = priv->gScreen->getProgram (priv->shaders);
     priv->vertexBuffer->setProgram (program);
-    GLVertexBuffer::streamingBuffer()->setProgram (program);
     priv->shaders.clear ();
 
     texture->enable (filter);
diff --git a/plugins/opengl/src/privates.h b/plugins/opengl/src/privates.h
index a25a27d..9664dad 100644
--- a/plugins/opengl/src/privates.h
+++ b/plugins/opengl/src/privates.h
@@ -129,6 +129,7 @@ class PrivateGLScreen :
        GLIcon defaultIcon;
 
        GLProgramCache *programCache;
+       static GLShaderData mainShaders;
 };
 
 class PrivateGLWindow :
diff --git a/plugins/opengl/src/screen.cpp b/plugins/opengl/src/screen.cpp
index af27693..51300f1 100644
--- a/plugins/opengl/src/screen.cpp
+++ b/plugins/opengl/src/screen.cpp
@@ -28,6 +28,7 @@
  */
 
 #include "privates.h"
+#include "shaders.h"
 
 #include <dlfcn.h>
 #include <math.h>
@@ -119,6 +120,8 @@ GLScreen::GLScreen (CompScreen *s) :
     PluginClassHandler<GLScreen, CompScreen, COMPIZ_OPENGL_ABI> (s),
     priv (new PrivateGLScreen (this))
 {
+    std::list<GLShaderData *> tempShaders;
+
     #ifdef USE_GLES
     Display             *xdpy;
     Window               overlay;
@@ -794,6 +797,9 @@ GLScreen::GLScreen (CompScreen *s) :
     if (GL::textureFromPixmap)
        registerBindPixmap (TfpTexture::bindPixmapToTexture);
     #endif
+
+    tempShaders.push_back(&PrivateGLScreen::mainShaders);
+    GLVertexBuffer::streamingBuffer ()->setProgram (getProgram (tempShaders));
 }
 
 GLScreen::~GLScreen ()
@@ -839,6 +845,9 @@ PrivateGLScreen::PrivateGLScreen (GLScreen   *gs) :
     ScreenInterface::setHandler (screen);
 }
 
+GLShaderData PrivateGLScreen::mainShaders = {
+    "opengl", mainVertexShader, mainFragmentShader };
+
 PrivateGLScreen::~PrivateGLScreen ()
 {
     delete programCache;
diff --git a/plugins/opengl/src/shaders.h b/plugins/opengl/src/shaders.h
index 9ed4032..2bd08b5 100644
--- a/plugins/opengl/src/shaders.h
+++ b/plugins/opengl/src/shaders.h
@@ -26,7 +26,7 @@
 #ifndef _COMPIZ_GLSHADERS_H
 #define _COMPIZ_GLSHADERS_H
 
-static std::string vertex_shader = "                            \n\
+static const char mainVertexShader[] = "                        \n\
 #ifdef GL_ES                                                    \n\
 precision mediump float;                                        \n\
 #endif                                                          \n\
@@ -76,7 +76,7 @@ void main () {                                                
  \n\
 // - y is brightness
 // - z is saturation
 
-static std::string fragment_shader = "                                       
\n\
+static const char mainFragmentShader[] = "                                   
\n\
 #ifdef GL_ES                                                                 
\n\
 precision mediump float;                                                     
\n\
 #endif                                                                       
\n\
-- 
1.7.3.4

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

Reply via email to