[Mesa-dev] [PATCH 1/5] mesa: Clean up vertex attrib binding patch.

Eric Anholt eric at anholt.net
Thu Oct 31 19:50:20 CET 2013


I didn't like how the getters looked in the code (I have a hard enough
time keeping the ArrayObj members straight without moving some of their
names farther from their usage), so I tried this cleanup.  It is intended
to be squashed with "[PATCH 05/11] mesa: Add ARB_vertex_attrib_binding"
---
 src/mesa/main/varray.c | 50 +++++++++++++++-----------------------------------
 1 file changed, 15 insertions(+), 35 deletions(-)

diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c
index 93581ea..f8837e8 100644
--- a/src/mesa/main/varray.c
+++ b/src/mesa/main/varray.c
@@ -101,23 +101,6 @@ type_to_bit(const struct gl_context *ctx, GLenum type)
    }
 }
 
-
-static inline struct gl_vertex_attrib_array *
-gl_vertex_attrib_array(struct gl_context *ctx, GLuint index)
-{
-   ASSERT(index < Elements(arrayObj->VertexAttrib));
-   return &ctx->Array.ArrayObj->VertexAttrib[index];
-}
-
-
-static inline struct gl_vertex_buffer_binding *
-gl_vertex_buffer_binding(struct gl_context *ctx, GLuint index)
-{
-   ASSERT(index < Elements(arrayObj->VertexBinding));
-   return &ctx->Array.ArrayObj->VertexBinding[index];
-}
-
-
 /**
  * Sets the VertexBinding field in the vertex attribute given by attribIndex.
  */
@@ -125,24 +108,20 @@ static void
 vertex_attrib_binding(struct gl_context *ctx, GLuint attribIndex,
                       GLuint bindingIndex)
 {
-   struct gl_vertex_attrib_array *array =
-               gl_vertex_attrib_array(ctx, attribIndex);
+   struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
+   struct gl_vertex_attrib_array *array = &arrayObj->VertexAttrib[attribIndex];
 
    if (array->VertexBinding != bindingIndex) {
       const GLbitfield64 array_bit = VERT_BIT(attribIndex);
-      struct gl_vertex_buffer_binding *new_binding =
-                  gl_vertex_buffer_binding(ctx, bindingIndex);
-      struct gl_vertex_buffer_binding *old_binding =
-                  gl_vertex_buffer_binding(ctx, array->VertexBinding);
 
       FLUSH_VERTICES(ctx, _NEW_ARRAY);
 
-      array->VertexBinding = bindingIndex;
+      arrayObj->VertexBinding[array->VertexBinding]._BoundArrays &= ~array_bit;
+      arrayObj->VertexBinding[bindingIndex]._BoundArrays |= array_bit;
 
-      old_binding->_BoundArrays &= ~array_bit;
-      new_binding->_BoundArrays |= array_bit;
+      array->VertexBinding = bindingIndex;
 
-      ctx->Array.ArrayObj->NewArrays |= array_bit;
+      arrayObj->NewArrays |= array_bit;
    }
 }
 
@@ -156,8 +135,8 @@ bind_vertex_buffer(struct gl_context *ctx, GLuint index,
                    struct gl_buffer_object *vbo,
                    GLintptr offset, GLsizei stride)
 {
-   struct gl_vertex_buffer_binding *binding =
-               gl_vertex_buffer_binding(ctx, index);
+   struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
+   struct gl_vertex_buffer_binding *binding = &arrayObj->VertexBinding[index];
 
    if (binding->BufferObj != vbo ||
        binding->Offset != offset ||
@@ -170,7 +149,7 @@ bind_vertex_buffer(struct gl_context *ctx, GLuint index,
       binding->Offset = offset;
       binding->Stride = stride;
 
-      ctx->Array.ArrayObj->NewArrays |= binding->_BoundArrays;
+      arrayObj->NewArrays |= binding->_BoundArrays;
    }
 }
 
@@ -183,13 +162,14 @@ static void
 vertex_binding_divisor(struct gl_context *ctx, GLuint bindingIndex,
                        GLuint divisor)
 {
+   struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
    struct gl_vertex_buffer_binding *binding =
-               gl_vertex_buffer_binding(ctx, bindingIndex);
+      &arrayObj->VertexBinding[bindingIndex];
 
    if (binding->InstanceDivisor != divisor) {
       FLUSH_VERTICES(ctx, _NEW_ARRAY);
       binding->InstanceDivisor = divisor;
-      ctx->Array.ArrayObj->NewArrays |= binding->_BoundArrays;
+      arrayObj->NewArrays |= binding->_BoundArrays;
    }
 }
 
@@ -336,7 +316,7 @@ update_array_format(struct gl_context *ctx,
    elementSize = _mesa_bytes_per_vertex_attrib(size, type);
    assert(elementSize != -1);
 
-   array = gl_vertex_attrib_array(ctx, attrib);
+   array = &ctx->Array.ArrayObj->VertexAttrib[attrib];
    array->Size = size;
    array->Type = type;
    array->Format = format;
@@ -429,7 +409,7 @@ update_array(struct gl_context *ctx,
    vertex_attrib_binding(ctx, attrib, attrib);
 
    /* The Stride and Ptr fields are not set by update_array_format() */
-   array = gl_vertex_attrib_array(ctx, attrib);
+   array = &ctx->Array.ArrayObj->VertexAttrib[attrib];
    array->Stride = stride;
    array->Ptr = (const GLvoid *) ptr;
 
@@ -1404,7 +1384,7 @@ _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
     */
    if (offset < 0) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glBindVertexBuffer(offset=%d < 0)", offset);
+                  "glBindVertexBuffer(offset=%lld < 0)", (long long)offset);
       return;
    }
 
-- 
1.8.4.rc3



More information about the mesa-dev mailing list