2
#include <clutter/clutter.h>
5
#include "test-conform-common.h"
7
/* This test verifies that the simplest usage of the vertex buffer API,
8
* where we add contiguous (x,y) GLfloat vertices, and RGBA GLubyte color
9
* attributes to a buffer, submit, and draw.
11
* It also tries to verify that the enable/disable attribute APIs are working
14
* If you want visual feedback of what this test paints for debugging purposes,
15
* then remove the call to clutter_main_quit() in validate_result.
18
typedef struct _TestState
23
ClutterGeometry stage_geom;
28
validate_result (TestState *state)
33
if (g_test_verbose ())
34
g_print ("y_off = %d\n", y_off);
36
/* NB: We ignore the alpha, since we don't know if our render target is
43
/* Should see a blue pixel */
44
cogl_read_pixels (10, y_off, 1, 1,
45
COGL_READ_PIXELS_COLOR_BUFFER,
46
COGL_PIXEL_FORMAT_RGBA_8888,
48
if (g_test_verbose ())
49
g_print ("pixel 0 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
50
g_assert (pixel[RED] == 0 && pixel[GREEN] == 0 && pixel[BLUE] != 0);
52
/* Should see a red pixel */
53
cogl_read_pixels (110, y_off, 1, 1,
54
COGL_READ_PIXELS_COLOR_BUFFER,
55
COGL_PIXEL_FORMAT_RGBA_8888,
57
if (g_test_verbose ())
58
g_print ("pixel 1 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
59
g_assert (pixel[RED] != 0 && pixel[GREEN] == 0 && pixel[BLUE] == 0);
61
/* Should see a blue pixel */
62
cogl_read_pixels (210, y_off, 1, 1,
63
COGL_READ_PIXELS_COLOR_BUFFER,
64
COGL_PIXEL_FORMAT_RGBA_8888,
66
if (g_test_verbose ())
67
g_print ("pixel 2 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
68
g_assert (pixel[RED] == 0 && pixel[GREEN] == 0 && pixel[BLUE] != 0);
70
/* Should see a green pixel, at bottom of 4th triangle */
71
cogl_read_pixels (310, y_off, 1, 1,
72
COGL_READ_PIXELS_COLOR_BUFFER,
73
COGL_PIXEL_FORMAT_RGBA_8888,
75
if (g_test_verbose ())
76
g_print ("pixel 3 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
77
g_assert (pixel[GREEN] > pixel[RED] && pixel[GREEN] > pixel[BLUE]);
79
/* Should see a red pixel, at top of 4th triangle */
80
cogl_read_pixels (310, y_off - 70, 1, 1,
81
COGL_READ_PIXELS_COLOR_BUFFER,
82
COGL_PIXEL_FORMAT_RGBA_8888,
84
if (g_test_verbose ())
85
g_print ("pixel 4 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
86
g_assert (pixel[RED] > pixel[GREEN] && pixel[RED] > pixel[BLUE]);
93
/* Comment this out if you want visual feedback of what this test
100
on_paint (ClutterActor *actor, TestState *state)
102
/* Draw a faded blue triangle */
103
cogl_vertex_buffer_enable (state->buffer, "gl_Color::blue");
104
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
105
cogl_vertex_buffer_draw (state->buffer,
106
GL_TRIANGLE_STRIP, /* mode */
110
/* Draw a red triangle */
111
/* Here we are testing that the disable attribute works; if it doesn't
112
* the triangle will remain faded blue */
113
cogl_translate (100, 0, 0);
114
cogl_vertex_buffer_disable (state->buffer, "gl_Color::blue");
115
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
116
cogl_vertex_buffer_draw (state->buffer,
117
GL_TRIANGLE_STRIP, /* mode */
121
/* Draw a faded blue triangle */
122
/* Here we are testing that the re-enable works; if it doesn't
123
* the triangle will remain red */
124
cogl_translate (100, 0, 0);
125
cogl_vertex_buffer_enable (state->buffer, "gl_Color::blue");
126
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
127
cogl_vertex_buffer_draw (state->buffer,
128
GL_TRIANGLE_STRIP, /* mode */
132
/* Draw a textured triangle */
133
cogl_translate (100, 0, 0);
134
cogl_vertex_buffer_disable (state->buffer, "gl_Color::blue");
135
cogl_set_source (state->material);
136
cogl_material_set_color4ub (state->material, 0xff, 0xff, 0xff, 0xff);
137
cogl_vertex_buffer_draw (state->buffer,
138
GL_TRIANGLE_STRIP, /* mode */
142
/* XXX: Experiments have shown that for some buggy drivers, when using
143
* glReadPixels there is some kind of race, so we delay our test for a
144
* few frames and a few seconds:
146
if (state->frame >= 2)
147
validate_result (state);
149
g_usleep (G_USEC_PER_SEC);
155
queue_redraw (gpointer stage)
157
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
165
test_vertex_buffer_contiguous (TestConformSimpleFixture *fixture,
170
ClutterColor stage_clr = {0x0, 0x0, 0x0, 0xff};
173
guchar tex_data[] = {
174
0xff, 0x00, 0x00, 0xff,
175
0xff, 0x00, 0x00, 0xff,
176
0x00, 0xff, 0x00, 0xff,
177
0x00, 0xff, 0x00, 0xff
182
stage = clutter_stage_get_default ();
184
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_clr);
185
clutter_actor_get_geometry (stage, &state.stage_geom);
187
group = clutter_group_new ();
188
clutter_actor_set_size (group,
189
state.stage_geom.width,
190
state.stage_geom.height);
191
clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
193
/* We force continuous redrawing of the stage, since we need to skip
194
* the first few frames, and we wont be doing anything else that
195
* will trigger redrawing. */
196
idle_source = g_idle_add (queue_redraw, stage);
198
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
200
state.texture = cogl_texture_new_from_data (2, 2,
201
COGL_TEXTURE_NO_SLICING,
202
COGL_PIXEL_FORMAT_RGBA_8888,
203
COGL_PIXEL_FORMAT_ANY,
204
0, /* auto calc row stride */
207
state.material = cogl_material_new ();
208
cogl_material_set_color4ub (state.material, 0x00, 0xff, 0x00, 0xff);
209
cogl_material_set_layer (state.material, 0, state.texture);
212
GLfloat triangle_verts[3][2] =
218
GLbyte triangle_colors[3][4] =
220
{0x00, 0x00, 0xff, 0xff}, /* blue */
221
{0x00, 0x00, 0xff, 0x00}, /* transparent blue */
222
{0x00, 0x00, 0xff, 0x00} /* transparent blue */
224
GLfloat triangle_tex_coords[3][2] =
230
state.buffer = cogl_vertex_buffer_new (3 /* n vertices */);
231
cogl_vertex_buffer_add (state.buffer,
233
2, /* n components */
235
FALSE, /* normalized */
238
cogl_vertex_buffer_add (state.buffer,
240
4, /* n components */
242
FALSE, /* normalized */
245
cogl_vertex_buffer_add (state.buffer,
247
2, /* n components */
249
FALSE, /* normalized */
251
triangle_tex_coords);
253
cogl_vertex_buffer_submit (state.buffer);
256
clutter_actor_show_all (stage);
260
cogl_handle_unref (state.buffer);
261
cogl_handle_unref (state.material);
262
cogl_handle_unref (state.texture);
264
g_source_remove (idle_source);
266
if (g_test_verbose ())