From d66fe947a07e2dec6375060ea0d955eddf832b89 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Fri, 6 Jun 2008 15:41:52 +0000 Subject: [PATCH] * tests/test-shader.c: Use the special wrapper vars when building for GLES 2 and automatically cycle the shaders because it's difficult to right-click. --- ChangeLog | 6 ++++ tests/test-shader.c | 100 +++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 85 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 74bff6a..fef61d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2008-06-06 Neil Roberts + * tests/test-shader.c: Use the special wrapper vars when building + for GLES 2 and automatically cycle the shaders because it's + difficult to right-click. + +2008-06-06 Neil Roberts + * tests/test-shader.c: Fixed to use sampler2D instead of sampler2DRect now that GL_TEXTURE_RECTANGLE support is disabled in revision 2834. The ClutterTexture actor now has the diff --git a/tests/test-shader.c b/tests/test-shader.c index 758c459..9a4fadb 100644 --- a/tests/test-shader.c +++ b/tests/test-shader.c @@ -1,6 +1,7 @@ /*#define TEST_GROUP */ #include +#include "../config.h" #include #include @@ -17,6 +18,25 @@ typedef struct gchar *source; } ShaderSource; +/* These variables are used instead of the standard GLSL variables on + GLES 2 */ +#ifdef HAVE_COGL_GLES2 + +#define GLES2_VARS \ + "precision mediump float;\n" \ + "varying vec2 tex_coord;\n" \ + "varying vec4 frag_color;\n" +#define TEX_COORD "tex_coord" +#define COLOR_VAR "frag_color" + +#else /* HAVE_COGL_GLES2 */ + +#define GLES2_VARS "" +#define TEX_COORD "gl_TexCoord[0]" +#define COLOR_VAR "gl_Color" + +#endif /* HAVE_COGL_GLES2 */ + /* a couple of boilerplate defines that are common amongst all the * sample shaders */ @@ -24,11 +44,14 @@ typedef struct /* FRAGMENT_SHADER_BEGIN: generate boilerplate with a local vec4 color already * initialized, from a sampler2D in a variable tex. */ -#define FRAGMENT_SHADER_BEGIN \ +#define FRAGMENT_SHADER_VARS \ + GLES2_VARS \ "uniform sampler2D tex;" \ "uniform float x_step, y_step;" \ + +#define FRAGMENT_SHADER_BEGIN \ "void main (){" \ - " vec4 color = texture2D (tex, vec2(gl_TexCoord[0].st));" + " vec4 color = texture2D (tex, vec2(" TEX_COORD "));" /* FRAGMENT_SHADER_END: apply the changed color to the output buffer correctly * blended with the gl specified color (makes the opacity of actors work @@ -36,12 +59,13 @@ typedef struct */ #define FRAGMENT_SHADER_END \ " gl_FragColor = color;" \ - " gl_FragColor = gl_FragColor * gl_Color;" \ + " gl_FragColor = gl_FragColor * " COLOR_VAR ";" \ "}" static ShaderSource shaders[]= { {"brightness-contrast", + FRAGMENT_SHADER_VARS "uniform float brightness, contrast;" FRAGMENT_SHADER_BEGIN " color.rgb = (color.rgb - vec3(0.5, 0.5, 0.5)) * contrast + " @@ -50,6 +74,8 @@ static ShaderSource shaders[]= }, {"box-blur", + FRAGMENT_SHADER_VARS + #if GPU_SUPPORTS_DYNAMIC_BRANCHING "uniform float radius;" FRAGMENT_SHADER_BEGIN @@ -59,8 +85,8 @@ static ShaderSource shaders[]= " for (v=-radius;vbutton.button == 1) - { - new_no = shader_no - 1; - } - else - { - new_no = shader_no + 1; - } - if (new_no >= 0 && shaders[new_no].name) { ClutterShader *shader; @@ -199,9 +217,43 @@ button_release_cb (ClutterActor *actor, } } } +} + +static gboolean +button_release_cb (ClutterActor *actor, + ClutterEvent *event, + gpointer data) +{ + gint new_no; + + if (event->button.button == 1) + { + new_no = shader_no - 1; + } + else + { + new_no = shader_no + 1; + } + + set_shader_num (actor, new_no); + return FALSE; } +#ifdef HAVE_COGL_GLES2 +static gboolean +timeout_cb (gpointer data) +{ + int new_no = shader_no + 1; + + if (shaders[new_no].name == NULL) + new_no = 0; + + set_shader_num (CLUTTER_ACTOR (data), new_no); + + return TRUE; +} +#endif /* HAVE_COGL_GLES2 */ gint main (gint argc, @@ -299,6 +351,12 @@ main (gint argc, g_signal_connect (actor, "button-release-event", G_CALLBACK (button_release_cb), NULL); +#ifdef HAVE_COGL_GLES2 + /* On an embedded platform it is difficult to right click so we will + cycle through the shaders automatically */ + g_timeout_add_seconds (3, timeout_cb, actor); +#endif + /*clutter_actor_set_opacity (actor, 0x77);*/ /* Show everying ( and map window ) */ -- 2.7.4