* 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.
This commit is contained in:
parent
7b7e76ba27
commit
d66fe947a0
@ -1,3 +1,9 @@
|
|||||||
|
2008-06-06 Neil Roberts <neil@o-hand.com>
|
||||||
|
|
||||||
|
* 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 <neil@o-hand.com>
|
2008-06-06 Neil Roberts <neil@o-hand.com>
|
||||||
|
|
||||||
* tests/test-shader.c: Fixed to use sampler2D instead of
|
* tests/test-shader.c: Fixed to use sampler2D instead of
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/*#define TEST_GROUP */
|
/*#define TEST_GROUP */
|
||||||
|
|
||||||
#include <clutter/clutter.h>
|
#include <clutter/clutter.h>
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -17,6 +18,25 @@ typedef struct
|
|||||||
gchar *source;
|
gchar *source;
|
||||||
} ShaderSource;
|
} 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
|
/* a couple of boilerplate defines that are common amongst all the
|
||||||
* sample shaders
|
* sample shaders
|
||||||
*/
|
*/
|
||||||
@ -24,11 +44,14 @@ typedef struct
|
|||||||
/* FRAGMENT_SHADER_BEGIN: generate boilerplate with a local vec4 color already
|
/* FRAGMENT_SHADER_BEGIN: generate boilerplate with a local vec4 color already
|
||||||
* initialized, from a sampler2D in a variable tex.
|
* initialized, from a sampler2D in a variable tex.
|
||||||
*/
|
*/
|
||||||
#define FRAGMENT_SHADER_BEGIN \
|
#define FRAGMENT_SHADER_VARS \
|
||||||
|
GLES2_VARS \
|
||||||
"uniform sampler2D tex;" \
|
"uniform sampler2D tex;" \
|
||||||
"uniform float x_step, y_step;" \
|
"uniform float x_step, y_step;" \
|
||||||
|
|
||||||
|
#define FRAGMENT_SHADER_BEGIN \
|
||||||
"void main (){" \
|
"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
|
/* FRAGMENT_SHADER_END: apply the changed color to the output buffer correctly
|
||||||
* blended with the gl specified color (makes the opacity of actors work
|
* blended with the gl specified color (makes the opacity of actors work
|
||||||
@ -36,12 +59,13 @@ typedef struct
|
|||||||
*/
|
*/
|
||||||
#define FRAGMENT_SHADER_END \
|
#define FRAGMENT_SHADER_END \
|
||||||
" gl_FragColor = color;" \
|
" gl_FragColor = color;" \
|
||||||
" gl_FragColor = gl_FragColor * gl_Color;" \
|
" gl_FragColor = gl_FragColor * " COLOR_VAR ";" \
|
||||||
"}"
|
"}"
|
||||||
|
|
||||||
static ShaderSource shaders[]=
|
static ShaderSource shaders[]=
|
||||||
{
|
{
|
||||||
{"brightness-contrast",
|
{"brightness-contrast",
|
||||||
|
FRAGMENT_SHADER_VARS
|
||||||
"uniform float brightness, contrast;"
|
"uniform float brightness, contrast;"
|
||||||
FRAGMENT_SHADER_BEGIN
|
FRAGMENT_SHADER_BEGIN
|
||||||
" color.rgb = (color.rgb - vec3(0.5, 0.5, 0.5)) * contrast + "
|
" color.rgb = (color.rgb - vec3(0.5, 0.5, 0.5)) * contrast + "
|
||||||
@ -50,6 +74,8 @@ static ShaderSource shaders[]=
|
|||||||
},
|
},
|
||||||
|
|
||||||
{"box-blur",
|
{"box-blur",
|
||||||
|
FRAGMENT_SHADER_VARS
|
||||||
|
|
||||||
#if GPU_SUPPORTS_DYNAMIC_BRANCHING
|
#if GPU_SUPPORTS_DYNAMIC_BRANCHING
|
||||||
"uniform float radius;"
|
"uniform float radius;"
|
||||||
FRAGMENT_SHADER_BEGIN
|
FRAGMENT_SHADER_BEGIN
|
||||||
@ -59,8 +85,8 @@ static ShaderSource shaders[]=
|
|||||||
" for (v=-radius;v<radius;v++)"
|
" for (v=-radius;v<radius;v++)"
|
||||||
" {"
|
" {"
|
||||||
" color += texture2D(tex, "
|
" color += texture2D(tex, "
|
||||||
" vec2(gl_TexCoord[0].s + u * 2.0 * x_step, "
|
" vec2(" TEX_COORD ".s + u * 2.0 * x_step, "
|
||||||
" gl_TexCoord[0].t + v * 2.0 * y_step));"
|
" " TEX_COORD ".t + v * 2.0 * y_step));"
|
||||||
" count ++;"
|
" count ++;"
|
||||||
" }"
|
" }"
|
||||||
"color = color / float(count);"
|
"color = color / float(count);"
|
||||||
@ -68,7 +94,7 @@ static ShaderSource shaders[]=
|
|||||||
#else
|
#else
|
||||||
"vec4 get_rgba_rel(sampler2D tex, float dx, float dy)"
|
"vec4 get_rgba_rel(sampler2D tex, float dx, float dy)"
|
||||||
"{"
|
"{"
|
||||||
" return texture2D (tex, gl_TexCoord[0].st "
|
" return texture2D (tex, " TEX_COORD ".st "
|
||||||
" + vec2(dx, dy) * 2.0);"
|
" + vec2(dx, dy) * 2.0);"
|
||||||
"}"
|
"}"
|
||||||
|
|
||||||
@ -89,12 +115,14 @@ static ShaderSource shaders[]=
|
|||||||
},
|
},
|
||||||
|
|
||||||
{"invert",
|
{"invert",
|
||||||
|
FRAGMENT_SHADER_VARS
|
||||||
FRAGMENT_SHADER_BEGIN
|
FRAGMENT_SHADER_BEGIN
|
||||||
" color.rgb = vec3(1.0, 1.0, 1.0) - color.rgb;\n"
|
" color.rgb = vec3(1.0, 1.0, 1.0) - color.rgb;\n"
|
||||||
FRAGMENT_SHADER_END
|
FRAGMENT_SHADER_END
|
||||||
},
|
},
|
||||||
|
|
||||||
{"brightness-contrast",
|
{"brightness-contrast",
|
||||||
|
FRAGMENT_SHADER_VARS
|
||||||
"uniform float brightness;"
|
"uniform float brightness;"
|
||||||
"uniform float contrast;"
|
"uniform float contrast;"
|
||||||
FRAGMENT_SHADER_BEGIN
|
FRAGMENT_SHADER_BEGIN
|
||||||
@ -105,6 +133,7 @@ static ShaderSource shaders[]=
|
|||||||
},
|
},
|
||||||
|
|
||||||
{"gray",
|
{"gray",
|
||||||
|
FRAGMENT_SHADER_VARS
|
||||||
FRAGMENT_SHADER_BEGIN
|
FRAGMENT_SHADER_BEGIN
|
||||||
" float avg = (color.r + color.g + color.b) / 3.0;"
|
" float avg = (color.r + color.g + color.b) / 3.0;"
|
||||||
" color.r = avg;"
|
" color.r = avg;"
|
||||||
@ -114,8 +143,9 @@ static ShaderSource shaders[]=
|
|||||||
},
|
},
|
||||||
|
|
||||||
{"combined-mirror",
|
{"combined-mirror",
|
||||||
|
FRAGMENT_SHADER_VARS
|
||||||
FRAGMENT_SHADER_BEGIN
|
FRAGMENT_SHADER_BEGIN
|
||||||
" vec4 colorB = texture2D (tex, vec2(gl_TexCoord[0].ts));"
|
" vec4 colorB = texture2D (tex, vec2(" TEX_COORD ".ts));"
|
||||||
" float avg = (color.r + color.g + color.b) / 3.0;"
|
" float avg = (color.r + color.g + color.b) / 3.0;"
|
||||||
" color.r = avg;"
|
" color.r = avg;"
|
||||||
" color.g = avg;"
|
" color.g = avg;"
|
||||||
@ -129,24 +159,12 @@ static ShaderSource shaders[]=
|
|||||||
|
|
||||||
static gint shader_no = 0;
|
static gint shader_no = 0;
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
button_release_cb (ClutterActor *actor,
|
set_shader_num (ClutterActor *actor, gint new_no)
|
||||||
ClutterEvent *event,
|
|
||||||
gpointer data)
|
|
||||||
{
|
{
|
||||||
gint new_no;
|
|
||||||
int tex_width;
|
int tex_width;
|
||||||
int tex_height;
|
int tex_height;
|
||||||
|
|
||||||
if (event->button.button == 1)
|
|
||||||
{
|
|
||||||
new_no = shader_no - 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
new_no = shader_no + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_no >= 0 && shaders[new_no].name)
|
if (new_no >= 0 && shaders[new_no].name)
|
||||||
{
|
{
|
||||||
ClutterShader *shader;
|
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;
|
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
|
gint
|
||||||
main (gint argc,
|
main (gint argc,
|
||||||
@ -299,6 +351,12 @@ main (gint argc,
|
|||||||
g_signal_connect (actor, "button-release-event",
|
g_signal_connect (actor, "button-release-event",
|
||||||
G_CALLBACK (button_release_cb), NULL);
|
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);*/
|
/*clutter_actor_set_opacity (actor, 0x77);*/
|
||||||
|
|
||||||
/* Show everying ( and map window ) */
|
/* Show everying ( and map window ) */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user