1
#include <clutter/clutter.h>
5
#include "test-conform-common.h"
7
static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
16
typedef struct _TestState
22
assert_region_color (int x,
31
guint8 *data = g_malloc0 (width * height * 4);
32
cogl_read_pixels (x, y, width, height,
33
COGL_READ_PIXELS_COLOR_BUFFER,
34
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
36
for (y = 0; y < height; y++)
37
for (x = 0; x < width; x++)
39
guint8 *pixel = &data[y * width * 4 + x * 4];
41
g_assert (pixel[RED] == red &&
42
pixel[GREEN] == green &&
43
pixel[BLUE] == blue &&
44
pixel[ALPHA] == alpha);
50
/* Creates a texture divided into 4 quads with colors arranged as follows:
51
* (The same value are used in all channels for each texel)
64
make_texture (guchar ref)
72
tex_data = g_malloc (QUAD_WIDTH * QUAD_WIDTH * 16);
74
for (y = 0; y < QUAD_WIDTH * 2; y++)
75
for (x = 0; x < QUAD_WIDTH * 2; x++)
77
p = tex_data + (QUAD_WIDTH * 8 * y) + x * 4;
78
if (x < QUAD_WIDTH && y < QUAD_WIDTH)
80
else if (x >= QUAD_WIDTH && y >= QUAD_WIDTH)
84
p[0] = p[1] = p[2] = p[3] = val;
87
/* Note: we don't use COGL_PIXEL_FORMAT_ANY for the internal format here
88
* since we don't want to allow Cogl to premultiply our data. */
89
tex = cogl_texture_new_from_data (QUAD_WIDTH * 2,
92
COGL_PIXEL_FORMAT_RGBA_8888,
93
COGL_PIXEL_FORMAT_RGBA_8888,
103
on_paint (ClutterActor *actor, TestState *state)
105
CoglHandle tex0, tex1;
108
GError *error = NULL;
109
float tex_coords[] = {
110
0, 0, 0.5, 0.5, /* tex0 */
111
0.5, 0.5, 1, 1 /* tex1 */
115
* We haven't always had good luck with GL drivers implementing glReadPixels
116
* reliably and skipping the first two frames improves our chances... */
117
if (state->frame++ <= 2)
119
g_usleep (G_USEC_PER_SEC);
123
tex0 = make_texture (0x00);
124
tex1 = make_texture (0x11);
126
material = cogl_material_new ();
128
/* An arbitrary color which should be replaced by the first texture layer */
129
cogl_material_set_color4ub (material, 0x80, 0x80, 0x80, 0x80);
130
cogl_material_set_blend (material, "RGBA = ADD (SRC_COLOR, 0)", NULL);
132
cogl_material_set_layer (material, 0, tex0);
133
cogl_material_set_layer_combine (material, 0,
134
"RGBA = REPLACE (TEXTURE)", NULL);
136
cogl_material_set_layer (material, 1, tex1);
137
status = cogl_material_set_layer_combine (material, 1,
138
"RGBA = ADD (PREVIOUS, TEXTURE)",
142
/* It's not strictly a test failure; you need a more capable GPU or
143
* driver to test this texture combine string. */
144
g_debug ("Failed to setup texture combine string "
145
"RGBA = ADD (PREVIOUS, TEXTURE): %s",
149
cogl_set_source (material);
150
cogl_rectangle_with_multitexture_coords (0, 0, QUAD_WIDTH, QUAD_WIDTH,
153
cogl_handle_unref (material);
154
cogl_handle_unref (tex0);
155
cogl_handle_unref (tex1);
157
/* See what we got... */
159
assert_region_color (0, 0, QUAD_WIDTH, QUAD_WIDTH,
160
0x55, 0x55, 0x55, 0x55);
162
/* Comment this out if you want visual feedback for what this test paints */
164
clutter_main_quit ();
169
queue_redraw (gpointer stage)
171
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
177
test_cogl_multitexture (TestConformSimpleFixture *fixture,
187
stage = clutter_stage_get_default ();
189
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
191
group = clutter_group_new ();
192
clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
194
/* We force continuous redrawing of the stage, since we need to skip
195
* the first few frames, and we wont be doing anything else that
196
* will trigger redrawing. */
197
idle_source = g_idle_add (queue_redraw, stage);
199
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
201
clutter_actor_show_all (stage);
205
g_source_remove (idle_source);
207
if (g_test_verbose ())