From b7752724d930aa8b93617829d814b20509f85069 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sun, 21 Apr 2002 18:49:18 +0000 Subject: vertex program attribute array work --- src/mesa/array_cache/ac_import.c | 121 +++++++++++++++++++++++++++++++++++---- 1 file changed, 110 insertions(+), 11 deletions(-) (limited to 'src/mesa/array_cache/ac_import.c') diff --git a/src/mesa/array_cache/ac_import.c b/src/mesa/array_cache/ac_import.c index 2fc13dc2d7..9867f9f51b 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.16 2002/01/05 20:51:12 brianp Exp $ */ +/* $Id: ac_import.c,v 1.17 2002/04/21 18:49:19 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -147,6 +147,7 @@ static void reset_index( GLcontext *ctx ) ac->NewArrayState &= ~_NEW_ARRAY_INDEX; } + static void reset_fogcoord( GLcontext *ctx ) { ACcontext *ac = AC_CONTEXT(ctx); @@ -162,6 +163,7 @@ static void reset_fogcoord( GLcontext *ctx ) ac->NewArrayState &= ~_NEW_ARRAY_FOGCOORD; } + static void reset_edgeflag( GLcontext *ctx ) { ACcontext *ac = AC_CONTEXT(ctx); @@ -178,7 +180,33 @@ static void reset_edgeflag( GLcontext *ctx ) } +static void reset_attrib( GLcontext *ctx, GLuint index ) +{ + ACcontext *ac = AC_CONTEXT(ctx); + + 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 { + ac->Raw.Attrib[index] = ac->Fallback.Attrib[index]; + + if (ctx->Current.Attrib[index][3] != 1.0) + ac->Raw.Attrib[index].Size = 4; + else if (ctx->Current.Attrib[index][2] != 0.0) + ac->Raw.Attrib[index].Size = 3; + else + ac->Raw.Attrib[index].Size = 2; + } + + ac->IsCached.Attrib[index] = GL_FALSE; + ac->NewArrayState &= ~_NEW_ARRAY_ATTRIB(index); +} + +/* + * Generic import function for color data + */ static void import( GLcontext *ctx, GLenum type, struct gl_client_array *to, @@ -237,8 +265,12 @@ static void import( GLcontext *ctx, -/* Functions to import array ranges with specified types and strides. +/* + * Functions to import array ranges with specified types and strides. + * For example, if the vertex data is GLshort[2] and we want GLfloat[3] + * we'll use an import function to do the data conversion. */ + static void import_texcoord( GLcontext *ctx, GLuint unit, GLenum type, GLuint stride ) { @@ -246,6 +278,8 @@ static void import_texcoord( GLcontext *ctx, GLuint unit, struct gl_client_array *from = &ac->Raw.TexCoord[unit]; struct gl_client_array *to = &ac->Cache.TexCoord[unit]; + ASSERT(unit < ctx->Const.MaxTextureUnits); + /* Limited choices at this stage: */ ASSERT(type == GL_FLOAT); @@ -316,9 +350,6 @@ static void import_normal( GLcontext *ctx, ac->IsCached.Normal = GL_TRUE; } - - - static void import_color( GLcontext *ctx, GLenum type, GLuint stride ) { @@ -415,10 +446,42 @@ static void import_edgeflag( GLcontext *ctx, ac->IsCached.EdgeFlag = GL_TRUE; } +static void import_attrib( GLcontext *ctx, GLuint index, + GLenum type, GLuint stride ) +{ + ACcontext *ac = AC_CONTEXT(ctx); + struct gl_client_array *from = &ac->Raw.Attrib[index]; + struct gl_client_array *to = &ac->Cache.Attrib[index]; + ASSERT(index < VERT_ATTRIB_MAX); -/* Externals to request arrays with specific properties: + /* Limited choices at this stage: + */ + ASSERT(type == GL_FLOAT); + ASSERT(stride == 4*sizeof(GLfloat) || stride == 0); + ASSERT(ac->count - ac->start < ctx->Const.MaxArrayLockSize); + + _math_trans_4f( (GLfloat (*)[4]) to->Ptr, + from->Ptr, + from->StrideB, + from->Type, + from->Size, + 0, + ac->count - ac->start); + + to->Size = from->Size; + to->StrideB = 4 * sizeof(GLfloat); + to->Type = GL_FLOAT; + ac->IsCached.Attrib[index] = GL_TRUE; +} + + + +/* + * Externals to request arrays with specific properties: */ + + struct gl_client_array *_ac_import_texcoord( GLcontext *ctx, GLuint unit, GLenum type, @@ -429,6 +492,8 @@ struct gl_client_array *_ac_import_texcoord( GLcontext *ctx, { ACcontext *ac = AC_CONTEXT(ctx); + ASSERT(unit < ctx->Const.MaxTextureUnits); + /* Can we keep the existing version? */ if (ac->NewArrayState & _NEW_ARRAY_TEXCOORD(unit)) @@ -656,9 +721,6 @@ struct gl_client_array *_ac_import_fogcoord( GLcontext *ctx, } } - - - struct gl_client_array *_ac_import_edgeflag( GLcontext *ctx, GLenum type, GLuint reqstride, @@ -689,8 +751,45 @@ struct gl_client_array *_ac_import_edgeflag( GLcontext *ctx, } } +/* GL_NV_vertex_program */ +struct gl_client_array *_ac_import_attrib( GLcontext *ctx, + GLuint index, + GLenum type, + GLuint reqstride, + GLuint reqsize, + GLboolean reqwriteable, + GLboolean *writeable ) +{ + ACcontext *ac = AC_CONTEXT(ctx); + + ASSERT(index < VERT_ATTRIB_MAX); + /* Can we keep the existing version? + */ + if (ac->NewArrayState & _NEW_ARRAY_ATTRIB(index)) + reset_attrib( ctx, index ); + /* Is the request impossible? + */ + if (reqsize != 0 && ac->Raw.Attrib[index].Size > (GLint) reqsize) + return 0; + + /* Do we need to pull in a copy of the client data: + */ + if (ac->Raw.Attrib[index].Type != type || + (reqstride != 0 && ac->Raw.Attrib[index].StrideB != (GLint)reqstride) || + reqwriteable) + { + if (!ac->IsCached.Attrib[index]) + import_attrib(ctx, index, type, reqstride ); + *writeable = GL_TRUE; + return &ac->Cache.Attrib[index]; + } + else { + *writeable = GL_FALSE; + return &ac->Raw.Attrib[index]; + } +} /* Clients must call this function to validate state and set bounds @@ -723,8 +822,8 @@ void _ac_import_range( GLcontext *ctx, GLuint start, GLuint count ) -/* Additional convienence function for importing a the element list - * for drawelements, drawrangeelements: +/* Additional convienence function for importing the element list + * for glDrawElements() and glDrawRangeElements(). */ CONST void * _ac_import_elements( GLcontext *ctx, -- cgit v1.2.3