[Mesa-dev] [PATCH 1/2] vbo: introduce vbo_sizeof_ib_type() function
Yuanhan Liu
yuanhan.liu at linux.intel.com
Tue Dec 27 21:54:42 PST 2011
introduce vbo_sizeof_ib_type() function to return the index data type
size. I see some place use switch(ib->type) to get the index data type,
which is sort of duplicate.
Signed-off-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>
---
src/mesa/state_tracker/st_draw.c | 15 +--------
src/mesa/state_tracker/st_draw_feedback.c | 17 ++--------
src/mesa/tnl/t_draw.c | 20 +----------
src/mesa/vbo/vbo.h | 4 ++
src/mesa/vbo/vbo_exec_array.c | 52 ++++++++++------------------
5 files changed, 29 insertions(+), 79 deletions(-)
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index 87a9978..954f15a 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -584,20 +584,7 @@ setup_index_buffer(struct gl_context *ctx,
if (ib) {
struct gl_buffer_object *bufobj = ib->obj;
- switch (ib->type) {
- case GL_UNSIGNED_INT:
- ibuffer->index_size = 4;
- break;
- case GL_UNSIGNED_SHORT:
- ibuffer->index_size = 2;
- break;
- case GL_UNSIGNED_BYTE:
- ibuffer->index_size = 1;
- break;
- default:
- assert(0);
- return;
- }
+ ibuffer->index_size = vbo_sizeof_ib_type(ib->type);
/* get/create the index buffer object */
if (_mesa_is_bufferobj(bufobj)) {
diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c
index 4c1e674..a99eb2b 100644
--- a/src/mesa/state_tracker/st_draw_feedback.c
+++ b/src/mesa/state_tracker/st_draw_feedback.c
@@ -218,20 +218,9 @@ st_feedback_draw_vbo(struct gl_context *ctx,
if (ib) {
struct gl_buffer_object *bufobj = ib->obj;
- switch (ib->type) {
- case GL_UNSIGNED_INT:
- ibuffer.index_size = 4;
- break;
- case GL_UNSIGNED_SHORT:
- ibuffer.index_size = 2;
- break;
- case GL_UNSIGNED_BYTE:
- ibuffer.index_size = 1;
- break;
- default:
- assert(0);
- goto out_unref_vertex;
- }
+ ibuffer.index_size = vbo_sizeof_ib_type(ib->type);
+ if (ibuffer.index_size == 0)
+ goto out_unref_vertex;
if (bufobj && bufobj->Name) {
struct st_buffer_object *stobj = st_buffer_object(bufobj);
diff --git a/src/mesa/tnl/t_draw.c b/src/mesa/tnl/t_draw.c
index 83ded19..f949c34 100644
--- a/src/mesa/tnl/t_draw.c
+++ b/src/mesa/tnl/t_draw.c
@@ -349,26 +349,10 @@ static void bind_indices( struct gl_context *ctx,
if (_mesa_is_bufferobj(ib->obj) && !_mesa_bufferobj_mapped(ib->obj)) {
/* if the buffer object isn't mapped yet, map it now */
- unsigned map_size;
-
- switch (ib->type) {
- case GL_UNSIGNED_BYTE:
- map_size = ib->count * sizeof(GLubyte);
- break;
- case GL_UNSIGNED_SHORT:
- map_size = ib->count * sizeof(GLushort);
- break;
- case GL_UNSIGNED_INT:
- map_size = ib->count * sizeof(GLuint);
- break;
- default:
- assert(0);
- map_size = 0;
- }
-
bo[*nr_bo] = ib->obj;
(*nr_bo)++;
- ptr = ctx->Driver.MapBufferRange(ctx, (GLsizeiptr) ib->ptr, map_size,
+ ptr = ctx->Driver.MapBufferRange(ctx, (GLsizeiptr) ib->ptr,
+ ib->count * vbo_sizeof_ib_type(ib->type),
GL_MAP_READ_BIT, ib->obj);
assert(ib->obj->Pointer);
} else {
diff --git a/src/mesa/vbo/vbo.h b/src/mesa/vbo/vbo.h
index 7384790..ed8fc17 100644
--- a/src/mesa/vbo/vbo.h
+++ b/src/mesa/vbo/vbo.h
@@ -122,6 +122,10 @@ void vbo_rebase_prims( struct gl_context *ctx,
GLuint min_index,
GLuint max_index,
vbo_draw_func draw );
+
+int
+vbo_sizeof_ib_type(GLenum type);
+
void
vbo_get_minmax_index(struct gl_context *ctx, const struct _mesa_prim *prim,
const struct _mesa_index_buffer *ib,
diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c
index 2db85e2..fec49d3 100644
--- a/src/mesa/vbo/vbo_exec_array.c
+++ b/src/mesa/vbo/vbo_exec_array.c
@@ -75,6 +75,22 @@ vbo_check_buffers_are_unmapped(struct gl_context *ctx)
assert(!_mesa_bufferobj_mapped(exec->vtx.bufferobj));
}
+int
+vbo_sizeof_ib_type(GLenum type)
+{
+ switch (type) {
+ case GL_UNSIGNED_INT:
+ return sizeof(GLuint);
+ case GL_UNSIGNED_SHORT:
+ return sizeof(GLushort);
+ case GL_UNSIGNED_BYTE:
+ return sizeof(GLubyte);
+ default:
+ assert(!"unsupported index data type");
+ /* In case assert is turned off */
+ return 0;
+ }
+}
/**
@@ -96,24 +112,8 @@ vbo_get_minmax_index(struct gl_context *ctx,
GLuint i;
if (_mesa_is_bufferobj(ib->obj)) {
- unsigned map_size;
-
- switch (ib->type) {
- case GL_UNSIGNED_INT:
- map_size = count * sizeof(GLuint);
- break;
- case GL_UNSIGNED_SHORT:
- map_size = count * sizeof(GLushort);
- break;
- case GL_UNSIGNED_BYTE:
- map_size = count * sizeof(GLubyte);
- break;
- default:
- assert(0);
- map_size = 0;
- }
-
- indices = ctx->Driver.MapBufferRange(ctx, (GLsizeiptr) ib->ptr, map_size,
+ indices = ctx->Driver.MapBufferRange(ctx, (GLsizeiptr) ib->ptr,
+ count * vbo_sizeof_ib_type(ib->type),
GL_MAP_READ_BIT, ib->obj);
} else {
indices = ib->ptr;
@@ -1053,7 +1053,7 @@ vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
struct vbo_exec_context *exec = &vbo->exec;
struct _mesa_index_buffer ib;
struct _mesa_prim *prim;
- unsigned int index_type_size = 0;
+ unsigned int index_type_size = vbo_sizeof_ib_type(type);
uintptr_t min_index_ptr, max_index_ptr;
GLboolean fallback = GL_FALSE;
int i;
@@ -1083,20 +1083,6 @@ vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
if (ctx->NewState)
_mesa_update_state( ctx );
- switch (type) {
- case GL_UNSIGNED_INT:
- index_type_size = 4;
- break;
- case GL_UNSIGNED_SHORT:
- index_type_size = 2;
- break;
- case GL_UNSIGNED_BYTE:
- index_type_size = 1;
- break;
- default:
- assert(0);
- }
-
min_index_ptr = (uintptr_t)indices[0];
max_index_ptr = 0;
for (i = 0; i < primcount; i++) {
--
1.7.4.4
More information about the mesa-dev
mailing list