2008-11-10 13:53:14 -05:00
|
|
|
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
|
|
|
#include "test-conform-common.h"
|
|
|
|
|
2009-01-20 16:12:44 -05:00
|
|
|
/* This test verifies that modifying a vertex buffer works, by updating
|
2008-11-10 13:53:14 -05:00
|
|
|
* vertex positions, and deleting and re-adding different color attributes.
|
|
|
|
*
|
|
|
|
* If you want visual feedback of what this test paints for debugging purposes,
|
|
|
|
* then remove the call to clutter_main_quit() in validate_result.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct _TestState
|
|
|
|
{
|
2009-01-20 16:12:44 -05:00
|
|
|
CoglHandle buffer;
|
2008-11-10 13:53:14 -05:00
|
|
|
ClutterGeometry stage_geom;
|
|
|
|
guint frame;
|
|
|
|
} TestState;
|
|
|
|
|
|
|
|
static void
|
|
|
|
validate_result (TestState *state)
|
|
|
|
{
|
|
|
|
GLubyte pixel[4];
|
2009-06-17 09:30:44 -04:00
|
|
|
GLint y_off = 90;
|
2008-11-10 13:53:14 -05:00
|
|
|
|
|
|
|
/* NB: We ignore the alpha, since we don't know if our render target is
|
|
|
|
* RGB or RGBA */
|
|
|
|
|
|
|
|
#define RED 0
|
|
|
|
#define GREEN 1
|
|
|
|
#define BLUE 2
|
|
|
|
|
|
|
|
/* Should see a red pixel */
|
2009-06-17 09:30:44 -04:00
|
|
|
cogl_read_pixels (110, y_off, 1, 1,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
pixel);
|
2008-11-18 07:54:34 -05:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("pixel 0 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
|
2008-11-10 13:53:14 -05:00
|
|
|
g_assert (pixel[RED] != 0 && pixel[GREEN] == 0 && pixel[BLUE] == 0);
|
|
|
|
|
|
|
|
/* Should see a green pixel */
|
2009-06-17 09:30:44 -04:00
|
|
|
cogl_read_pixels (210, y_off, 1, 1,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
pixel);
|
2008-11-18 07:54:34 -05:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("pixel 1 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
|
2008-11-10 13:53:14 -05:00
|
|
|
g_assert (pixel[RED] == 0 && pixel[GREEN] != 0 && pixel[BLUE] == 0);
|
|
|
|
|
|
|
|
#undef RED
|
|
|
|
#undef GREEN
|
|
|
|
#undef BLUE
|
2009-01-20 16:12:44 -05:00
|
|
|
|
2008-11-10 13:53:14 -05:00
|
|
|
/* Comment this out if you want visual feedback of what this test
|
|
|
|
* paints.
|
|
|
|
*/
|
|
|
|
clutter_main_quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_paint (ClutterActor *actor, TestState *state)
|
|
|
|
{
|
|
|
|
GLfloat triangle_verts[3][2] =
|
|
|
|
{
|
|
|
|
{100.0, 0.0},
|
|
|
|
{200.0, 100.0},
|
|
|
|
{100.0, 100.0}
|
|
|
|
};
|
|
|
|
GLbyte triangle_colors[3][4] =
|
|
|
|
{
|
|
|
|
{0x00, 0xff, 0x00, 0xff}, /* blue */
|
|
|
|
{0x00, 0xff, 0x00, 0x00}, /* transparent blue */
|
|
|
|
{0x00, 0xff, 0x00, 0x00} /* transparent blue */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Draw a red triangle
|
|
|
|
*/
|
|
|
|
|
2008-11-13 09:28:16 -05:00
|
|
|
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
|
2008-11-10 13:53:14 -05:00
|
|
|
|
2009-01-20 16:12:44 -05:00
|
|
|
cogl_vertex_buffer_add (state->buffer,
|
|
|
|
"gl_Vertex",
|
|
|
|
2, /* n components */
|
|
|
|
GL_FLOAT,
|
|
|
|
FALSE, /* normalized */
|
|
|
|
0, /* stride */
|
|
|
|
triangle_verts);
|
|
|
|
cogl_vertex_buffer_delete (state->buffer, "gl_Color");
|
|
|
|
cogl_vertex_buffer_submit (state->buffer);
|
|
|
|
|
|
|
|
cogl_vertex_buffer_draw (state->buffer,
|
|
|
|
GL_TRIANGLE_STRIP, /* mode */
|
|
|
|
0, /* first */
|
|
|
|
3); /* count */
|
|
|
|
|
2008-11-10 13:53:14 -05:00
|
|
|
/*
|
|
|
|
* Draw a faded green triangle
|
|
|
|
*/
|
|
|
|
|
2009-01-20 16:12:44 -05:00
|
|
|
cogl_vertex_buffer_add (state->buffer,
|
|
|
|
"gl_Color",
|
|
|
|
4, /* n components */
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
FALSE, /* normalized */
|
|
|
|
0, /* stride */
|
|
|
|
triangle_colors);
|
|
|
|
cogl_vertex_buffer_submit (state->buffer);
|
2008-11-10 13:53:14 -05:00
|
|
|
|
|
|
|
cogl_translate (100, 0, 0);
|
2009-01-20 16:12:44 -05:00
|
|
|
cogl_vertex_buffer_draw (state->buffer,
|
|
|
|
GL_TRIANGLE_STRIP, /* mode */
|
|
|
|
0, /* first */
|
|
|
|
3); /* count */
|
|
|
|
|
2008-11-10 13:53:14 -05:00
|
|
|
|
|
|
|
/* XXX: Experiments have shown that for some buggy drivers, when using
|
|
|
|
* glReadPixels there is some kind of race, so we delay our test for a
|
|
|
|
* few frames and a few seconds:
|
|
|
|
*/
|
|
|
|
if (state->frame >= 2)
|
|
|
|
validate_result (state);
|
|
|
|
else
|
2008-11-12 05:55:06 -05:00
|
|
|
g_usleep (G_USEC_PER_SEC);
|
2009-01-20 16:12:44 -05:00
|
|
|
|
2008-11-10 13:53:14 -05:00
|
|
|
state->frame++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
queue_redraw (gpointer stage)
|
|
|
|
{
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
2008-11-12 05:55:06 -05:00
|
|
|
|
|
|
|
return TRUE;
|
2008-11-10 13:53:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-20 16:12:44 -05:00
|
|
|
test_vertex_buffer_mutability (TestConformSimpleFixture *fixture,
|
|
|
|
gconstpointer data)
|
2008-11-10 13:53:14 -05:00
|
|
|
{
|
|
|
|
TestState state;
|
|
|
|
ClutterActor *stage;
|
|
|
|
ClutterColor stage_clr = {0x0, 0x0, 0x0, 0xff};
|
|
|
|
ClutterActor *group;
|
2008-11-28 11:25:20 -05:00
|
|
|
guint idle_source;
|
2008-11-10 13:53:14 -05:00
|
|
|
|
|
|
|
state.frame = 0;
|
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
|
|
|
|
|
|
|
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_clr);
|
|
|
|
clutter_actor_get_geometry (stage, &state.stage_geom);
|
|
|
|
|
|
|
|
group = clutter_group_new ();
|
|
|
|
clutter_actor_set_size (group,
|
|
|
|
state.stage_geom.width,
|
|
|
|
state.stage_geom.height);
|
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
|
|
|
|
|
|
|
|
/* We force continuous redrawing of the stage, since we need to skip
|
|
|
|
* the first few frames, and we wont be doing anything else that
|
|
|
|
* will trigger redrawing. */
|
2008-11-28 11:25:20 -05:00
|
|
|
idle_source = g_idle_add (queue_redraw, stage);
|
2008-11-10 13:53:14 -05:00
|
|
|
|
|
|
|
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
|
2009-01-20 16:12:44 -05:00
|
|
|
|
2008-11-10 13:53:14 -05:00
|
|
|
{
|
|
|
|
GLfloat triangle_verts[3][2] =
|
|
|
|
{
|
|
|
|
{0.0, 0.0},
|
|
|
|
{100.0, 100.0},
|
|
|
|
{0.0, 100.0}
|
|
|
|
};
|
|
|
|
GLbyte triangle_colors[3][4] =
|
|
|
|
{
|
|
|
|
{0x00, 0x00, 0xff, 0xff}, /* blue */
|
|
|
|
{0x00, 0x00, 0xff, 0x00}, /* transparent blue */
|
|
|
|
{0x00, 0x00, 0xff, 0x00} /* transparent blue */
|
|
|
|
};
|
2009-01-20 16:12:44 -05:00
|
|
|
state.buffer = cogl_vertex_buffer_new (3 /* n vertices */);
|
|
|
|
cogl_vertex_buffer_add (state.buffer,
|
|
|
|
"gl_Vertex",
|
|
|
|
2, /* n components */
|
|
|
|
GL_FLOAT,
|
|
|
|
FALSE, /* normalized */
|
|
|
|
0, /* stride */
|
|
|
|
triangle_verts);
|
|
|
|
cogl_vertex_buffer_add (state.buffer,
|
|
|
|
"gl_Color",
|
|
|
|
4, /* n components */
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
FALSE, /* normalized */
|
|
|
|
0, /* stride */
|
|
|
|
triangle_colors);
|
|
|
|
cogl_vertex_buffer_submit (state.buffer);
|
2008-11-10 13:53:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
clutter_actor_show_all (stage);
|
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
2009-04-01 12:16:44 -04:00
|
|
|
cogl_handle_unref (state.buffer);
|
2008-11-10 13:53:14 -05:00
|
|
|
|
2008-11-28 11:25:20 -05:00
|
|
|
g_source_remove (idle_source);
|
|
|
|
|
2008-11-18 07:54:34 -05:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("OK\n");
|
2008-11-10 13:53:14 -05:00
|
|
|
}
|
|
|
|
|