Debian Codegraph @

tests/interactive/test-texture-slicing.c

raw
1 #include <stdlib.h>
2 #include <gmodule.h>
3
4 #include <clutter/clutter.h>
5
6 guchar*
7 make_rgba_data (int width, int height, int bpp, int has_alpha, int *rowstride_p)
8 {
9 #define CHECK_SIZE 20
10
11 gint x,y, rowstride, i = 0;
12 guchar *pixels;
13
14 g_assert(bpp == 4);
15 g_assert(has_alpha == TRUE);
16
17 rowstride = width * bpp;
18 *rowstride_p = rowstride;
19
20 pixels = g_try_malloc (height * rowstride);
21 if (!pixels)
22 return NULL;
23
24 for (y = 0; y < height; y++)
25 {
26 i = 0;
27 for (x = 0; x < width; x++)
28 {
29 guchar *p;
30
31 p = pixels + y * rowstride + x * bpp;
32
33 p[0] = p[1] = p[2] = 0; p[3] = 0xff;
34
35 if (x && y && y % CHECK_SIZE && x % CHECK_SIZE)
36 {
37 if (x % CHECK_SIZE == 1)
38 {
39 if (++i > 3)
40 i = 0;
41 }
42 p[i] = 0xff;
43 }
44 }
45 }
46
47 return pixels;
48 }
49
50 static void
51 exit_on_destroy (ClutterActor *actor)
52 {
53 exit(EXIT_SUCCESS);
54 }
55
56 #define SPIN() while (g_main_context_pending (NULL)) \
57 g_main_context_iteration (NULL, FALSE);
58
59 G_MODULE_EXPORT int
60 test_textures_main (int argc, char *argv[])
61 {
62 ClutterActor *texture;
63 ClutterActor *stage;
64 gint i, j;
65
66 if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
67 return 1;
68
69 stage = clutter_stage_new ();
70 clutter_actor_show_all (CLUTTER_ACTOR (stage));
71 g_signal_connect (stage, "destroy", G_CALLBACK (exit_on_destroy), NULL);
72
73 SPIN();
74
75 for (i=100; i<=5000; i += 100)
76 for (j=0; j<4; j++)
77 {
78 const int width = i+j;
79 const int height = i+j;
80 const gboolean has_alpha = TRUE;
81 const int bpp = has_alpha ? 4 : 3;
82 int rowstride;
83 guchar *pixels;
84
85 pixels = make_rgba_data (width, height, bpp, has_alpha, &rowstride);
86 if (!pixels)
87 g_error("No memory for %ix%i RGBA data failed", width, height);
88
89 printf("o %ix%i texture... ", width, height);
90
91 texture = clutter_texture_new ();
92 if (!clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (texture),
93 pixels,
94 has_alpha,
95 width,
96 height,
97 rowstride,
98 bpp,
99 0, NULL))
100 g_error("texture creation failed");
101 g_free(pixels);
102
103 printf("uploaded to texture...\n");
104
105 clutter_container_add (CLUTTER_CONTAINER (stage), texture, NULL);
106 clutter_actor_set_size (texture, 400, 400);
107 clutter_actor_show (texture);
108
109 /* Hide & show to unreaise then realise the texture */
110 clutter_actor_hide (texture);
111 clutter_actor_show (texture);
112
113 SPIN();
114
115 clutter_container_remove (CLUTTER_CONTAINER (stage), texture, NULL);
116 }
117
118 return EXIT_SUCCESS;
119 }
120
121 G_MODULE_EXPORT const char *
122 test_texture_slicing_describe (void)
123 {
124 return "Check texture slicing support in CoglTexture";
125 }