mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 09:30:45 -05:00
tests/clutter: Port to using non-implicit framebuffer Cogl API
Port tests to use API such as cogl_framebuffer_push_matrix() instead of cogl_push_matrix() all over the Clutter tests, with one exception: cogl_polygon(). It'll be ported over in a separate commit, as it is less straight forward. Implicitly set CoglMaterial properties are changed to explicitly created and destructed CoglPipelines with the equivalent properties set. cogl_push|pop_framebuffer() is replaced by explicitly passing the right framebuffer, but tests still rely on cogl_get_draw_framebuffer() to get the target framebuffer. https://gitlab.gnome.org/GNOME/mutter/merge_requests/935
This commit is contained in:
parent
8329c6b069
commit
8c7ec44681
@ -40,8 +40,12 @@ static void
|
||||
foo_actor_paint (ClutterActor *actor,
|
||||
ClutterPaintContext *paint_context)
|
||||
{
|
||||
CoglContext *ctx =
|
||||
clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
||||
FooActor *foo_actor = (FooActor *) actor;
|
||||
ClutterActorBox allocation;
|
||||
CoglPipeline *pipeline;
|
||||
CoglFramebuffer *framebuffer;
|
||||
|
||||
foo_actor->last_paint_opacity = clutter_actor_get_paint_opacity (actor);
|
||||
foo_actor->paint_count++;
|
||||
@ -49,14 +53,19 @@ foo_actor_paint (ClutterActor *actor,
|
||||
clutter_actor_get_allocation_box (actor, &allocation);
|
||||
|
||||
/* Paint a red rectangle with the right opacity */
|
||||
cogl_set_source_color4ub (255,
|
||||
0,
|
||||
0,
|
||||
foo_actor->last_paint_opacity);
|
||||
cogl_rectangle (allocation.x1,
|
||||
allocation.y1,
|
||||
allocation.x2,
|
||||
allocation.y2);
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
cogl_pipeline_set_color4ub (pipeline,
|
||||
255, 0, 0,
|
||||
foo_actor->last_paint_opacity);
|
||||
|
||||
framebuffer = cogl_get_draw_framebuffer ();
|
||||
cogl_framebuffer_draw_rectangle (framebuffer,
|
||||
pipeline,
|
||||
allocation.x1,
|
||||
allocation.y1,
|
||||
allocation.x2,
|
||||
allocation.y2);
|
||||
cogl_object_unref (pipeline);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -136,10 +136,19 @@ key_group_paint (ClutterActor *actor,
|
||||
ClutterPaintContext *paint_context)
|
||||
{
|
||||
KeyGroup *self = KEY_GROUP (actor);
|
||||
CoglContext *ctx =
|
||||
clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
||||
ClutterActorIter iter;
|
||||
ClutterActor *child;
|
||||
CoglPipeline *pipeline;
|
||||
CoglFramebuffer *framebuffer;
|
||||
gint i = 0;
|
||||
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
cogl_pipeline_set_color4ub (pipeline, 255, 255, 0, 224);
|
||||
|
||||
framebuffer = cogl_get_draw_framebuffer ();
|
||||
|
||||
clutter_actor_iter_init (&iter, actor);
|
||||
while (clutter_actor_iter_next (&iter, &child))
|
||||
{
|
||||
@ -155,12 +164,14 @@ key_group_paint (ClutterActor *actor,
|
||||
box.x2 += 2;
|
||||
box.y2 += 2;
|
||||
|
||||
cogl_set_source_color4ub (255, 255, 0, 224);
|
||||
cogl_rectangle (box.x1, box.y1, box.x2, box.y2);
|
||||
cogl_framebuffer_draw_rectangle (framebuffer, pipeline,
|
||||
box.x1, box.y1, box.x2, box.y2);
|
||||
}
|
||||
|
||||
clutter_actor_paint (child, paint_context);
|
||||
}
|
||||
|
||||
cogl_object_unref (pipeline);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -157,6 +157,11 @@ key_group_paint (ClutterActor *actor,
|
||||
ClutterActorIter iter;
|
||||
ClutterActor *child;
|
||||
gint i = 0;
|
||||
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||
CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
|
||||
CoglPipeline *pipeline;
|
||||
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
|
||||
clutter_actor_iter_init (&iter, actor);
|
||||
while (clutter_actor_iter_next (&iter, &child))
|
||||
@ -173,8 +178,10 @@ key_group_paint (ClutterActor *actor,
|
||||
box.x2 += 2;
|
||||
box.y2 += 2;
|
||||
|
||||
cogl_set_source_color4ub (255, 255, 0, 224);
|
||||
cogl_rectangle (box.x1, box.y1, box.x2, box.y2);
|
||||
cogl_pipeline_set_color4ub (pipeline, 255, 255, 0, 224);
|
||||
|
||||
cogl_framebuffer_draw_rectangle (framebuffer, pipeline,
|
||||
box.x1, box.y1, box.x2, box.y2);
|
||||
}
|
||||
|
||||
clutter_actor_paint (child, paint_context);
|
||||
|
@ -60,22 +60,26 @@ material_rectangle_paint (ClutterActor *actor,
|
||||
gpointer data)
|
||||
{
|
||||
TestMultiLayerMaterialState *state = data;
|
||||
CoglFramebuffer *framebuffer =
|
||||
clutter_paint_context_get_framebuffer (paint_context);
|
||||
|
||||
cogl_push_matrix ();
|
||||
cogl_framebuffer_push_matrix (framebuffer);
|
||||
|
||||
cogl_translate (150, 15, 0);
|
||||
cogl_framebuffer_translate (framebuffer, 150, 15, 0);
|
||||
|
||||
cogl_set_source (state->material0);
|
||||
cogl_rectangle_with_multitexture_coords (0, 0, 200, 213,
|
||||
state->tex_coords,
|
||||
12);
|
||||
cogl_translate (-300, -30, 0);
|
||||
cogl_set_source (state->material1);
|
||||
cogl_rectangle_with_multitexture_coords (0, 0, 200, 213,
|
||||
state->tex_coords,
|
||||
12);
|
||||
cogl_framebuffer_draw_multitextured_rectangle (framebuffer,
|
||||
COGL_FRAMEBUFFER (state->material0),
|
||||
0, 0, 200, 213,
|
||||
state->tex_coords,
|
||||
12);
|
||||
cogl_framebuffer_translate (framebuffer, -300, -30, 0);
|
||||
cogl_framebuffer_draw_multitextured_rectangle (framebuffer,
|
||||
COGL_FRAMEBUFFER (state->material1),
|
||||
0, 0, 200, 213,
|
||||
state->tex_coords,
|
||||
12);
|
||||
|
||||
cogl_pop_matrix ();
|
||||
cogl_framebuffer_pop_matrix (framebuffer);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -87,38 +87,46 @@ test_coglbox_paint (ClutterActor *self,
|
||||
ClutterPaintContext *paint_context)
|
||||
{
|
||||
TestCoglboxPrivate *priv = TEST_COGLBOX_GET_PRIVATE (self);
|
||||
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||
CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
|
||||
gfloat texcoords[4] = { 0, 0, 1, 1 };
|
||||
CoglHandle material;
|
||||
CoglPipeline *pipeline;
|
||||
|
||||
cogl_set_source_color4ub (0x66, 0x66, 0xdd, 0xff);
|
||||
cogl_rectangle (0, 0, 400, 400);
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
cogl_pipeline_set_color4ub (pipeline, 0x66, 0x66, 0xdd, 0xff);
|
||||
cogl_framebuffer_draw_rectangle (framebuffer, pipeline, 0, 0, 400, 400);
|
||||
cogl_object_unref (pipeline);
|
||||
|
||||
cogl_set_source_texture (priv->texhand_id);
|
||||
cogl_rectangle_with_texture_coords (0, 0,
|
||||
400, 400,
|
||||
0, 0,
|
||||
6, 6);
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
cogl_pipeline_set_layer_texture (pipeline, 0, priv->texhand_id);
|
||||
cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline,
|
||||
0, 0,
|
||||
400, 400,
|
||||
0, 0,
|
||||
6, 6);
|
||||
cogl_object_unref (pipeline);
|
||||
|
||||
cogl_push_framebuffer (priv->offscreen_id);
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
cogl_pipeline_set_color4ub (pipeline, 0xff, 0, 0, 0xff);
|
||||
cogl_framebuffer_draw_rectangle (priv->offscreen_id, pipeline,
|
||||
20, 20, 20 + 100, 20 + 100);
|
||||
|
||||
cogl_set_source_color4ub (0xff, 0, 0, 0xff);
|
||||
cogl_rectangle (20, 20, 20 + 100, 20 + 100);
|
||||
cogl_pipeline_set_color4ub (pipeline, 0, 0xff, 0, 0xff);
|
||||
cogl_framebuffer_draw_rectangle (priv->offscreen_id, pipeline,
|
||||
80, 80, 80 + 100, 80 + 100);
|
||||
cogl_object_unref (pipeline);
|
||||
|
||||
cogl_set_source_color4ub (0, 0xff, 0, 0xff);
|
||||
cogl_rectangle (80, 80, 80 + 100, 80 + 100);
|
||||
|
||||
cogl_pop_framebuffer ();
|
||||
|
||||
material = cogl_material_new ();
|
||||
cogl_material_set_color4ub (material, 0x88, 0x88, 0x88, 0x88);
|
||||
cogl_material_set_layer (material, 0, priv->texture_id);
|
||||
cogl_set_source (material);
|
||||
cogl_rectangle_with_texture_coords (100, 100,
|
||||
300, 300,
|
||||
texcoords[0],
|
||||
texcoords[1],
|
||||
texcoords[2],
|
||||
texcoords[3]);
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
cogl_pipeline_set_color4ub (pipeline, 0x88, 0x88, 0x88, 0x88);
|
||||
cogl_pipeline_set_layer_texture (pipeline, 0, priv->texture_id);
|
||||
cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline,
|
||||
100, 100,
|
||||
300, 300,
|
||||
texcoords[0],
|
||||
texcoords[1],
|
||||
texcoords[2],
|
||||
texcoords[3]);
|
||||
cogl_object_unref (pipeline);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -161,24 +169,25 @@ test_coglbox_dispose (GObject *object)
|
||||
* framebuffer
|
||||
*/
|
||||
static void
|
||||
setup_viewport (unsigned int width,
|
||||
unsigned int height,
|
||||
float fovy,
|
||||
float aspect,
|
||||
float z_near,
|
||||
float z_far)
|
||||
setup_viewport (CoglFramebuffer *framebuffer,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
float fovy,
|
||||
float aspect,
|
||||
float z_near,
|
||||
float z_far)
|
||||
{
|
||||
float z_camera;
|
||||
CoglMatrix projection_matrix;
|
||||
CoglMatrix mv_matrix;
|
||||
|
||||
cogl_set_viewport (0, 0, width, height);
|
||||
cogl_framebuffer_set_viewport (framebuffer, 0, 0, width, height);
|
||||
|
||||
/* For Ortho projection.
|
||||
* _cogl_matrix_stack_ortho (projection_stack, 0, width, 0, height, -1, 1);
|
||||
*/
|
||||
|
||||
cogl_perspective (fovy, aspect, z_near, z_far);
|
||||
cogl_framebuffer_perspective (framebuffer, fovy, aspect, z_near, z_far);
|
||||
|
||||
/*
|
||||
* In theory, we can compute the camera distance from screen as:
|
||||
@ -219,14 +228,14 @@ setup_viewport (unsigned int width,
|
||||
* doesn't make sense.
|
||||
*/
|
||||
|
||||
cogl_get_projection_matrix (&projection_matrix);
|
||||
cogl_framebuffer_get_projection_matrix (framebuffer, &projection_matrix);
|
||||
z_camera = 0.5 * projection_matrix.xx;
|
||||
|
||||
cogl_matrix_init_identity (&mv_matrix);
|
||||
cogl_matrix_translate (&mv_matrix, -0.5f, -0.5f, -z_camera);
|
||||
cogl_matrix_scale (&mv_matrix, 1.0f / width, -1.0f / height, 1.0f / width);
|
||||
cogl_matrix_translate (&mv_matrix, 0.0f, -1.0 * height, 0.0f);
|
||||
cogl_set_modelview_matrix (&mv_matrix);
|
||||
cogl_framebuffer_set_modelview_matrix (framebuffer, &mv_matrix);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -247,16 +256,13 @@ test_coglbox_map (ClutterActor *actor)
|
||||
clutter_stage_get_perspective (CLUTTER_STAGE (stage), &perspective);
|
||||
clutter_actor_get_size (stage, &stage_width, &stage_height);
|
||||
|
||||
cogl_push_framebuffer (priv->offscreen_id);
|
||||
|
||||
setup_viewport (stage_width, stage_height,
|
||||
setup_viewport (priv->offscreen_id,
|
||||
stage_width, stage_height,
|
||||
perspective.fovy,
|
||||
perspective.aspect,
|
||||
perspective.z_near,
|
||||
perspective.z_far);
|
||||
|
||||
cogl_pop_framebuffer ();
|
||||
|
||||
if (priv->offscreen_id == NULL)
|
||||
printf ("Failed creating offscreen to texture!\n");
|
||||
}
|
||||
|
@ -99,17 +99,18 @@ paint_cb (ClutterActor *stage,
|
||||
ClutterPaintContext *paint_context,
|
||||
Data *data)
|
||||
{
|
||||
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||
CoglMatrix old_matrix, new_matrix;
|
||||
int i;
|
||||
float diff_time;
|
||||
|
||||
cogl_get_projection_matrix (&old_matrix);
|
||||
cogl_framebuffer_get_projection_matrix (framebuffer, &old_matrix);
|
||||
/* Use an orthogonal projection from -1 -> 1 in both axes */
|
||||
cogl_matrix_init_identity (&new_matrix);
|
||||
cogl_set_projection_matrix (&new_matrix);
|
||||
cogl_framebuffer_set_projection_matrix (framebuffer, &new_matrix);
|
||||
|
||||
cogl_push_matrix ();
|
||||
cogl_set_modelview_matrix (&new_matrix);
|
||||
cogl_framebuffer_push_matrix (framebuffer);
|
||||
cogl_framebuffer_set_modelview_matrix (framebuffer, &new_matrix);
|
||||
|
||||
/* Update all of the firework's positions */
|
||||
for (i = 0; i < N_FIREWORKS; i++)
|
||||
@ -196,8 +197,8 @@ paint_cb (ClutterActor *stage,
|
||||
g_timer_reset (data->last_spark_time);
|
||||
}
|
||||
|
||||
cogl_set_projection_matrix (&old_matrix);
|
||||
cogl_pop_matrix ();
|
||||
cogl_framebuffer_set_projection_matrix (framebuffer, &old_matrix);
|
||||
cogl_framebuffer_pop_matrix (framebuffer);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -164,18 +164,21 @@ static unsigned int timeout_id = 0;
|
||||
static int shader_no = 0;
|
||||
|
||||
static void
|
||||
paint_cb (ClutterActor *actor)
|
||||
paint_cb (ClutterActor *actor,
|
||||
ClutterPaintContext *paint_context)
|
||||
{
|
||||
CoglFramebuffer *framebuffer =
|
||||
clutter_paint_context_get_framebuffer (paint_context);
|
||||
float stage_width = clutter_actor_get_width (actor);
|
||||
float stage_height = clutter_actor_get_height (actor);
|
||||
float image_width = cogl_texture_get_width (redhand);
|
||||
float image_height = cogl_texture_get_height (redhand);
|
||||
|
||||
cogl_set_source (material);
|
||||
cogl_rectangle (stage_width/2.0f - image_width/2.0f,
|
||||
stage_height/2.0f - image_height/2.0f,
|
||||
stage_width/2.0f + image_width/2.0f,
|
||||
stage_height/2.0f + image_height/2.0f);
|
||||
cogl_framebuffer_draw_rectangle (framebuffer, COGL_PIPELINE (material),
|
||||
stage_width / 2.0f - image_width / 2.0f,
|
||||
stage_height / 2.0f - image_height / 2.0f,
|
||||
stage_width / 2.0f + image_width / 2.0f,
|
||||
stage_height / 2.0f + image_height / 2.0f);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -86,44 +86,57 @@ test_coglbox_paint (ClutterActor *self,
|
||||
ClutterPaintContext *paint_context)
|
||||
{
|
||||
TestCoglboxPrivate *priv = TEST_COGLBOX_GET_PRIVATE (self);
|
||||
CoglPipeline *pipeline;
|
||||
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||
CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
|
||||
gfloat texcoords[4] = { 0.0, 0.0, 1.0, 1.0 };
|
||||
|
||||
priv = TEST_COGLBOX_GET_PRIVATE (self);
|
||||
|
||||
cogl_set_source_color4ub (0x66, 0x66, 0xdd, 0xff);
|
||||
cogl_rectangle (0, 0, 400, 400);
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
cogl_pipeline_set_color4ub (pipeline, 0x66, 0x66, 0xdd, 0xff);
|
||||
cogl_framebuffer_draw_rectangle (framebuffer, pipeline, 0, 0, 400, 400);
|
||||
cogl_object_unref (pipeline);
|
||||
|
||||
cogl_push_matrix ();
|
||||
cogl_set_source_texture (priv->cogl_tex_id[0]);
|
||||
cogl_rectangle_with_texture_coords (0, 0, 200, 213,
|
||||
texcoords[0], texcoords[1],
|
||||
texcoords[2], texcoords[3]);
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
|
||||
cogl_pop_matrix ();
|
||||
cogl_push_matrix ();
|
||||
cogl_translate (200, 0, 0);
|
||||
cogl_set_source_texture (priv->cogl_tex_id[1]);
|
||||
cogl_rectangle_with_texture_coords (0, 0, 200, 213,
|
||||
texcoords[0], texcoords[1],
|
||||
texcoords[2], texcoords[3]);
|
||||
cogl_framebuffer_push_matrix (framebuffer);
|
||||
cogl_pipeline_set_layer_texture (pipeline, 0, priv->cogl_tex_id[0]);
|
||||
cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline,
|
||||
0, 0, 200, 213,
|
||||
texcoords[0], texcoords[1],
|
||||
texcoords[2], texcoords[3]);
|
||||
|
||||
cogl_pop_matrix ();
|
||||
cogl_push_matrix ();
|
||||
cogl_translate (0, 200, 0);
|
||||
cogl_set_source_texture (priv->cogl_tex_id[2]);
|
||||
cogl_rectangle_with_texture_coords (0, 0, 200, 213,
|
||||
texcoords[0], texcoords[1],
|
||||
texcoords[2], texcoords[3]);
|
||||
cogl_framebuffer_pop_matrix (framebuffer);
|
||||
cogl_framebuffer_push_matrix (framebuffer);
|
||||
cogl_framebuffer_translate (framebuffer, 200, 0, 0);
|
||||
cogl_pipeline_set_layer_texture (pipeline, 0, priv->cogl_tex_id[1]);
|
||||
cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline,
|
||||
0, 0, 200, 213,
|
||||
texcoords[0], texcoords[1],
|
||||
texcoords[2], texcoords[3]);
|
||||
|
||||
cogl_pop_matrix ();
|
||||
cogl_push_matrix ();
|
||||
cogl_translate (200, 200, 0);
|
||||
cogl_set_source_texture (priv->cogl_tex_id[3]);
|
||||
cogl_rectangle_with_texture_coords (0, 0, 200, 213,
|
||||
texcoords[0], texcoords[1],
|
||||
texcoords[2], texcoords[3]);
|
||||
cogl_framebuffer_pop_matrix (framebuffer);
|
||||
cogl_framebuffer_push_matrix (framebuffer);
|
||||
cogl_framebuffer_translate (framebuffer, 0, 200, 0);
|
||||
cogl_pipeline_set_layer_texture (pipeline, 0, priv->cogl_tex_id[2]);
|
||||
cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline,
|
||||
0, 0, 200, 213,
|
||||
texcoords[0], texcoords[1],
|
||||
texcoords[2], texcoords[3]);
|
||||
|
||||
cogl_framebuffer_pop_matrix (framebuffer);
|
||||
cogl_framebuffer_push_matrix (framebuffer);
|
||||
cogl_framebuffer_translate (framebuffer, 200, 200, 0);
|
||||
cogl_pipeline_set_layer_texture (pipeline, 0, priv->cogl_tex_id[3]);
|
||||
cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline,
|
||||
0, 0, 200, 213,
|
||||
texcoords[0], texcoords[1],
|
||||
texcoords[2], texcoords[3]);
|
||||
cogl_framebuffer_pop_matrix (framebuffer);
|
||||
|
||||
cogl_object_unref (pipeline);
|
||||
|
||||
cogl_pop_matrix();
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -174,6 +174,7 @@ test_coglbox_paint (ClutterActor *self,
|
||||
: priv->not_sliced_tex;
|
||||
int tex_width = cogl_texture_get_width (tex_handle);
|
||||
int tex_height = cogl_texture_get_height (tex_handle);
|
||||
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||
CoglHandle material = cogl_material_new ();
|
||||
|
||||
cogl_material_set_layer (material, 0, tex_handle);
|
||||
@ -186,26 +187,26 @@ test_coglbox_paint (ClutterActor *self,
|
||||
? COGL_MATERIAL_FILTER_LINEAR :
|
||||
COGL_MATERIAL_FILTER_NEAREST);
|
||||
|
||||
cogl_push_matrix ();
|
||||
cogl_translate (tex_width / 2, 0, 0);
|
||||
cogl_rotate (priv->frame, 0, 1, 0);
|
||||
cogl_translate (-tex_width / 2, 0, 0);
|
||||
cogl_framebuffer_push_matrix (framebuffer);
|
||||
cogl_framebuffer_translate (framebuffer, tex_width / 2, 0, 0);
|
||||
cogl_framebuffer_rotate (framebuffer, priv->frame, 0, 1, 0);
|
||||
cogl_framebuffer_translate (framebuffer, -tex_width / 2, 0, 0);
|
||||
|
||||
/* Draw a hand and refect it */
|
||||
cogl_set_source (material);
|
||||
cogl_rectangle_with_texture_coords (0, 0, tex_width, tex_height,
|
||||
0, 0, 1, 1);
|
||||
cogl_framebuffer_draw_textured_rectangle (framebuffer, material,
|
||||
0, 0, tex_width, tex_height,
|
||||
0, 0, 1, 1);
|
||||
test_coglbox_fade_texture (0, tex_height,
|
||||
tex_width, (tex_height * 3 / 2),
|
||||
0.0, 1.0,
|
||||
1.0, 0.5);
|
||||
|
||||
cogl_pop_matrix ();
|
||||
cogl_framebuffer_pop_matrix (framebuffer);
|
||||
|
||||
cogl_push_matrix ();
|
||||
cogl_translate (tex_width * 3 / 2 + 60, 0, 0);
|
||||
cogl_rotate (priv->frame, 0, 1, 0);
|
||||
cogl_translate (-tex_width / 2 - 10, 0, 0);
|
||||
cogl_framebuffer_push_matrix (framebuffer);
|
||||
cogl_framebuffer_translate (framebuffer, tex_width * 3 / 2 + 60, 0, 0);
|
||||
cogl_framebuffer_rotate (framebuffer, priv->frame, 0, 1, 0);
|
||||
cogl_framebuffer_translate (framebuffer, -tex_width / 2 - 10, 0, 0);
|
||||
|
||||
/* Draw the texture split into two triangles */
|
||||
test_coglbox_triangle_texture (tex_width, tex_height,
|
||||
@ -219,7 +220,7 @@ test_coglbox_paint (ClutterActor *self,
|
||||
1, 0,
|
||||
1, 1);
|
||||
|
||||
cogl_pop_matrix ();
|
||||
cogl_framebuffer_pop_matrix (framebuffer);
|
||||
|
||||
cogl_object_unref (material);
|
||||
}
|
||||
|
@ -87,6 +87,9 @@ test_coglbox_paint (ClutterActor *self,
|
||||
ClutterPaintContext *paint_context)
|
||||
{
|
||||
TestCoglboxPrivate *priv = TEST_COGLBOX_GET_PRIVATE (self);
|
||||
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||
CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
|
||||
CoglPipeline *pipeline;
|
||||
gfloat texcoords[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
|
||||
gfloat angle;
|
||||
gfloat frac;
|
||||
@ -109,18 +112,24 @@ test_coglbox_paint (ClutterActor *self,
|
||||
|
||||
priv = TEST_COGLBOX_GET_PRIVATE (self);
|
||||
|
||||
cogl_push_matrix ();
|
||||
cogl_framebuffer_push_matrix (framebuffer);
|
||||
|
||||
cogl_set_source_color4ub (0x66, 0x66, 0xdd, 0xff);
|
||||
cogl_rectangle (0, 0, 400, 400);
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
cogl_pipeline_set_color4ub (pipeline, 0x66, 0x66, 0xdd, 0xff);
|
||||
cogl_framebuffer_draw_rectangle (framebuffer, pipeline, 0, 0, 400, 400);
|
||||
cogl_object_unref (pipeline);
|
||||
|
||||
cogl_translate (100, 100, 0);
|
||||
cogl_set_source_texture (priv->cogl_tex_id);
|
||||
cogl_rectangle_with_texture_coords (0, 0, 200, 213,
|
||||
texcoords[0], texcoords[1],
|
||||
texcoords[2], texcoords[3]);
|
||||
cogl_framebuffer_translate (framebuffer, 100, 100, 0);
|
||||
|
||||
cogl_pop_matrix();
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
cogl_pipeline_set_layer_texture (pipeline, 0, priv->cogl_tex_id);
|
||||
cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline,
|
||||
0, 0, 200, 213,
|
||||
texcoords[0], texcoords[1],
|
||||
texcoords[2], texcoords[3]);
|
||||
cogl_object_unref (pipeline);
|
||||
|
||||
cogl_framebuffer_pop_matrix (framebuffer);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -148,6 +148,9 @@ hand_pre_paint (ClutterActor *actor,
|
||||
ClutterPaintContext *paint_context,
|
||||
gpointer user_data)
|
||||
{
|
||||
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||
CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
|
||||
CoglPipeline *pipeline;
|
||||
SuperOH *oh = user_data;
|
||||
gfloat w, h;
|
||||
int actor_num;
|
||||
@ -159,8 +162,11 @@ hand_pre_paint (ClutterActor *actor,
|
||||
|
||||
clutter_actor_get_size (actor, &w, &h);
|
||||
|
||||
cogl_set_source_color4ub (255, 0, 0, 128);
|
||||
cogl_rectangle (0, 0, w / 2, h / 2);
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
cogl_pipeline_set_color4ub (pipeline, 255, 0, 0, 128);
|
||||
cogl_framebuffer_draw_rectangle (framebuffer, pipeline,
|
||||
0, 0, w / 2, h / 2);
|
||||
cogl_object_unref (pipeline);
|
||||
|
||||
oh->paint_guards[actor_num] = TRUE;
|
||||
}
|
||||
@ -170,6 +176,9 @@ hand_post_paint (ClutterActor *actor,
|
||||
ClutterPaintContext *paint_context,
|
||||
gpointer user_data)
|
||||
{
|
||||
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||
CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
|
||||
CoglPipeline *pipeline;
|
||||
SuperOH *oh = user_data;
|
||||
gfloat w, h;
|
||||
int actor_num;
|
||||
@ -181,8 +190,11 @@ hand_post_paint (ClutterActor *actor,
|
||||
|
||||
clutter_actor_get_size (actor, &w, &h);
|
||||
|
||||
cogl_set_source_color4ub (0, 255, 0, 128);
|
||||
cogl_rectangle (w / 2, h / 2, w, h);
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
cogl_pipeline_set_color4ub (pipeline, 0, 255, 0, 128);
|
||||
cogl_framebuffer_draw_rectangle (framebuffer, pipeline,
|
||||
w / 2, h / 2, w, h);
|
||||
cogl_object_unref (pipeline);
|
||||
|
||||
oh->paint_guards[actor_num] = FALSE;
|
||||
}
|
||||
|
@ -34,8 +34,11 @@ test_rectangles (TestState *state)
|
||||
{
|
||||
#define RECT_WIDTH 5
|
||||
#define RECT_HEIGHT 5
|
||||
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
||||
CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
|
||||
int x;
|
||||
int y;
|
||||
CoglPipeline *pipeline;
|
||||
|
||||
/* Should the rectangles be randomly positioned/colored/rotated?
|
||||
*
|
||||
@ -59,19 +62,23 @@ test_rectangles (TestState *state)
|
||||
*
|
||||
*/
|
||||
|
||||
pipeline = cogl_pipeline_new (ctx);
|
||||
|
||||
for (y = 0; y < STAGE_HEIGHT; y += RECT_HEIGHT)
|
||||
{
|
||||
for (x = 0; x < STAGE_WIDTH; x += RECT_WIDTH)
|
||||
{
|
||||
cogl_push_matrix ();
|
||||
cogl_translate (x, y, 0);
|
||||
cogl_rotate (45, 0, 0, 1);
|
||||
cogl_set_source_color4f (1,
|
||||
(1.0f/STAGE_WIDTH)*y,
|
||||
(1.0f/STAGE_HEIGHT)*x,
|
||||
1);
|
||||
cogl_rectangle (0, 0, RECT_WIDTH, RECT_HEIGHT);
|
||||
cogl_pop_matrix ();
|
||||
cogl_framebuffer_push_matrix (framebuffer);
|
||||
cogl_framebuffer_translate (framebuffer, x, y, 0);
|
||||
cogl_framebuffer_rotate (framebuffer, 45, 0, 0, 1);
|
||||
cogl_pipeline_set_color4f (pipeline,
|
||||
1,
|
||||
(1.0f / STAGE_WIDTH) * y,
|
||||
(1.0f / STAGE_HEIGHT) * x,
|
||||
1);
|
||||
cogl_framebuffer_draw_rectangle (framebuffer, pipeline,
|
||||
0, 0, RECT_WIDTH, RECT_HEIGHT);
|
||||
cogl_framebuffer_pop_matrix (framebuffer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,15 +86,17 @@ test_rectangles (TestState *state)
|
||||
{
|
||||
for (x = 0; x < STAGE_WIDTH; x += RECT_WIDTH)
|
||||
{
|
||||
cogl_push_matrix ();
|
||||
cogl_translate (x, y, 0);
|
||||
cogl_rotate (0, 0, 0, 1);
|
||||
cogl_set_source_color4f (1,
|
||||
(1.0f/STAGE_WIDTH)*x,
|
||||
(1.0f/STAGE_HEIGHT)*y,
|
||||
(1.0f/STAGE_WIDTH)*x);
|
||||
cogl_rectangle (0, 0, RECT_WIDTH, RECT_HEIGHT);
|
||||
cogl_pop_matrix ();
|
||||
cogl_framebuffer_push_matrix (framebuffer);
|
||||
cogl_framebuffer_translate (framebuffer, x, y, 0);
|
||||
cogl_framebuffer_rotate (framebuffer, 0, 0, 0, 1);
|
||||
cogl_pipeline_set_color4f (pipeline,
|
||||
1,
|
||||
(1.0f / STAGE_WIDTH) * x,
|
||||
(1.0f / STAGE_HEIGHT) * y,
|
||||
(1.0f / STAGE_WIDTH) * x);
|
||||
cogl_framebuffer_draw_rectangle (framebuffer, pipeline,
|
||||
0, 0, RECT_WIDTH, RECT_HEIGHT);
|
||||
cogl_framebuffer_pop_matrix (framebuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user