Debian Codegraph @

tests/interactive/test-cogl-tex-convert.c

raw
1 #include <glib.h>
2 #include <gmodule.h>
3 #include <stdlib.h>
4 #include <clutter/clutter.h>
5 #include <cogl/cogl.h>
6
7 /* Coglbox declaration
8 *--------------------------------------------------*/
9
10 G_BEGIN_DECLS
11
12 #define TEST_TYPE_COGLBOX test_coglbox_get_type()
13
14 #define TEST_COGLBOX(obj) \
15 (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
16 TEST_TYPE_COGLBOX, TestCoglboxClass))
17
18 #define TEST_COGLBOX_CLASS(klass) \
19 (G_TYPE_CHECK_CLASS_CAST ((klass), \
20 TEST_TYPE_COGLBOX, TestCoglboxClass))
21
22 #define TEST_IS_COGLBOX(obj) \
23 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
24 TEST_TYPE_COGLBOX))
25
26 #define TEST_IS_COGLBOX_CLASS(klass) \
27 (G_TYPE_CHECK_CLASS_TYPE ((klass), \
28 TEST_TYPE_COGLBOX))
29
30 #define TEST_COGLBOX_GET_CLASS(obj) \
31 (G_TYPE_INSTANCE_GET_CLASS ((obj), \
32 TEST_TYPE_COGLBOX, TestCoglboxClass))
33
34 typedef struct _TestCoglbox TestCoglbox;
35 typedef struct _TestCoglboxClass TestCoglboxClass;
36 typedef struct _TestCoglboxPrivate TestCoglboxPrivate;
37
38 struct _TestCoglbox
39 {
40 ClutterActor parent;
41
42 /*< private >*/
43 TestCoglboxPrivate *priv;
44 };
45
46 struct _TestCoglboxClass
47 {
48 ClutterActorClass parent_class;
49
50 /* padding for future expansion */
51 void (*_test_coglbox1) (void);
52 void (*_test_coglbox2) (void);
53 void (*_test_coglbox3) (void);
54 void (*_test_coglbox4) (void);
55 };
56
57 static GType test_coglbox_get_type (void) G_GNUC_CONST;
58
59 G_END_DECLS
60
61 /* Coglbox private declaration
62 *--------------------------------------------------*/
63
64 G_DEFINE_TYPE (TestCoglbox, test_coglbox, CLUTTER_TYPE_ACTOR);
65
66 #define TEST_COGLBOX_GET_PRIVATE(obj) \
67 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TEST_TYPE_COGLBOX, TestCoglboxPrivate))
68
69 struct _TestCoglboxPrivate
70 {
71 CoglHandle cogl_tex_id[4];
72 gint frame;
73 };
74
75 /* Coglbox implementation
76 *--------------------------------------------------*/
77
78 static void
79 test_coglbox_paint(ClutterActor *self)
80 {
81 TestCoglboxPrivate *priv = TEST_COGLBOX_GET_PRIVATE (self);
82 gfloat texcoords[4] = { 0.0, 0.0, 1.0, 1.0 };
83
84 priv = TEST_COGLBOX_GET_PRIVATE (self);
85
86 cogl_set_source_color4ub (0x66, 0x66, 0xdd, 0xff);
87 cogl_rectangle (0, 0, 400, 400);
88
89 cogl_push_matrix ();
90 cogl_set_source_texture (priv->cogl_tex_id[0]);
91 cogl_rectangle_with_texture_coords (0, 0, 200, 213,
92 texcoords[0], texcoords[1],
93 texcoords[2], texcoords[3]);
94
95 cogl_pop_matrix ();
96 cogl_push_matrix ();
97 cogl_translate (200, 0, 0);
98 cogl_set_source_texture (priv->cogl_tex_id[1]);
99 cogl_rectangle_with_texture_coords (0, 0, 200, 213,
100 texcoords[0], texcoords[1],
101 texcoords[2], texcoords[3]);
102
103 cogl_pop_matrix ();
104 cogl_push_matrix ();
105 cogl_translate (0, 200, 0);
106 cogl_set_source_texture (priv->cogl_tex_id[2]);
107 cogl_rectangle_with_texture_coords (0, 0, 200, 213,
108 texcoords[0], texcoords[1],
109 texcoords[2], texcoords[3]);
110
111 cogl_pop_matrix ();
112 cogl_push_matrix ();
113 cogl_translate (200, 200, 0);
114 cogl_set_source_texture (priv->cogl_tex_id[3]);
115 cogl_rectangle_with_texture_coords (0, 0, 200, 213,
116 texcoords[0], texcoords[1],
117 texcoords[2], texcoords[3]);
118
119 cogl_pop_matrix();
120 }
121
122 static void
123 test_coglbox_finalize (GObject *object)
124 {
125 G_OBJECT_CLASS (test_coglbox_parent_class)->finalize (object);
126 }
127
128 static void
129 test_coglbox_dispose (GObject *object)
130 {
131 TestCoglboxPrivate *priv;
132
133 priv = TEST_COGLBOX_GET_PRIVATE (object);
134 cogl_handle_unref (priv->cogl_tex_id);
135
136 G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object);
137 }
138
139 static void
140 test_coglbox_init (TestCoglbox *self)
141 {
142 TestCoglboxPrivate *priv;
143 gchar *file;
144
145 self->priv = priv = TEST_COGLBOX_GET_PRIVATE(self);
146
147 file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
148
149 priv->cogl_tex_id[0] =
150 cogl_texture_new_from_file (file,
151 COGL_TEXTURE_NONE,
152 COGL_PIXEL_FORMAT_ANY,
153 NULL);
154
155 priv->cogl_tex_id[1] =
156 cogl_texture_new_from_file (file,
157 COGL_TEXTURE_NONE,
158 COGL_PIXEL_FORMAT_BGRA_8888,
159 NULL);
160
161 priv->cogl_tex_id[2] =
162 cogl_texture_new_from_file (file,
163 COGL_TEXTURE_NONE,
164 COGL_PIXEL_FORMAT_ARGB_8888,
165 NULL);
166
167 priv->cogl_tex_id[3] =
168 cogl_texture_new_from_file (file,
169 COGL_TEXTURE_NONE,
170 COGL_PIXEL_FORMAT_G_8,
171 NULL);
172
173 g_free (file);
174 }
175
176 static void
177 test_coglbox_class_init (TestCoglboxClass *klass)
178 {
179 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
180 ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
181
182 gobject_class->finalize = test_coglbox_finalize;
183 gobject_class->dispose = test_coglbox_dispose;
184 actor_class->paint = test_coglbox_paint;
185
186 g_type_class_add_private (gobject_class, sizeof (TestCoglboxPrivate));
187 }
188
189 static ClutterActor*
190 test_coglbox_new (void)
191 {
192 return g_object_new (TEST_TYPE_COGLBOX, NULL);
193 }
194
195 G_MODULE_EXPORT int
196 test_cogl_tex_convert_main (int argc, char *argv[])
197 {
198 ClutterActor *stage;
199 ClutterActor *coglbox;
200
201 if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
202 return 1;
203
204 /* Stage */
205 stage = clutter_stage_new ();
206 clutter_actor_set_size (stage, 400, 400);
207 clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Texture Conversion");
208 g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
209
210 /* Cogl Box */
211 coglbox = test_coglbox_new ();
212 clutter_container_add_actor (CLUTTER_CONTAINER (stage), coglbox);
213
214 clutter_actor_show_all (stage);
215
216 clutter_main ();
217
218 return 0;
219 }
220
221 G_MODULE_EXPORT const char *
222 test_cogl_tex_convert_describe (void)
223 {
224 return "Pixel format conversion of Cogl textures.";
225 }