Renames the mesh api to the "vertex buffer api".

This better reflects the fact that the api manages sets of vertex attributes,
and the attributes really have no implied form. It is only when you use the
attributes to draw that they become mesh like; when you specify how they should
be interpreted, e.g. as triangle lists or fans etc. This rename frees up the
term "mesh", which can later be applied to a concept slightly more fitting.
E.g. at some point it would be nice to have a higher level abstraction that
sits on top of cogl vertex buffers that adds the concept of faces. (Somthing
like Blender's mesh objects.) There have also been some discussions over
particle engines, and these can be defined in terms of emitter faces; so some
other kind of mesh abstraction might be usefull here.
This commit is contained in:
Robert Bragg
2009-01-20 21:12:44 +00:00
parent 4bc1e567fc
commit e338245827
19 changed files with 845 additions and 822 deletions

View File

@ -12,9 +12,9 @@ test_conformance_SOURCES = \
test-timeline-rewind.c \
test-timeline-smoothness.c \
test-timeline.c \
test-mesh-contiguous.c \
test-mesh-interleved.c \
test-mesh-mutability.c \
test-vertex-buffer-contiguous.c \
test-vertex-buffer-interleved.c \
test-vertex-buffer-mutability.c \
test-path.c \
test-pick.c \
test-clutter-rectangle.c \

View File

@ -46,17 +46,17 @@ main (int argc, char **argv)
#endif
g_test_init (&argc, &argv, NULL);
g_test_bug_base ("http://bugzilla.openedhand.com/show_bug.cgi?id=%s");
g_assert (clutter_init (shared_state->argc_addr, shared_state->argv_addr)
== CLUTTER_INIT_SUCCESS);
/* Initialise the state you need to share with everything.
*/
shared_state->argc_addr = &argc;
shared_state->argv_addr = &argv;
TEST_CONFORM_SIMPLE ("/timeline", test_timeline);
if (g_test_slow ())
{
@ -65,7 +65,7 @@ main (int argc, char **argv)
TEST_CONFORM_SIMPLE ("/timeline", test_timeline_rewind);
TEST_CONFORM_SIMPLE ("/timeline", test_timeline_smoothness);
}
TEST_CONFORM_SIMPLE ("/picking", test_pick);
/* ClutterText */
@ -88,15 +88,15 @@ main (int argc, char **argv)
TEST_CONFORM_SIMPLE ("/rectangle", test_rect_set_color);
TEST_CONFORM_SIMPLE ("/fixed", test_fixed_constants);
TEST_CONFORM_SIMPLE ("/invariants", test_initial_state);
TEST_CONFORM_SIMPLE ("/invariants", test_realized);
TEST_CONFORM_SIMPLE ("/invariants", test_mapped);
TEST_CONFORM_SIMPLE ("/invariants", test_show_on_set_parent);
TEST_CONFORM_SIMPLE ("/mesh", test_mesh_contiguous);
TEST_CONFORM_SIMPLE ("/mesh", test_mesh_interleved);
TEST_CONFORM_SIMPLE ("/mesh", test_mesh_mutability);
TEST_CONFORM_SIMPLE ("/vertex-buffer", test_vertex_buffer_contiguous);
TEST_CONFORM_SIMPLE ("/vertex-buffer", test_vertex_buffer_interleved);
TEST_CONFORM_SIMPLE ("/vertex-buffer", test_vertex_buffer_mutability);
TEST_CONFORM_SIMPLE ("/opacity", test_label_opacity);
TEST_CONFORM_SIMPLE ("/opacity", test_rectangle_opacity);

View File

@ -4,9 +4,9 @@
#include "test-conform-common.h"
/* This test verifies that the simplest usage of the mesh API, where we add
* contiguous (x,y) GLfloat vertices, and RGBA GLubyte color attributes to a
* mesh object, submit, and draw.
/* This test verifies that the simplest usage of the vertex buffer API,
* where we add contiguous (x,y) GLfloat vertices, and RGBA GLubyte color
* attributes to a buffer, submit, and draw.
*
* It also tries to verify that the enable/disable attribute APIs are working
* too.
@ -17,7 +17,7 @@
typedef struct _TestState
{
CoglHandle mesh;
CoglHandle buffer;
ClutterGeometry stage_geom;
guint frame;
} TestState;
@ -44,7 +44,7 @@ validate_result (TestState *state)
if (g_test_verbose ())
g_print ("pixel 0 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
g_assert (pixel[RED] == 0 && pixel[GREEN] == 0 && pixel[BLUE] != 0);
/* Should see a red pixel */
glReadPixels (110, y_off, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
if (g_test_verbose ())
@ -56,11 +56,11 @@ validate_result (TestState *state)
if (g_test_verbose ())
g_print ("pixel 2 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
g_assert (pixel[RED] == 0 && pixel[GREEN] == 0 && pixel[BLUE] != 0);
#undef RED
#undef GREEN
#undef BLUE
/* Comment this out if you want visual feedback of what this test
* paints.
*/
@ -71,35 +71,35 @@ static void
on_paint (ClutterActor *actor, TestState *state)
{
/* Draw a faded blue triangle */
cogl_mesh_enable_attribute (state->mesh, "gl_Color::blue");
cogl_vertex_buffer_enable (state->buffer, "gl_Color::blue");
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
cogl_mesh_draw_arrays (state->mesh,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
cogl_vertex_buffer_draw (state->buffer,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
/* Draw a red triangle */
/* Here we are testing that the disable attribute works; if it doesn't
* the triangle will remain faded blue */
cogl_translate (100, 0, 0);
cogl_mesh_disable_attribute (state->mesh, "gl_Color::blue");
cogl_vertex_buffer_disable (state->buffer, "gl_Color::blue");
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
cogl_mesh_draw_arrays (state->mesh,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
cogl_vertex_buffer_draw (state->buffer,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
/* Draw a faded blue triangle */
/* Here we are testing that the re-enable works; if it doesn't
* the triangle will remain red */
cogl_translate (100, 0, 0);
cogl_mesh_enable_attribute (state->mesh, "gl_Color::blue");
cogl_vertex_buffer_enable (state->buffer, "gl_Color::blue");
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
cogl_mesh_draw_arrays (state->mesh,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
cogl_vertex_buffer_draw (state->buffer,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
/* 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:
@ -108,7 +108,7 @@ on_paint (ClutterActor *actor, TestState *state)
validate_result (state);
else
g_usleep (G_USEC_PER_SEC);
state->frame++;
}
@ -121,8 +121,8 @@ queue_redraw (gpointer stage)
}
void
test_mesh_contiguous (TestConformSimpleFixture *fixture,
gconstpointer data)
test_vertex_buffer_contiguous (TestConformSimpleFixture *fixture,
gconstpointer data)
{
TestState state;
ClutterActor *stage;
@ -149,7 +149,7 @@ test_mesh_contiguous (TestConformSimpleFixture *fixture,
idle_source = g_idle_add (queue_redraw, stage);
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
{
GLfloat triangle_verts[3][2] =
{
@ -163,29 +163,29 @@ test_mesh_contiguous (TestConformSimpleFixture *fixture,
{0x00, 0x00, 0xff, 0x00}, /* transparent blue */
{0x00, 0x00, 0xff, 0x00} /* transparent blue */
};
state.mesh = cogl_mesh_new (3 /* n vertices */);
cogl_mesh_add_attribute (state.mesh,
"gl_Vertex",
2, /* n components */
GL_FLOAT,
FALSE, /* normalized */
0, /* stride */
triangle_verts);
cogl_mesh_add_attribute (state.mesh,
"gl_Color::blue",
4, /* n components */
GL_UNSIGNED_BYTE,
FALSE, /* normalized */
0, /* stride */
triangle_colors);
cogl_mesh_submit (state.mesh);
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::blue",
4, /* n components */
GL_UNSIGNED_BYTE,
FALSE, /* normalized */
0, /* stride */
triangle_colors);
cogl_vertex_buffer_submit (state.buffer);
}
clutter_actor_show_all (stage);
clutter_main ();
cogl_mesh_unref (state.mesh);
cogl_vertex_buffer_unref (state.buffer);
g_source_remove (idle_source);

View File

@ -4,9 +4,9 @@
#include "test-conform-common.h"
/* This test verifies that interleved attributes work with the mesh API.
* We add (x,y) GLfloat vertices, interleved with RGBA GLubyte color
* attributes to a mesh object, submit and draw.
/* This test verifies that interleved attributes work with the vertex buffer
* API. We add (x,y) GLfloat vertices, interleved with RGBA GLubyte color
* attributes to a buffer, submit and draw.
*
* If you want visual feedback of what this test paints for debugging purposes,
* then remove the call to clutter_main_quit() in validate_result.
@ -14,7 +14,7 @@
typedef struct _TestState
{
CoglHandle mesh;
CoglHandle buffer;
ClutterGeometry stage_geom;
guint frame;
} TestState;
@ -51,11 +51,11 @@ validate_result (TestState *state)
if (g_test_verbose ())
g_print ("pixel 0 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
g_assert (pixel[RED] == 0 && pixel[GREEN] == 0 && pixel[BLUE] != 0);
#undef RED
#undef GREEN
#undef BLUE
/* Comment this out if you want visual feedback of what this test
* paints.
*/
@ -66,10 +66,10 @@ static void
on_paint (ClutterActor *actor, TestState *state)
{
/* Draw a faded blue triangle */
cogl_mesh_draw_arrays (state->mesh,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
cogl_vertex_buffer_draw (state->buffer,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
/* 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
@ -79,7 +79,7 @@ on_paint (ClutterActor *actor, TestState *state)
validate_result (state);
else
g_usleep (G_USEC_PER_SEC);
state->frame++;
}
@ -92,8 +92,8 @@ queue_redraw (gpointer stage)
}
void
test_mesh_interleved (TestConformSimpleFixture *fixture,
gconstpointer data)
test_vertex_buffer_interleved (TestConformSimpleFixture *fixture,
gconstpointer data)
{
TestState state;
ClutterActor *stage;
@ -120,7 +120,7 @@ test_mesh_interleved (TestConformSimpleFixture *fixture,
idle_source = g_idle_add (queue_redraw, stage);
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
{
InterlevedVertex verts[3] =
{
@ -141,29 +141,29 @@ test_mesh_interleved (TestConformSimpleFixture *fixture,
*/
g_assert (sizeof (InterlevedVertex) == 12);
state.mesh = cogl_mesh_new (3 /* n vertices */);
cogl_mesh_add_attribute (state.mesh,
"gl_Vertex",
2, /* n components */
GL_FLOAT,
FALSE, /* normalized */
12, /* stride */
&verts[0].x);
cogl_mesh_add_attribute (state.mesh,
"gl_Color",
4, /* n components */
GL_UNSIGNED_BYTE,
FALSE, /* normalized */
12, /* stride */
&verts[0].r);
cogl_mesh_submit (state.mesh);
state.buffer = cogl_vertex_buffer_new (3 /* n vertices */);
cogl_vertex_buffer_add (state.buffer,
"gl_Vertex",
2, /* n components */
GL_FLOAT,
FALSE, /* normalized */
12, /* stride */
&verts[0].x);
cogl_vertex_buffer_add (state.buffer,
"gl_Color",
4, /* n components */
GL_UNSIGNED_BYTE,
FALSE, /* normalized */
12, /* stride */
&verts[0].r);
cogl_vertex_buffer_submit (state.buffer);
}
clutter_actor_show_all (stage);
clutter_main ();
cogl_mesh_unref (state.mesh);
cogl_vertex_buffer_unref (state.buffer);
g_source_remove (idle_source);

View File

@ -4,7 +4,7 @@
#include "test-conform-common.h"
/* This test verifies that modifying mesh objects works, by updating
/* This test verifies that modifying a vertex buffer works, by updating
* vertex positions, and deleting and re-adding different color attributes.
*
* If you want visual feedback of what this test paints for debugging purposes,
@ -13,7 +13,7 @@
typedef struct _TestState
{
CoglHandle mesh;
CoglHandle buffer;
ClutterGeometry stage_geom;
guint frame;
} TestState;
@ -47,7 +47,7 @@ validate_result (TestState *state)
#undef RED
#undef GREEN
#undef BLUE
/* Comment this out if you want visual feedback of what this test
* paints.
*/
@ -76,41 +76,41 @@ on_paint (ClutterActor *actor, TestState *state)
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
cogl_mesh_add_attribute (state->mesh,
"gl_Vertex",
2, /* n components */
GL_FLOAT,
FALSE, /* normalized */
0, /* stride */
triangle_verts);
cogl_mesh_delete_attribute (state->mesh, "gl_Color");
cogl_mesh_submit (state->mesh);
cogl_mesh_draw_arrays (state->mesh,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
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 */
/*
* Draw a faded green triangle
*/
cogl_mesh_add_attribute (state->mesh,
"gl_Color",
4, /* n components */
GL_UNSIGNED_BYTE,
FALSE, /* normalized */
0, /* stride */
triangle_colors);
cogl_mesh_submit (state->mesh);
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);
cogl_translate (100, 0, 0);
cogl_mesh_draw_arrays (state->mesh,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
cogl_vertex_buffer_draw (state->buffer,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
/* 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:
@ -119,7 +119,7 @@ on_paint (ClutterActor *actor, TestState *state)
validate_result (state);
else
g_usleep (G_USEC_PER_SEC);
state->frame++;
}
@ -132,8 +132,8 @@ queue_redraw (gpointer stage)
}
void
test_mesh_mutability (TestConformSimpleFixture *fixture,
gconstpointer data)
test_vertex_buffer_mutability (TestConformSimpleFixture *fixture,
gconstpointer data)
{
TestState state;
ClutterActor *stage;
@ -160,7 +160,7 @@ test_mesh_mutability (TestConformSimpleFixture *fixture,
idle_source = g_idle_add (queue_redraw, stage);
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
{
GLfloat triangle_verts[3][2] =
{
@ -174,29 +174,29 @@ test_mesh_mutability (TestConformSimpleFixture *fixture,
{0x00, 0x00, 0xff, 0x00}, /* transparent blue */
{0x00, 0x00, 0xff, 0x00} /* transparent blue */
};
state.mesh = cogl_mesh_new (3 /* n vertices */);
cogl_mesh_add_attribute (state.mesh,
"gl_Vertex",
2, /* n components */
GL_FLOAT,
FALSE, /* normalized */
0, /* stride */
triangle_verts);
cogl_mesh_add_attribute (state.mesh,
"gl_Color",
4, /* n components */
GL_UNSIGNED_BYTE,
FALSE, /* normalized */
0, /* stride */
triangle_colors);
cogl_mesh_submit (state.mesh);
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);
}
clutter_actor_show_all (stage);
clutter_main ();
cogl_mesh_unref (state.mesh);
cogl_vertex_buffer_unref (state.buffer);
g_source_remove (idle_source);