summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Watkins <travis.watkins@linaro.org>2011-08-05 11:33:42 +0100
committerTravis Watkins <travis.watkins@linaro.org>2011-08-05 11:33:42 +0100
commit5baedd1f242153db2a07bf2bf34ed1c04385f33d (patch)
tree25c477088a45d6326c64b357c206de63c83276f5
parent5b765b065aafeb76f60f29e13f99f844815678e9 (diff)
downloadmobileperf-5baedd1f242153db2a07bf2bf34ed1c04385f33d.tar.gz
mobileperf-5baedd1f242153db2a07bf2bf34ed1c04385f33d.tar.bz2
first pass of new shader framework
Add new framework for handling per-plugin shaders. Plugins hook GLWindow::glDraw and add their shader functions to the list. The opengl plugin then adds its functions and tries to get a GLProgram from the cache. If the cache does not currently have a program with that set of plugins enabled a new GLProgram will be created and added to the cache. The cache is a LRU with a configurable max capacity. Also moved opengl plugin shaders to shaders.h instead of separate files that get loaded at runtime.
-rw-r--r--plugins/opengl/CMakeLists.txt14
-rw-r--r--plugins/opengl/include/opengl/opengl.h25
-rw-r--r--plugins/opengl/include/opengl/program.h2
-rw-r--r--plugins/opengl/include/opengl/programcache.h51
-rw-r--r--plugins/opengl/include/opengl/vertexbuffer.h3
-rw-r--r--plugins/opengl/src/generic_fragment.glsl55
-rw-r--r--plugins/opengl/src/generic_vertex.glsl32
-rw-r--r--plugins/opengl/src/paint.cpp8
-rw-r--r--plugins/opengl/src/privates.h6
-rw-r--r--plugins/opengl/src/privatevertexbuffer.h3
-rw-r--r--plugins/opengl/src/program.cpp24
-rw-r--r--plugins/opengl/src/programcache.cpp133
-rw-r--r--plugins/opengl/src/screen.cpp9
-rw-r--r--plugins/opengl/src/shaders.h121
-rw-r--r--plugins/opengl/src/vertexbuffer.cpp24
-rw-r--r--plugins/opengl/src/window.cpp13
16 files changed, 381 insertions, 142 deletions
diff --git a/plugins/opengl/CMakeLists.txt b/plugins/opengl/CMakeLists.txt
index 3274c2a..e1f7495 100644
--- a/plugins/opengl/CMakeLists.txt
+++ b/plugins/opengl/CMakeLists.txt
@@ -2,20 +2,6 @@ find_package (Compiz REQUIRED)
include (CompizPlugin)
-add_definitions (
- -DMETADATADIR=\\\"${compiz_metadatadir}\\\"
-)
-
-set (_shaders
- src/generic_vertex.glsl
- src/generic_fragment.glsl
-)
-
-install (
- FILES ${_shaders}
- DESTINATION ${COMPIZ_DESTDIR}${compiz_metadatadir}
-)
-
if (USE_GLES)
compiz_plugin(opengl PLUGINDEPS composite CFLAGSADD -DUSE_GLES LIBRARIES ${OPENGLES2_LIBRARIES} INCDIRS ${OPENGLES2_INCLUDE_DIR})
else (USE_GLES)
diff --git a/plugins/opengl/include/opengl/opengl.h b/plugins/opengl/include/opengl/opengl.h
index a9ce09a..0bc6f94 100644
--- a/plugins/opengl/include/opengl/opengl.h
+++ b/plugins/opengl/include/opengl/opengl.h
@@ -43,6 +43,7 @@
#include <opengl/texture.h>
#include <opengl/vertexbuffer.h>
#include <opengl/program.h>
+#include <opengl/programcache.h>
#define COMPIZ_OPENGL_ABI 3
@@ -288,6 +289,13 @@ struct GLFBConfig {
};
#endif
+struct GLShaderData
+{
+ std::string name;
+ std::string vertex_shader;
+ std::string fragment_shader;
+};
+
#define NOTHING_TRANS_FILTER 0
#define SCREEN_TRANS_FILTER 1
#define WINDOW_TRANS_FILTER 2
@@ -443,6 +451,11 @@ class GLScreen :
#endif
/**
+ * Returns a GLProgram from the cache or creates one and caches it
+ */
+ GLProgram *getProgram (std::list<GLShaderData*>);
+
+ /**
* Returns a default icon texture
*/
GLTexture *defaultIcon ();
@@ -600,6 +613,17 @@ class GLWindow :
*/
GLVertexBuffer * vertexBuffer ();
+ /**
+ * Add a vertex and/or fragment shader function to the pipeline.
+ *
+ * @param name Name of the plugin adding the functions
+ * @param vertex_shader Function to add to the vertex shader
+ * @param fragment_shader Function to add to the fragment shader
+ */
+ void addShaders (std::string name,
+ std::string vertex_shader,
+ std::string fragment_shader);
+
GLTexture *getIcon (int width, int height);
WRAPABLE_HND (0, GLWindowInterface, bool, glPaint,
@@ -624,3 +648,4 @@ class GLWindow :
};
#endif
+
diff --git a/plugins/opengl/include/opengl/program.h b/plugins/opengl/include/opengl/program.h
index 396e912..f7ac571 100644
--- a/plugins/opengl/include/opengl/program.h
+++ b/plugins/opengl/include/opengl/program.h
@@ -40,7 +40,7 @@ class PrivateProgram;
class GLProgram
{
public:
- GLProgram (CompString &vertexFile, CompString &fragmentFile);
+ GLProgram (CompString &vertexShader, CompString &fragmentShader);
~GLProgram ();
bool valid ();
diff --git a/plugins/opengl/include/opengl/programcache.h b/plugins/opengl/include/opengl/programcache.h
new file mode 100644
index 0000000..c2784f1
--- /dev/null
+++ b/plugins/opengl/include/opengl/programcache.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright © 2011 Linaro Ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Linaro Ltd. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Linaro Ltd. makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * LINARO LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL LINARO LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Travis Watkins <travis.watkins@linaro.org>
+ */
+
+#ifndef _COMPIZ_GLPROGRAMCACHE_H
+#define _COMPIZ_GLPROGRAMCACHE_H
+
+#include <string>
+#include <list>
+#include <map>
+#include <boost/bind.hpp>
+#include <opengl/program.h>
+
+class PrivateProgramCache;
+struct GLShaderData;
+
+class GLProgramCache
+{
+ private:
+ PrivateProgramCache *priv;
+
+ public:
+ GLProgramCache (size_t);
+ ~GLProgramCache ();
+
+ GLProgram* operator () (std::list<GLShaderData*>);
+};
+
+#endif // _COMPIZ_GLPROGRAMCACHE_H
+
diff --git a/plugins/opengl/include/opengl/vertexbuffer.h b/plugins/opengl/include/opengl/vertexbuffer.h
index 1707618..f819685 100644
--- a/plugins/opengl/include/opengl/vertexbuffer.h
+++ b/plugins/opengl/include/opengl/vertexbuffer.h
@@ -64,9 +64,8 @@ class GLVertexBuffer
GLuint nTexcoords,
GLfloat *texcoords);
- void useProgram (GLProgram *program);
+ void setProgram (GLProgram *program);
- // render data using default shader or given one
int render (const GLMatrix &modelview);
int render (const GLMatrix &modelview,
diff --git a/plugins/opengl/src/generic_fragment.glsl b/plugins/opengl/src/generic_fragment.glsl
deleted file mode 100644
index 32a0b2a..0000000
--- a/plugins/opengl/src/generic_fragment.glsl
+++ /dev/null
@@ -1,55 +0,0 @@
-#if __VERSION__ == 100
-precision mediump float;
-#endif
-
-//params is a 4-part system for determining how to draw the scene
-// - x is whether or not to use a single color for drawing
-// - y is whether or not to use the varying color for drawing
-// - z is the number of texture units to use
-// - w is the blend mode to use
-uniform vec4 params;
-
-//paintAttrib is a list of opacity, brightness, and saturation values
-// - x is opacity
-// - y is brightness
-// - z is saturation
-uniform vec3 paintAttrib;
-
-uniform sampler2D texture0;
-uniform sampler2D texture1;
-uniform sampler2D texture2;
-uniform sampler2D texture3;
-
-uniform vec4 singleColor;
-
-varying vec4 vColor;
-varying vec2 vTexCoord0;
-varying vec2 vTexCoord1;
-varying vec2 vTexCoord2;
-varying vec2 vTexCoord3;
-
-void main () {
- vec4 color = vec4 (1, 1, 1, 1);
-
- if (params.x == 1.0)
- color *= singleColor;
- if (params.y == 1.0)
- color *= vColor;
-
- if (params.z == 0.25)
- color *= texture2D (texture0, vTexCoord0);
-
- if (paintAttrib.z != 1.0)
- {
- vec3 desaturated = color.rgb * vec3 (0.30, 0.59, 0.11);
- desaturated = vec3 (dot (desaturated, color.rgb));
- color.rgb = color.rgb * vec3 (paintAttrib.z) + desaturated *
- vec3 (1.0 - paintAttrib.z);
- }
-
- color.rgb = color.rgb * paintAttrib.x * paintAttrib.y;
- color.a = color.a * paintAttrib.x;
-
- gl_FragColor = color;
-}
-
diff --git a/plugins/opengl/src/generic_vertex.glsl b/plugins/opengl/src/generic_vertex.glsl
deleted file mode 100644
index b3a7b08..0000000
--- a/plugins/opengl/src/generic_vertex.glsl
+++ /dev/null
@@ -1,32 +0,0 @@
-#if __VERSION__ == 100
-precision mediump float;
-#endif
-
-uniform vec3 singleNormal;
-uniform mat4 modelview;
-uniform mat4 projection;
-
-attribute vec3 normal;
-attribute vec4 color;
-attribute vec2 texCoord0;
-attribute vec2 texCoord1;
-attribute vec2 texCoord2;
-attribute vec2 texCoord3;
-attribute vec3 position;
-
-varying vec4 vColor;
-varying vec2 vTexCoord0;
-varying vec2 vTexCoord1;
-varying vec2 vTexCoord2;
-varying vec2 vTexCoord3;
-
-void main () {
- vTexCoord0 = texCoord0;
- vTexCoord1 = texCoord1;
- vTexCoord2 = texCoord2;
- vTexCoord3 = texCoord3;
- vColor = color;
-
- gl_Position = projection * modelview * vec4(position, 1.0);
-}
-
diff --git a/plugins/opengl/src/paint.cpp b/plugins/opengl/src/paint.cpp
index d52c5d3..316b381 100644
--- a/plugins/opengl/src/paint.cpp
+++ b/plugins/opengl/src/paint.cpp
@@ -36,6 +36,7 @@
#include <opengl/opengl.h>
#include "privates.h"
+#include "shaders.h"
GLScreenPaintAttrib defaultScreenPaintAttrib = {
@@ -1040,6 +1041,7 @@ GLWindow::glDraw (const GLMatrix &transform,
WRAPABLE_HND_FUNC_RETURN (1, bool, glDraw, transform,
attrib, region, mask)
+ GLProgram *program = NULL;
const CompRegion reg = (mask & PAINT_WINDOW_TRANSFORMED_MASK) ?
infiniteRegion : region;
@@ -1055,6 +1057,12 @@ GLWindow::glDraw (const GLMatrix &transform,
if (mask & PAINT_WINDOW_TRANSLUCENT_MASK)
mask |= PAINT_WINDOW_BLEND_MASK;
+ // add the opengl functions (main) to the shader list, use it, then clear it
+ addShaders ("opengl", vertex_shader, fragment_shader);
+ program = priv->gScreen->getProgram (priv->shaders);
+ priv->vertexBuffer->setProgram (program);
+ priv->shaders.clear ();
+
GLTexture::MatrixList ml (1);
if (priv->textures.size () == 1)
diff --git a/plugins/opengl/src/privates.h b/plugins/opengl/src/privates.h
index 7f4b38b..a25a27d 100644
--- a/plugins/opengl/src/privates.h
+++ b/plugins/opengl/src/privates.h
@@ -127,6 +127,8 @@ class PrivateGLScreen :
bool hasCompositing;
GLIcon defaultIcon;
+
+ GLProgramCache *programCache;
};
class PrivateGLWindow :
@@ -171,6 +173,10 @@ class PrivateGLWindow :
GLVertexBuffer *vertexBuffer;
+ // map of shaders, plugin name is key, pair of vertex and fragment
+ // shader source code is value
+ std::list<GLShaderData*> shaders;
+
std::list<GLIcon> icons;
};
diff --git a/plugins/opengl/src/privatevertexbuffer.h b/plugins/opengl/src/privatevertexbuffer.h
index 39adc03..71a2bcb 100644
--- a/plugins/opengl/src/privatevertexbuffer.h
+++ b/plugins/opengl/src/privatevertexbuffer.h
@@ -51,14 +51,13 @@ class PrivateVertexBuffer
public:
static GLVertexBuffer *streamingBuffer;
- static GLProgram *genericProgram;
std::vector<GLfloat> vertexData;
std::vector<GLfloat> normalData;
std::vector<GLfloat> colorData;
std::vector<std::vector<GLfloat> > textureData;
- GLProgram *customProgram;
+ GLProgram *program;
GLenum primitiveType;
GLenum usage;
diff --git a/plugins/opengl/src/program.cpp b/plugins/opengl/src/program.cpp
index 9abe2a8..5f24dc0 100644
--- a/plugins/opengl/src/program.cpp
+++ b/plugins/opengl/src/program.cpp
@@ -71,26 +71,12 @@ void printProgramInfoLog(GLuint program)
}
}
-static bool compileShader (GLuint *shader, GLenum type, CompString &path)
+static bool compileShader (GLuint *shader, GLenum type, CompString &source)
{
- std::ifstream in;
const GLchar *data;
GLint status;
- if (path[0] != '/')
- {
- std::string temp = METADATADIR;
- temp.append ("/");
- temp.append (path);
- path = temp;
- }
-
- in.open (path.c_str (), std::ios::in);
-
- std::string temp((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
- in.close ();
-
- data = (GLchar *)temp.c_str ();
+ data = (GLchar *)source.c_str ();
*shader = glCreateShader (type);
glShaderSource (*shader, 1, &data, NULL);
@@ -100,7 +86,7 @@ static bool compileShader (GLuint *shader, GLenum type, CompString &path)
return (status == GL_TRUE);
}
-GLProgram::GLProgram (CompString &vertexFile, CompString &fragmentFile) :
+GLProgram::GLProgram (CompString &vertexShader, CompString &fragmentShader) :
priv (new PrivateProgram ())
{
GLuint vertex, fragment;
@@ -109,13 +95,13 @@ GLProgram::GLProgram (CompString &vertexFile, CompString &fragmentFile) :
priv->valid = false;
priv->program = glCreateProgram ();
- if (!compileShader (&vertex, GL_VERTEX_SHADER, vertexFile))
+ if (!compileShader (&vertex, GL_VERTEX_SHADER, vertexShader))
{
printShaderInfoLog (vertex);
return;
}
- if (!compileShader (&fragment, GL_FRAGMENT_SHADER, fragmentFile))
+ if (!compileShader (&fragment, GL_FRAGMENT_SHADER, fragmentShader))
{
printShaderInfoLog (fragment);
return;
diff --git a/plugins/opengl/src/programcache.cpp b/plugins/opengl/src/programcache.cpp
new file mode 100644
index 0000000..23aaa4c
--- /dev/null
+++ b/plugins/opengl/src/programcache.cpp
@@ -0,0 +1,133 @@
+/*
+ * Copyright © 2011 Linaro Ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Linaro Ltd. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Linaro Ltd. makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * LINARO LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL LINARO LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Travis Watkins <travis.watkins@linaro.org>
+ */
+
+#include <opengl/programcache.h>
+#include "privates.h"
+
+typedef std::list<std::string> access_history_t;
+typedef std::pair<GLProgram*, access_history_t::iterator> value;
+
+static GLProgram *
+compileProgram (std::string name, std::list<GLShaderData*> shaders)
+{
+ std::list<GLShaderData*>::iterator it;
+ std::string vertex_shader;
+ std::string fragment_shader;
+
+ for (it = shaders.begin(); it != shaders.end(); it++)
+ {
+ vertex_shader += (*it)->vertex_shader;
+ fragment_shader += (*it)->fragment_shader;
+ }
+
+ return new GLProgram (vertex_shader, fragment_shader);
+}
+
+class PrivateProgramCache
+{
+ public:
+ PrivateProgramCache (size_t);
+
+ const size_t capacity;
+ access_history_t access_history;
+ std::map<std::string, value> cache;
+
+ void insert (std::string, GLProgram *);
+ void evict ();
+};
+
+GLProgramCache::GLProgramCache (size_t capacity) :
+ priv (new PrivateProgramCache (capacity))
+{
+ assert (priv->capacity != 0);
+}
+
+GLProgramCache::~GLProgramCache ()
+{
+ delete priv;
+}
+
+GLProgram* GLProgramCache::operator () (std::list<GLShaderData*> shaders)
+{
+ std::list<GLShaderData*>::iterator name_it;
+ std::string name;
+
+ for (name_it = shaders.begin(); name_it != shaders.end(); name_it++)
+ {
+ if (name.length () == 0)
+ name += (*name_it)->name;
+ else
+ name += ":" + (*name_it)->name;
+ }
+
+ std::map<std::string, value>::iterator it = priv->cache.find (name);
+
+ if (it == priv->cache.end ())
+ {
+ GLProgram *program = compileProgram (name, shaders);
+ priv->insert (name, program);
+ return program;
+ }
+ else
+ {
+ priv->access_history.splice (priv->access_history.end (),
+ priv->access_history,
+ (*it).second.second);
+ (*it).second.second = priv->access_history.rbegin ().base ();
+
+ return (*it).second.first;
+ }
+}
+
+PrivateProgramCache::PrivateProgramCache (size_t c) :
+ capacity (c)
+{
+}
+
+void PrivateProgramCache::insert (std::string name, GLProgram *program)
+{
+ assert (cache.find (name) == cache.end ());
+
+ if (cache.size () == capacity)
+ evict ();
+
+ // update most recently used GLProgram
+ access_history_t::iterator it = access_history.insert (access_history.end (), name);
+
+ cache.insert (std::make_pair (name, std::make_pair (program, it)));
+}
+
+void PrivateProgramCache::evict ()
+{
+ assert (!access_history.empty ());
+
+ // find least recently used GLProgram
+ std::map<std::string, value>::iterator it = cache.find (access_history.front ());
+ assert (it != cache.end ());
+
+ cache.erase (it);
+ access_history.pop_front ();
+}
+
diff --git a/plugins/opengl/src/screen.cpp b/plugins/opengl/src/screen.cpp
index a124f1a..01a87d9 100644
--- a/plugins/opengl/src/screen.cpp
+++ b/plugins/opengl/src/screen.cpp
@@ -780,7 +780,8 @@ PrivateGLScreen::PrivateGLScreen (GLScreen *gs) :
outputRegion (),
pendingCommands (false),
bindPixmap (),
- hasCompositing (false)
+ hasCompositing (false),
+ programCache (new GLProgramCache (30))
{
ScreenInterface::setHandler (screen);
}
@@ -1245,6 +1246,12 @@ GLScreen::getEGLContext ()
}
#endif
+GLProgram *
+GLScreen::getProgram (std::list<GLShaderData*> shaders)
+{
+ return (*priv->programCache)(shaders);
+}
+
void
PrivateGLScreen::waitForVideoSync ()
{
diff --git a/plugins/opengl/src/shaders.h b/plugins/opengl/src/shaders.h
new file mode 100644
index 0000000..59be443
--- /dev/null
+++ b/plugins/opengl/src/shaders.h
@@ -0,0 +1,121 @@
+/*
+ * Copyright © 2011 Linaro Ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Linaro Ltd. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Linaro Ltd. makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * LINARO LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL LINARO LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Travis Watkins <travis.watkins@linaro.org>
+ */
+
+#ifndef _COMPIZ_GLSHADERS_H
+#define _COMPIZ_GLSHADERS_H
+
+static std::string vertex_shader = " \n\
+#ifdef GL_ES \n\
+precision mediump float; \n\
+#endif \n\
+ \n\
+uniform vec3 singleNormal; \n\
+uniform mat4 modelview; \n\
+uniform mat4 projection; \n\
+ \n\
+attribute vec3 normal; \n\
+attribute vec4 color; \n\
+attribute vec2 texCoord0; \n\
+attribute vec2 texCoord1; \n\
+attribute vec2 texCoord2; \n\
+attribute vec2 texCoord3; \n\
+attribute vec3 position; \n\
+ \n\
+varying vec4 vColor; \n\
+varying vec2 vTexCoord0; \n\
+varying vec2 vTexCoord1; \n\
+varying vec2 vTexCoord2; \n\
+varying vec2 vTexCoord3; \n\
+ \n\
+void main () { \n\
+ vTexCoord0 = texCoord0; \n\
+ vTexCoord1 = texCoord1; \n\
+ vTexCoord2 = texCoord2; \n\
+ vTexCoord3 = texCoord3; \n\
+ vColor = color; \n\
+ \n\
+ gl_Position = projection * modelview * vec4(position, 1.0); \n\
+}";
+
+
+//params is a 4-part system for determining how to draw the scene
+// - x is whether or not to use a single color for drawing
+// - y is whether or not to use the varying color for drawing
+// - z is the number of texture units to use
+// - w is the blend mode to use
+
+//paintAttrib is a list of opacity, brightness, and saturation values
+// - x is opacity
+// - y is brightness
+// - z is saturation
+
+static std::string fragment_shader = " \n\
+#ifdef GL_ES \n\
+precision mediump float; \n\
+#endif \n\
+ \n\
+uniform vec4 params; \n\
+uniform vec3 paintAttrib; \n\
+ \n\
+uniform sampler2D texture0; \n\
+uniform sampler2D texture1; \n\
+uniform sampler2D texture2; \n\
+uniform sampler2D texture3; \n\
+ \n\
+uniform vec4 singleColor; \n\
+ \n\
+varying vec4 vColor; \n\
+varying vec2 vTexCoord0; \n\
+varying vec2 vTexCoord1; \n\
+varying vec2 vTexCoord2; \n\
+varying vec2 vTexCoord3; \n\
+ \n\
+void main () { \n\
+ vec4 color = vec4 (1, 1, 1, 1); \n\
+ \n\
+ if (params.x == 1.0) \n\
+ color *= singleColor; \n\
+ if (params.y == 1.0) \n\
+ color *= vColor; \n\
+ \n\
+ if (params.z == 0.25) \n\
+ color *= texture2D (texture0, vTexCoord0); \n\
+ \n\
+ if (paintAttrib.z != 1.0) \n\
+ { \n\
+ vec3 desaturated = color.rgb * vec3 (0.30, 0.59, 0.11); \n\
+ desaturated = vec3 (dot (desaturated, color.rgb)); \n\
+ color.rgb = color.rgb * vec3 (paintAttrib.z) + desaturated * \n\
+ vec3 (1.0 - paintAttrib.z); \n\
+ } \n\
+ \n\
+ color.rgb = color.rgb * paintAttrib.x * paintAttrib.y; \n\
+ color.a = color.a * paintAttrib.x; \n\
+ \n\
+ gl_FragColor = color; \n\
+}";
+
+#endif // _COMPIZ_GLSHADERS_H
+
diff --git a/plugins/opengl/src/vertexbuffer.cpp b/plugins/opengl/src/vertexbuffer.cpp
index 00c0092..52b6c4b 100644
--- a/plugins/opengl/src/vertexbuffer.cpp
+++ b/plugins/opengl/src/vertexbuffer.cpp
@@ -40,7 +40,6 @@
#include "privates.h"
GLVertexBuffer *PrivateVertexBuffer::streamingBuffer = NULL;
-GLProgram *PrivateVertexBuffer::genericProgram = NULL;
GLVertexBuffer::GLVertexBuffer () :
priv (new PrivateVertexBuffer ())
@@ -180,9 +179,9 @@ void GLVertexBuffer::addTexCoords (GLuint texture,
}
}
-void GLVertexBuffer::useProgram (GLProgram *program)
+void GLVertexBuffer::setProgram (GLProgram *program)
{
- priv->customProgram = program;
+ priv->program = program;
}
int GLVertexBuffer::render (const GLMatrix &modelview)
@@ -219,7 +218,7 @@ int GLVertexBuffer::render (const GLMatrix &projection,
}
PrivateVertexBuffer::PrivateVertexBuffer () :
- customProgram (NULL)
+ program (NULL)
{
if (!GL::vbo)
return;
@@ -230,13 +229,6 @@ PrivateVertexBuffer::PrivateVertexBuffer () :
textureBuffers.reserve (4);
GL::genBuffers (4, &textureBuffers[0]);
-
- if (PrivateVertexBuffer::genericProgram == NULL)
- {
- CompString vertex("generic_vertex.glsl");
- CompString fragment("generic_fragment.glsl");
- PrivateVertexBuffer::genericProgram = new GLProgram (vertex, fragment);
- }
}
PrivateVertexBuffer::~PrivateVertexBuffer ()
@@ -257,12 +249,12 @@ int PrivateVertexBuffer::render (const GLMatrix &projection,
GLfloat params[4] = {0, 0, 0, 0};
GLfloat attribs[3] = {1, 1, 1};
GLint index = 0;
- GLProgram *program;
- if (customProgram == NULL)
- program = genericProgram;
- else
- program = customProgram;
+ if (program == NULL)
+ {
+ std::cerr << "no program defined!" << std::endl;
+ return -1;
+ }
program->bind ();
if (!program->valid ())
diff --git a/plugins/opengl/src/window.cpp b/plugins/opengl/src/window.cpp
index 10a05dc..01fc150 100644
--- a/plugins/opengl/src/window.cpp
+++ b/plugins/opengl/src/window.cpp
@@ -267,6 +267,19 @@ GLWindow::getIcon (int width, int height)
}
void
+GLWindow::addShaders (std::string name,
+ std::string vertex_shader,
+ std::string fragment_shader)
+{
+ GLShaderData *data = new GLShaderData;
+ data->name = name;
+ data->vertex_shader = vertex_shader;
+ data->fragment_shader = fragment_shader;
+
+ priv->shaders.push_back(data);
+}
+
+void
PrivateGLWindow::updateFrameRegion (CompRegion &region)
{
window->updateFrameRegion (region);