From 3acdab82cba03ea2a0dfaa3d7d5d940f1e94a374 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 6 May 2009 10:36:33 -0600 Subject: mesa: vbo code reformatting, clean-up, comments --- src/mesa/vbo/vbo_split_copy.c | 95 +++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 43 deletions(-) (limited to 'src/mesa/vbo/vbo_split_copy.c') diff --git a/src/mesa/vbo/vbo_split_copy.c b/src/mesa/vbo/vbo_split_copy.c index 4fc0e36156..44b748dad7 100644 --- a/src/mesa/vbo/vbo_split_copy.c +++ b/src/mesa/vbo/vbo_split_copy.c @@ -41,7 +41,8 @@ #define ELT_TABLE_SIZE 16 -/* Used for vertex-level splitting of indexed buffers. Note that +/** + * Used for vertex-level splitting of indexed buffers. Note that * non-indexed primitives may be converted to indexed in some cases * (eg loops, fans) in order to use this splitting path. */ @@ -73,23 +74,21 @@ struct copy_context { GLuint *translated_elt_buf; const GLuint *srcelt; - /* A baby hash table to avoid re-emitting (some) duplicate + /** A baby hash table to avoid re-emitting (some) duplicate * vertices when splitting indexed primitives. */ struct { GLuint in; GLuint out; } vert_cache[ELT_TABLE_SIZE]; - GLuint vertex_size; GLubyte *dstbuf; - GLubyte *dstptr; /* dstptr == dstbuf + dstelt_max * vertsize */ - GLuint dstbuf_size; /* in vertices */ - GLuint dstbuf_nr; /* count of emitted vertices, also the - * largest value in dstelt. Our - * MaxIndex. - */ + GLubyte *dstptr; /**< dstptr == dstbuf + dstelt_max * vertsize */ + GLuint dstbuf_size; /**< in vertices */ + GLuint dstbuf_nr; /**< count of emitted vertices, also the largest value + * in dstelt. Our MaxIndex. + */ GLuint *dstelt; GLuint dstelt_nr; @@ -123,11 +122,13 @@ static GLuint attr_size( const struct gl_client_array *array ) } -/* Starts returning true slightly before the buffer fills, to ensure +/** + * Starts returning true slightly before the buffer fills, to ensure * that there is sufficient room for any remaining vertices to finish * off the prim: */ -static GLboolean check_flush( struct copy_context *copy ) +static GLboolean +check_flush( struct copy_context *copy ) { GLenum mode = copy->dstprim[copy->dstprim_nr].mode; @@ -145,7 +146,9 @@ static GLboolean check_flush( struct copy_context *copy ) return GL_FALSE; } -static void flush( struct copy_context *copy ) + +static void +flush( struct copy_context *copy ) { GLuint i; @@ -175,8 +178,11 @@ static void flush( struct copy_context *copy ) } - -static void begin( struct copy_context *copy, GLenum mode, GLboolean begin_flag ) +/** + * Called at begin of each primitive during replay. + */ +static void +begin( struct copy_context *copy, GLenum mode, GLboolean begin_flag ) { struct _mesa_prim *prim = ©->dstprim[copy->dstprim_nr]; @@ -187,10 +193,12 @@ static void begin( struct copy_context *copy, GLenum mode, GLboolean begin_flag } -/* Use a hashtable to attempt to identify recently-emitted vertices +/** + * Use a hashtable to attempt to identify recently-emitted vertices * and avoid re-emitting them. */ -static GLuint elt(struct copy_context *copy, GLuint elt_idx) +static GLuint +elt(struct copy_context *copy, GLuint elt_idx) { GLuint elt = copy->srcelt[elt_idx]; GLuint slot = elt & (ELT_TABLE_SIZE-1); @@ -222,7 +230,6 @@ static GLuint elt(struct copy_context *copy, GLuint elt_idx) _mesa_printf("%x ", f[j]); _mesa_printf("\n"); } - } copy->vert_cache[slot].in = elt; @@ -230,9 +237,8 @@ static GLuint elt(struct copy_context *copy, GLuint elt_idx) copy->dstptr += copy->vertex_size; assert(csr == copy->dstptr); - assert(copy->dstptr == (copy->dstbuf + - copy->dstbuf_nr * - copy->vertex_size)); + assert(copy->dstptr == (copy->dstbuf + + copy->dstbuf_nr * copy->vertex_size)); } /* else */ /* _mesa_printf(" --> reuse vertex\n"); */ @@ -242,7 +248,12 @@ static GLuint elt(struct copy_context *copy, GLuint elt_idx) return check_flush(copy); } -static void end( struct copy_context *copy, GLboolean end_flag ) + +/** + * Called at end of each primitive during replay. + */ +static void +end( struct copy_context *copy, GLboolean end_flag ) { struct _mesa_prim *prim = ©->dstprim[copy->dstprim_nr]; @@ -257,8 +268,8 @@ static void end( struct copy_context *copy, GLboolean end_flag ) } - -static void replay_elts( struct copy_context *copy ) +static void +replay_elts( struct copy_context *copy ) { GLuint i, j, k; GLboolean split; @@ -362,7 +373,8 @@ static void replay_elts( struct copy_context *copy ) } -static void replay_init( struct copy_context *copy ) +static void +replay_init( struct copy_context *copy ) { GLcontext *ctx = copy->ctx; GLuint i; @@ -388,10 +400,7 @@ static void replay_init( struct copy_context *copy ) copy->vertex_size += attr_size(copy->array[i]); if (vbo->Name && !vbo->Pointer) - ctx->Driver.MapBuffer(ctx, - GL_ARRAY_BUFFER, - GL_READ_ONLY, - vbo); + ctx->Driver.MapBuffer(ctx, GL_ARRAY_BUFFER, GL_READ_ONLY, vbo); copy->varying[j].src_ptr = ADD_POINTERS(vbo->Pointer, copy->array[i]->Ptr); @@ -405,12 +414,11 @@ static void replay_init( struct copy_context *copy ) * do it internally. */ if (copy->ib->obj->Name && !copy->ib->obj->Pointer) - ctx->Driver.MapBuffer(ctx, - GL_ELEMENT_ARRAY_BUFFER, - GL_READ_ONLY, + ctx->Driver.MapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER, GL_READ_ONLY, copy->ib->obj); - srcptr = (const GLubyte *)ADD_POINTERS(copy->ib->obj->Pointer, copy->ib->ptr); + srcptr = (const GLubyte *) ADD_POINTERS(copy->ib->obj->Pointer, + copy->ib->ptr); switch (copy->ib->type) { case GL_UNSIGNED_BYTE: @@ -434,7 +442,6 @@ static void replay_init( struct copy_context *copy ) copy->srcelt = (const GLuint *)srcptr; break; } - /* Figure out the maximum allowed vertex buffer size: */ @@ -449,8 +456,7 @@ static void replay_init( struct copy_context *copy ) * * XXX: This should be a VBO! */ - copy->dstbuf = _mesa_malloc(copy->dstbuf_size * - copy->vertex_size); + copy->dstbuf = _mesa_malloc(copy->dstbuf_size * copy->vertex_size); copy->dstptr = copy->dstbuf; /* Setup new vertex arrays to point into the output buffer: @@ -492,7 +498,11 @@ static void replay_init( struct copy_context *copy ) } -static void replay_finish( struct copy_context *copy ) +/** + * Free up everything allocated during split/replay. + */ +static void +replay_finish( struct copy_context *copy ) { GLcontext *ctx = copy->ctx; GLuint i; @@ -502,12 +512,11 @@ static void replay_finish( struct copy_context *copy ) _mesa_free(copy->translated_elt_buf); _mesa_free(copy->dstbuf); _mesa_free(copy->dstelt); - + /* Unmap VBO's */ for (i = 0; i < copy->nr_varying; i++) { struct gl_buffer_object *vbo = copy->varying[i].array->BufferObj; - if (vbo->Name && vbo->Pointer) ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER, vbo); } @@ -515,12 +524,14 @@ static void replay_finish( struct copy_context *copy ) /* Unmap index buffer: */ if (copy->ib->obj->Name && copy->ib->obj->Pointer) { - ctx->Driver.UnmapBuffer(ctx, - GL_ELEMENT_ARRAY_BUFFER, - copy->ib->obj); + ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER, copy->ib->obj); } } + +/** + * Split VBO into smaller pieces, draw the pieces. + */ void vbo_split_copy( GLcontext *ctx, const struct gl_client_array *arrays[], const struct _mesa_prim *prim, @@ -546,13 +557,11 @@ void vbo_split_copy( GLcontext *ctx, copy.draw = draw; copy.limits = limits; - /* Clear the vertex cache: */ for (i = 0; i < ELT_TABLE_SIZE; i++) copy.vert_cache[i].in = ~0; - replay_init(©); replay_elts(©); replay_finish(©); -- cgit v1.2.3