mesa: Use the gl_vertex_array_object::Enabled bitfield.
authorMathias Fröhlich <mathias.froehlich@web.de>
Sat, 17 Nov 2018 06:13:11 +0000 (07:13 +0100)
committerMathias Fröhlich <mathias.froehlich@web.de>
Wed, 21 Nov 2018 05:27:19 +0000 (06:27 +0100)
Instead of using gl_array_attributes::Enabled use the
much more compact representation stored in
gl_vertex_array_object::Enabled using the corresponding bits.

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Signed-off-by: Mathias Fröhlich <Mathias.Froehlich@web.de>
src/mesa/main/api_arrayelt.c
src/mesa/main/arrayobj.c
src/mesa/main/draw.c
src/mesa/main/enable.c
src/mesa/main/varray.c

index afa30120211e16d6c0791e4534d304dbc8023785..25cbc5326f8aad0acc9ff34b542b7419b2f15d26 100644 (file)
@@ -1572,7 +1572,7 @@ _ae_update_state(struct gl_context *ctx)
    actx->nr_vbos = 0;
 
    /* conventional vertex arrays */
-   if (vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled) {
+   if (vao->Enabled & VERT_BIT_COLOR_INDEX) {
       aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX];
       aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
       aa->offset = IndexFuncs[TYPE_IDX(aa->array->Type)];
@@ -1580,7 +1580,7 @@ _ae_update_state(struct gl_context *ctx)
       aa++;
    }
 
-   if (vao->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled) {
+   if (vao->Enabled & VERT_BIT_EDGEFLAG) {
       aa->array = &vao->VertexAttrib[VERT_ATTRIB_EDGEFLAG];
       aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
       aa->offset = _gloffset_EdgeFlagv;
@@ -1588,7 +1588,7 @@ _ae_update_state(struct gl_context *ctx)
       aa++;
    }
 
-   if (vao->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled) {
+   if (vao->Enabled & VERT_BIT_NORMAL) {
       aa->array = &vao->VertexAttrib[VERT_ATTRIB_NORMAL];
       aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
       aa->offset = NormalFuncs[TYPE_IDX(aa->array->Type)];
@@ -1596,7 +1596,7 @@ _ae_update_state(struct gl_context *ctx)
       aa++;
    }
 
-   if (vao->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled) {
+   if (vao->Enabled & VERT_BIT_COLOR0) {
       aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR0];
       aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
       aa->offset = ColorFuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
@@ -1604,7 +1604,7 @@ _ae_update_state(struct gl_context *ctx)
       aa++;
    }
 
-   if (vao->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled) {
+   if (vao->Enabled & VERT_BIT_COLOR1) {
       aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR1];
       aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
       aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Type)];
@@ -1612,7 +1612,7 @@ _ae_update_state(struct gl_context *ctx)
       aa++;
    }
 
-   if (vao->VertexAttrib[VERT_ATTRIB_FOG].Enabled) {
+   if (vao->Enabled & VERT_BIT_FOG) {
       aa->array = &vao->VertexAttrib[VERT_ATTRIB_FOG];
       aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
       aa->offset = FogCoordFuncs[TYPE_IDX(aa->array->Type)];
@@ -1621,9 +1621,9 @@ _ae_update_state(struct gl_context *ctx)
    }
 
    for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
-      struct gl_array_attributes *attribArray =
-         &vao->VertexAttrib[VERT_ATTRIB_TEX(i)];
-      if (attribArray->Enabled) {
+      if (vao->Enabled & VERT_BIT_TEX(i)) {
+         struct gl_array_attributes *attribArray =
+            &vao->VertexAttrib[VERT_ATTRIB_TEX(i)];
          /* NOTE: we use generic glVertexAttribNV functions here.
           * If we ever remove GL_NV_vertex_program this will have to change.
           */
@@ -1641,9 +1641,9 @@ _ae_update_state(struct gl_context *ctx)
 
    /* generic vertex attribute arrays */
    for (i = 1; i < VERT_ATTRIB_GENERIC_MAX; i++) {  /* skip zero! */
-      struct gl_array_attributes *attribArray =
-         &vao->VertexAttrib[VERT_ATTRIB_GENERIC(i)];
-      if (attribArray->Enabled) {
+      if (vao->Enabled & VERT_BIT_GENERIC(i)) {
+         struct gl_array_attributes *attribArray =
+            &vao->VertexAttrib[VERT_ATTRIB_GENERIC(i)];
          GLint intOrNorm;
          at->array = attribArray;
          at->binding = &vao->BufferBinding[attribArray->BufferBindingIndex];
@@ -1672,7 +1672,7 @@ _ae_update_state(struct gl_context *ctx)
    }
 
    /* finally, vertex position */
-   if (vao->VertexAttrib[VERT_ATTRIB_GENERIC0].Enabled) {
+   if (vao->Enabled & VERT_BIT_GENERIC0) {
       /* Use glVertex(v) instead of glVertexAttrib(0, v) to be sure it's
        * issued as the last (provoking) attribute).
        */
@@ -1683,7 +1683,7 @@ _ae_update_state(struct gl_context *ctx)
       check_vbo(actx, aa->binding->BufferObj);
       aa++;
    }
-   else if (vao->VertexAttrib[VERT_ATTRIB_POS].Enabled) {
+   else if (vao->Enabled & VERT_BIT_POS) {
       aa->array = &vao->VertexAttrib[VERT_ATTRIB_POS];
       aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
       aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
index c4e61a9954dd22f7ba9598ddd70c11481a47b0da..5572ae550f8a8ed0224c1b752145c1fc29978ed5 100644 (file)
@@ -832,8 +832,8 @@ _mesa_update_vao_derived_arrays(struct gl_context *ctx,
    for (gl_vert_attrib attr = 0; attr < VERT_ATTRIB_MAX; ++attr) {
       /* Query the original api defined attrib/binding information ... */
       const unsigned char *const map =_mesa_vao_attribute_map[mode];
-      const struct gl_array_attributes *attrib = &vao->VertexAttrib[map[attr]];
-      if (attrib->Enabled) {
+      if (vao->Enabled & VERT_BIT(map[attr])) {
+         const struct gl_array_attributes *attrib = &vao->VertexAttrib[map[attr]];
          const struct gl_vertex_buffer_binding *binding =
             &vao->BufferBinding[attrib->BufferBindingIndex];
          /* ... and compare that with the computed attrib/binding */
index 99ea4d928bee5526b85a874261c14898fc729af6..313df6aa8bc20e4f135b9b24588dedd59a827da4 100644 (file)
@@ -67,7 +67,7 @@ check_array_data(struct gl_context *ctx, struct gl_vertex_array_object *vao,
                  GLuint attrib, GLuint j)
 {
    const struct gl_array_attributes *array = &vao->VertexAttrib[attrib];
-   if (array->Enabled) {
+   if (vao->Enabled & VERT_BIT(attrib)) {
       const struct gl_vertex_buffer_binding *binding =
          &vao->BufferBinding[array->BufferBindingIndex];
       struct gl_buffer_object *bo = binding->BufferObj;
@@ -117,7 +117,7 @@ unmap_array_buffer(struct gl_context *ctx, struct gl_vertex_array_object *vao,
                    GLuint attrib)
 {
    const struct gl_array_attributes *array = &vao->VertexAttrib[attrib];
-   if (array->Enabled) {
+   if (vao->Enabled & VERT_BIT(attrib)) {
       const struct gl_vertex_buffer_binding *binding =
          &vao->BufferBinding[array->BufferBindingIndex];
       struct gl_buffer_object *bo = binding->BufferObj;
@@ -225,7 +225,7 @@ skip_validated_draw(struct gl_context *ctx)
    case API_OPENGLES:
       /* For OpenGL ES, only draw if we have vertex positions
        */
-      if (!ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled)
+      if (!(ctx->Array.VAO->Enabled & VERT_BIT_POS))
          return true;
       break;
 
@@ -252,8 +252,7 @@ skip_validated_draw(struct gl_context *ctx)
          /* Draw if we have vertex positions (GL_VERTEX_ARRAY or generic
           * array [0]).
           */
-         return (!ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled &&
-                 !ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC0].Enabled);
+         return !(ctx->Array.VAO->Enabled & (VERT_BIT_POS|VERT_BIT_GENERIC0));
       }
       break;
 
@@ -277,20 +276,19 @@ print_draw_arrays(struct gl_context *ctx,
    printf("_mesa_DrawArrays(mode 0x%x, start %d, count %d):\n",
           mode, start, count);
 
-   unsigned i;
-   for (i = 0; i < VERT_ATTRIB_MAX; ++i) {
+   GLbitfield mask = vao->Enabled;
+   while (mask) {
+      const gl_vert_attrib i = u_bit_scan(&mask);
       const struct gl_array_attributes *array = &vao->VertexAttrib[i];
-      if (!array->Enabled)
-         continue;
 
       const struct gl_vertex_buffer_binding *binding =
          &vao->BufferBinding[array->BufferBindingIndex];
       struct gl_buffer_object *bufObj = binding->BufferObj;
 
-      printf("attr %s: size %d stride %d  enabled %d  "
+      printf("attr %s: size %d stride %d  "
              "ptr %p  Bufobj %u\n",
              gl_vert_attrib_name((gl_vert_attrib) i),
-             array->Size, binding->Stride, array->Enabled,
+             array->Size, binding->Stride,
              array->Ptr, bufObj->Name);
 
       if (_mesa_is_bufferobj(bufObj)) {
index bd3e493da536f5de05101293d3e85175582f6046..21d6a812e07f6ac131fcbf592867f031a745dae9 100644 (file)
@@ -1582,41 +1582,40 @@ _mesa_IsEnabled( GLenum cap )
       case GL_VERTEX_ARRAY:
          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
-         return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled;
+         return !!(ctx->Array.VAO->Enabled & VERT_BIT_POS);
       case GL_NORMAL_ARRAY:
          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
-         return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
+         return !!(ctx->Array.VAO->Enabled & VERT_BIT_NORMAL);
       case GL_COLOR_ARRAY:
          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
-         return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
+         return !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR0);
       case GL_INDEX_ARRAY:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-         return ctx->Array.VAO->
-            VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
+         return !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR_INDEX);
       case GL_TEXTURE_COORD_ARRAY:
          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
-         return ctx->Array.VAO->
-            VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
+         return !!(ctx->Array.VAO->Enabled &
+                   VERT_BIT_TEX(ctx->Array.ActiveTexture));
       case GL_EDGE_FLAG_ARRAY:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-         return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
+         return !!(ctx->Array.VAO->Enabled & VERT_BIT_EDGEFLAG);
       case GL_FOG_COORDINATE_ARRAY_EXT:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-         return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
+         return !!(ctx->Array.VAO->Enabled & VERT_BIT_FOG);
       case GL_SECONDARY_COLOR_ARRAY_EXT:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-         return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
+         return !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR1);
       case GL_POINT_SIZE_ARRAY_OES:
          if (ctx->API != API_OPENGLES)
             goto invalid_enum_error;
-         return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
+         return !!(ctx->Array.VAO->Enabled & VERT_BIT_POINT_SIZE);
 
       /* GL_ARB_texture_cube_map */
       case GL_TEXTURE_CUBE_MAP:
index e1675ff5135be27b3d0e3a9f1c573ce72e681934..e8969eb954a627695bb76983142ea56c8e374fa8 100644 (file)
@@ -1267,7 +1267,7 @@ get_vertex_array_attrib(struct gl_context *ctx,
 
    switch (pname) {
    case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
-      return array->Enabled;
+      return !!(vao->Enabled & VERT_BIT_GENERIC(index));
    case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
       return (array->Format == GL_BGRA) ? GL_BGRA : array->Size;
    case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
@@ -2812,11 +2812,10 @@ _mesa_print_arrays(struct gl_context *ctx)
 
    fprintf(stderr, "Array Object %u\n", vao->Name);
 
-   gl_vert_attrib i;
-   for (i = 0; i < VERT_ATTRIB_MAX; ++i) {
+   GLbitfield mask = vao->Enabled;
+   while (mask) {
+      const gl_vert_attrib i = u_bit_scan(&mask);
       const struct gl_array_attributes *array = &vao->VertexAttrib[i];
-      if (!array->Enabled)
-         continue;
 
       const struct gl_vertex_buffer_binding *binding =
          &vao->BufferBinding[array->BufferBindingIndex];