diff options
author | Brian Paul <[email protected]> | 2002-04-21 20:37:04 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2002-04-21 20:37:04 +0000 |
commit | 12bab63f09975504c20a5dc9b9831a8072c43506 (patch) | |
tree | e1bb3a48e6a65cf6c563444ad12da5317b79d90b | |
parent | f3781eaafa54d1e4fef0de427b294c02257a3c4d (diff) |
Vertex program attribute arrays seem to work now. This includes fallbacks
to the conventional arrays when attribute arrays aren't enabled.
-rw-r--r-- | src/mesa/array_cache/ac_import.c | 54 | ||||
-rw-r--r-- | src/mesa/main/mtypes.h | 4 | ||||
-rw-r--r-- | src/mesa/tnl/t_array_import.c | 86 | ||||
-rw-r--r-- | src/mesa/tnl/t_vb_program.c | 31 |
4 files changed, 122 insertions, 53 deletions
diff --git a/src/mesa/array_cache/ac_import.c b/src/mesa/array_cache/ac_import.c index 9867f9f51bf..0f45dc1f891 100644 --- a/src/mesa/array_cache/ac_import.c +++ b/src/mesa/array_cache/ac_import.c @@ -1,4 +1,4 @@ -/* $Id: ac_import.c,v 1.17 2002/04/21 18:49:19 brianp Exp $ */ +/* $Id: ac_import.c,v 1.18 2002/04/21 20:37:04 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -183,12 +183,55 @@ static void reset_edgeflag( GLcontext *ctx ) static void reset_attrib( GLcontext *ctx, GLuint index ) { ACcontext *ac = AC_CONTEXT(ctx); + GLboolean fallback = GL_FALSE; + /* + * The 16 NV vertex attribute arrays have top priority. If one of those + * is not enabled, look if a corresponding conventional array is enabled. + * If nothing else, use the fallback (ctx->Current.Attrib) values. + */ if (ctx->Array._Enabled & _NEW_ARRAY_ATTRIB(index)) { ac->Raw.Attrib[index] = ctx->Array.VertexAttrib[index]; STRIDE_ARRAY(ac->Raw.Attrib[index], ac->start); } + else if (ctx->Array._Enabled & (1 << index)) { + /* use conventional vertex array */ + switch (index) { + case VERT_ATTRIB_POS: + ac->Raw.Attrib[index] = ctx->Array.Vertex; + break; + case VERT_ATTRIB_NORMAL: + ac->Raw.Attrib[index] = ctx->Array.Normal; + break; + case VERT_ATTRIB_COLOR0: + ac->Raw.Attrib[index] = ctx->Array.Color; + break; + case VERT_ATTRIB_COLOR1: + ac->Raw.Attrib[index] = ctx->Array.SecondaryColor; + break; + case VERT_ATTRIB_FOG: + ac->Raw.Attrib[index] = ctx->Array.FogCoord; + break; + default: + if (index >= VERT_ATTRIB_TEX0 && index <= VERT_ATTRIB_TEX7) { + GLuint unit = index - VERT_ATTRIB_TEX0; + ac->Raw.Attrib[index] = ctx->Array.TexCoord[unit]; + } + else { + /* missing conventional array (vertex weight, for example) */ + fallback = GL_TRUE; + } + break; + } + if (!fallback) + STRIDE_ARRAY(ac->Raw.Attrib[index], ac->start); + } else { + fallback = GL_TRUE; + } + + if (fallback) { + /* fallback to ctx->Current.Attrib values */ ac->Raw.Attrib[index] = ac->Fallback.Attrib[index]; if (ctx->Current.Attrib[index][3] != 1.0) @@ -766,13 +809,18 @@ struct gl_client_array *_ac_import_attrib( GLcontext *ctx, /* Can we keep the existing version? */ - if (ac->NewArrayState & _NEW_ARRAY_ATTRIB(index)) + if (ac->NewArrayState & _NEW_ARRAY_ATTRIB(index)) { reset_attrib( ctx, index ); + } + else if (ac->NewArrayState & (1 << index)) { + /* Also need to check conventional attributes */ + reset_attrib( ctx, index ); + } /* Is the request impossible? */ if (reqsize != 0 && ac->Raw.Attrib[index].Size > (GLint) reqsize) - return 0; + return NULL; /* Do we need to pull in a copy of the client data: */ diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index a14347fb553..28a1921edd4 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1,4 +1,4 @@ -/* $Id: mtypes.h,v 1.72 2002/04/21 18:49:18 brianp Exp $ */ +/* $Id: mtypes.h,v 1.73 2002/04/21 20:37:04 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -1537,8 +1537,8 @@ struct matrix_stack #define _NEW_ARRAY_TEXCOORD_5 VERT_BIT_TEX5 #define _NEW_ARRAY_TEXCOORD_6 VERT_BIT_TEX6 #define _NEW_ARRAY_TEXCOORD_7 VERT_BIT_TEX7 -#define _NEW_ARRAY_ALL 0xffff #define _NEW_ARRAY_ATTRIB_0 0x10000 /* start at bit 16 */ +#define _NEW_ARRAY_ALL 0xffffffff #define _NEW_ARRAY_TEXCOORD(i) (_NEW_ARRAY_TEXCOORD_0 << (i)) diff --git a/src/mesa/tnl/t_array_import.c b/src/mesa/tnl/t_array_import.c index 50ef1c86e30..082ae4ad3ca 100644 --- a/src/mesa/tnl/t_array_import.c +++ b/src/mesa/tnl/t_array_import.c @@ -1,4 +1,4 @@ -/* $Id: t_array_import.c,v 1.23 2002/04/19 00:45:50 brianp Exp $ */ +/* $Id: t_array_import.c,v 1.24 2002/04/21 20:37:04 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -177,7 +177,7 @@ static void _tnl_import_index( GLcontext *ctx, static void _tnl_import_texcoord( GLcontext *ctx, - GLuint i, + GLuint unit, GLboolean writeable, GLboolean stride ) { @@ -185,21 +185,21 @@ static void _tnl_import_texcoord( GLcontext *ctx, struct gl_client_array *tmp; GLboolean is_writeable = 0; - tmp = _ac_import_texcoord(ctx, i, GL_FLOAT, - stride ? 4*sizeof(GLfloat) : 0, + tmp = _ac_import_texcoord(ctx, unit, GL_FLOAT, + stride ? 4 * sizeof(GLfloat) : 0, 0, writeable, &is_writeable); - inputs->TexCoord[i].data = (GLfloat (*)[4]) tmp->Ptr; - inputs->TexCoord[i].start = (GLfloat *) tmp->Ptr; - inputs->TexCoord[i].stride = tmp->StrideB; - inputs->TexCoord[i].size = tmp->Size; - inputs->TexCoord[i].flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE); - if (inputs->TexCoord[i].stride != 4*sizeof(GLfloat)) - inputs->TexCoord[i].flags |= VEC_BAD_STRIDE; + inputs->TexCoord[unit].data = (GLfloat (*)[4]) tmp->Ptr; + inputs->TexCoord[unit].start = (GLfloat *) tmp->Ptr; + inputs->TexCoord[unit].stride = tmp->StrideB; + inputs->TexCoord[unit].size = tmp->Size; + inputs->TexCoord[unit].flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE); + if (inputs->TexCoord[unit].stride != 4*sizeof(GLfloat)) + inputs->TexCoord[unit].flags |= VEC_BAD_STRIDE; if (!is_writeable) - inputs->TexCoord[i].flags |= VEC_NOT_WRITEABLE; + inputs->TexCoord[unit].flags |= VEC_NOT_WRITEABLE; } @@ -228,6 +228,34 @@ static void _tnl_import_edgeflag( GLcontext *ctx, +static void _tnl_import_attrib( GLcontext *ctx, + GLuint index, + GLboolean writeable, + GLboolean stride ) +{ + struct vertex_arrays *inputs = &TNL_CONTEXT(ctx)->array_inputs; + struct gl_client_array *tmp; + GLboolean is_writeable = 0; + + tmp = _ac_import_attrib(ctx, index, GL_FLOAT, + stride ? 4 * sizeof(GLfloat) : 0, + 4, /* want GLfloat[4] */ + writeable, + &is_writeable); + + inputs->Attribs[index].data = (GLfloat (*)[4]) tmp->Ptr; + inputs->Attribs[index].start = (GLfloat *) tmp->Ptr; + inputs->Attribs[index].stride = tmp->StrideB; + inputs->Attribs[index].size = tmp->Size; + inputs->Attribs[index].flags &= ~(VEC_BAD_STRIDE|VEC_NOT_WRITEABLE); + if (inputs->Attribs[index].stride != 4 * sizeof(GLfloat)) + inputs->Attribs[index].flags |= VEC_BAD_STRIDE; + if (!is_writeable) + inputs->Attribs[index].flags |= VEC_NOT_WRITEABLE; +} + + + /** * Callback for VB stages that need to improve the quality of arrays * bound to the VB. This is only necessary for client arrays which @@ -300,6 +328,7 @@ static void _tnl_upgrade_client_data( GLcontext *ctx, VB->importable_data &= ~VERT_BIT_TEX(i); } + /* XXX not sure what to do here for vertex program arrays */ } @@ -310,7 +339,6 @@ void _tnl_vb_bind_arrays( GLcontext *ctx, GLint start, GLsizei count ) struct vertex_buffer *VB = &tnl->vb; GLuint inputs = tnl->pipeline.inputs; struct vertex_arrays *tmp = &tnl->array_inputs; - GLuint i; /* fprintf(stderr, "%s %d..%d // %d..%d\n", __FUNCTION__, */ /* start, count, ctx->Array.LockFirst, ctx->Array.LockCount); */ @@ -355,11 +383,12 @@ void _tnl_vb_bind_arrays( GLcontext *ctx, GLint start, GLsizei count ) } if (inputs & VERT_BITS_TEX_ANY) { - for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { - if (inputs & VERT_BIT_TEX(i)) { - _tnl_import_texcoord( ctx, i, 0, 0 ); - tmp->TexCoord[i].count = VB->Count; - VB->TexCoordPtr[i] = &tmp->TexCoord[i]; + GLuint unit; + for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { + if (inputs & VERT_BIT_TEX(unit)) { + _tnl_import_texcoord( ctx, unit, GL_FALSE, GL_FALSE ); + tmp->TexCoord[unit].count = VB->Count; + VB->TexCoordPtr[unit] = &tmp->TexCoord[unit]; } } } @@ -391,20 +420,13 @@ void _tnl_vb_bind_arrays( GLcontext *ctx, GLint start, GLsizei count ) } } + /* XXX not 100% sure this is finished. Keith should probably inspect. */ if (ctx->VertexProgram.Enabled) { - /* XXX lots of work to do here */ - - VB->AttribPtr[VERT_ATTRIB_POS] = VB->ObjPtr; - /* - printf("bind vp arrays!\n"); - printf(" data = %p\n", VB->ObjPtr->data); - printf(" stride = %d\n", VB->ObjPtr->stride); - printf(" size = %d\n", VB->ObjPtr->size); - */ - - VB->AttribPtr[VERT_ATTRIB_NORMAL] = VB->NormalPtr; + GLuint index; + for (index = 0; index < VERT_ATTRIB_MAX; index++) { + /* XXX check program->InputsRead to reduce work here */ + _tnl_import_attrib( ctx, index, GL_FALSE, GL_TRUE ); + VB->AttribPtr[index] = &tmp->Attribs[index]; + } } - } - - diff --git a/src/mesa/tnl/t_vb_program.c b/src/mesa/tnl/t_vb_program.c index fea8c11f2b7..d89d006d4f6 100644 --- a/src/mesa/tnl/t_vb_program.c +++ b/src/mesa/tnl/t_vb_program.c @@ -1,4 +1,4 @@ -/* $Id: t_vb_program.c,v 1.11 2002/04/04 18:25:40 kschultz Exp $ */ +/* $Id: t_vb_program.c,v 1.12 2002/04/21 20:37:04 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -182,10 +182,6 @@ static GLboolean run_vp( GLcontext *ctx, struct gl_pipeline_stage *stage ) VB->AttribPtr[2]->data[i][3]); #endif - /* XXXX - * We have to deal with stride!=16 bytes, size!=4, etc in these loops!!! - */ - /* load the input attribute registers */ if (VB->Flag) { /* the traditional glBegin/glVertex/glEnd case */ @@ -199,13 +195,14 @@ static GLboolean run_vp( GLcontext *ctx, struct gl_pipeline_stage *stage ) else { /* the vertex array case */ for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) { - const GLubyte *ptr = (const GLubyte *) VB->AttribPtr[attr]->data; - const GLint stride = VB->AttribPtr[attr]->stride; - const GLfloat *data = (GLfloat *) (ptr + stride * i); - const GLint size = VB->AttribPtr[attr]->size; - COPY_4V(machine->Registers[VP_INPUT_REG_START + attr], data); - if (size == 3) - machine->Registers[VP_INPUT_REG_START + attr][3] = 1.0; + if (program->InputsRead & (1 << attr)) { + const GLubyte *ptr = (const GLubyte*) VB->AttribPtr[attr]->data; + const GLuint stride = VB->AttribPtr[attr]->stride; + const GLfloat *data = (GLfloat *) (ptr + stride * i); + COPY_4V(machine->Registers[VP_INPUT_REG_START + attr], data); + /*ASSERT(VB->AttribPtr[attr]->size == 4);*/ + ASSERT(stride == 4 * sizeof(GLfloat) || stride == 0); + } } } @@ -406,10 +403,12 @@ static void check_vp( GLcontext *ctx, struct gl_pipeline_stage *stage ) stage->active = ctx->VertexProgram.Enabled; if (stage->active) { - /* XXX what do we need here??? */ - /* - GLbitfield vpInput = ctx->VertexProgram.Current->InputsRead; - */ + /* XXX what do we need here??? + * + * I think that: + * stage->inputs = ctx->VertexProgram.Current->InputsRead; + * would be correct, and something similar for the outputs. + */ #if 000 if (stage->privatePtr) |