2
#include <clutter/clutter.h>
5
#include "test-conform-common.h"
7
/* This test verifies that interleved attributes work with the vertex buffer
8
* API. We add (x,y) GLfloat vertices, interleved with RGBA GLubyte color
9
* attributes to a buffer, submit and draw.
11
* If you want visual feedback of what this test paints for debugging purposes,
12
* then remove the call to clutter_main_quit() in validate_result.
15
typedef struct _TestState
18
ClutterGeometry stage_geom;
21
typedef struct _InterlevedVertex
29
validate_result (TestState *state)
34
/* NB: We ignore the alpha, since we don't know if our render target is
41
/* Should see a blue pixel */
42
cogl_read_pixels (10, y_off, 1, 1,
43
COGL_READ_PIXELS_COLOR_BUFFER,
44
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
46
if (g_test_verbose ())
47
g_print ("pixel 0 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
48
g_assert (pixel[RED] == 0 && pixel[GREEN] == 0 && pixel[BLUE] != 0);
54
/* Comment this out if you want visual feedback of what this test
61
on_paint (ClutterActor *actor, TestState *state)
63
/* Draw a faded blue triangle */
64
cogl_vertex_buffer_draw (state->buffer,
65
COGL_VERTICES_MODE_TRIANGLE_STRIP, /* mode */
69
validate_result (state);
73
queue_redraw (gpointer stage)
75
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
81
test_cogl_vertex_buffer_interleved (TestConformSimpleFixture *fixture,
86
ClutterColor stage_clr = {0x0, 0x0, 0x0, 0xff};
90
stage = clutter_stage_new ();
92
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_clr);
93
clutter_actor_get_geometry (stage, &state.stage_geom);
95
group = clutter_group_new ();
96
clutter_actor_set_size (group,
97
state.stage_geom.width,
98
state.stage_geom.height);
99
clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
101
/* We force continuous redrawing incase someone comments out the
102
* clutter_main_quit and wants visual feedback for the test since we
103
* wont be doing anything else that will trigger redrawing. */
104
idle_source = g_idle_add (queue_redraw, stage);
106
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
109
InterlevedVertex verts[3] =
111
{ /* .x = */ 0.0, /* .y = */ 0.0,
113
/* .r = */ 0x00, /* .g = */ 0x00, /* .b = */ 0xff, /* .a = */ 0xff },
115
{ /* .x = */ 100.0, /* .y = */ 100.0,
116
/* transparent blue */
117
/* .r = */ 0x00, /* .g = */ 0x00, /* .b = */ 0xff, /* .a = */ 0x00 },
119
{ /* .x = */ 0.0, /* .y = */ 100.0,
120
/* transparent blue */
121
/* .r = */ 0x00, /* .g = */ 0x00, /* .b = */ 0xff, /* .a = */ 0x00 },
124
/* We assume the compiler is doing no funny struct padding for this test:
126
g_assert (sizeof (InterlevedVertex) == 12);
128
state.buffer = cogl_vertex_buffer_new (3 /* n vertices */);
129
cogl_vertex_buffer_add (state.buffer,
131
2, /* n components */
132
COGL_ATTRIBUTE_TYPE_FLOAT,
133
FALSE, /* normalized */
136
cogl_vertex_buffer_add (state.buffer,
138
4, /* n components */
139
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE,
140
FALSE, /* normalized */
143
cogl_vertex_buffer_submit (state.buffer);
146
clutter_actor_show_all (stage);
150
cogl_handle_unref (state.buffer);
152
g_source_remove (idle_source);
154
clutter_actor_destroy (stage);
156
if (g_test_verbose ())