Beispiel #1
0
void
_mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
{
   GET_CURRENT_CONTEXT(ctx);

   if (size<3 || size>4) {
      gl_error( ctx, GL_INVALID_VALUE, "glColorPointer(size)" );
      return;
   }
   if (stride<0) {
      gl_error( ctx, GL_INVALID_VALUE, "glColorPointer(stride)" );
      return;
   }

   if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
      fprintf(stderr, "glColorPointer( sz %d type %s stride %d )\n", size, 
	  gl_lookup_enum_by_nr( type ),
	  stride);

   ctx->Array.Color.StrideB = stride;
   if (!stride) {
      switch (type) {
      case GL_BYTE:
         ctx->Array.Color.StrideB =  size*sizeof(GLbyte);
         break;
      case GL_UNSIGNED_BYTE:
         ctx->Array.Color.StrideB =  size*sizeof(GLubyte);
         break;
      case GL_SHORT:
         ctx->Array.Color.StrideB =  size*sizeof(GLshort);
         break;
      case GL_UNSIGNED_SHORT:
         ctx->Array.Color.StrideB =  size*sizeof(GLushort);
         break;
      case GL_INT:
         ctx->Array.Color.StrideB =  size*sizeof(GLint);
         break;
      case GL_UNSIGNED_INT:
         ctx->Array.Color.StrideB =  size*sizeof(GLuint);
         break;
      case GL_FLOAT:
         ctx->Array.Color.StrideB =  size*sizeof(GLfloat);
         break;
      case GL_DOUBLE:
         ctx->Array.Color.StrideB =  size*sizeof(GLdouble);
         break;
      default:
         gl_error( ctx, GL_INVALID_ENUM, "glColorPointer(type)" );
         return;
      }
   }
   ctx->Array.Color.Size = size;
   ctx->Array.Color.Type = type;
   ctx->Array.Color.Stride = stride;
   ctx->Array.Color.Ptr = (void *) ptr;
   ctx->Array.ColorFunc = gl_trans_4ub_tab[size][TYPE_IDX(type)];
   ctx->Array.ColorEltFunc = gl_trans_elt_4ub_tab[size][TYPE_IDX(type)];
   ctx->Array.NewArrayState |= VERT_RGBA;
   ctx->NewState |= NEW_CLIENT_STATE;
}
Beispiel #2
0
void
_mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
{
   GET_CURRENT_CONTEXT(ctx);
   GLuint texUnit;
   
   texUnit = ctx->Array.ActiveTexture;

   if (size<1 || size>4) {
      gl_error( ctx, GL_INVALID_VALUE, "glTexCoordPointer(size)" );
      return;
   }
   if (stride<0) {
      gl_error( ctx, GL_INVALID_VALUE, "glTexCoordPointer(stride)" );
      return;
   }

   if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
      fprintf(stderr, "glTexCoordPointer( unit %u sz %d type %s stride %d )\n", 
	  texUnit,
	  size, 
	  gl_lookup_enum_by_nr( type ),
	  stride);

   ctx->Array.TexCoord[texUnit].StrideB = stride;
   if (!stride) {
      switch (type) {
      case GL_SHORT:
         ctx->Array.TexCoord[texUnit].StrideB =  size*sizeof(GLshort);
         break;
      case GL_INT:
         ctx->Array.TexCoord[texUnit].StrideB =  size*sizeof(GLint);
         break;
      case GL_FLOAT:
         ctx->Array.TexCoord[texUnit].StrideB =  size*sizeof(GLfloat);
         break;
      case GL_DOUBLE:
         ctx->Array.TexCoord[texUnit].StrideB =  size*sizeof(GLdouble);
         break;
      default:
         gl_error( ctx, GL_INVALID_ENUM, "glTexCoordPointer(type)" );
         return;
      }
   }
   ctx->Array.TexCoord[texUnit].Size = size;
   ctx->Array.TexCoord[texUnit].Type = type;
   ctx->Array.TexCoord[texUnit].Stride = stride;
   ctx->Array.TexCoord[texUnit].Ptr = (void *) ptr;

   ctx->Array.TexCoordFunc[texUnit] = gl_trans_4f_tab[size][TYPE_IDX(type)];
   ctx->Array.TexCoordEltFunc[texUnit] = gl_trans_elt_4f_tab[size][TYPE_IDX(type)];
   ctx->Array.NewArrayState |= PIPE_TEX(texUnit);
   ctx->NewState |= NEW_CLIENT_STATE;
}
Beispiel #3
0
void
_mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
{
   GET_CURRENT_CONTEXT(ctx);
   
   if (stride<0) {
      gl_error( ctx, GL_INVALID_VALUE, "glNormalPointer(stride)" );
      return;
   }

   if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API))
      fprintf(stderr, "glNormalPointer( type %s stride %d )\n", 
	      gl_lookup_enum_by_nr( type ),
	      stride);

   ctx->Array.Normal.StrideB = stride;
   if (!stride) {
      switch (type) {
      case GL_BYTE:
         ctx->Array.Normal.StrideB =  3*sizeof(GLbyte);
         break;
      case GL_SHORT:
         ctx->Array.Normal.StrideB =  3*sizeof(GLshort);
         break;
      case GL_INT:
         ctx->Array.Normal.StrideB =  3*sizeof(GLint);
         break;
      case GL_FLOAT:
         ctx->Array.Normal.StrideB =  3*sizeof(GLfloat);
         break;
      case GL_DOUBLE:
         ctx->Array.Normal.StrideB =  3*sizeof(GLdouble);
         break;
      default:
         gl_error( ctx, GL_INVALID_ENUM, "glNormalPointer(type)" );
         return;
      }
   }
   ctx->Array.Normal.Type = type;
   ctx->Array.Normal.Stride = stride;
   ctx->Array.Normal.Ptr = (void *) ptr;
   ctx->Array.NormalFunc = gl_trans_3f_tab[TYPE_IDX(type)];
   ctx->Array.NormalEltFunc = gl_trans_elt_3f_tab[TYPE_IDX(type)];
   ctx->Array.NewArrayState |= VERT_NORM;
   ctx->NewState |= NEW_CLIENT_STATE;
}
Beispiel #4
0
/**
 * Translate vector of values to GLfloat[3], normalized to [-1, 1].
 */
void _math_trans_3fn(GLfloat (*to)[3],
		    const void *ptr,
		    GLuint stride,
		    GLenum type,
		    GLuint start,
		    GLuint n )
{
   _math_trans_3fn_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
}
Beispiel #5
0
/**
 * Translate vector of values to GLubyte [1].
 */
void _math_trans_1ub(GLubyte *to,
		     const void *ptr,
		     GLuint stride,
		     GLenum type,
		     GLuint start,
		     GLuint n )
{
   _math_trans_1ub_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
}
Beispiel #6
0
/**
 * Translate vector of values to GLfloat [1].
 */
void _math_trans_1f(GLfloat *to,
		    const void *ptr,
		    GLuint stride,
		    GLenum type,
		    GLuint start,
		    GLuint n )
{
   _math_trans_1f_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
}
Beispiel #7
0
/**
 * Translate vector of values to GLuint [1].
 */
void _math_trans_1ui(GLuint *to,
		     CONST void *ptr,
		     GLuint stride,
		     GLenum type,
		     GLuint start,
		     GLuint n )
{
   _math_trans_1ui_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
}
Beispiel #8
0
/**
 * Translate vector of values to GLfloat [4].
 */
void _math_trans_4f(GLfloat (*to)[4],
		    const void *ptr,
		    GLuint stride,
		    GLenum type,
		    GLuint size,
		    GLuint start,
		    GLuint n )
{
   _math_trans_4f_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
}
Beispiel #9
0
/**
 * Translate vector of values to GLushort [4].
 */
void _math_trans_4us(GLushort (*to)[4],
		     CONST void *ptr,
		     GLuint stride,
		     GLenum type,
		     GLuint size,
		     GLuint start,
		     GLuint n )
{
   _math_trans_4us_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
}
Beispiel #10
0
void
_mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
{
   GET_CURRENT_CONTEXT(ctx);
   
   if (stride<0) {
      gl_error( ctx, GL_INVALID_VALUE, "glIndexPointer(stride)" );
      return;
   }

   ctx->Array.Index.StrideB = stride;
   if (!stride) {
      switch (type) {
      case GL_UNSIGNED_BYTE:
         ctx->Array.Index.StrideB =  sizeof(GLubyte);
         break;
      case GL_SHORT:
         ctx->Array.Index.StrideB =  sizeof(GLshort);
         break;
      case GL_INT:
         ctx->Array.Index.StrideB =  sizeof(GLint);
         break;
      case GL_FLOAT:
         ctx->Array.Index.StrideB =  sizeof(GLfloat);
         break;
      case GL_DOUBLE:
         ctx->Array.Index.StrideB =  sizeof(GLdouble);
         break;
      default:
         gl_error( ctx, GL_INVALID_ENUM, "glIndexPointer(type)" );
         return;
      }
   }
   ctx->Array.Index.Type = type;
   ctx->Array.Index.Stride = stride;
   ctx->Array.Index.Ptr = (void *) ptr;
   ctx->Array.IndexFunc = gl_trans_1ui_tab[TYPE_IDX(type)];
   ctx->Array.IndexEltFunc = gl_trans_elt_1ui_tab[TYPE_IDX(type)];
   ctx->Array.NewArrayState |= VERT_INDEX;
   ctx->NewState |= NEW_CLIENT_STATE;
}
Beispiel #11
0
void
_mesa_EdgeFlagPointer(GLsizei stride, const void *vptr)
{
   GET_CURRENT_CONTEXT(ctx);
   const GLboolean *ptr = (GLboolean *)vptr;

   if (stride<0) {
      gl_error( ctx, GL_INVALID_VALUE, "glEdgeFlagPointer(stride)" );
      return;
   }
   ctx->Array.EdgeFlag.Stride = stride;
   ctx->Array.EdgeFlag.StrideB = stride ? stride : sizeof(GLboolean);
   ctx->Array.EdgeFlag.Ptr = (GLboolean *) ptr;
   if (stride != sizeof(GLboolean)) {
      ctx->Array.EdgeFlagFunc = gl_trans_1ub_tab[TYPE_IDX(GL_UNSIGNED_BYTE)];
   } else {
      ctx->Array.EdgeFlagFunc = 0;
   }
   ctx->Array.EdgeFlagEltFunc = gl_trans_elt_1ub_tab[TYPE_IDX(GL_UNSIGNED_BYTE)];
   ctx->Array.NewArrayState |= VERT_EDGE;
   ctx->NewState |= NEW_CLIENT_STATE;
}
Beispiel #12
0
static void init_translate_raw(void)
{
   memset( TAB(_1ui), 0, sizeof(TAB(_1ui)) );
   memset( TAB(_1ub), 0, sizeof(TAB(_1ub)) );
   memset( TAB(_3fn),  0, sizeof(TAB(_3fn)) );
   memset( TAB(_4ub), 0, sizeof(TAB(_4ub)) );
   memset( TAB(_4us), 0, sizeof(TAB(_4us)) );
   memset( TAB(_4f),  0, sizeof(TAB(_4f)) );
   memset( TAB(_4fn),  0, sizeof(TAB(_4fn)) );

   init_trans_4_GLbyte_raw();
   init_trans_3_GLbyte_raw();
   init_trans_2_GLbyte_raw();
   init_trans_1_GLbyte_raw();
   init_trans_1_GLubyte_raw();
   init_trans_3_GLubyte_raw();
   init_trans_4_GLubyte_raw();
   init_trans_4_GLshort_raw();
   init_trans_3_GLshort_raw();
   init_trans_2_GLshort_raw();
   init_trans_1_GLshort_raw();
   init_trans_4_GLushort_raw();
   init_trans_3_GLushort_raw();
   init_trans_2_GLushort_raw();
   init_trans_1_GLushort_raw();
   init_trans_4_GLint_raw();
   init_trans_3_GLint_raw();
   init_trans_2_GLint_raw();
   init_trans_1_GLint_raw();
   init_trans_4_GLuint_raw();
   init_trans_3_GLuint_raw();
   init_trans_2_GLuint_raw();
   init_trans_1_GLuint_raw();
   init_trans_4_GLdouble_raw();
   init_trans_3_GLdouble_raw();
   init_trans_2_GLdouble_raw();
   init_trans_1_GLdouble_raw();
   init_trans_4_GLfloat_raw();
   init_trans_3_GLfloat_raw();
   init_trans_2_GLfloat_raw();
   init_trans_1_GLfloat_raw();

   TAB(_4ub)[4][TYPE_IDX(GL_UNSIGNED_BYTE)] = trans_4_GLubyte_4ub_raw;
}
Beispiel #13
0
/* Called only from gl_DrawElements
 */
void gl_CVAEltPointer( GLcontext *ctx, GLenum type, const GLvoid *ptr )
{
   switch (type) {
      case GL_UNSIGNED_BYTE:
         ctx->CVA.Elt.StrideB = sizeof(GLubyte);
         break;
      case GL_UNSIGNED_SHORT:
         ctx->CVA.Elt.StrideB = sizeof(GLushort);
         break;
      case GL_UNSIGNED_INT:
         ctx->CVA.Elt.StrideB = sizeof(GLuint);
         break;
      default:
         gl_error( ctx, GL_INVALID_ENUM, "glEltPointer(type)" );
         return;
   }
   ctx->CVA.Elt.Type = type;
   ctx->CVA.Elt.Stride = 0;
   ctx->CVA.Elt.Ptr = (void *) ptr;
   ctx->CVA.EltFunc = gl_trans_1ui_tab[TYPE_IDX(type)];
   ctx->Array.NewArrayState |= VERT_ELT; /* ??? */
}
Beispiel #14
0
/**
 * Make a list of per-vertex functions to call for each glArrayElement call.
 * These functions access the array data (i.e. glVertex, glColor, glNormal,
 * etc).
 * Note: this may be called during display list construction.
 */
static void _ae_update_state( GLcontext *ctx )
{
   AEcontext *actx = AE_CONTEXT(ctx);
   AEarray *aa = actx->arrays;
   AEattrib *at = actx->attribs;
   GLuint i;

   actx->nr_vbos = 0;

   /* conventional vertex arrays */
  if (ctx->Array.ArrayObj->Index.Enabled) {
      aa->array = &ctx->Array.ArrayObj->Index;
      aa->offset = IndexFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }
   if (ctx->Array.ArrayObj->EdgeFlag.Enabled) {
      aa->array = &ctx->Array.ArrayObj->EdgeFlag;
      aa->offset = _gloffset_EdgeFlagv;
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }
   if (ctx->Array.ArrayObj->Normal.Enabled) {
      aa->array = &ctx->Array.ArrayObj->Normal;
      aa->offset = NormalFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }
   if (ctx->Array.ArrayObj->Color.Enabled) {
      aa->array = &ctx->Array.ArrayObj->Color;
      aa->offset = ColorFuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }
   if (ctx->Array.ArrayObj->SecondaryColor.Enabled) {
      aa->array = &ctx->Array.ArrayObj->SecondaryColor;
      aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }
   if (ctx->Array.ArrayObj->FogCoord.Enabled) {
      aa->array = &ctx->Array.ArrayObj->FogCoord;
      aa->offset = FogCoordFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }
   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
      struct gl_client_array *attribArray = &ctx->Array.ArrayObj->TexCoord[i];
      if (attribArray->Enabled) {
         /* NOTE: we use generic glVertexAttribNV functions here.
          * If we ever remove GL_NV_vertex_program this will have to change.
          */
         at->array = attribArray;
         ASSERT(!at->array->Normalized);
         at->func = AttribFuncsNV[at->array->Normalized]
                                 [at->array->Size-1]
                                 [TYPE_IDX(at->array->Type)];
         at->index = VERT_ATTRIB_TEX0 + i;
	 check_vbo(actx, at->array->BufferObj);
         at++;
      }
   }

   /* generic vertex attribute arrays */   
   for (i = 1; i < VERT_ATTRIB_MAX; i++) {  /* skip zero! */
      struct gl_client_array *attribArray = &ctx->Array.ArrayObj->VertexAttrib[i];
      if (attribArray->Enabled) {
         at->array = attribArray;
         /* Note: we can't grab the _glapi_Dispatch->VertexAttrib1fvNV
          * function pointer here (for float arrays) since the pointer may
          * change from one execution of _ae_loopback_array_elt() to
          * the next.  Doing so caused UT to break.
          */
         if (ctx->VertexProgram._Enabled
             && ctx->VertexProgram.Current->IsNVProgram) {
            at->func = AttribFuncsNV[at->array->Normalized]
                                    [at->array->Size-1]
                                    [TYPE_IDX(at->array->Type)];
         }
         else {
            at->func = AttribFuncsARB[at->array->Normalized]
                                     [at->array->Size-1]
                                     [TYPE_IDX(at->array->Type)];
         }
         at->index = i;
	 check_vbo(actx, at->array->BufferObj);
         at++;
      }
   }

   /* finally, vertex position */
   if (ctx->Array.ArrayObj->VertexAttrib[0].Enabled) {
      /* Use glVertex(v) instead of glVertexAttrib(0, v) to be sure it's
       * issued as the last (provoking) attribute).
       */
      aa->array = &ctx->Array.ArrayObj->VertexAttrib[0];
      assert(aa->array->Size >= 2); /* XXX fix someday? */
      aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }
   else if (ctx->Array.ArrayObj->Vertex.Enabled) {
      aa->array = &ctx->Array.ArrayObj->Vertex;
      aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }

   check_vbo(actx, ctx->Array.ElementArrayBufferObj);

   ASSERT(at - actx->attribs <= VERT_ATTRIB_MAX);
   ASSERT(aa - actx->arrays < 32);
   at->func = NULL;  /* terminate the list */
   aa->offset = -1;  /* terminate the list */

   actx->NewState = 0;
}
Beispiel #15
0
/**
 * Make a list of per-vertex functions to call for each glArrayElement call.
 * These functions access the array data (i.e. glVertex, glColor, glNormal, etc);
 */
static void _ae_update_state( GLcontext *ctx )
{
   AEcontext *actx = AE_CONTEXT(ctx);
   AEarray *aa = actx->arrays;
   AEattrib *at = actx->attribs;
   GLuint i;

   /* yuck, no generic array to correspond to color index or edge flag */
   if (ctx->Array.Index.Enabled) {
      aa->array = &ctx->Array.Index;
      aa->func = indexfuncs[TYPE_IDX(aa->array->Type)];
      aa++;
   }
   if (ctx->Array.EdgeFlag.Enabled) {
      aa->array = &ctx->Array.EdgeFlag;
      aa->func = (array_func) glEdgeFlagv;
      aa++;
   }

   /* all other arrays handled here */
   for (i = 0; i < VERT_ATTRIB_MAX; i++) {
      /* Note: we count down to zero so glVertex (attrib 0) is last!!! */
      const GLuint index = VERT_ATTRIB_MAX - i - 1;
      struct gl_client_array *attribArray = NULL;

      /* Generic arrays take priority over conventional arrays if vertex program
       * mode is enabled.
       */
      if (ctx->VertexProgram.Enabled
          && ctx->Array.VertexAttrib[index].Enabled) {
         if (index == 0) {
            /* Special case: use glVertex() for vertex position so
             * that it's always executed last.
             */
            aa->array = &ctx->Array.VertexAttrib[0];
            aa->func = vertexfuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
            aa++;
         }
         else {
            attribArray = &ctx->Array.VertexAttrib[index];
         }
      }
      else {
         switch (index) {
         case VERT_ATTRIB_POS:
            if (ctx->Array.Vertex.Enabled) {
               aa->array = &ctx->Array.Vertex;
               aa->func = vertexfuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
               aa++;
            }
            break;
         case VERT_ATTRIB_NORMAL:
            if (ctx->Array.Normal.Enabled) {
               aa->array = &ctx->Array.Normal;
               aa->func = normalfuncs[TYPE_IDX(aa->array->Type)];
               aa++;
            }
            break;
         case VERT_ATTRIB_COLOR0:
            if (ctx->Array.Color.Enabled) {
               aa->array = &ctx->Array.Color;
               aa->func = colorfuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
               aa++;
            }
            break;
         case VERT_ATTRIB_COLOR1:
            if (ctx->Array.SecondaryColor.Enabled) {
               aa->array = &ctx->Array.SecondaryColor;
               aa->func = secondarycolorfuncs[TYPE_IDX(aa->array->Type)];
               aa++;
            }
            break;
         case VERT_ATTRIB_FOG:
            if (ctx->Array.FogCoord.Enabled) {
               aa->array = &ctx->Array.FogCoord;
               aa->func = fogcoordfuncs[TYPE_IDX(aa->array->Type)];
               aa++;
            }
            break;
         case VERT_ATTRIB_TEX0:
         case VERT_ATTRIB_TEX1:
         case VERT_ATTRIB_TEX2:
         case VERT_ATTRIB_TEX3:
         case VERT_ATTRIB_TEX4:
         case VERT_ATTRIB_TEX5:
         case VERT_ATTRIB_TEX6:
         case VERT_ATTRIB_TEX7:
            /* use generic vertex attribs for texcoords */
            if (ctx->Array.TexCoord[index - VERT_ATTRIB_TEX0].Enabled) {
               attribArray = &ctx->Array.TexCoord[index - VERT_ATTRIB_TEX0];
            }
         default:
            /* nothing */;
         }
      }

      /* Save glVertexAttrib call (may be for glMultiTexCoord) */
      if (attribArray) {
         at->array = attribArray;
         /* Note: we can't grab the _glapi_Dispatch->VertexAttrib1fvNV
          * function pointer here (for float arrays) since the pointer may
          * change from one execution of _ae_loopback_array_elt() to
          * the next.  Doing so caused UT to break.
          */
         at->func = attribfuncs[at->array->Normalized][at->array->Size-1][TYPE_IDX(at->array->Type)];
         at->index = index;
         at++;
      }
   }
   ASSERT(at - actx->attribs <= VERT_ATTRIB_MAX);
   ASSERT(aa - actx->arrays < 32);
   at->func = NULL;  /* terminate the list */
   aa->func = NULL;  /* terminate the list */

   actx->NewState = 0;
}
/**
 * Make a list of per-vertex functions to call for each glArrayElement call.
 * These functions access the array data (i.e. glVertex, glColor, glNormal,
 * etc).
 * Note: this may be called during display list construction.
 */
static void _ae_update_state( GLcontext *ctx )
{
   AEcontext *actx = AE_CONTEXT(ctx);
   AEarray *aa = actx->arrays;
   AEattrib *at = actx->attribs;
   GLuint i;

   /* conventional vertex arrays */
  if (ctx->Array.Index.Enabled) {
      aa->array = &ctx->Array.Index;
      aa->func = IndexFuncs[TYPE_IDX(aa->array->Type)];
      aa++;
   }
   if (ctx->Array.EdgeFlag.Enabled) {
      aa->array = &ctx->Array.EdgeFlag;
      aa->func = (array_func) EdgeFlagv;
      aa++;
   }
   if (ctx->Array.Normal.Enabled) {
      aa->array = &ctx->Array.Normal;
      aa->func = NormalFuncs[TYPE_IDX(aa->array->Type)];
      aa++;
   }
   if (ctx->Array.Color.Enabled) {
      aa->array = &ctx->Array.Color;
      aa->func = ColorFuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
      aa++;
   }
   if (ctx->Array.SecondaryColor.Enabled) {
      aa->array = &ctx->Array.SecondaryColor;
      aa->func = SecondaryColorFuncs[TYPE_IDX(aa->array->Type)];
      aa++;
   }
   if (ctx->Array.FogCoord.Enabled) {
      aa->array = &ctx->Array.FogCoord;
      aa->func = FogCoordFuncs[TYPE_IDX(aa->array->Type)];
      aa++;
   }
   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
      if (ctx->Array.TexCoord[i].Enabled) {
         /* NOTE: we use generic glVertexAttrib functions here.
          * If we ever de-alias conventional/generic vertex attribs this
          * will have to change.
          */
         struct gl_client_array *attribArray = &ctx->Array.TexCoord[i];
         at->array = attribArray;
         at->func = AttribFuncsNV[at->array->Normalized][at->array->Size-1][TYPE_IDX(at->array->Type)];
         at->index = VERT_ATTRIB_TEX0 + i;
         at++;
      }
   }

   /* generic vertex attribute arrays */
   for (i = 1; i < VERT_ATTRIB_MAX; i++) {  /* skip zero! */
      if (ctx->Array.VertexAttrib[i].Enabled) {
         struct gl_client_array *attribArray = &ctx->Array.VertexAttrib[i];
         at->array = attribArray;
         /* Note: we can't grab the _glapi_Dispatch->VertexAttrib1fvNV
          * function pointer here (for float arrays) since the pointer may
          * change from one execution of _ae_loopback_array_elt() to
          * the next.  Doing so caused UT to break.
          */
         at->func = AttribFuncsNV[at->array->Normalized][at->array->Size-1][TYPE_IDX(at->array->Type)];
         at->index = i;
         at++;
      }
   }

   /* finally, vertex position */
   if (ctx->Array.VertexAttrib[0].Enabled) {
      /* Use glVertex(v) instead of glVertexAttrib(0, v) to be sure it's
       * issued as the last (proviking) attribute).
       */
      aa->array = &ctx->Array.VertexAttrib[0];
      assert(aa->array->Size >= 2); /* XXX fix someday? */
      aa->func = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
      aa++;
   }
   else if (ctx->Array.Vertex.Enabled) {
      aa->array = &ctx->Array.Vertex;
      aa->func = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
      aa++;
   }

   ASSERT(at - actx->attribs <= VERT_ATTRIB_MAX);
   ASSERT(aa - actx->arrays < 32);
   at->func = NULL;  /* terminate the list */
   aa->func = NULL;  /* terminate the list */

   actx->NewState = 0;
}
Beispiel #17
0
/**
 * Make a list of per-vertex functions to call for each glArrayElement call.
 * These functions access the array data (i.e. glVertex, glColor, glNormal,
 * etc).
 * Note: this may be called during display list construction.
 */
static void
_ae_update_state(struct gl_context *ctx)
{
   AEcontext *actx = AE_CONTEXT(ctx);
   AEarray *aa = actx->arrays;  /* non-indexed arrays (ex: glNormal) */
   AEattrib *at = actx->attribs;  /* indexed arrays (ex: glMultiTexCoord) */
   GLuint i;
   struct gl_vertex_array_object *vao = ctx->Array.VAO;

   actx->nr_vbos = 0;

   /* conventional vertex arrays */
   if (vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled) {
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      aa->offset = IndexFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }

   if (vao->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled) {
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_EDGEFLAG];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      aa->offset = _gloffset_EdgeFlagv;
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }

   if (vao->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled) {
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_NORMAL];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      aa->offset = NormalFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }

   if (vao->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled) {
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR0];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      aa->offset = ColorFuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }

   if (vao->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled) {
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR1];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }

   if (vao->VertexAttrib[VERT_ATTRIB_FOG].Enabled) {
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_FOG];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      aa->offset = FogCoordFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }

   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
      struct gl_vertex_attrib_array *attribArray =
         &vao->VertexAttrib[VERT_ATTRIB_TEX(i)];
      if (attribArray->Enabled) {
         /* NOTE: we use generic glVertexAttribNV functions here.
          * If we ever remove GL_NV_vertex_program this will have to change.
          */
         at->array = attribArray;
         at->binding = &vao->VertexBinding[attribArray->VertexBinding];
         ASSERT(!at->array->Normalized);
         at->func = AttribFuncsNV[at->array->Normalized]
                                 [at->array->Size-1]
                                 [TYPE_IDX(at->array->Type)];
         at->index = VERT_ATTRIB_TEX0 + i;
	 check_vbo(actx, at->binding->BufferObj);
         at++;
      }
   }

   /* generic vertex attribute arrays */
   for (i = 1; i < VERT_ATTRIB_GENERIC_MAX; i++) {  /* skip zero! */
      struct gl_vertex_attrib_array *attribArray =
         &vao->VertexAttrib[VERT_ATTRIB_GENERIC(i)];
      if (attribArray->Enabled) {
         GLint intOrNorm;
         at->array = attribArray;
         at->binding = &vao->VertexBinding[attribArray->VertexBinding];
         /* Note: we can't grab the _glapi_Dispatch->VertexAttrib1fvNV
          * function pointer here (for float arrays) since the pointer may
          * change from one execution of _ae_ArrayElement() to
          * the next.  Doing so caused UT to break.
          */
         if (at->array->Integer)
            intOrNorm = 2;
         else if (at->array->Normalized)
            intOrNorm = 1;
         else
            intOrNorm = 0;

         at->func = AttribFuncsARB[intOrNorm]
            [at->array->Size-1]
            [TYPE_IDX(at->array->Type)];

         at->index = i;
	 check_vbo(actx, at->binding->BufferObj);
         at++;
      }
   }

   /* finally, vertex position */
   if (vao->VertexAttrib[VERT_ATTRIB_GENERIC0].Enabled) {
      /* Use glVertex(v) instead of glVertexAttrib(0, v) to be sure it's
       * issued as the last (provoking) attribute).
       */
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC0];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      assert(aa->array->Size >= 2); /* XXX fix someday? */
      aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }
   else if (vao->VertexAttrib[VERT_ATTRIB_POS].Enabled) {
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_POS];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }

   check_vbo(actx, vao->IndexBufferObj);

   ASSERT(at - actx->attribs <= VERT_ATTRIB_MAX);
   ASSERT(aa - actx->arrays < 32);
   at->func = NULL;  /* terminate the list */
   aa->offset = -1;  /* terminate the list */

   actx->NewState = 0;
}
Beispiel #18
0
void
_mesa_DrawArrays(GLenum mode, GLint start, GLsizei count)
{
   GET_CURRENT_CONTEXT(ctx);
   struct vertex_buffer *VB = ctx->VB;
   GLint i;

   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDrawArrays");

   if (count<0) {
      gl_error( ctx, GL_INVALID_VALUE, "glDrawArrays(count)" );
      return;
   }

   if (!ctx->CompileFlag && ctx->Array.Vertex.Enabled)
   {
      GLint remaining = count;
      GLint i;
      struct gl_client_array *Normal;
      struct gl_client_array *Color;
      struct gl_client_array *Index;
      struct gl_client_array *TexCoord[MAX_TEXTURE_UNITS];
      struct gl_client_array *EdgeFlag;
      struct immediate *IM = VB->IM;
      struct gl_pipeline *elt = &ctx->CVA.elt;
      GLboolean relock;
      GLuint fallback, required;

      if (ctx->NewState)
	 gl_update_state( ctx );	

      /* Just turn off cva on this path.  Could be useful for multipass
       * rendering to keep it turned on.
       */
      relock = ctx->CompileCVAFlag;
      ctx->CompileCVAFlag = 0;

      if (!elt->pipeline_valid || relock)
	 gl_build_immediate_pipeline( ctx );

      required = elt->inputs;
      fallback = (elt->inputs & ~ctx->Array.Summary);

      if (required & VERT_RGBA) 
      {
	 Color = &ctx->Array.Color;
	 if (fallback & VERT_RGBA) {
	    Color = &ctx->Fallback.Color;
	    ctx->Array.ColorFunc = 
	       gl_trans_4ub_tab[4][TYPE_IDX(GL_UNSIGNED_BYTE)];
	 }
      }
   
      if (required & VERT_INDEX) 
      {
	 Index = &ctx->Array.Index;
	 if (fallback & VERT_INDEX) {
	    Index = &ctx->Fallback.Index;
	    ctx->Array.IndexFunc = gl_trans_1ui_tab[TYPE_IDX(GL_UNSIGNED_INT)];
	 }
      }

      for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) 
      {
	 GLuint flag = VERT_TEX_ANY(i);

	 if (required & flag) {
	    TexCoord[i] = &ctx->Array.TexCoord[i];

	    if (fallback & flag) 
	    {
	       TexCoord[i] = &ctx->Fallback.TexCoord[i];
	       TexCoord[i]->Size = gl_texcoord_size( ctx->Current.Flag, i );

	       ctx->Array.TexCoordFunc[i] = 
		  gl_trans_4f_tab[TexCoord[i]->Size][TYPE_IDX(GL_FLOAT)];
	    }
	 }
      }

      if (ctx->Array.Flags != ctx->Array.Flag[0])
 	 for (i = 0 ; i < VB_MAX ; i++) 
	    ctx->Array.Flag[i] = ctx->Array.Flags;


      if (required & VERT_NORM) 
      {
	 Normal = &ctx->Array.Normal;
	 if (fallback & VERT_NORM) {
	    Normal = &ctx->Fallback.Normal;
	    ctx->Array.NormalFunc = gl_trans_3f_tab[TYPE_IDX(GL_FLOAT)];
	 }
      }

      if ( required & VERT_EDGE )
      {
	 if (mode == GL_TRIANGLES || 
	     mode == GL_QUADS || 
	     mode == GL_POLYGON)
	 {
	    EdgeFlag = &ctx->Array.EdgeFlag;
	    if (fallback & VERT_EDGE) {
	       EdgeFlag = &ctx->Fallback.EdgeFlag;
	       ctx->Array.EdgeFlagFunc = 
		  gl_trans_1ub_tab[TYPE_IDX(GL_UNSIGNED_BYTE)];
	    }
	 }
	 else
	    required &= ~VERT_EDGE;
      }

      VB->Primitive = IM->Primitive; 
      VB->NextPrimitive = IM->NextPrimitive; 
      VB->MaterialMask = IM->MaterialMask;
      VB->Material = IM->Material;
      VB->BoundsPtr = 0;

      while (remaining > 0) {
         GLint vbspace = VB_MAX - VB_START;
	 GLuint count, n;
	 
	 if (vbspace >= remaining) {
	    n = remaining;
	    VB->LastPrimitive = VB_START + n;
	 } else {
	    n = vbspace;
	    VB->LastPrimitive = VB_START;
	 }
	 
	 VB->CullMode = 0;
	 
	 ctx->Array.VertexFunc( IM->Obj + VB_START, 
				&ctx->Array.Vertex, start, n );
	 
	 if (required & VERT_NORM) {
	    ctx->Array.NormalFunc( IM->Normal + VB_START, 
				   Normal, start, n );
	 }
	 
	 if (required & VERT_EDGE) {
	    ctx->Array.EdgeFlagFunc( IM->EdgeFlag + VB_START, 
				     EdgeFlag, start, n );
	 }
	 
	 if (required & VERT_RGBA) {
	    ctx->Array.ColorFunc( IM->Color + VB_START, 
				  Color, start, n );
	 }
	 
	 if (required & VERT_INDEX) {
	    ctx->Array.IndexFunc( IM->Index + VB_START, 
				  Index, start, n );
	 }
	 
	 if (required & VERT_TEX0_ANY) {
	    IM->v.TexCoord[0].size = TexCoord[0]->Size;
	    ctx->Array.TexCoordFunc[0]( IM->TexCoord[0] + VB_START, 
					TexCoord[0], start, n );
	 }
	 
	 if (required & VERT_TEX1_ANY) {
	    IM->v.TexCoord[1].size = TexCoord[1]->Size;
	    ctx->Array.TexCoordFunc[1]( IM->TexCoord[1] + VB_START, 
					TexCoord[1], start, n );
	 }

	 VB->ObjPtr = &IM->v.Obj;
	 VB->NormalPtr = &IM->v.Normal;
	 VB->ColorPtr = &IM->v.Color;
	 VB->Color[0] = VB->Color[1] = VB->ColorPtr;
	 VB->IndexPtr = &IM->v.Index;
	 VB->EdgeFlagPtr = &IM->v.EdgeFlag;
	 VB->TexCoordPtr[0] = &IM->v.TexCoord[0];
	 VB->TexCoordPtr[1] = &IM->v.TexCoord[1];

	 VB->Flag = ctx->Array.Flag;
	 VB->OrFlag = ctx->Array.Flags;

	 VB->Start = IM->Start = VB_START;
	 count = VB->Count = IM->Count = VB_START + n;

#define RESET_VEC(v, t, s, c) (v.start = t v.data[s], v.count = c)  

	 RESET_VEC(IM->v.Obj, (GLfloat *), VB_START, count);
	 RESET_VEC(IM->v.Normal, (GLfloat *), VB_START, count);
	 RESET_VEC(IM->v.TexCoord[0], (GLfloat *), VB_START, count);
	 RESET_VEC(IM->v.TexCoord[1], (GLfloat *), VB_START, count);
	 RESET_VEC(IM->v.Index, &, VB_START, count);
	 RESET_VEC(IM->v.Elt, &, VB_START, count);
	 RESET_VEC(IM->v.EdgeFlag, &, VB_START, count);
	 RESET_VEC(IM->v.Color, (GLubyte *), VB_START, count);
	 RESET_VEC(VB->Clip, (GLfloat *), VB_START, count);
	 RESET_VEC(VB->Eye, (GLfloat *), VB_START, count);
	 RESET_VEC(VB->Win, (GLfloat *), VB_START, count);
	 RESET_VEC(VB->BColor, (GLubyte *), VB_START, count); 
	 RESET_VEC(VB->BIndex, &, VB_START, count);

	 VB->NextPrimitive[VB->CopyStart] = VB->Count;
	 VB->Primitive[VB->CopyStart] = mode;

         /* Transform and render.
	  */
         gl_run_pipeline( VB );
	 gl_reset_vb( VB );

	 ctx->Array.Flag[count] = ctx->Array.Flags;
	 ctx->Array.Flag[VB_START] = ctx->Array.Flags;

         start += n;
         remaining -= n;
      }

      ctx->CompileCVAFlag = relock;
   }