~ubuntu-branches/ubuntu/precise/clutter-1.0/precise

« back to all changes in this revision

Viewing changes to tests/interactive/test-shader.c

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2010-03-21 13:27:56 UTC
  • mto: (2.1.3 experimental) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20100321132756-nf8yd30yxo3zzwcm
Tags: upstream-1.2.2
ImportĀ upstreamĀ versionĀ 1.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
203
203
 
204
204
static gint shader_no = 0;
205
205
 
 
206
static int
 
207
next_p2 (gint a)
 
208
{
 
209
  int rval = 1;
 
210
 
 
211
  while (rval < a)
 
212
    rval <<= 1;
 
213
 
 
214
  return rval;
 
215
}
 
216
 
206
217
static void
207
218
set_shader_num (ClutterActor *actor, gint new_no)
208
219
{
251
262
 
252
263
          if (CLUTTER_IS_TEXTURE (actor))
253
264
            {
 
265
              /* XXX - this assumes *a lot* about how things are done
 
266
               * internally on *some* hardware and driver
 
267
               */
254
268
              tex_width = clutter_actor_get_width (actor);
255
 
              tex_width = clutter_util_next_p2 (tex_width);
 
269
              tex_width = next_p2 (tex_width);
 
270
 
256
271
              tex_height = clutter_actor_get_height (actor);
257
 
              tex_height = clutter_util_next_p2 (tex_height);
 
272
              tex_height = next_p2 (tex_height);
258
273
 
259
274
              clutter_actor_set_shader_param_float (actor, "x_step",
260
275
                                                    1.0f / tex_width);
304
319
G_MODULE_EXPORT gint
305
320
test_shader_main (gint argc, gchar *argv[])
306
321
{
307
 
  ClutterActor     *actor;
308
 
  ClutterActor     *stage;
309
 
  ClutterColor      stage_color = { 0x61, 0x64, 0x8c, 0xff };
310
 
  ClutterShader    *shader;
311
 
  GError           *error;
 
322
  ClutterActor  *actor;
 
323
  ClutterActor  *stage;
 
324
  ClutterColor   stage_color = { 0x61, 0x64, 0x8c, 0xff };
 
325
  ClutterShader *shader;
 
326
  GError        *error;
 
327
  gchar         *file;
312
328
 
313
329
  clutter_init (&argc, &argv);
314
330
 
338
354
  clutter_stage_set_title (CLUTTER_STAGE (stage), "Shader Test");
339
355
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
340
356
 
 
357
  file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
 
358
 
341
359
#ifndef TEST_GROUP
342
 
  actor = g_object_new (CLUTTER_TYPE_TEXTURE,
343
 
                        "filename", "redhand.png",
344
 
                        "disable-slicing", TRUE,
345
 
                        NULL);
346
 
  actor = clutter_texture_new_from_file ("redhand.png", &error);
 
360
  actor = clutter_texture_new_from_file (file, &error);
347
361
  if (!actor)
348
362
    g_error("pixbuf load failed: %s", error ? error->message : "Unknown");
349
 
 
350
363
#else
351
364
  actor = clutter_group_new ();
352
 
    {
353
 
      ClutterActor *child1, *child2, *child3, *child4;
354
 
      ClutterColor  color = { 0xff, 0x22, 0x66, 0x99 };
355
 
 
356
 
      child1 = clutter_texture_new_from_file ("redhand.png", &error);
357
 
      if (!child1)
358
 
        g_error("pixbuf load failed: %s", error ? error->message : "Unknown");
359
 
      child2 = clutter_texture_new_from_file ("redhand.png", &error);
360
 
      if (!child2)
361
 
        g_error("pixbuf load failed: %s", error ? error->message : "Unknown");
362
 
      child3 = clutter_rectangle_new ();
363
 
      child4 = clutter_text_new_with_text ("Sans 20px", "Shady stuff");
364
 
 
365
 
      clutter_rectangle_set_color (child3, &color);
366
 
      clutter_actor_set_size (child3, 50, 50);
367
 
      clutter_actor_set_position (child1, 0, 0);
368
 
      clutter_actor_set_position (child2, 50, 100);
369
 
      clutter_actor_set_position (child3, 30, -30);
370
 
      clutter_actor_set_position (child4, -50, 20);
371
 
 
372
 
      clutter_group_add (CLUTTER_GROUP (actor), child1);
373
 
      clutter_group_add (CLUTTER_GROUP (actor), child2);
374
 
      clutter_group_add (CLUTTER_GROUP (actor), child3);
375
 
      clutter_group_add (CLUTTER_GROUP (actor), child4);
376
 
 
377
 
      clutter_actor_show_all (actor);
378
 
    }
379
 
#endif
 
365
 
 
366
  {
 
367
    ClutterActor *child1, *child2, *child3, *child4;
 
368
    ClutterColor  color = { 0xff, 0x22, 0x66, 0x99 };
 
369
 
 
370
    child1 = clutter_texture_new_from_file (file, &error);
 
371
    if (!child1)
 
372
      g_error("pixbuf load failed: %s", error ? error->message : "Unknown");
 
373
 
 
374
    child2 = clutter_texture_new_from_file (file, &error);
 
375
    if (!child2)
 
376
      g_error("pixbuf load failed: %s", error ? error->message : "Unknown");
 
377
 
 
378
    child3 = clutter_rectangle_new ();
 
379
    child4 = clutter_text_new_with_text ("Sans 20px", "Shady stuff");
 
380
 
 
381
    clutter_rectangle_set_color (CLUTTER_RECTANGLE (child3), &color);
 
382
    clutter_actor_set_size (child3, 50, 50);
 
383
 
 
384
    clutter_actor_set_position (child1, 0, 0);
 
385
    clutter_actor_set_position (child2, 50, 100);
 
386
    clutter_actor_set_position (child3, 30, -30);
 
387
    clutter_actor_set_position (child4, -50, 20);
 
388
 
 
389
    clutter_container_add (CLUTTER_CONTAINER (actor),
 
390
                           child1,
 
391
                           child2,
 
392
                           child3,
 
393
                           child4,
 
394
                           NULL);
 
395
 
 
396
    clutter_actor_show_all (actor);
 
397
  }
 
398
#endif /* !TEST_GROUP */
 
399
 
 
400
  g_free (file);
380
401
 
381
402
  clutter_actor_set_shader (actor, shader);
382
403
  clutter_actor_set_position (actor, 100, 100);