mesa: Add a vao parameter to get_vertex_array_attrib
[mesa.git] / src / mesa / main / varray.c
index 7d169f9d49b6085a162041bdbf23a30e6619cb87..7f14ffb297096d9811e7b42c8b578c3c478213da 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 
+#include <stdio.h>
 #include <inttypes.h>  /* for PRId64 macro */
 
 #include "glheader.h"
 #define UNSIGNED_INT_10F_11F_11F_REV_BIT  (1 << 14)
 #define ALL_TYPE_BITS                    ((1 << 15) - 1)
 
+#define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
+                                  SHORT_BIT | UNSIGNED_SHORT_BIT | \
+                                  INT_BIT | UNSIGNED_INT_BIT | \
+                                  HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
+                                  FIXED_GL_BIT | \
+                                  UNSIGNED_INT_2_10_10_10_REV_BIT | \
+                                  INT_2_10_10_10_REV_BIT | \
+                                  UNSIGNED_INT_10F_11F_11F_REV_BIT)
+
+#define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
+                                   SHORT_BIT | UNSIGNED_SHORT_BIT | \
+                                   INT_BIT | UNSIGNED_INT_BIT)
+
+#define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
+
 
 /** Convert GL datatype enum into a <type>_BIT value seen above */
 static GLbitfield
@@ -112,10 +128,11 @@ type_to_bit(const struct gl_context *ctx, GLenum type)
  * Sets the VertexBinding field in the vertex attribute given by attribIndex.
  */
 static void
-vertex_attrib_binding(struct gl_context *ctx, GLuint attribIndex,
+vertex_attrib_binding(struct gl_context *ctx,
+                      struct gl_vertex_array_object *vao,
+                      GLuint attribIndex,
                       GLuint bindingIndex)
 {
-   struct gl_vertex_array_object *vao = ctx->Array.VAO;
    struct gl_vertex_attrib_array *array = &vao->VertexAttrib[attribIndex];
 
    if (array->VertexBinding != bindingIndex) {
@@ -138,11 +155,12 @@ vertex_attrib_binding(struct gl_context *ctx, GLuint attribIndex,
  * and sets the Offset and Stride fields.
  */
 static void
-bind_vertex_buffer(struct gl_context *ctx, GLuint index,
+bind_vertex_buffer(struct gl_context *ctx,
+                   struct gl_vertex_array_object *vao,
+                   GLuint index,
                    struct gl_buffer_object *vbo,
                    GLintptr offset, GLsizei stride)
 {
-   struct gl_vertex_array_object *vao = ctx->Array.VAO;
    struct gl_vertex_buffer_binding *binding = &vao->VertexBinding[index];
 
    if (binding->BufferObj != vbo ||
@@ -166,10 +184,11 @@ bind_vertex_buffer(struct gl_context *ctx, GLuint index,
  * given by bindingIndex.
  */
 static void
-vertex_binding_divisor(struct gl_context *ctx, GLuint bindingIndex,
+vertex_binding_divisor(struct gl_context *ctx,
+                       struct gl_vertex_array_object *vao,
+                       GLuint bindingIndex,
                        GLuint divisor)
 {
-   struct gl_vertex_array_object *vao = ctx->Array.VAO;
    struct gl_vertex_buffer_binding *binding =
       &vao->VertexBinding[bindingIndex];
 
@@ -242,27 +261,32 @@ get_legal_types_mask(const struct gl_context *ctx)
  * \param type         Datatype of each component (GL_FLOAT, GL_INT, etc)
  * \param normalized   Whether integer types are converted to floats in [-1, 1]
  * \param integer      Integer-valued values (will not be normalized to [-1, 1])
+ * \param doubles      Double values not reduced to floats
  * \param relativeOffset Offset of the first element relative to the binding offset.
  */
 static bool
 update_array_format(struct gl_context *ctx,
                     const char *func,
+                    struct gl_vertex_array_object *vao,
                     GLuint attrib, GLbitfield legalTypesMask,
                     GLint sizeMin, GLint sizeMax,
                     GLint size, GLenum type,
-                    GLboolean normalized, GLboolean integer,
+                    GLboolean normalized, GLboolean integer, GLboolean doubles,
                     GLuint relativeOffset)
 {
    struct gl_vertex_attrib_array *array;
    GLbitfield typeBit;
-   GLuint elementSize;
+   GLint elementSize;
    GLenum format = GL_RGBA;
 
-   if (ctx->Array.LegalTypesMask == 0) {
-      /* One-time initialization.  We can't do this in _mesa_init_varrays()
-       * below because extensions are not yet enabled at that point.
+   if (ctx->Array.LegalTypesMask == 0 || ctx->Array.LegalTypesMaskAPI != ctx->API) {
+      /* Compute the LegalTypesMask only once, unless the context API has
+       * changed, in which case we want to compute it again.  We can't do this
+       * in _mesa_init_varrays() below because extensions are not yet enabled
+       * at that point.
        */
       ctx->Array.LegalTypesMask = get_legal_types_mask(ctx);
+      ctx->Array.LegalTypesMaskAPI = ctx->API;
    }
 
    legalTypesMask &= ctx->Array.LegalTypesMask;
@@ -353,21 +377,22 @@ update_array_format(struct gl_context *ctx,
       return false;
    }
 
-   ASSERT(size <= 4);
+   assert(size <= 4);
 
    elementSize = _mesa_bytes_per_vertex_attrib(size, type);
    assert(elementSize != -1);
 
-   array = &ctx->Array.VAO->VertexAttrib[attrib];
+   array = &vao->VertexAttrib[attrib];
    array->Size = size;
    array->Type = type;
    array->Format = format;
    array->Normalized = normalized;
    array->Integer = integer;
+   array->Doubles = doubles;
    array->RelativeOffset = relativeOffset;
    array->_ElementSize = elementSize;
 
-   ctx->Array.VAO->NewArrays |= VERT_BIT(attrib);
+   vao->NewArrays |= VERT_BIT(attrib);
    ctx->NewState |= _NEW_ARRAY;
 
    return true;
@@ -388,6 +413,7 @@ update_array_format(struct gl_context *ctx,
  * \param stride  stride between elements, in elements
  * \param normalized  are integer types converted to floats in [-1, 1]?
  * \param integer  integer-valued values (will not be normalized to [-1,1])
+ * \param doubles  Double values not reduced to floats
  * \param ptr  the address (or offset inside VBO) of the array data
  */
 static void
@@ -396,7 +422,7 @@ update_array(struct gl_context *ctx,
              GLuint attrib, GLbitfield legalTypesMask,
              GLint sizeMin, GLint sizeMax,
              GLint size, GLenum type, GLsizei stride,
-             GLboolean normalized, GLboolean integer,
+             GLboolean normalized, GLboolean integer, GLboolean doubles,
              const GLvoid *ptr)
 {
    struct gl_vertex_attrib_array *array;
@@ -449,13 +475,14 @@ update_array(struct gl_context *ctx,
       return;
    }
 
-   if (!update_array_format(ctx, func, attrib, legalTypesMask, sizeMin,
-                            sizeMax, size, type, normalized, integer, 0)) {
+   if (!update_array_format(ctx, func, ctx->Array.VAO, attrib,
+                            legalTypesMask, sizeMin, sizeMax,
+                            size, type, normalized, integer, doubles, 0)) {
       return;
    }
 
    /* Reset the vertex attrib binding */
-   vertex_attrib_binding(ctx, attrib, attrib);
+   vertex_attrib_binding(ctx, ctx->Array.VAO, attrib, attrib);
 
    /* The Stride and Ptr fields are not set by update_array_format() */
    array = &ctx->Array.VAO->VertexAttrib[attrib];
@@ -464,7 +491,7 @@ update_array(struct gl_context *ctx,
 
    /* Update the vertex buffer binding */
    effectiveStride = stride != 0 ? stride : array->_ElementSize;
-   bind_vertex_buffer(ctx, attrib, ctx->Array.ArrayBufferObj,
+   bind_vertex_buffer(ctx, ctx->Array.VAO, attrib, ctx->Array.ArrayBufferObj,
                       (GLintptr) ptr, effectiveStride);
 }
 
@@ -484,7 +511,7 @@ _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
 
    update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS,
                 legalTypes, 2, 4,
-                size, type, stride, GL_FALSE, GL_FALSE, ptr);
+                size, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
 }
 
 
@@ -503,7 +530,7 @@ _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
 
    update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL,
                 legalTypes, 3, 3,
-                3, type, stride, GL_TRUE, GL_FALSE, ptr);
+                3, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
 }
 
 
@@ -525,7 +552,7 @@ _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
 
    update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR0,
                 legalTypes, sizeMin, BGRA_OR_4,
-                size, type, stride, GL_TRUE, GL_FALSE, ptr);
+                size, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
 }
 
 
@@ -539,7 +566,7 @@ _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
 
    update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG,
                 legalTypes, 1, 1,
-                1, type, stride, GL_FALSE, GL_FALSE, ptr);
+                1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
 }
 
 
@@ -554,7 +581,7 @@ _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
 
    update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX,
                 legalTypes, 1, 1,
-                1, type, stride, GL_FALSE, GL_FALSE, ptr);
+                1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
 }
 
 
@@ -574,7 +601,7 @@ _mesa_SecondaryColorPointer(GLint size, GLenum type,
 
    update_array(ctx, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1,
                 legalTypes, 3, BGRA_OR_4,
-                size, type, stride, GL_TRUE, GL_FALSE, ptr);
+                size, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
 }
 
 
@@ -596,7 +623,7 @@ _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
 
    update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX(unit),
                 legalTypes, sizeMin, 4,
-                size, type, stride, GL_FALSE, GL_FALSE,
+                size, type, stride, GL_FALSE, GL_FALSE, GL_FALSE,
                 ptr);
 }
 
@@ -613,7 +640,7 @@ _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
 
    update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG,
                 legalTypes, 1, 1,
-                1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr);
+                1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, GL_FALSE, ptr);
 }
 
 
@@ -633,7 +660,7 @@ _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr)
       
    update_array(ctx, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE,
                 legalTypes, 1, 1,
-                1, type, stride, GL_FALSE, GL_FALSE, ptr);
+                1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
 }
 
 
@@ -664,7 +691,7 @@ _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
 
    update_array(ctx, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index),
                 legalTypes, 1, BGRA_OR_4,
-                size, type, stride, normalized, GL_FALSE, ptr);
+                size, type, stride, normalized, GL_FALSE, GL_FALSE, ptr);
 }
 
 
@@ -692,26 +719,38 @@ _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
 
    update_array(ctx, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index),
                 legalTypes, 1, 4,
-                size, type, stride, normalized, integer, ptr);
+                size, type, stride, normalized, integer, GL_FALSE, ptr);
 }
 
-
-
 void GLAPIENTRY
-_mesa_EnableVertexAttribArray(GLuint index)
+_mesa_VertexAttribLPointer(GLuint index, GLint size, GLenum type,
+                           GLsizei stride, const GLvoid *ptr)
 {
-   struct gl_vertex_array_object *vao;
    GET_CURRENT_CONTEXT(ctx);
-
+   const GLbitfield legalTypes = (DOUBLE_BIT);
    if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
-      _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glEnableVertexAttribArrayARB(index)");
+      _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribLPointer(index)");
       return;
    }
 
-   vao = ctx->Array.VAO;
+   update_array(ctx, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index),
+                legalTypes, 1, 4,
+                size, type, stride, GL_TRUE, GL_FALSE, GL_TRUE, ptr);
+}
 
-   ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(vao->_VertexAttrib));
+
+static void
+enable_vertex_array_attrib(struct gl_context *ctx,
+                           struct gl_vertex_array_object *vao,
+                           GLuint index,
+                           const char *func)
+{
+   if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
+      return;
+   }
+
+   assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
 
    if (!vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
       /* was disabled, now being enabled */
@@ -724,20 +763,47 @@ _mesa_EnableVertexAttribArray(GLuint index)
 
 
 void GLAPIENTRY
-_mesa_DisableVertexAttribArray(GLuint index)
+_mesa_EnableVertexAttribArray(GLuint index)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   enable_vertex_array_attrib(ctx, ctx->Array.VAO, index,
+                              "glEnableVertexAttribArray");
+}
+
+
+void GLAPIENTRY
+_mesa_EnableVertexArrayAttrib(GLuint vaobj, GLuint index)
 {
-   struct gl_vertex_array_object *vao;
    GET_CURRENT_CONTEXT(ctx);
+   struct gl_vertex_array_object *vao;
+
+   /* The ARB_direct_state_access specification says:
+    *
+    *   "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
+    *    and DisableVertexArrayAttrib if <vaobj> is not
+    *    [compatibility profile: zero or] the name of an existing vertex
+    *    array object."
+    */
+   vao = _mesa_lookup_vao_err(ctx, vaobj, "glEnableVertexArrayAttrib");
+   if (!vao)
+      return;
 
+   enable_vertex_array_attrib(ctx, vao, index, "glEnableVertexArrayAttrib");
+}
+
+
+static void
+disable_vertex_array_attrib(struct gl_context *ctx,
+                            struct gl_vertex_array_object *vao,
+                            GLuint index,
+                            const char *func)
+{
    if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
-      _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glDisableVertexAttribArrayARB(index)");
+      _mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
       return;
    }
 
-   vao = ctx->Array.VAO;
-
-   ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(vao->_VertexAttrib));
+   assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
 
    if (vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
       /* was enabled, now being disabled */
@@ -749,16 +815,47 @@ _mesa_DisableVertexAttribArray(GLuint index)
 }
 
 
+void GLAPIENTRY
+_mesa_DisableVertexAttribArray(GLuint index)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   disable_vertex_array_attrib(ctx, ctx->Array.VAO, index,
+                               "glDisableVertexAttribArray");
+}
+
+
+void GLAPIENTRY
+_mesa_DisableVertexArrayAttrib(GLuint vaobj, GLuint index)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_vertex_array_object *vao;
+
+   /* The ARB_direct_state_access specification says:
+    *
+    *   "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
+    *    and DisableVertexArrayAttrib if <vaobj> is not
+    *    [compatibility profile: zero or] the name of an existing vertex
+    *    array object."
+    */
+   vao = _mesa_lookup_vao_err(ctx, vaobj, "glDisableVertexArrayAttrib");
+   if (!vao)
+      return;
+
+   disable_vertex_array_attrib(ctx, vao, index, "glDisableVertexArrayAttrib");
+}
+
+
 /**
  * Return info for a vertex attribute array (no alias with legacy
  * vertex attributes (pos, normal, color, etc)).  This function does
  * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
  */
 static GLuint
-get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname,
-                  const char *caller)
+get_vertex_array_attrib(struct gl_context *ctx,
+                        const struct gl_vertex_array_object *vao,
+                        GLuint index, GLenum pname,
+                        const char *caller)
 {
-   const struct gl_vertex_array_object *vao = ctx->Array.VAO;
    const struct gl_vertex_attrib_array *array;
 
    if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
@@ -766,7 +863,7 @@ get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname,
       return 0;
    }
 
-   ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(vao->VertexAttrib));
+   assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
 
    array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
 
@@ -831,7 +928,7 @@ get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
       return NULL;
    }
 
-   ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.VAO->_VertexAttrib));
+   assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
 
    FLUSH_CURRENT(ctx, 0);
    return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
@@ -849,7 +946,8 @@ _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
       }
    }
    else {
-      params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname,
+      params[0] = (GLfloat) get_vertex_array_attrib(ctx, ctx->Array.VAO,
+                                                    index, pname,
                                                     "glGetVertexAttribfv");
    }
 }
@@ -870,11 +968,32 @@ _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
       }
    }
    else {
-      params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname,
+      params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
+                                                     index, pname,
                                                      "glGetVertexAttribdv");
    }
 }
 
+void GLAPIENTRY
+_mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
+      const GLdouble *v = (const GLdouble *)get_current_attrib(ctx, index, "glGetVertexAttribLdv");
+      if (v != NULL) {
+         params[0] = v[0];
+         params[1] = v[1];
+         params[2] = v[2];
+         params[3] = v[3];
+      }
+   }
+   else {
+      params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
+                                                     index, pname,
+                                                     "glGetVertexAttribLdv");
+   }
+}
 
 void GLAPIENTRY
 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
@@ -892,7 +1011,8 @@ _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
       }
    }
    else {
-      params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
+      params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
+                                                  index, pname,
                                                   "glGetVertexAttribiv");
    }
 }
@@ -912,7 +1032,8 @@ _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
       }
    }
    else {
-      params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
+      params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
+                                                  index, pname,
                                                   "glGetVertexAttribIiv");
    }
 }
@@ -932,7 +1053,8 @@ _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
       }
    }
    else {
-      params[0] = get_vertex_array_attrib(ctx, index, pname,
+      params[0] = get_vertex_array_attrib(ctx, ctx->Array.VAO,
+                                          index, pname,
                                           "glGetVertexAttribIuiv");
    }
 }
@@ -953,7 +1075,7 @@ _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
       return;
    }
 
-   ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.VAO->_VertexAttrib));
+   assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
 
    *pointer = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
 }
@@ -1333,6 +1455,7 @@ _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
    GET_CURRENT_CONTEXT(ctx);
 
    const GLuint genericIndex = VERT_ATTRIB_GENERIC(index);
+   struct gl_vertex_array_object * const vao = ctx->Array.VAO;
 
    if (!ctx->Extensions.ARB_instanced_arrays) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
@@ -1345,7 +1468,7 @@ _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
       return;
    }
 
-   ASSERT(genericIndex < Elements(ctx->Array.VAO->VertexAttrib));
+   assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
 
    /* The ARB_vertex_attrib_binding spec says:
     *
@@ -1358,8 +1481,8 @@ _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
     *       VertexAttribBinding(index, index);
     *       VertexBindingDivisor(index, divisor);"
     */
-   vertex_attrib_binding(ctx, genericIndex, genericIndex);
-   vertex_binding_divisor(ctx, genericIndex, divisor);
+   vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
+   vertex_binding_divisor(ctx, vao, genericIndex, divisor);
 }
 
 
@@ -1391,28 +1514,15 @@ _mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type)
 /**
  * GL_ARB_vertex_attrib_binding
  */
-void GLAPIENTRY
-_mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
-                       GLsizei stride)
+static void
+vertex_array_vertex_buffer(struct gl_context *ctx, struct gl_vertex_array_object *vao,
+                           GLuint bindingIndex, GLuint buffer, GLintptr offset,
+                           GLsizei stride, const char *func)
 {
-   GET_CURRENT_CONTEXT(ctx);
-   const struct gl_vertex_array_object *vao = ctx->Array.VAO;
    struct gl_buffer_object *vbo;
 
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   /* The ARB_vertex_attrib_binding spec says:
-    *
-    *    "An INVALID_OPERATION error is generated if no vertex array object
-    *     is bound."
-    */
-   if (ctx->API == API_OPENGL_CORE &&
-       ctx->Array.VAO == ctx->Array.DefaultVAO) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glBindVertexBuffer(No array object bound)");
-      return;
-   }
-
    /* The ARB_vertex_attrib_binding spec says:
     *
     *    "An INVALID_VALUE error is generated if <bindingindex> is greater than
@@ -1420,9 +1530,9 @@ _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
     */
    if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glBindVertexBuffer(bindingindex=%u > "
+                  "%s(bindingindex=%u > "
                   "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
-                  bindingIndex);
+                  func, bindingIndex);
       return;
    }
 
@@ -1433,21 +1543,21 @@ _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
     */
    if (offset < 0) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glBindVertexBuffer(offset=%" PRId64 " < 0)",
-                  (int64_t) offset);
+                  "%s(offset=%" PRId64 " < 0)",
+                  func, (int64_t) offset);
       return;
    }
 
    if (stride < 0) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glBindVertexBuffer(stride=%d < 0)", stride);
+                  "%s(stride=%d < 0)", func, stride);
       return;
    }
 
    if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
        stride > ctx->Const.MaxVertexAttribStride) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glBindVertexBuffer(stride=%d > "
-                  "GL_MAX_VERTEX_ATTRIB_STRIDE)", stride);
+      _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
+                  "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
       return;
    }
 
@@ -1467,7 +1577,7 @@ _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
        * object references (automatically gen it).
        */
       if (!_mesa_handle_bind_buffer_gen(ctx, GL_ARRAY_BUFFER, buffer,
-                                        &vbo, "glBindVertexBuffer"))
+                                        &vbo, func))
          return;
    } else {
       /* The ARB_vertex_attrib_binding spec says:
@@ -1478,33 +1588,68 @@ _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
       vbo = ctx->Shared->NullBufferObj;
    }
 
-   bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(bindingIndex),
+   bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex),
                       vbo, offset, stride);
 }
 
 
 void GLAPIENTRY
-_mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
-                        const GLintptr *offsets, const GLsizei *strides)
+_mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
+                       GLsizei stride)
 {
    GET_CURRENT_CONTEXT(ctx);
-   struct gl_vertex_array_object * const vao = ctx->Array.VAO;
-   GLuint i;
-
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    /* The ARB_vertex_attrib_binding spec says:
     *
-    *    "An INVALID_OPERATION error is generated if no
-    *     vertex array object is bound."
+    *    "An INVALID_OPERATION error is generated if no vertex array object
+    *     is bound."
     */
    if (ctx->API == API_OPENGL_CORE &&
        ctx->Array.VAO == ctx->Array.DefaultVAO) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glBindVertexBuffers(No array object bound)");
+                  "glBindVertexBuffer(No array object bound)");
       return;
    }
 
+   vertex_array_vertex_buffer(ctx, ctx->Array.VAO, bindingIndex,
+                              buffer, offset, stride, "glBindVertexBuffer");
+}
+
+
+void GLAPIENTRY
+_mesa_VertexArrayVertexBuffer(GLuint vaobj, GLuint bindingIndex, GLuint buffer,
+                              GLintptr offset, GLsizei stride)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_vertex_array_object *vao;
+
+   /* The ARB_direct_state_access specification says:
+    *
+    *   "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
+    *    if <vaobj> is not [compatibility profile: zero or] the name of an
+    *    existing vertex array object."
+    */
+   vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffer");
+   if (!vao)
+      return;
+
+   vertex_array_vertex_buffer(ctx, vao, bindingIndex,
+                              buffer, offset, stride,
+                              "glVertexArrayVertexBuffer");
+}
+
+
+static void
+vertex_array_vertex_buffers(struct gl_context *ctx,
+                            struct gl_vertex_array_object *vao,
+                            GLuint first, GLsizei count, const GLuint *buffers,
+                            const GLintptr *offsets, const GLsizei *strides,
+                            const char *func)
+{
+   GLuint i;
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
    /* The ARB_multi_bind spec says:
     *
     *    "An INVALID_OPERATION error is generated if <first> + <count>
@@ -1512,9 +1657,9 @@ _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
     */
    if (first + count > ctx->Const.MaxVertexAttribBindings) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glBindVertexBuffers(first=%u + count=%d > the value of "
+                  "%s(first=%u + count=%d > the value of "
                   "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
-                  first, count, ctx->Const.MaxVertexAttribBindings);
+                  func, first, count, ctx->Const.MaxVertexAttribBindings);
       return;
    }
 
@@ -1531,7 +1676,8 @@ _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
       struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj;
 
       for (i = 0; i < count; i++)
-         bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(first + i), vbo, 0, 16);
+         bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
+                            vbo, 0, 16);
 
       return;
    }
@@ -1567,23 +1713,23 @@ _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
        */
       if (offsets[i] < 0) {
          _mesa_error(ctx, GL_INVALID_VALUE,
-                     "glBindVertexBuffers(offsets[%u]=%" PRId64 " < 0)",
-                     i, (int64_t) offsets[i]);
+                     "%s(offsets[%u]=%" PRId64 " < 0)",
+                     func, i, (int64_t) offsets[i]);
          continue;
       }
 
       if (strides[i] < 0) {
          _mesa_error(ctx, GL_INVALID_VALUE,
-                     "glBindVertexBuffers(strides[%u]=%d < 0)",
-                     i, strides[i]);
+                     "%s(strides[%u]=%d < 0)",
+                     func, i, strides[i]);
          continue;
       }
 
       if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
           strides[i] > ctx->Const.MaxVertexAttribStride) {
          _mesa_error(ctx, GL_INVALID_VALUE,
-                     "glBindVertexBuffers(strides[%u]=%d > "
-                     "GL_MAX_VERTEX_ATTRIB_STRIDE)", i, strides[i]);
+                     "%s(strides[%u]=%d > "
+                     "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, i, strides[i]);
          continue;
       }
 
@@ -1594,8 +1740,7 @@ _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
          if (buffers[i] == binding->BufferObj->Name)
             vbo = binding->BufferObj;
          else
-            vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i,
-                                                    "glBindVertexBuffers");
+            vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, func);
 
          if (!vbo)
             continue;
@@ -1603,8 +1748,8 @@ _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
          vbo = ctx->Shared->NullBufferObj;
       }
 
-      bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(first + i), vbo,
-                         offsets[i], strides[i]);
+      bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
+                         vbo, offsets[i], strides[i]);
    }
 
    _mesa_end_bufferobj_lookups(ctx);
@@ -1612,65 +1757,60 @@ _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
 
 
 void GLAPIENTRY
-_mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
-                         GLboolean normalized, GLuint relativeOffset)
+_mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
+                        const GLintptr *offsets, const GLsizei *strides)
 {
-    const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
-                                   SHORT_BIT | UNSIGNED_SHORT_BIT |
-                                   INT_BIT | UNSIGNED_INT_BIT |
-                                   HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
-                                   FIXED_GL_BIT |
-                                   UNSIGNED_INT_2_10_10_10_REV_BIT |
-                                   INT_2_10_10_10_REV_BIT |
-                                   UNSIGNED_INT_10F_11F_11F_REV_BIT);
-
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    /* The ARB_vertex_attrib_binding spec says:
     *
-    *    "An INVALID_OPERATION error is generated under any of the following
-    *     conditions:
-    *     - if no vertex array object is currently bound (see section 2.10);
-    *     - ..."
+    *    "An INVALID_OPERATION error is generated if no
+    *     vertex array object is bound."
     */
    if (ctx->API == API_OPENGL_CORE &&
        ctx->Array.VAO == ctx->Array.DefaultVAO) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glVertexAttribFormat(No array object bound)");
+                  "glBindVertexBuffers(No array object bound)");
       return;
    }
 
-   /* The ARB_vertex_attrib_binding spec says:
+   vertex_array_vertex_buffers(ctx, ctx->Array.VAO, first, count,
+                               buffers, offsets, strides,
+                               "glBindVertexBuffers");
+}
+
+
+void GLAPIENTRY
+_mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count,
+                               const GLuint *buffers,
+                               const GLintptr *offsets, const GLsizei *strides)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_vertex_array_object *vao;
+
+   /* The ARB_direct_state_access specification says:
     *
-    *   "The error INVALID_VALUE is generated if index is greater than or equal
-    *     to the value of MAX_VERTEX_ATTRIBS."
+    *   "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
+    *    if <vaobj> is not [compatibility profile: zero or] the name of an
+    *    existing vertex array object."
     */
-   if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
-      _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glVertexAttribFormat(attribindex=%u > "
-                  "GL_MAX_VERTEX_ATTRIBS)",
-                  attribIndex);
+   vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffers");
+   if (!vao)
       return;
-   }
 
-   FLUSH_VERTICES(ctx, 0);
-
-   update_array_format(ctx, "glVertexAttribFormat",
-                       VERT_ATTRIB_GENERIC(attribIndex),
-                       legalTypes, 1, BGRA_OR_4, size, type, normalized,
-                       GL_FALSE, relativeOffset);
+   vertex_array_vertex_buffers(ctx, vao, first, count,
+                               buffers, offsets, strides,
+                               "glVertexArrayVertexBuffers");
 }
 
 
-void GLAPIENTRY
-_mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
-                          GLuint relativeOffset)
+static void
+vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type,
+                     GLboolean normalized, GLboolean integer,
+                     GLboolean doubles, GLbitfield legalTypes,
+                     GLsizei maxSize, GLuint relativeOffset,
+                     const char *func)
 {
-   const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
-                                  SHORT_BIT | UNSIGNED_SHORT_BIT |
-                                  INT_BIT | UNSIGNED_INT_BIT);
-
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
@@ -1680,33 +1820,59 @@ _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
     *     conditions:
     *     - if no vertex array object is currently bound (see section 2.10);
     *     - ..."
+    *
+    * This error condition only applies to VertexAttribFormat and
+    * VertexAttribIFormat in the extension spec, but we assume that this
+    * is an oversight.  In the OpenGL 4.3 (Core Profile) spec, it applies
+    * to all three functions.
     */
    if (ctx->API == API_OPENGL_CORE &&
        ctx->Array.VAO == ctx->Array.DefaultVAO) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glVertexAttribIFormat(No array object bound)");
+                  "%s(No array object bound)", func);
       return;
    }
 
    /* The ARB_vertex_attrib_binding spec says:
     *
-    *   "The error INVALID_VALUE is generated if index is greater than
-    *    or equal to the value of MAX_VERTEX_ATTRIBS."
+    *   "The error INVALID_VALUE is generated if index is greater than or equal
+    *     to the value of MAX_VERTEX_ATTRIBS."
     */
    if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glVertexAttribIFormat(attribindex=%u > "
+                  "%s(attribindex=%u > "
                   "GL_MAX_VERTEX_ATTRIBS)",
-                  attribIndex);
+                  func, attribIndex);
       return;
    }
 
    FLUSH_VERTICES(ctx, 0);
 
-   update_array_format(ctx, "glVertexAttribIFormat",
+   update_array_format(ctx, func, ctx->Array.VAO,
                        VERT_ATTRIB_GENERIC(attribIndex),
-                       legalTypes, 1, 4, size, type, GL_FALSE, GL_TRUE,
-                       relativeOffset);
+                       legalTypes, 1, maxSize, size, type,
+                       normalized, integer, doubles, relativeOffset);
+}
+
+
+void GLAPIENTRY
+_mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
+                         GLboolean normalized, GLuint relativeOffset)
+{
+   vertex_attrib_format(attribIndex, size, type, normalized,
+                        GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
+                        BGRA_OR_4, relativeOffset,
+                        "glVertexAttribFormat");
+}
+
+
+void GLAPIENTRY
+_mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
+                          GLuint relativeOffset)
+{
+   vertex_attrib_format(attribIndex, size, type, GL_FALSE,
+                        GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK, 4,
+                        relativeOffset, "glVertexAttribIFormat");
 }
 
 
@@ -1714,67 +1880,98 @@ void GLAPIENTRY
 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
                           GLuint relativeOffset)
 {
-   const GLbitfield legalTypes = DOUBLE_BIT;
+   vertex_attrib_format(attribIndex, size, type, GL_FALSE, GL_FALSE,
+                        GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK, 4,
+                        relativeOffset, "glVertexAttribLFormat");
+}
+
 
+static void
+vertex_array_attrib_format(GLuint vaobj, GLuint attribIndex, GLint size,
+                           GLenum type, GLboolean normalized,
+                           GLboolean integer, GLboolean doubles,
+                           GLbitfield legalTypes, GLsizei maxSize,
+                           GLuint relativeOffset, const char *func)
+{
    GET_CURRENT_CONTEXT(ctx);
+   struct gl_vertex_array_object *vao;
+
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
-    *
-    *    "An INVALID_OPERATION error is generated under any of the following
-    *     conditions:
-    *     • if no vertex array object is currently bound (see section 10.4);
-    *     • ..."
+   /* The ARB_direct_state_access spec says:
     *
-    * This language is missing from the extension spec, but we assume
-    * that this is an oversight.
+    *   "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
+    *    if <vaobj> is not [compatibility profile: zero or] the name of an
+    *    existing vertex array object."
     */
-   if (ctx->API == API_OPENGL_CORE &&
-       ctx->Array.VAO == ctx->Array.DefaultVAO) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glVertexAttribLFormat(No array object bound)");
+   vao = _mesa_lookup_vao_err(ctx, vaobj, func);
+   if (!vao)
       return;
-   }
 
    /* The ARB_vertex_attrib_binding spec says:
     *
-    *   "The error INVALID_VALUE is generated if <attribindex> is greater than
-    *    or equal to the value of MAX_VERTEX_ATTRIBS."
+    *   "The error INVALID_VALUE is generated if index is greater than or equal
+    *    to the value of MAX_VERTEX_ATTRIBS."
     */
    if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glVertexAttribLFormat(attribindex=%u > "
-                  "GL_MAX_VERTEX_ATTRIBS)",
-                  attribIndex);
+                  "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
+                  func, attribIndex);
       return;
    }
 
    FLUSH_VERTICES(ctx, 0);
 
-   update_array_format(ctx, "glVertexAttribLFormat",
+   update_array_format(ctx, func, vao,
                        VERT_ATTRIB_GENERIC(attribIndex),
-                       legalTypes, 1, 4, size, type, GL_FALSE, GL_FALSE,
-                       relativeOffset);
+                       legalTypes, 1, maxSize, size, type, normalized,
+                       integer, doubles, relativeOffset);
 }
 
 
 void GLAPIENTRY
-_mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
+_mesa_VertexArrayAttribFormat(GLuint vaobj, GLuint attribIndex, GLint size,
+                              GLenum type, GLboolean normalized,
+                              GLuint relativeOffset)
 {
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
+   vertex_array_attrib_format(vaobj, attribIndex, size, type, normalized,
+                              GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
+                              BGRA_OR_4, relativeOffset,
+                              "glVertexArrayAttribFormat");
+}
+
+
+void GLAPIENTRY
+_mesa_VertexArrayAttribIFormat(GLuint vaobj, GLuint attribIndex,
+                               GLint size, GLenum type,
+                               GLuint relativeOffset)
+{
+   vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
+                              GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK,
+                              4, relativeOffset,
+                              "glVertexArrayAttribIFormat");
+}
 
-   /* The ARB_vertex_attrib_binding spec says:
-    *
-    *    "An INVALID_OPERATION error is generated if no vertex array object
-    *     is bound."
-    */
-   if (ctx->API == API_OPENGL_CORE &&
-       ctx->Array.VAO == ctx->Array.DefaultVAO) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glVertexAttribBinding(No array object bound)");
-      return;
-   }
+
+void GLAPIENTRY
+_mesa_VertexArrayAttribLFormat(GLuint vaobj, GLuint attribIndex,
+                               GLint size, GLenum type,
+                               GLuint relativeOffset)
+{
+   vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
+                              GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK,
+                              4, relativeOffset,
+                              "glVertexArrayAttribLFormat");
+}
+
+
+static void
+vertex_array_attrib_binding(struct gl_context *ctx,
+                            struct gl_vertex_array_object *vao,
+                            GLuint attribIndex, GLuint bindingIndex,
+                            const char *func)
+{
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    /* The ARB_vertex_attrib_binding spec says:
     *
@@ -1785,38 +1982,32 @@ _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
     */
    if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glVertexAttribBinding(attribindex=%u >= "
+                  "%s(attribindex=%u >= "
                   "GL_MAX_VERTEX_ATTRIBS)",
-                  attribIndex);
+                  func, attribIndex);
       return;
    }
 
    if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glVertexAttribBinding(bindingindex=%u >= "
+                  "%s(bindingindex=%u >= "
                   "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
-                  bindingIndex);
+                  func, bindingIndex);
       return;
    }
 
-   ASSERT(VERT_ATTRIB_GENERIC(attribIndex) <
-          Elements(ctx->Array.VAO->VertexAttrib));
+   assert(VERT_ATTRIB_GENERIC(attribIndex) < ARRAY_SIZE(vao->VertexAttrib));
 
-   vertex_attrib_binding(ctx, VERT_ATTRIB_GENERIC(attribIndex),
+   vertex_attrib_binding(ctx, vao,
+                         VERT_ATTRIB_GENERIC(attribIndex),
                          VERT_ATTRIB_GENERIC(bindingIndex));
 }
 
 
 void GLAPIENTRY
-_mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
+_mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
 {
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if (!ctx->Extensions.ARB_instanced_arrays) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexBindingDivisor()");
-      return;
-   }
 
    /* The ARB_vertex_attrib_binding spec says:
     *
@@ -1826,7 +2017,47 @@ _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
    if (ctx->API == API_OPENGL_CORE &&
        ctx->Array.VAO == ctx->Array.DefaultVAO) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glVertexBindingDivisor(No array object bound)");
+                  "glVertexAttribBinding(No array object bound)");
+      return;
+   }
+
+   vertex_array_attrib_binding(ctx, ctx->Array.VAO,
+                               attribIndex, bindingIndex,
+                               "glVertexAttribBinding");
+}
+
+
+void GLAPIENTRY
+_mesa_VertexArrayAttribBinding(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_vertex_array_object *vao;
+
+   /* The ARB_direct_state_access specification says:
+    *
+    *   "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
+    *    if <vaobj> is not [compatibility profile: zero or] the name of an
+    *    existing vertex array object."
+    */
+   vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayAttribBinding");
+   if (!vao)
+      return;
+
+   vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex,
+                               "glVertexArrayAttribBinding");
+}
+
+
+static void
+vertex_array_binding_divisor(struct gl_context *ctx,
+                             struct gl_vertex_array_object *vao,
+                             GLuint bindingIndex, GLuint divisor,
+                             const char *func)
+{
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (!ctx->Extensions.ARB_instanced_arrays) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "%s()", func);
       return;
    }
 
@@ -1837,13 +2068,57 @@ _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
     */
    if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glVertexBindingDivisor(bindingindex=%u > "
+                  "%s(bindingindex=%u > "
                   "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
-                  bindingIndex);
+                  func, bindingIndex);
+      return;
+   }
+
+   vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
+}
+
+
+void GLAPIENTRY
+_mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   /* The ARB_vertex_attrib_binding spec says:
+    *
+    *    "An INVALID_OPERATION error is generated if no vertex array object
+    *     is bound."
+    */
+   if (ctx->API == API_OPENGL_CORE &&
+       ctx->Array.VAO == ctx->Array.DefaultVAO) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glVertexBindingDivisor(No array object bound)");
       return;
    }
 
-   vertex_binding_divisor(ctx, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
+   vertex_array_binding_divisor(ctx, ctx->Array.VAO,
+                                bindingIndex, divisor,
+                                "glVertexBindingDivisor");
+}
+
+
+void GLAPIENTRY
+_mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex, GLuint divisor)
+{
+   struct gl_vertex_array_object *vao;
+   GET_CURRENT_CONTEXT(ctx);
+
+   /* The ARB_direct_state_access specification says:
+    *
+    *   "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
+    *    if <vaobj> is not [compatibility profile: zero or] the name of an
+    *    existing vertex array object."
+    */
+   vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayBindingDivisor");
+   if (!vao)
+       return;
+
+   vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor,
+                                "glVertexArrayBindingDivisor");
 }
 
 
@@ -1864,10 +2139,10 @@ _mesa_copy_client_array(struct gl_context *ctx,
    dst->Enabled = src->Enabled;
    dst->Normalized = src->Normalized;
    dst->Integer = src->Integer;
+   dst->Doubles = src->Doubles;
    dst->InstanceDivisor = src->InstanceDivisor;
    dst->_ElementSize = src->_ElementSize;
    _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
-   dst->_MaxElement = src->_MaxElement;
 }
 
 void
@@ -1882,6 +2157,7 @@ _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
    dst->RelativeOffset = src->RelativeOffset;
    dst->Format         = src->Format;
    dst->Integer        = src->Integer;
+   dst->Doubles        = src->Doubles;
    dst->Normalized     = src->Normalized;
    dst->Ptr            = src->Ptr;
    dst->Enabled        = src->Enabled;
@@ -1908,14 +2184,13 @@ static void
 print_array(const char *name, GLint index, const struct gl_client_array *array)
 {
    if (index >= 0)
-      printf("  %s[%d]: ", name, index);
+      fprintf(stderr, "  %s[%d]: ", name, index);
    else
-      printf("  %s: ", name);
-   printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
+      fprintf(stderr, "  %s: ", name);
+   fprintf(stderr, "Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
          array->Ptr, array->Type, array->Size,
          array->_ElementSize, array->StrideB,
-         array->BufferObj->Name, (unsigned long) array->BufferObj->Size,
-         array->_MaxElement);
+         array->BufferObj->Name, (unsigned long) array->BufferObj->Size);
 }
 
 
@@ -1928,8 +2203,6 @@ _mesa_print_arrays(struct gl_context *ctx)
    struct gl_vertex_array_object *vao = ctx->Array.VAO;
    GLuint i;
 
-   _mesa_update_vao_max_element(ctx, vao);
-
    printf("Array Object %u\n", vao->Name);
    if (vao->_VertexAttrib[VERT_ATTRIB_POS].Enabled)
       print_array("Vertex", -1, &vao->_VertexAttrib[VERT_ATTRIB_POS]);
@@ -1943,7 +2216,6 @@ _mesa_print_arrays(struct gl_context *ctx)
    for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++)
       if (vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled)
          print_array("Attrib", i, &vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)]);
-   printf("  _MaxElement = %u\n", vao->_MaxElement);
 }