mesa: add #define FEATURE_ARB_pixel_buffer_object
[mesa.git] / src / mesa / main / varray.c
index 52f8c8cef95b23a902dca4e2223db36c090c09e4..72b3e834b3a6ab3616c4b0aa198ef7609a7b78eb 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  7.2
  *
- * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
 #include "context.h"
 #include "enable.h"
 #include "enums.h"
-#include "dlist.h"
-#include "texstate.h"
 #include "mtypes.h"
 #include "varray.h"
-
-
-#ifndef GL_BOOLEAN
-#define GL_BOOLEAN 0x9999
-#endif
+#include "arrayobj.h"
+#include "glapi/dispatch.h"
 
 
 /**
- * Update the fields of a vertex array structure.
+ * Update the fields of a vertex array object.
  * We need to do a few special things for arrays that live in
  * vertex buffer objects.
+ *
+ * \param array  the array to update
+ * \param dirtyBit  which bit to set in ctx->Array.NewState for this array
+ * \param elementSize  size of each array element, in bytes
+ * \param size  components per element (1, 2, 3 or 4)
+ * \param type  datatype of each component (GL_FLOAT, GL_INT, etc)
+ * \param stride  stride between elements, in elements
+ * \param normalized  are integer types converted to floats in [-1, 1]?
+ * \param ptr  the address (or offset inside VBO) of the array data
  */
 static void
 update_array(GLcontext *ctx, struct gl_client_array *array,
-             GLuint dirtyFlag, GLsizei elementSize,
-             GLint size, GLenum type,
+             GLbitfield dirtyBit, GLsizei elementSize,
+             GLint size, GLenum type, GLenum format,
              GLsizei stride, GLboolean normalized, const GLvoid *ptr)
 {
+   ASSERT(format == GL_RGBA || format == GL_BGRA);
    array->Size = size;
    array->Type = type;
+   array->Format = format;
    array->Stride = stride;
    array->StrideB = stride ? stride : elementSize;
    array->Normalized = normalized;
    array->Ptr = (const GLubyte *) ptr;
 #if FEATURE_ARB_vertex_buffer_object
-   array->BufferObj->RefCount--;
-   if (array->BufferObj->RefCount <= 0) {
-      _mesa_remove_buffer_object( ctx, array->BufferObj );
-      (*ctx->Driver.DeleteBuffer)( ctx, array->BufferObj );
-   }
-   array->BufferObj = ctx->Array.ArrayBufferObj;
-   array->BufferObj->RefCount++;
+   _mesa_reference_buffer_object(ctx, &array->BufferObj,
+                                 ctx->Array.ArrayBufferObj);
+
    /* Compute the index of the last array element that's inside the buffer.
     * Later in glDrawArrays we'll check if start + count > _MaxElement to
     * be sure we won't go out of bounds.
     */
    if (ctx->Array.ArrayBufferObj->Name)
       array->_MaxElement = ((GLsizeiptrARB) ctx->Array.ArrayBufferObj->Size
-                            - (GLsizeiptrARB) array->Ptr) / array->StrideB;
+                            - (GLsizeiptrARB) array->Ptr + array->StrideB
+                            - elementSize) / array->StrideB;
    else
 #endif
       array->_MaxElement = 2 * 1000 * 1000 * 1000; /* just a big number */
 
    ctx->NewState |= _NEW_ARRAY;
-   ctx->Array.NewState |= dirtyFlag;
+   ctx->Array.NewState |= dirtyBit;
 }
 
 
@@ -115,13 +118,23 @@ _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
       case GL_DOUBLE:
          elementSize = size * sizeof(GLdouble);
          break;
+#if FEATURE_fixedpt
+      case GL_FIXED:
+         elementSize = size * sizeof(GLfixed);
+         break;
+#endif
+#if FEATURE_vertex_array_byte
+      case GL_BYTE:
+         elementSize = size * sizeof(GLbyte);
+         break;
+#endif
       default:
          _mesa_error( ctx, GL_INVALID_ENUM, "glVertexPointer(type)" );
          return;
    }
 
-   update_array(ctx, &ctx->Array.Vertex, _NEW_ARRAY_VERTEX,
-                elementSize, size, type, stride, GL_FALSE, ptr);
+   update_array(ctx, &ctx->Array.ArrayObj->Vertex, _NEW_ARRAY_VERTEX,
+                elementSize, size, type, GL_RGBA, stride, GL_FALSE, ptr);
 
    if (ctx->Driver.VertexPointer)
       ctx->Driver.VertexPointer( ctx, size, type, stride, ptr );
@@ -160,13 +173,18 @@ _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
       case GL_DOUBLE:
          elementSize = 3 * sizeof(GLdouble);
          break;
+#if FEATURE_fixedpt
+      case GL_FIXED:
+         elementSize = 3 * sizeof(GLfixed);
+         break;
+#endif
       default:
          _mesa_error( ctx, GL_INVALID_ENUM, "glNormalPointer(type)" );
          return;
    }
 
-   update_array(ctx, &ctx->Array.Normal, _NEW_ARRAY_NORMAL,
-                elementSize, 3, type, stride, GL_FALSE, ptr);
+   update_array(ctx, &ctx->Array.ArrayObj->Normal, _NEW_ARRAY_NORMAL,
+                elementSize, 3, type, GL_RGBA, stride, GL_TRUE, ptr);
 
    if (ctx->Driver.NormalPointer)
       ctx->Driver.NormalPointer( ctx, type, stride, ptr );
@@ -177,12 +195,15 @@ void GLAPIENTRY
 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
 {
    GLsizei elementSize;
+   GLenum format;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    if (size < 3 || size > 4) {
-      _mesa_error( ctx, GL_INVALID_VALUE, "glColorPointer(size)" );
-      return;
+      if (!ctx->Extensions.EXT_vertex_array_bgra || size != GL_BGRA) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glColorPointer(size)");
+         return;
+      }
    }
    if (stride < 0) {
       _mesa_error( ctx, GL_INVALID_VALUE, "glColorPointer(stride)" );
@@ -193,6 +214,18 @@ _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
       _mesa_debug(ctx, "glColorPointer( sz %d type %s stride %d )\n", size,
                   _mesa_lookup_enum_by_nr( type ), stride);
 
+   if (size == GL_BGRA) {
+      if (type != GL_UNSIGNED_BYTE) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glColorPointer(GL_BGRA/GLubyte)");
+         return;
+      }
+      format = GL_BGRA;
+      size = 4;
+   }
+   else {
+      format = GL_RGBA;
+   }
+
    switch (type) {
       case GL_BYTE:
          elementSize = size * sizeof(GLbyte);
@@ -218,13 +251,18 @@ _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
       case GL_DOUBLE:
          elementSize = size * sizeof(GLdouble);
          break;
+#if FEATURE_fixedpt
+      case GL_FIXED:
+         elementSize = size * sizeof(GLfixed);
+         break;
+#endif
       default:
          _mesa_error( ctx, GL_INVALID_ENUM, "glColorPointer(type)" );
          return;
    }
 
-   update_array(ctx, &ctx->Array.Color, _NEW_ARRAY_COLOR0,
-                elementSize, size, type, stride, GL_FALSE, ptr);
+   update_array(ctx, &ctx->Array.ArrayObj->Color, _NEW_ARRAY_COLOR0,
+                elementSize, size, type, format, stride, GL_TRUE, ptr);
 
    if (ctx->Driver.ColorPointer)
       ctx->Driver.ColorPointer( ctx, size, type, stride, ptr );
@@ -255,8 +293,8 @@ _mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr)
          return;
    }
 
-   update_array(ctx, &ctx->Array.FogCoord, _NEW_ARRAY_FOGCOORD,
-                elementSize, 1, type, stride, GL_FALSE, ptr);
+   update_array(ctx, &ctx->Array.ArrayObj->FogCoord, _NEW_ARRAY_FOGCOORD,
+                elementSize, 1, type, GL_RGBA, stride, GL_FALSE, ptr);
 
    if (ctx->Driver.FogCoordPointer)
       ctx->Driver.FogCoordPointer( ctx, type, stride, ptr );
@@ -296,8 +334,8 @@ _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
          return;
    }
 
-   update_array(ctx, &ctx->Array.Index, _NEW_ARRAY_INDEX,
-                elementSize, 1, type, stride, GL_FALSE, ptr);
+   update_array(ctx, &ctx->Array.ArrayObj->Index, _NEW_ARRAY_INDEX,
+                elementSize, 1, type, GL_RGBA, stride, GL_FALSE, ptr);
 
    if (ctx->Driver.IndexPointer)
       ctx->Driver.IndexPointer( ctx, type, stride, ptr );
@@ -309,12 +347,15 @@ _mesa_SecondaryColorPointerEXT(GLint size, GLenum type,
                               GLsizei stride, const GLvoid *ptr)
 {
    GLsizei elementSize;
+   GLenum format;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    if (size != 3 && size != 4) {
-      _mesa_error( ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(size)" );
-      return;
+      if (!ctx->Extensions.EXT_vertex_array_bgra || size != GL_BGRA) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(size)");
+         return;
+      }
    }
    if (stride < 0) {
       _mesa_error( ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(stride)" );
@@ -325,6 +366,18 @@ _mesa_SecondaryColorPointerEXT(GLint size, GLenum type,
       _mesa_debug(ctx, "glSecondaryColorPointer( sz %d type %s stride %d )\n",
                   size, _mesa_lookup_enum_by_nr( type ), stride);
 
+   if (size == GL_BGRA) {
+      if (type != GL_UNSIGNED_BYTE) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glColorPointer(GL_BGRA/GLubyte)");
+         return;
+      }
+      format = GL_BGRA;
+      size = 4;
+   }
+   else {
+      format = GL_RGBA;
+   }
+
    switch (type) {
       case GL_BYTE:
          elementSize = size * sizeof(GLbyte);
@@ -355,8 +408,8 @@ _mesa_SecondaryColorPointerEXT(GLint size, GLenum type,
          return;
    }
 
-   update_array(ctx, &ctx->Array.SecondaryColor, _NEW_ARRAY_COLOR1,
-                elementSize, size, type, stride, GL_FALSE, ptr);
+   update_array(ctx, &ctx->Array.ArrayObj->SecondaryColor, _NEW_ARRAY_COLOR1,
+                elementSize, size, type, format, stride, GL_TRUE, ptr);
 
    if (ctx->Driver.SecondaryColorPointer)
       ctx->Driver.SecondaryColorPointer( ctx, size, type, stride, ptr );
@@ -399,13 +452,24 @@ _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
       case GL_DOUBLE:
          elementSize = size * sizeof(GLdouble);
          break;
+#if FEATURE_fixedpt
+      case GL_FIXED:
+         elementSize = size * sizeof(GLfixed);
+         break;
+#endif
+#if FEATURE_vertex_array_byte
+      case GL_BYTE:
+         elementSize = size * sizeof(GLbyte);
+         break;
+#endif
       default:
          _mesa_error( ctx, GL_INVALID_ENUM, "glTexCoordPointer(type)" );
          return;
    }
 
-   update_array(ctx, &ctx->Array.TexCoord[unit], _NEW_ARRAY_TEXCOORD(unit),
-                elementSize, size, type, stride, GL_FALSE, ptr);
+   update_array(ctx, &ctx->Array.ArrayObj->TexCoord[unit],
+                _NEW_ARRAY_TEXCOORD(unit),
+                elementSize, size, type, GL_RGBA, stride, GL_FALSE, ptr);
 
    if (ctx->Driver.TexCoordPointer)
       ctx->Driver.TexCoordPointer( ctx, size, type, stride, ptr );
@@ -423,24 +487,57 @@ _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
       return;
    }
 
-   update_array(ctx, &ctx->Array.EdgeFlag, _NEW_ARRAY_EDGEFLAG,
-                sizeof(GLboolean), 1, GL_BOOLEAN, stride, GL_FALSE, ptr);
+   update_array(ctx, &ctx->Array.ArrayObj->EdgeFlag, _NEW_ARRAY_EDGEFLAG,
+                sizeof(GLboolean), 1, GL_UNSIGNED_BYTE, GL_RGBA,
+                stride, GL_FALSE, ptr);
 
    if (ctx->Driver.EdgeFlagPointer)
       ctx->Driver.EdgeFlagPointer( ctx, stride, ptr );
 }
 
 
+void GLAPIENTRY
+_mesa_PointSizePointer(GLenum type, GLsizei stride, const GLvoid *ptr)
+{
+   GLsizei elementSize;
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+   if (stride < 0) {
+      _mesa_error( ctx, GL_INVALID_VALUE, "glPointSizePointer(stride)" );
+      return;
+   }
+
+   switch (type) {
+      case GL_FLOAT:
+         elementSize = sizeof(GLfloat);
+         break;
+#if FEATURE_fixedpt
+      case GL_FIXED:
+         elementSize = sizeof(GLfixed);
+         break;
+#endif
+      default:
+         _mesa_error( ctx, GL_INVALID_ENUM, "glPointSizePointer(type)" );
+         return;
+   }
+
+   update_array(ctx, &ctx->Array.ArrayObj->PointSize, _NEW_ARRAY_POINT_SIZE,
+                elementSize, 1, type, GL_RGBA, stride, GL_FALSE, ptr);
+}
+
+
 #if FEATURE_NV_vertex_program
 void GLAPIENTRY
 _mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type,
                             GLsizei stride, const GLvoid *ptr)
 {
+   GLboolean normalized = GL_FALSE;
    GLsizei elementSize;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (index >= VERT_ATTRIB_MAX) {
+   if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(index)");
       return;
    }
@@ -463,6 +560,7 @@ _mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type,
    /* check for valid 'type' and compute StrideB right away */
    switch (type) {
       case GL_UNSIGNED_BYTE:
+         normalized = GL_TRUE;
          elementSize = size * sizeof(GLubyte);
          break;
       case GL_SHORT:
@@ -479,8 +577,9 @@ _mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type,
          return;
    }
 
-   update_array(ctx, &ctx->Array.VertexAttrib[index], _NEW_ARRAY_ATTRIB(index),
-                elementSize, size, type, stride, GL_FALSE, ptr);
+   update_array(ctx, &ctx->Array.ArrayObj->VertexAttrib[index],
+                _NEW_ARRAY_ATTRIB(index),
+                elementSize, size, type, GL_RGBA, stride, normalized, ptr);
 
    if (ctx->Driver.VertexAttribPointer)
       ctx->Driver.VertexAttribPointer( ctx, index, size, type, stride, ptr );
@@ -495,17 +594,20 @@ _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type,
                              GLsizei stride, const GLvoid *ptr)
 {
    GLsizei elementSize;
+   GLenum format;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (index >= ctx->Const.MaxVertexProgramAttribs) {
+   if (index >= ctx->Const.VertexProgram.MaxAttribs) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
       return;
    }
 
    if (size < 1 || size > 4) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(size)");
-      return;
+      if (!ctx->Extensions.EXT_vertex_array_bgra || size != GL_BGRA) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(size)");
+         return;
+      }
    }
 
    if (stride < 0) {
@@ -513,9 +615,18 @@ _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type,
       return;
    }
 
-   if (type == GL_UNSIGNED_BYTE && size != 4) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(size!=4)");
-      return;
+   if (size == GL_BGRA) {
+      if (type != GL_UNSIGNED_BYTE) {
+         _mesa_error(ctx, GL_INVALID_VALUE,
+                     "glVertexAttribPointerARB(GL_BGRA/type)");
+         return;
+      }
+      format = GL_BGRA;
+      size = 4;
+      normalized = GL_TRUE;
+   }
+   else {
+      format = GL_RGBA;
    }
 
    /* check for valid 'type' and compute StrideB right away */
@@ -545,18 +656,22 @@ _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type,
       case GL_DOUBLE:
          elementSize = size * sizeof(GLdouble);
          break;
+#if FEATURE_fixedpt
+      case GL_FIXED:
+         elementSize = size * sizeof(GLfixed);
+         break;
+#endif
       default:
          _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttribPointerARB(type)" );
          return;
    }
 
-   update_array(ctx, &ctx->Array.VertexAttrib[index], _NEW_ARRAY_ATTRIB(index),
-                elementSize, size, type, stride, normalized, ptr);
+   update_array(ctx, &ctx->Array.ArrayObj->VertexAttrib[index],
+                _NEW_ARRAY_ATTRIB(index),
+                elementSize, size, type, GL_RGBA, stride, normalized, ptr);
 
-   /* XXX fix
    if (ctx->Driver.VertexAttribPointer)
-      ctx->Driver.VertexAttribPointer( ctx, index, size, type, stride, ptr );
-   */
+      ctx->Driver.VertexAttribPointer(ctx, index, size, type, stride, ptr);
 }
 #endif
 
@@ -625,7 +740,6 @@ _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
    const GLint toffset = 0;        /* always zero */
    GLint defstride;                /* default stride */
    GLint c, f;
-   GLint coordUnitSave;
 
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
@@ -754,33 +868,17 @@ _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
 
    _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
    _mesa_DisableClientState( GL_INDEX_ARRAY );
+   /* XXX also disable secondary color and generic arrays? */
 
    /* Texcoords */
-   coordUnitSave = ctx->Array.ActiveTexture;
    if (tflag) {
-      GLuint i=0;
-      /* enable unit 0 texcoord array */
-      _mesa_ClientActiveTextureARB( GL_TEXTURE0_ARB );
       _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
       _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
-                             (GLubyte *) pointer + i * toffset );
-      /* disable all other texcoord arrays */
-      for (i = 1; i < ctx->Const.MaxTextureCoordUnits; i++) {
-         _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
-         _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
-      }
+                             (GLubyte *) pointer + toffset );
    }
    else {
-      /* disable all texcoord arrays */
-      GLuint i;
-      for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
-         _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
-         _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
-      }
+      _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
    }
-   /* Restore texture coordinate unit index */
-   _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + coordUnitSave) );
-
 
    /* Color */
    if (cflag) {
@@ -818,16 +916,22 @@ _mesa_LockArraysEXT(GLint first, GLsizei count)
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
 
-   if (first == 0 && count > 0 &&
-       count <= (GLint) ctx->Const.MaxArrayLockSize) {
-      ctx->Array.LockFirst = first;
-      ctx->Array.LockCount = count;
+   if (first < 0) {
+      _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
+      return;
    }
-   else {
-      ctx->Array.LockFirst = 0;
-      ctx->Array.LockCount = 0;
+   if (count <= 0) {
+      _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
+      return;
+   }
+   if (ctx->Array.LockCount != 0) {
+      _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
+      return;
    }
 
+   ctx->Array.LockFirst = first;
+   ctx->Array.LockCount = count;
+
    ctx->NewState |= _NEW_ARRAY;
    ctx->Array.NewState |= _NEW_ARRAY_ALL;
 
@@ -845,6 +949,11 @@ _mesa_UnlockArraysEXT( void )
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glUnlockArrays\n");
 
+   if (ctx->Array.LockCount == 0) {
+      _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
+      return;
+   }
+
    ctx->Array.LockFirst = 0;
    ctx->Array.LockCount = 0;
    ctx->NewState |= _NEW_ARRAY;
@@ -868,7 +977,7 @@ _mesa_MultiDrawArraysEXT( GLenum mode, GLint *first,
 
    for (i = 0; i < primcount; i++) {
       if (count[i] > 0) {
-         (ctx->Exec->DrawArrays)(mode, first[i], count[i]);
+         CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i]));
       }
    }
 }
@@ -886,7 +995,7 @@ _mesa_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type,
 
    for (i = 0; i < primcount; i++) {
       if (count[i] > 0) {
-         (ctx->Exec->DrawElements)(mode, count[i], type, indices[i]);
+         CALL_DrawElements(ctx->Exec, (mode, count[i], type, indices[i]));
       }
    }
 }
@@ -906,7 +1015,7 @@ _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
    for ( i = 0 ; i < primcount ; i++ ) {
       if ( count[i] > 0 ) {
          GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
-        (ctx->Exec->DrawArrays)( m, first[i], count[i] );
+        CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] ));
       }
    }
 }
@@ -928,84 +1037,20 @@ _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
    for ( i = 0 ; i < primcount ; i++ ) {
       if ( count[i] > 0 ) {
          GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
-        (ctx->Exec->DrawElements)( m, count[i], type, indices[i] );
+        CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] ));
       }
    }
 }
 
 
-/**********************************************************************/
-/*****                      Initialization                        *****/
-/**********************************************************************/
-
+/**
+ * Initialize vertex array state for given context.
+ */
 void 
-_mesa_init_varray( GLcontext * ctx )
+_mesa_init_varray(GLcontext *ctx)
 {
-   GLuint i;
-
-   /* Vertex arrays */
-   ctx->Array.Vertex.Size = 4;
-   ctx->Array.Vertex.Type = GL_FLOAT;
-   ctx->Array.Vertex.Stride = 0;
-   ctx->Array.Vertex.StrideB = 0;
-   ctx->Array.Vertex.Ptr = NULL;
-   ctx->Array.Vertex.Enabled = GL_FALSE;
-   ctx->Array.Vertex.Flags = CA_CLIENT_DATA;
-   ctx->Array.Normal.Type = GL_FLOAT;
-   ctx->Array.Normal.Stride = 0;
-   ctx->Array.Normal.StrideB = 0;
-   ctx->Array.Normal.Ptr = NULL;
-   ctx->Array.Normal.Enabled = GL_FALSE;
-   ctx->Array.Normal.Flags = CA_CLIENT_DATA;
-   ctx->Array.Color.Size = 4;
-   ctx->Array.Color.Type = GL_FLOAT;
-   ctx->Array.Color.Stride = 0;
-   ctx->Array.Color.StrideB = 0;
-   ctx->Array.Color.Ptr = NULL;
-   ctx->Array.Color.Enabled = GL_FALSE;
-   ctx->Array.Color.Flags = CA_CLIENT_DATA;
-   ctx->Array.SecondaryColor.Size = 4;
-   ctx->Array.SecondaryColor.Type = GL_FLOAT;
-   ctx->Array.SecondaryColor.Stride = 0;
-   ctx->Array.SecondaryColor.StrideB = 0;
-   ctx->Array.SecondaryColor.Ptr = NULL;
-   ctx->Array.SecondaryColor.Enabled = GL_FALSE;
-   ctx->Array.SecondaryColor.Flags = CA_CLIENT_DATA;
-   ctx->Array.FogCoord.Size = 1;
-   ctx->Array.FogCoord.Type = GL_FLOAT;
-   ctx->Array.FogCoord.Stride = 0;
-   ctx->Array.FogCoord.StrideB = 0;
-   ctx->Array.FogCoord.Ptr = NULL;
-   ctx->Array.FogCoord.Enabled = GL_FALSE;
-   ctx->Array.FogCoord.Flags = CA_CLIENT_DATA;
-   ctx->Array.Index.Type = GL_FLOAT;
-   ctx->Array.Index.Stride = 0;
-   ctx->Array.Index.StrideB = 0;
-   ctx->Array.Index.Ptr = NULL;
-   ctx->Array.Index.Enabled = GL_FALSE;
-   ctx->Array.Index.Flags = CA_CLIENT_DATA;
-   for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
-      ctx->Array.TexCoord[i].Size = 4;
-      ctx->Array.TexCoord[i].Type = GL_FLOAT;
-      ctx->Array.TexCoord[i].Stride = 0;
-      ctx->Array.TexCoord[i].StrideB = 0;
-      ctx->Array.TexCoord[i].Ptr = NULL;
-      ctx->Array.TexCoord[i].Enabled = GL_FALSE;
-      ctx->Array.TexCoord[i].Flags = CA_CLIENT_DATA;
-   }
-   ctx->Array.EdgeFlag.Stride = 0;
-   ctx->Array.EdgeFlag.StrideB = 0;
-   ctx->Array.EdgeFlag.Ptr = NULL;
-   ctx->Array.EdgeFlag.Enabled = GL_FALSE;
-   ctx->Array.EdgeFlag.Flags = CA_CLIENT_DATA;
+   ctx->Array.DefaultArrayObj = _mesa_new_array_object(ctx, 0);
+   _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj,
+                                ctx->Array.DefaultArrayObj);
    ctx->Array.ActiveTexture = 0;   /* GL_ARB_multitexture */
-   for (i = 0; i < VERT_ATTRIB_MAX; i++) {
-      ctx->Array.VertexAttrib[i].Size = 4;
-      ctx->Array.VertexAttrib[i].Type = GL_FLOAT;
-      ctx->Array.VertexAttrib[i].Stride = 0;
-      ctx->Array.VertexAttrib[i].StrideB = 0;
-      ctx->Array.VertexAttrib[i].Ptr = NULL;
-      ctx->Array.VertexAttrib[i].Enabled = GL_FALSE;
-      ctx->Array.VertexAttrib[i].Flags = CA_CLIENT_DATA;
-   }
 }