Ejemplo n.º 1
0
G_MODULE_EXPORT int
test_fbo_main (int argc, char *argv[])
{
  ClutterColor      blue   = {0x33, 0x44, 0x55, 0xff};

  ClutterActor     *fbo;
  ClutterActor     *onscreen_source;
  ClutterActor     *stage;
  ClutterAnimation *animation;
  int               x_pos = 200;
  int               y_pos = 100;

  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_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT);
  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);

  y_pos = (STAGE_HEIGHT/2.0) -
          (clutter_actor_get_height (onscreen_source)/2.0);
  clutter_actor_set_position (onscreen_source, x_pos, y_pos);
  x_pos += clutter_actor_get_width (onscreen_source);

  animation = clutter_actor_animate (onscreen_source,
                                     CLUTTER_LINEAR,
                                     5000, /* 1 second duration */
                                     "rotation-angle-y", 360.0f,
                                     NULL);
  clutter_animation_set_loop (animation, TRUE);

  /* Second hand = actor from onscreen_source */
  if ((fbo = clutter_texture_new_from_actor (onscreen_source)) == NULL)
    g_error("onscreen fbo creation failed");

  clutter_actor_set_position (fbo, x_pos, y_pos);
  x_pos += clutter_actor_get_width (fbo);
  clutter_group_add (stage, fbo);

  /* Third hand = actor from Second hand */
  if ((fbo = clutter_texture_new_from_actor (fbo)) == NULL)
    g_error("fbo from fbo creation failed");

  clutter_actor_set_position (fbo, x_pos, y_pos);
  x_pos += clutter_actor_get_width (fbo);
  clutter_group_add (stage, fbo);

  clutter_actor_show_all (stage);
  clutter_main ();

  return 0;
}
Ejemplo n.º 2
0
void
test_texture_fbo (TestConformSimpleFixture *fixture,
                  gconstpointer data)
{
  TestState state;
  guint idle_source;
  gulong paint_handler;
  ClutterActor *actor;
  int ypos = 0;

  state.frame = 0;

  state.stage = clutter_stage_get_default ();

  clutter_stage_set_color (CLUTTER_STAGE (state.stage), &stage_color);

  /* Onscreen source with clone next to it */
  actor = create_source ();
  clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL);
  clutter_actor_set_position (actor, 0, ypos * SOURCE_SIZE);
  actor = clutter_texture_new_from_actor (actor);
  clutter_actor_set_position (actor, SOURCE_SIZE, ypos * SOURCE_SIZE);
  clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL);
  ypos++;

  /* Offscreen source with clone */
#if 0 /* this doesn't work */
  actor = create_source ();
  actor = clutter_texture_new_from_actor (actor);
  clutter_actor_set_position (actor, SOURCE_SIZE, ypos * SOURCE_SIZE);
  clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL);
#endif
  ypos++;

  /* Source clipped to the top left division */
  actor = create_source ();
  clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL);
  clutter_actor_set_position (actor, 0, ypos * SOURCE_SIZE);
  clutter_actor_set_clip (actor, 0, 0, DIVISION_WIDTH, DIVISION_HEIGHT);
  actor = clutter_texture_new_from_actor (actor);
  clutter_actor_set_position (actor, SOURCE_SIZE, ypos * SOURCE_SIZE);
  clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL);
  ypos++;

  /* Source clipped to everything but top left division using a
     path */
  actor = create_source ();
  clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL);
  clutter_actor_set_position (actor, 0, ypos * SOURCE_SIZE);
  g_signal_connect (actor, "paint",
                    G_CALLBACK (pre_paint_clip_cb), NULL);
  g_signal_connect_after (actor, "paint",
                          G_CALLBACK (post_paint_clip_cb), NULL);
  actor = clutter_texture_new_from_actor (actor);
  clutter_actor_set_position (actor, SOURCE_SIZE, ypos * SOURCE_SIZE);
  clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL);
  ypos++;

  /* We force continuous redrawing of the stage, since we need to skip
   * the first few frames, and we wont be doing anything else that
   * will trigger redrawing. */
  idle_source = g_idle_add (queue_redraw, state.stage);

  paint_handler = g_signal_connect_after (state.stage, "paint",
                                          G_CALLBACK (on_paint), &state);

  clutter_actor_show_all (state.stage);

  clutter_main ();

  g_signal_handler_disconnect (state.stage, paint_handler);

  g_source_remove (idle_source);

  /* Remove all of the actors from the stage */
  clutter_container_foreach (CLUTTER_CONTAINER (state.stage),
                             (ClutterCallback) clutter_actor_destroy,
                             NULL);

  if (g_test_verbose ())
    g_print ("OK\n");
}