From: Mathias Fröhlich Date: Mon, 31 Oct 2011 15:23:40 +0000 (+0100) Subject: vbo: Use The VERT_{ATTRIB,BIT} defines. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ed42c2580717527b2005580940fc766d95bb6b0b;p=mesa.git vbo: Use The VERT_{ATTRIB,BIT} defines. Signed-off-by: Mathias Froehlich Reviewed-by: Brian Paul Reviewed-by: Eric Anholt --- diff --git a/src/mesa/vbo/vbo_context.c b/src/mesa/vbo/vbo_context.c index 9de770d0bcf..b2e6bbc12fb 100644 --- a/src/mesa/vbo/vbo_context.c +++ b/src/mesa/vbo/vbo_context.c @@ -33,13 +33,8 @@ #include "vbo.h" #include "vbo_context.h" - - -#define NR_LEGACY_ATTRIBS 16 -#define NR_GENERIC_ATTRIBS 16 #define NR_MAT_ATTRIBS 12 - static GLuint check_size( const GLfloat *attr ) { if (attr[3] != 1.0) return 4; @@ -55,12 +50,12 @@ static void init_legacy_currval(struct gl_context *ctx) struct gl_client_array *arrays = vbo->legacy_currval; GLuint i; - memset(arrays, 0, sizeof(*arrays) * NR_LEGACY_ATTRIBS); + memset(arrays, 0, sizeof(*arrays) * VERT_ATTRIB_FF_MAX); /* Set up a constant (StrideB == 0) array for each current * attribute: */ - for (i = 0; i < NR_LEGACY_ATTRIBS; i++) { + for (i = 0; i < VERT_ATTRIB_FF_MAX; i++) { struct gl_client_array *cl = &arrays[i]; /* Size will have to be determined at runtime: @@ -85,9 +80,9 @@ static void init_generic_currval(struct gl_context *ctx) struct gl_client_array *arrays = vbo->generic_currval; GLuint i; - memset(arrays, 0, sizeof(*arrays) * NR_GENERIC_ATTRIBS); + memset(arrays, 0, sizeof(*arrays) * VERT_ATTRIB_GENERIC_MAX); - for (i = 0; i < NR_GENERIC_ATTRIBS; i++) { + for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++) { struct gl_client_array *cl = &arrays[i]; /* This will have to be determined at runtime: @@ -182,14 +177,15 @@ GLboolean _vbo_CreateContext( struct gl_context *ctx ) GLuint i; /* When no vertex program, pull in the material attributes in - * the 16..32 generic range. + * the generic range. */ - for (i = 0; i < 16; i++) + for (i = 0; i < VERT_ATTRIB_FF_MAX; i++) vbo->map_vp_none[i] = i; - for (i = 0; i < 12; i++) - vbo->map_vp_none[16+i] = VBO_ATTRIB_MAT_FRONT_AMBIENT + i; - for (i = 0; i < 4; i++) - vbo->map_vp_none[28+i] = i; + for (i = 0; i < NR_MAT_ATTRIBS; i++) + vbo->map_vp_none[VERT_ATTRIB_GENERIC(i)] + = VBO_ATTRIB_MAT_FRONT_AMBIENT + i; + for (i = NR_MAT_ATTRIBS; i < VERT_ATTRIB_GENERIC_MAX; i++) + vbo->map_vp_none[VERT_ATTRIB_GENERIC(i)] = i; for (i = 0; i < Elements(vbo->map_vp_arb); i++) vbo->map_vp_arb[i] = i; diff --git a/src/mesa/vbo/vbo_exec.h b/src/mesa/vbo/vbo_exec.h index 8d6b8f95a7f..cfed8e86dc0 100644 --- a/src/mesa/vbo/vbo_exec.h +++ b/src/mesa/vbo/vbo_exec.h @@ -125,8 +125,8 @@ struct vbo_exec_context /* These just mirror the current arrayobj (todo: make arrayobj * look like this and remove the mirror): */ - const struct gl_client_array *legacy_array[16]; - const struct gl_client_array *generic_array[16]; + const struct gl_client_array *legacy_array[VERT_ATTRIB_FF_MAX]; + const struct gl_client_array *generic_array[VERT_ATTRIB_GENERIC_MAX]; /* Arrays and current values manipulated according to program * mode, etc. These are the attributes as seen by vertex diff --git a/src/mesa/vbo/vbo_exec_api.c b/src/mesa/vbo/vbo_exec_api.c index 62e7d03f38a..70551e0e181 100644 --- a/src/mesa/vbo/vbo_exec_api.c +++ b/src/mesa/vbo/vbo_exec_api.c @@ -1091,15 +1091,23 @@ void vbo_exec_vtx_init( struct vbo_exec_context *exec ) struct gl_client_array *arrays = exec->vtx.arrays; unsigned i; - memcpy(arrays, vbo->legacy_currval, 16 * sizeof(arrays[0])); - memcpy(arrays + 16, vbo->generic_currval, 16 * sizeof(arrays[0])); - - for (i = 0; i < 16; ++i) { - arrays[i ].BufferObj = NULL; - arrays[i + 16].BufferObj = NULL; - _mesa_reference_buffer_object(ctx, &arrays[i ].BufferObj, + memcpy(arrays, vbo->legacy_currval, + VERT_ATTRIB_FF_MAX * sizeof(arrays[0])); + for (i = 0; i < VERT_ATTRIB_FF_MAX; ++i) { + struct gl_client_array *array; + array = &arrays[VERT_ATTRIB_FF(i)]; + array->BufferObj = NULL; + _mesa_reference_buffer_object(ctx, &arrays->BufferObj, vbo->legacy_currval[i].BufferObj); - _mesa_reference_buffer_object(ctx, &arrays[i + 16].BufferObj, + } + + memcpy(arrays + VERT_ATTRIB_GENERIC(0), vbo->generic_currval, + VERT_ATTRIB_GENERIC_MAX * sizeof(arrays[0])); + for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; ++i) { + struct gl_client_array *array; + array = &arrays[VERT_ATTRIB_GENERIC(i)]; + array->BufferObj = NULL; + _mesa_reference_buffer_object(ctx, &array->BufferObj, vbo->generic_currval[i].BufferObj); } } diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c index 65552a291de..e829b2b89f1 100644 --- a/src/mesa/vbo/vbo_exec_array.c +++ b/src/mesa/vbo/vbo_exec_array.c @@ -449,26 +449,26 @@ recalculate_input_bindings(struct gl_context *ctx) * generic slots. This is the only situation where material values * are available as per-vertex attributes. */ - for (i = 0; i <= VERT_ATTRIB_TEX7; i++) { + for (i = 0; i < VERT_ATTRIB_FF_MAX; i++) { if (exec->array.legacy_array[i]->Enabled) inputs[i] = exec->array.legacy_array[i]; else { inputs[i] = &vbo->legacy_currval[i]; - const_inputs |= 1 << i; + const_inputs |= VERT_BIT(i); } } for (i = 0; i < MAT_ATTRIB_MAX; i++) { - inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->mat_currval[i]; - const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i); + inputs[VERT_ATTRIB_GENERIC(i)] = &vbo->mat_currval[i]; + const_inputs |= VERT_BIT_GENERIC(i); } /* Could use just about anything, just to fill in the empty * slots: */ - for (i = MAT_ATTRIB_MAX; i < VERT_ATTRIB_MAX - VERT_ATTRIB_GENERIC0; i++) { - inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->generic_currval[i]; - const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i); + for (i = MAT_ATTRIB_MAX; i < VERT_ATTRIB_GENERIC_MAX; i++) { + inputs[VERT_ATTRIB_GENERIC(i)] = &vbo->generic_currval[i]; + const_inputs |= VERT_BIT_GENERIC(i); } /* There is no need to make _NEW_ARRAY dirty here for the TnL program, @@ -485,23 +485,24 @@ recalculate_input_bindings(struct gl_context *ctx) * conventional, legacy arrays. No materials, and the generic * slots are vacant. */ - for (i = 0; i <= VERT_ATTRIB_TEX7; i++) { - if (exec->array.generic_array[i]->Enabled) + for (i = 0; i < VERT_ATTRIB_FF_MAX; i++) { + if (i < VERT_ATTRIB_GENERIC_MAX + && exec->array.generic_array[i]->Enabled) inputs[i] = exec->array.generic_array[i]; else if (exec->array.legacy_array[i]->Enabled) inputs[i] = exec->array.legacy_array[i]; else { inputs[i] = &vbo->legacy_currval[i]; - const_inputs |= 1 << i; + const_inputs |= VERT_BIT_FF(i); } } /* Could use just about anything, just to fill in the empty * slots: */ - for (i = VERT_ATTRIB_GENERIC0; i < VERT_ATTRIB_MAX; i++) { - inputs[i] = &vbo->generic_currval[i - VERT_ATTRIB_GENERIC0]; - const_inputs |= 1 << i; + for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++) { + inputs[VERT_ATTRIB_GENERIC(i)] = &vbo->generic_currval[i]; + const_inputs |= VERT_BIT_GENERIC(i); } ctx->NewState |= _NEW_ARRAY; @@ -521,24 +522,24 @@ recalculate_input_bindings(struct gl_context *ctx) inputs[0] = exec->array.legacy_array[0]; else { inputs[0] = &vbo->legacy_currval[0]; - const_inputs |= 1 << 0; + const_inputs |= VERT_BIT_POS; } - for (i = 1; i <= VERT_ATTRIB_TEX7; i++) { + for (i = 1; i < VERT_ATTRIB_FF_MAX; i++) { if (exec->array.legacy_array[i]->Enabled) inputs[i] = exec->array.legacy_array[i]; else { inputs[i] = &vbo->legacy_currval[i]; - const_inputs |= 1 << i; + const_inputs |= VERT_BIT_FF(i); } } - for (i = 1; i < MAX_VERTEX_GENERIC_ATTRIBS; i++) { + for (i = 1; i < VERT_ATTRIB_GENERIC_MAX; i++) { if (exec->array.generic_array[i]->Enabled) - inputs[VERT_ATTRIB_GENERIC0 + i] = exec->array.generic_array[i]; + inputs[VERT_ATTRIB_GENERIC(i)] = exec->array.generic_array[i]; else { - inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->generic_currval[i]; - const_inputs |= 1 << (VERT_ATTRIB_GENERIC0 + i); + inputs[VERT_ATTRIB_GENERIC(i)] = &vbo->generic_currval[i]; + const_inputs |= VERT_BIT_GENERIC(i); } } diff --git a/src/mesa/vbo/vbo_exec_draw.c b/src/mesa/vbo/vbo_exec_draw.c index efb6dd10a80..2df408eff3c 100644 --- a/src/mesa/vbo/vbo_exec_draw.c +++ b/src/mesa/vbo/vbo_exec_draw.c @@ -173,12 +173,12 @@ vbo_exec_bind_arrays( struct gl_context *ctx ) */ switch (get_program_mode(exec->ctx)) { case VP_NONE: - for (attr = 0; attr < 16; attr++) { + for (attr = 0; attr < VERT_ATTRIB_FF_MAX; attr++) { exec->vtx.inputs[attr] = &vbo->legacy_currval[attr]; } for (attr = 0; attr < MAT_ATTRIB_MAX; attr++) { - ASSERT(attr + 16 < Elements(exec->vtx.inputs)); - exec->vtx.inputs[attr + 16] = &vbo->mat_currval[attr]; + ASSERT(VERT_ATTRIB_GENERIC(attr) < Elements(exec->vtx.inputs)); + exec->vtx.inputs[VERT_ATTRIB_GENERIC(attr)] = &vbo->mat_currval[attr]; } map = vbo->map_vp_none; break; @@ -188,10 +188,12 @@ vbo_exec_bind_arrays( struct gl_context *ctx ) * occurred. NV vertex programs cannot access material values, * nor attributes greater than VERT_ATTRIB_TEX7. */ - for (attr = 0; attr < 16; attr++) { + for (attr = 0; attr < VERT_ATTRIB_FF_MAX; attr++) { exec->vtx.inputs[attr] = &vbo->legacy_currval[attr]; - ASSERT(attr + 16 < Elements(exec->vtx.inputs)); - exec->vtx.inputs[attr + 16] = &vbo->generic_currval[attr]; + } + for (attr = 0; attr < VERT_ATTRIB_GENERIC_MAX; attr++) { + ASSERT(VERT_ATTRIB_GENERIC(attr) < Elements(exec->vtx.inputs)); + exec->vtx.inputs[VERT_ATTRIB_GENERIC(attr)] = &vbo->generic_currval[attr]; } map = vbo->map_vp_arb; @@ -201,9 +203,9 @@ vbo_exec_bind_arrays( struct gl_context *ctx ) */ if ((ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_POS) == 0 && (ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_GENERIC0)) { - exec->vtx.inputs[16] = exec->vtx.inputs[0]; - exec->vtx.attrsz[16] = exec->vtx.attrsz[0]; - exec->vtx.attrptr[16] = exec->vtx.attrptr[0]; + exec->vtx.inputs[VERT_ATTRIB_GENERIC0] = exec->vtx.inputs[0]; + exec->vtx.attrsz[VERT_ATTRIB_GENERIC0] = exec->vtx.attrsz[0]; + exec->vtx.attrptr[VERT_ATTRIB_GENERIC0] = exec->vtx.attrptr[0]; exec->vtx.attrsz[0] = 0; } break; @@ -248,7 +250,7 @@ vbo_exec_bind_arrays( struct gl_context *ctx ) exec->vtx.bufferobj); arrays[attr]._MaxElement = count; /* ??? */ - varying_inputs |= 1 << attr; + varying_inputs |= VERT_BIT(attr); ctx->NewState |= _NEW_ARRAY; } } diff --git a/src/mesa/vbo/vbo_save.c b/src/mesa/vbo/vbo_save.c index 4343b348180..e0270619118 100644 --- a/src/mesa/vbo/vbo_save.c +++ b/src/mesa/vbo/vbo_save.c @@ -63,15 +63,23 @@ void vbo_save_init( struct gl_context *ctx ) struct gl_client_array *arrays = save->arrays; unsigned i; - memcpy(arrays, vbo->legacy_currval, 16 * sizeof(arrays[0])); - memcpy(arrays + 16, vbo->generic_currval, 16 * sizeof(arrays[0])); - - for (i = 0; i < 16; ++i) { - arrays[i ].BufferObj = NULL; - arrays[i + 16].BufferObj = NULL; - _mesa_reference_buffer_object(ctx, &arrays[i ].BufferObj, + memcpy(arrays, vbo->legacy_currval, + VERT_ATTRIB_FF_MAX * sizeof(arrays[0])); + for (i = 0; i < VERT_ATTRIB_FF_MAX; ++i) { + struct gl_client_array *array; + array = &arrays[VERT_ATTRIB_FF(i)]; + array->BufferObj = NULL; + _mesa_reference_buffer_object(ctx, &arrays->BufferObj, vbo->legacy_currval[i].BufferObj); - _mesa_reference_buffer_object(ctx, &arrays[i + 16].BufferObj, + } + + memcpy(arrays + VERT_ATTRIB_GENERIC(0), vbo->generic_currval, + VERT_ATTRIB_GENERIC_MAX * sizeof(arrays[0])); + for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; ++i) { + struct gl_client_array *array; + array = &arrays[VERT_ATTRIB_GENERIC(i)]; + array->BufferObj = NULL; + _mesa_reference_buffer_object(ctx, &array->BufferObj, vbo->generic_currval[i].BufferObj); } } diff --git a/src/mesa/vbo/vbo_save_draw.c b/src/mesa/vbo/vbo_save_draw.c index 6cda831aa85..08d2e4a07ef 100644 --- a/src/mesa/vbo/vbo_save_draw.c +++ b/src/mesa/vbo/vbo_save_draw.c @@ -146,11 +146,11 @@ static void vbo_bind_vertex_list(struct gl_context *ctx, */ switch (get_program_mode(ctx)) { case VP_NONE: - for (attr = 0; attr < 16; attr++) { + for (attr = 0; attr < VERT_ATTRIB_FF_MAX; attr++) { save->inputs[attr] = &vbo->legacy_currval[attr]; } for (attr = 0; attr < MAT_ATTRIB_MAX; attr++) { - save->inputs[attr + 16] = &vbo->mat_currval[attr]; + save->inputs[VERT_ATTRIB_GENERIC(attr)] = &vbo->mat_currval[attr]; } map = vbo->map_vp_none; break; @@ -160,9 +160,11 @@ static void vbo_bind_vertex_list(struct gl_context *ctx, * occurred. NV vertex programs cannot access material values, * nor attributes greater than VERT_ATTRIB_TEX7. */ - for (attr = 0; attr < 16; attr++) { + for (attr = 0; attr < VERT_ATTRIB_FF_MAX; attr++) { save->inputs[attr] = &vbo->legacy_currval[attr]; - save->inputs[attr + 16] = &vbo->generic_currval[attr]; + } + for (attr = 0; attr < VERT_ATTRIB_GENERIC_MAX; attr++) { + save->inputs[VERT_ATTRIB_GENERIC(attr)] = &vbo->generic_currval[attr]; } map = vbo->map_vp_arb; @@ -172,8 +174,8 @@ static void vbo_bind_vertex_list(struct gl_context *ctx, */ if ((ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_POS) == 0 && (ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_GENERIC0)) { - save->inputs[16] = save->inputs[0]; - node_attrsz[16] = node_attrsz[0]; + save->inputs[VERT_ATTRIB_GENERIC0] = save->inputs[0]; + node_attrsz[VERT_ATTRIB_GENERIC0] = node_attrsz[0]; node_attrsz[0] = 0; } break; @@ -204,7 +206,7 @@ static void vbo_bind_vertex_list(struct gl_context *ctx, assert(arrays[attr].BufferObj->Name); buffer_offset += node->attrsz[src] * sizeof(GLfloat); - varying_inputs |= 1<NewState |= _NEW_ARRAY; } }