dispatch: stop generating separate GLES1 API code.
[mesa.git] / src / mesa / main / api_arrayelt.c
index b93a057e68bfe4d05efa72a08e7fc3d3351f4d26..20b8ff4d1c733c959975e69d2aaf2fee73523b44 100644 (file)
@@ -83,9 +83,6 @@ typedef struct {
 #define NUM_TYPES 8
 
 
-#if FEATURE_arrayelt
-
-
 static const int ColorFuncs[2][NUM_TYPES] = {
    {
       _gloffset_Color3bv,
@@ -1426,7 +1423,7 @@ GLboolean _ae_create_context( struct gl_context *ctx )
    FogCoordFuncs[6] = _gloffset_FogCoordfvEXT;
    FogCoordFuncs[7] = _gloffset_FogCoorddvEXT;
 
-   ctx->aelt_context = CALLOC( sizeof(AEcontext) );
+   ctx->aelt_context = calloc(1, sizeof(AEcontext));
    if (!ctx->aelt_context)
       return GL_FALSE;
 
@@ -1438,7 +1435,7 @@ GLboolean _ae_create_context( struct gl_context *ctx )
 void _ae_destroy_context( struct gl_context *ctx )
 {
    if ( AE_CONTEXT( ctx ) ) {
-      FREE( ctx->aelt_context );
+      free(ctx->aelt_context);
       ctx->aelt_context = NULL;
    }
 }
@@ -1474,44 +1471,44 @@ static void _ae_update_state( struct gl_context *ctx )
    actx->nr_vbos = 0;
 
    /* conventional vertex arrays */
-   if (arrayObj->Index.Enabled) {
-      aa->array = &arrayObj->Index;
+   if (arrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled) {
+      aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX];
       aa->offset = IndexFuncs[TYPE_IDX(aa->array->Type)];
       check_vbo(actx, aa->array->BufferObj);
       aa++;
    }
-   if (arrayObj->EdgeFlag.Enabled) {
-      aa->array = &arrayObj->EdgeFlag;
+   if (arrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled) {
+      aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG];
       aa->offset = _gloffset_EdgeFlagv;
       check_vbo(actx, aa->array->BufferObj);
       aa++;
    }
-   if (arrayObj->Normal.Enabled) {
-      aa->array = &arrayObj->Normal;
+   if (arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled) {
+      aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL];
       aa->offset = NormalFuncs[TYPE_IDX(aa->array->Type)];
       check_vbo(actx, aa->array->BufferObj);
       aa++;
    }
-   if (arrayObj->Color.Enabled) {
-      aa->array = &arrayObj->Color;
+   if (arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled) {
+      aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0];
       aa->offset = ColorFuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
       check_vbo(actx, aa->array->BufferObj);
       aa++;
    }
-   if (arrayObj->SecondaryColor.Enabled) {
-      aa->array = &arrayObj->SecondaryColor;
+   if (arrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled) {
+      aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR1];
       aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Type)];
       check_vbo(actx, aa->array->BufferObj);
       aa++;
    }
-   if (arrayObj->FogCoord.Enabled) {
-      aa->array = &arrayObj->FogCoord;
+   if (arrayObj->VertexAttrib[VERT_ATTRIB_FOG].Enabled) {
+      aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_FOG];
       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 = &arrayObj->TexCoord[i];
+      struct gl_client_array *attribArray = &arrayObj->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.
@@ -1528,34 +1525,27 @@ static void _ae_update_state( struct gl_context *ctx )
    }
 
    /* generic vertex attribute arrays */   
-   for (i = 1; i < Elements(arrayObj->VertexAttrib); i++) {  /* skip zero! */
-      struct gl_client_array *attribArray = &arrayObj->VertexAttrib[i];
+   for (i = 1; i < VERT_ATTRIB_GENERIC_MAX; i++) {  /* skip zero! */
+      struct gl_client_array *attribArray = &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(i)];
       if (attribArray->Enabled) {
+         GLint intOrNorm;
          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_ArrayElement() 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 {
-            GLint intOrNorm;
-            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)];
-         }
+         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->array->BufferObj);
          at++;
@@ -1563,24 +1553,24 @@ static void _ae_update_state( struct gl_context *ctx )
    }
 
    /* finally, vertex position */
-   if (arrayObj->VertexAttrib[0].Enabled) {
+   if (arrayObj->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 = &arrayObj->VertexAttrib[0];
+      aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC0];
       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 (arrayObj->Vertex.Enabled) {
-      aa->array = &arrayObj->Vertex;
+   else if (arrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled) {
+      aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_POS];
       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);
+   check_vbo(actx, arrayObj->ElementArrayBufferObj);
 
    ASSERT(at - actx->attribs <= VERT_ATTRIB_MAX);
    ASSERT(aa - actx->arrays < 32);
@@ -1643,12 +1633,20 @@ void GLAPIENTRY _ae_ArrayElement( GLint elt )
    const struct _glapi_table * const disp = GET_DISPATCH();
    GLboolean do_map;
 
+   /* If PrimitiveRestart is enabled and the index is the RestartIndex
+    * then we call PrimitiveRestartNV and return.
+    */
+   if (ctx->Array.PrimitiveRestart && (elt == ctx->Array.RestartIndex)) {
+      CALL_PrimitiveRestartNV((struct _glapi_table *)disp, ());
+      return;
+   }
+
    if (actx->NewState) {
       assert(!actx->mapped_vbos);
       _ae_update_state( ctx );
    }
 
-   /* Determine if w need to map/unmap VBOs */
+   /* Determine if we need to map/unmap VBOs */
    do_map = actx->nr_vbos && !actx->mapped_vbos;
 
    if (do_map)
@@ -1703,6 +1701,3 @@ void _mesa_install_arrayelt_vtxfmt(struct _glapi_table *disp,
 {
    SET_ArrayElement(disp, vfmt->ArrayElement);
 }
-
-
-#endif /* FEATURE_arrayelt */