From: Michel Pollet Date: Wed, 13 Jun 2012 17:15:16 +0000 (+0100) Subject: c3geometry: Added geometry buffers X-Git-Tag: v1.0~83 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=a955e4d0e5341a01c3026f91b8867223b3022088;p=sx%2Fsimavr.git c3geometry: Added geometry buffers added storage fields for buffer objects Signed-off-by: Michel Pollet --- diff --git a/examples/shared/libc3/src/c3geometry.c b/examples/shared/libc3/src/c3geometry.c index 7f607f6..9c5d359 100644 --- a/examples/shared/libc3/src/c3geometry.c +++ b/examples/shared/libc3/src/c3geometry.c @@ -61,7 +61,11 @@ _c3geometry_project( const struct c3driver_geometry_t *d, c3mat4p m) { - if (g->vertice.count) { + /* make sure there are actual elements in the array + * if it had been purged, the element count might remain + * but the array size is zero + */ + if (g->vertice.count < g->vertice.size) { for (int vi = 0; vi < g->vertice.count; vi++) { c3vec3 v = c3mat4_mulv3(m, g->vertice.e[vi]); if (vi == 0) @@ -71,8 +75,9 @@ _c3geometry_project( g->bbox.max = c3vec3_max(g->bbox.max, v); } } - } else - g->bbox.min = g->bbox.max = c3vec3f(0,0,0); + } + /* else -- do not clear bbox on purged arrays + g->bbox.min = g->bbox.max = c3vec3f(0,0,0); */ if (g->object && g->object->context) C3_DRIVER(g->object->context, geometry_project, g, m); diff --git a/examples/shared/libc3/src/c3geometry.h b/examples/shared/libc3/src/c3geometry.h index 68831a8..18d26de 100644 --- a/examples/shared/libc3/src/c3geometry.h +++ b/examples/shared/libc3/src/c3geometry.h @@ -37,10 +37,23 @@ struct c3object_t; struct c3pixels_t; struct c3program_t; -DECLARE_C_ARRAY(c3vertex_t, c3vertex_array, 16, c3apiobject_t bid); -DECLARE_C_ARRAY(c3tex_t, c3tex_array, 16, c3apiobject_t bid); -DECLARE_C_ARRAY(c3colorf_t, c3colorf_array, 16, c3apiobject_t bid); -DECLARE_C_ARRAY(c3index_t, c3indices_array, 16, c3apiobject_t bid); +/* + * Allow per-array storage of an extra buffer object + * if 'mutable' is not set (default), the array can be clear()ed after + * the buffer is bound. + * If the array is mutable, setting the 'dirty' flag will signal + * the rendering layer that it needs to update the buffer object + */ +typedef struct c3geometry_buffer_t { + c3apiobject_t bid; // buffer object + void * refCon; // reference constant for application use + int mutable : 1, dirty : 1; +} c3geometry_buffer_t, * c3geometry_buffer_p; + +DECLARE_C_ARRAY(c3vertex_t, c3vertex_array, 16, c3geometry_buffer_t buffer); +DECLARE_C_ARRAY(c3tex_t, c3tex_array, 16, c3geometry_buffer_t buffer); +DECLARE_C_ARRAY(c3colorf_t, c3colorf_array, 16, c3geometry_buffer_t buffer); +DECLARE_C_ARRAY(c3index_t, c3indices_array, 16, c3geometry_buffer_t buffer); //! Geometry material. typedef struct c3material_t {