2
#include <clutter/clutter.h>
6
#include "test-conform-common.h"
8
static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
17
#define MASK_RED(COLOR) ((COLOR & 0xff000000) >> 24);
18
#define MASK_GREEN(COLOR) ((COLOR & 0xff0000) >> 16);
19
#define MASK_BLUE(COLOR) ((COLOR & 0xff00) >> 8);
20
#define MASK_ALPHA(COLOR) (COLOR & 0xff);
24
typedef struct _TestState
27
ClutterGeometry stage_geom;
32
check_pixel (TestState *state, int x, int y, guint32 color)
37
guint8 r = MASK_RED (color);
38
guint8 g = MASK_GREEN (color);
39
guint8 b = MASK_BLUE (color);
40
guint8 a = MASK_ALPHA (color);
42
/* See what we got... */
44
/* NB: glReadPixels is done in GL screen space so y = 0 is at the bottom */
45
y_off = y * QUAD_WIDTH + (QUAD_WIDTH / 2);
46
x_off = x * QUAD_WIDTH + (QUAD_WIDTH / 2);
49
* We haven't always had good luck with GL drivers implementing glReadPixels
50
* reliably and skipping the first two frames improves our chances... */
51
if (state->frame <= SKIP_FRAMES)
54
cogl_read_pixels (x_off, y_off, 1, 1,
55
COGL_READ_PIXELS_COLOR_BUFFER,
56
COGL_PIXEL_FORMAT_RGBA_8888,
58
if (g_test_verbose ())
59
g_print (" result = %02x, %02x, %02x, %02x\n",
60
pixel[RED], pixel[GREEN], pixel[BLUE], pixel[ALPHA]);
62
if (g_test_verbose ())
63
g_print (" expected = %x, %x, %x, %x\n",
65
/* FIXME - allow for hardware in-precision */
66
g_assert (pixel[RED] == r);
67
g_assert (pixel[GREEN] == g);
68
g_assert (pixel[BLUE] == b);
71
* We ignore the alpha, since we don't know if our render target is
73
/* g_assert (pixel[ALPHA] == a); */
77
test_invalid_texture_layers (TestState *state, int x, int y)
79
CoglHandle material = cogl_material_new ();
80
CoglTextureVertex verts[4] = {
81
{ .x = 0, .y = 0, .z = 0 },
82
{ .x = 0, .y = QUAD_WIDTH, .z = 0 },
83
{ .x = QUAD_WIDTH, .y = QUAD_WIDTH, .z = 0 },
84
{ .x = QUAD_WIDTH, .y = 0, .z = 0 },
90
cogl_translate (x * QUAD_WIDTH, y * QUAD_WIDTH, 0);
92
/* explicitly create a layer with an invalid handle. This may be desireable
93
* if the user also sets a texture combine string that e.g. refers to a
95
cogl_material_set_layer (material, 0, COGL_INVALID_HANDLE);
97
cogl_set_source (material);
98
cogl_rectangle (0, 0, QUAD_WIDTH, QUAD_WIDTH);
100
cogl_translate (0, QUAD_WIDTH, 0);
101
cogl_polygon (verts, 4, FALSE);
103
cogl_translate (0, QUAD_WIDTH, 0);
104
vbo = cogl_vertex_buffer_new (4);
105
cogl_vertex_buffer_add (vbo,
107
2, /* n components */
108
COGL_ATTRIBUTE_TYPE_FLOAT,
109
FALSE, /* normalized */
110
sizeof (CoglTextureVertex), /* stride */
112
cogl_vertex_buffer_draw (vbo,
113
COGL_VERTICES_MODE_TRIANGLE_FAN,
116
cogl_handle_unref (vbo);
120
cogl_handle_unref (material);
122
/* We expect a white fallback material to be used */
123
check_pixel (state, x, y, 0xffffffff);
124
check_pixel (state, x, y+1, 0xffffffff);
125
check_pixel (state, x, y+2, 0xffffffff);
129
on_paint (ClutterActor *actor, TestState *state)
133
test_invalid_texture_layers (state,
137
/* XXX: Experiments have shown that for some buggy drivers, when using
138
* glReadPixels there is some kind of race, so we delay our test for a
139
* few frames and a few seconds:
141
frame_num = state->frame++;
142
if (frame_num < SKIP_FRAMES)
143
g_usleep (G_USEC_PER_SEC);
145
/* Comment this out if you want visual feedback for what this test paints */
147
if (frame_num > SKIP_FRAMES)
148
clutter_main_quit ();
153
queue_redraw (gpointer stage)
155
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
161
test_materials (TestConformSimpleFixture *fixture,
171
stage = clutter_stage_get_default ();
173
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
174
clutter_actor_get_geometry (stage, &state.stage_geom);
176
group = clutter_group_new ();
177
clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
179
/* We force continuous redrawing of the stage, since we need to skip
180
* the first few frames, and we wont be doing anything else that
181
* will trigger redrawing. */
182
idle_source = g_idle_add (queue_redraw, stage);
184
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
186
clutter_actor_show_all (stage);
190
g_source_remove (idle_source);
192
if (g_test_verbose ())