2008-10-29 14:52:48 +00:00
|
|
|
|
2008-02-01 15:29:00 +00:00
|
|
|
/*#define TEST_GROUP */
|
|
|
|
|
2008-10-29 14:52:48 +00:00
|
|
|
/* 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 */
|
|
|
|
|
2008-02-01 15:29:00 +00:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <glib.h>
|
2008-11-07 19:32:28 +00:00
|
|
|
#include <gmodule.h>
|
2008-02-01 15:29:00 +00:00
|
|
|
|
2008-02-03 01:53:10 +00:00
|
|
|
ClutterActor*
|
|
|
|
make_source(void)
|
2008-02-01 15:29:00 +00:00
|
|
|
{
|
2008-02-03 01:53:10 +00:00
|
|
|
ClutterActor *source, *actor;
|
2008-02-01 15:29:00 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2008-02-03 01:53:10 +00:00
|
|
|
ClutterColor yellow = {0xff, 0xff, 0x00, 0xff};
|
2008-02-01 15:29:00 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
source = clutter_group_new();
|
|
|
|
actor = clutter_texture_new_from_file ("redhand.png", &error);
|
|
|
|
if (!actor)
|
2008-02-01 15:29:00 +00:00
|
|
|
g_error("pixbuf load failed: %s", error ? error->message : "Unknown");
|
|
|
|
|
2008-02-03 01:53:10 +00:00
|
|
|
clutter_group_add (source, actor);
|
2008-02-01 15:29:00 +00:00
|
|
|
|
2008-12-11 13:48:01 +00:00
|
|
|
actor = clutter_text_new_with_text ("Sans Bold 50px", "Clutter");
|
2008-02-01 15:29:00 +00:00
|
|
|
|
2008-12-11 13:48:01 +00:00
|
|
|
clutter_text_set_color (CLUTTER_TEXT (actor), &yellow);
|
2008-02-03 01:53:10 +00:00
|
|
|
clutter_actor_set_y (actor, clutter_actor_get_height(source) + 5);
|
|
|
|
clutter_group_add (source, actor);
|
2008-02-01 15:29:00 +00:00
|
|
|
|
2008-02-03 01:53:10 +00:00
|
|
|
return source;
|
|
|
|
}
|
2008-02-01 15:29:00 +00:00
|
|
|
|
2008-02-03 01:53:10 +00:00
|
|
|
ClutterShader*
|
|
|
|
make_shader(void)
|
|
|
|
{
|
|
|
|
ClutterShader *shader;
|
2008-10-29 14:52:48 +00:00
|
|
|
GError *error = NULL;
|
2008-02-01 15:29:00 +00:00
|
|
|
|
|
|
|
shader = clutter_shader_new ();
|
|
|
|
clutter_shader_set_fragment_source (shader,
|
|
|
|
|
2008-10-29 14:52:48 +00:00
|
|
|
GLES2_VARS
|
2008-02-01 15:29:00 +00:00
|
|
|
"uniform float radius ;"
|
2008-07-01 21:52:19 +00:00
|
|
|
"uniform sampler2D rectTexture;"
|
|
|
|
"uniform float x_step, y_step;"
|
2008-02-01 15:29:00 +00:00
|
|
|
""
|
|
|
|
"void main()"
|
|
|
|
"{"
|
2008-10-29 14:52:48 +00:00
|
|
|
" vec4 color = texture2D(rectTexture, " TEX_COORD ".st);"
|
2008-02-01 15:29:00 +00:00
|
|
|
" float u;"
|
|
|
|
" float v;"
|
|
|
|
" int count = 1;"
|
|
|
|
" for (u=-radius;u<radius;u++)"
|
|
|
|
" for (v=-radius;v<radius;v++)"
|
|
|
|
" {"
|
2008-07-01 21:52:19 +00:00
|
|
|
" color += texture2D(rectTexture, "
|
2008-10-29 14:52:48 +00:00
|
|
|
" vec2(" TEX_COORD ".s + u"
|
2008-07-01 21:52:19 +00:00
|
|
|
" * 2.0 * x_step,"
|
2008-10-29 14:52:48 +00:00
|
|
|
" " TEX_COORD ".t + v"
|
2008-07-01 21:52:19 +00:00
|
|
|
" * 2.0 * y_step));"
|
2008-02-01 15:29:00 +00:00
|
|
|
" count ++;"
|
|
|
|
" }"
|
|
|
|
""
|
|
|
|
" gl_FragColor = color / float(count);"
|
2008-10-29 14:52:48 +00:00
|
|
|
" gl_FragColor = gl_FragColor * " COLOR_VAR ";"
|
2008-02-01 15:29:00 +00:00
|
|
|
"}",
|
|
|
|
-1
|
|
|
|
);
|
|
|
|
|
2008-10-29 14:52:48 +00:00
|
|
|
if (!clutter_shader_compile (shader, &error))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "shader compilation failed:\n%s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
2008-02-03 01:53:10 +00:00
|
|
|
return shader;
|
|
|
|
}
|
|
|
|
|
2008-11-07 19:32:28 +00:00
|
|
|
G_MODULE_EXPORT gint
|
|
|
|
test_fbo_main (gint argc, gchar *argv[])
|
2008-02-03 01:53:10 +00:00
|
|
|
{
|
|
|
|
ClutterColor blue = {0x33, 0x44, 0x55, 0xff};
|
|
|
|
|
|
|
|
ClutterActor *fbo;
|
|
|
|
ClutterActor *onscreen_source, *offscreen_source, *trans_source;
|
|
|
|
ClutterActor *foo_source;
|
|
|
|
ClutterActor *stage;
|
|
|
|
ClutterActor *clone;
|
|
|
|
ClutterShader *shader;
|
|
|
|
gint padx, pady;
|
2008-07-01 21:52:19 +00:00
|
|
|
gint fbo_width, fbo_height;
|
2008-02-03 01:53:10 +00:00
|
|
|
|
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
|
|
|
|
if (clutter_feature_available (CLUTTER_FEATURE_OFFSCREEN) == FALSE)
|
|
|
|
g_error("This test requires CLUTTER_FEATURE_OFFSCREEN");
|
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
|
|
|
clutter_stage_set_color (CLUTTER_STAGE (stage), &blue);
|
|
|
|
|
|
|
|
/* Create the first source */
|
|
|
|
onscreen_source = make_source();
|
|
|
|
clutter_actor_show_all (onscreen_source);
|
|
|
|
clutter_group_add (stage, onscreen_source);
|
|
|
|
|
|
|
|
/* Basic sizing for alignment */
|
2008-07-01 21:52:19 +00:00
|
|
|
fbo_width = clutter_actor_get_width (onscreen_source);
|
|
|
|
fbo_height = clutter_actor_get_height (onscreen_source);
|
|
|
|
padx = fbo_width + 10;
|
|
|
|
pady = fbo_height + 10;
|
2008-02-03 01:53:10 +00:00
|
|
|
clutter_actor_set_size (stage, padx*4, pady*2);
|
|
|
|
|
|
|
|
/* Second hand from fbo onscreen */
|
|
|
|
if ((fbo = clutter_texture_new_from_actor (onscreen_source)) == NULL)
|
|
|
|
g_error("onscreen fbo creation failed");
|
|
|
|
|
|
|
|
clutter_actor_set_position (fbo, padx, 0);
|
|
|
|
clutter_group_add (stage, fbo);
|
|
|
|
|
|
|
|
/* apply a shader to it */
|
|
|
|
shader = make_shader();
|
2008-02-04 11:45:12 +00:00
|
|
|
clutter_actor_set_shader (fbo, shader);
|
2008-11-18 15:08:40 +00:00
|
|
|
clutter_actor_set_shader_param_float (fbo, "radius", 2.0);
|
|
|
|
clutter_actor_set_shader_param_float (fbo, "x_step",
|
2008-07-01 21:52:19 +00:00
|
|
|
1.0f / clutter_util_next_p2 (fbo_width));
|
2008-11-18 15:08:40 +00:00
|
|
|
clutter_actor_set_shader_param_float (fbo, "y_step",
|
2008-07-01 21:52:19 +00:00
|
|
|
1.0f / clutter_util_next_p2 (fbo_height));
|
2008-02-03 01:53:10 +00:00
|
|
|
|
|
|
|
/* Third from cloning the fbo texture */
|
2009-01-27 15:18:45 +00:00
|
|
|
clone = clutter_clone_new (fbo);
|
2008-02-01 15:29:00 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), clone);
|
2008-02-03 01:53:10 +00:00
|
|
|
clutter_actor_set_position (clone, padx*2, 0);
|
|
|
|
|
|
|
|
|
|
|
|
/* Forth - an offscreen source */
|
|
|
|
offscreen_source = make_source();
|
|
|
|
clutter_actor_show_all (offscreen_source); /* need to show() offscreen */
|
|
|
|
if ((fbo = clutter_texture_new_from_actor (offscreen_source)) == NULL)
|
|
|
|
g_error("offscreen fbo creation failed");
|
|
|
|
|
|
|
|
clutter_actor_set_position (fbo, padx*3, 0);
|
|
|
|
clutter_group_add (stage, fbo);
|
|
|
|
|
|
|
|
|
|
|
|
/* 5th transformed */
|
|
|
|
trans_source = make_source();
|
|
|
|
clutter_actor_show_all (trans_source); /* need to show() offscreen */
|
|
|
|
|
|
|
|
clutter_actor_set_scale (trans_source, 2.5, 2.5);
|
|
|
|
|
|
|
|
if ((fbo = clutter_texture_new_from_actor (trans_source)) == NULL)
|
|
|
|
g_error("transformed fbo creation failed");
|
|
|
|
|
|
|
|
clutter_actor_set_position (fbo, 0, pady);
|
|
|
|
clutter_group_add (stage, fbo);
|
|
|
|
|
|
|
|
|
|
|
|
/* 6th resized bigger, but after fbo creation */
|
|
|
|
trans_source = make_source();
|
|
|
|
clutter_actor_show_all (trans_source); /* need to show() offscreen */
|
|
|
|
|
|
|
|
if ((fbo = clutter_texture_new_from_actor (trans_source)) == NULL)
|
|
|
|
g_error("transformed fbo creation failed");
|
|
|
|
|
2008-02-06 14:50:15 +00:00
|
|
|
/* rotate after */
|
|
|
|
clutter_actor_move_anchor_point_from_gravity (trans_source,
|
|
|
|
CLUTTER_GRAVITY_CENTER);
|
|
|
|
clutter_actor_set_rotation (trans_source, CLUTTER_Z_AXIS, 90.0, 0, 0, 0);
|
|
|
|
|
2008-02-03 01:53:10 +00:00
|
|
|
clutter_actor_set_position (fbo, padx, pady);
|
|
|
|
clutter_group_add (stage, fbo);
|
|
|
|
|
|
|
|
|
|
|
|
/* non visual breaks */
|
|
|
|
foo_source = make_source();
|
2008-07-04 10:44:18 +00:00
|
|
|
g_object_ref_sink (foo_source);
|
|
|
|
|
2008-02-03 01:53:10 +00:00
|
|
|
clutter_actor_show_all (foo_source);
|
|
|
|
if ((fbo = clutter_texture_new_from_actor (foo_source)) == NULL)
|
|
|
|
g_error("foo fbo creation failed");
|
|
|
|
|
|
|
|
g_object_unref (foo_source); /* fbo should keep it around */
|
|
|
|
|
|
|
|
clutter_actor_set_position (fbo, padx*3, pady);
|
|
|
|
clutter_group_add (stage, fbo);
|
2008-02-01 15:29:00 +00:00
|
|
|
|
2008-02-03 23:25:12 +00:00
|
|
|
/* TODO:
|
|
|
|
* Check realize/unrealize
|
|
|
|
* get_pixbuf()
|
|
|
|
* set_rgba on fbo texture.
|
|
|
|
*/
|
2008-02-01 15:29:00 +00:00
|
|
|
|
|
|
|
clutter_actor_show_all (stage);
|
|
|
|
clutter_main ();
|
2008-02-11 16:29:31 +00:00
|
|
|
|
|
|
|
return 0;
|
2008-02-01 15:29:00 +00:00
|
|
|
}
|