mesa: simplify translate_tex_src_bit()
[mesa.git] / src / mesa / main / attrib.c
index 1d2c46048847ec08b3743d69b4e5c05cce0b37b6..ab99ca1c6420cd261beaa2f464918220f1159323 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.3
+ * Version:  7.6
  *
  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  * Copyright (C) 2009  VMware, Inc.   All Rights Reserved.
@@ -174,24 +174,30 @@ struct texture_state
 
 
 /**
- * Allocate a new attribute state node.  These nodes have a
- * "kind" value and a pointer to a struct of state data.
+ * Allocate new attribute node of given type/kind.  Attach payload data.
+ * Insert it into the linked list named by 'head'.
  */
-static struct gl_attrib_node *
-new_attrib_node( GLbitfield kind )
+static void
+save_attrib_data(struct gl_attrib_node **head,
+                 GLbitfield kind, void *payload)
 {
-   struct gl_attrib_node *an = MALLOC_STRUCT(gl_attrib_node);
-   if (an) {
-      an->kind = kind;
+   struct gl_attrib_node *n = MALLOC_STRUCT(gl_attrib_node);
+   if (n) {
+      n->kind = kind;
+      n->data = payload;
+      /* insert at head */
+      n->next = *head;
+      *head = n;
+   }
+   else {
+      /* out of memory! */
    }
-   return an;
 }
 
 
 void GLAPIENTRY
 _mesa_PushAttrib(GLbitfield mask)
 {
-   struct gl_attrib_node *newnode;
    struct gl_attrib_node *head;
 
    GET_CURRENT_CONTEXT(ctx);
@@ -213,10 +219,7 @@ _mesa_PushAttrib(GLbitfield mask)
       struct gl_accum_attrib *attr;
       attr = MALLOC_STRUCT( gl_accum_attrib );
       MEMCPY( attr, &ctx->Accum, sizeof(struct gl_accum_attrib) );
-      newnode = new_attrib_node( GL_ACCUM_BUFFER_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_ACCUM_BUFFER_BIT, attr);
    }
 
    if (mask & GL_COLOR_BUFFER_BIT) {
@@ -227,10 +230,7 @@ _mesa_PushAttrib(GLbitfield mask)
       /* push the Draw FBO's DrawBuffer[] state, not ctx->Color.DrawBuffer[] */
       for (i = 0; i < ctx->Const.MaxDrawBuffers; i ++)
          attr->DrawBuffer[i] = ctx->DrawBuffer->ColorDrawBuffer[i];
-      newnode = new_attrib_node( GL_COLOR_BUFFER_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_COLOR_BUFFER_BIT, attr);
    }
 
    if (mask & GL_CURRENT_BIT) {
@@ -238,20 +238,14 @@ _mesa_PushAttrib(GLbitfield mask)
       FLUSH_CURRENT( ctx, 0 );
       attr = MALLOC_STRUCT( gl_current_attrib );
       MEMCPY( attr, &ctx->Current, sizeof(struct gl_current_attrib) );
-      newnode = new_attrib_node( GL_CURRENT_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_CURRENT_BIT, attr);
    }
 
    if (mask & GL_DEPTH_BUFFER_BIT) {
       struct gl_depthbuffer_attrib *attr;
       attr = MALLOC_STRUCT( gl_depthbuffer_attrib );
       MEMCPY( attr, &ctx->Depth, sizeof(struct gl_depthbuffer_attrib) );
-      newnode = new_attrib_node( GL_DEPTH_BUFFER_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_DEPTH_BUFFER_BIT, attr);
    }
 
    if (mask & GL_ENABLE_BIT) {
@@ -331,40 +325,28 @@ _mesa_PushAttrib(GLbitfield mask)
       attr->VertexProgram = ctx->VertexProgram.Enabled;
       attr->VertexProgramPointSize = ctx->VertexProgram.PointSizeEnabled;
       attr->VertexProgramTwoSide = ctx->VertexProgram.TwoSideEnabled;
-      newnode = new_attrib_node( GL_ENABLE_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_ENABLE_BIT, attr);
    }
 
    if (mask & GL_EVAL_BIT) {
       struct gl_eval_attrib *attr;
       attr = MALLOC_STRUCT( gl_eval_attrib );
       MEMCPY( attr, &ctx->Eval, sizeof(struct gl_eval_attrib) );
-      newnode = new_attrib_node( GL_EVAL_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_EVAL_BIT, attr);
    }
 
    if (mask & GL_FOG_BIT) {
       struct gl_fog_attrib *attr;
       attr = MALLOC_STRUCT( gl_fog_attrib );
       MEMCPY( attr, &ctx->Fog, sizeof(struct gl_fog_attrib) );
-      newnode = new_attrib_node( GL_FOG_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_FOG_BIT, attr);
    }
 
    if (mask & GL_HINT_BIT) {
       struct gl_hint_attrib *attr;
       attr = MALLOC_STRUCT( gl_hint_attrib );
       MEMCPY( attr, &ctx->Hint, sizeof(struct gl_hint_attrib) );
-      newnode = new_attrib_node( GL_HINT_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_HINT_BIT, attr);
    }
 
    if (mask & GL_LIGHTING_BIT) {
@@ -372,30 +354,21 @@ _mesa_PushAttrib(GLbitfield mask)
       FLUSH_CURRENT(ctx, 0);   /* flush material changes */
       attr = MALLOC_STRUCT( gl_light_attrib );
       MEMCPY( attr, &ctx->Light, sizeof(struct gl_light_attrib) );
-      newnode = new_attrib_node( GL_LIGHTING_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_LIGHTING_BIT, attr);
    }
 
    if (mask & GL_LINE_BIT) {
       struct gl_line_attrib *attr;
       attr = MALLOC_STRUCT( gl_line_attrib );
       MEMCPY( attr, &ctx->Line, sizeof(struct gl_line_attrib) );
-      newnode = new_attrib_node( GL_LINE_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_LINE_BIT, attr);
    }
 
    if (mask & GL_LIST_BIT) {
       struct gl_list_attrib *attr;
       attr = MALLOC_STRUCT( gl_list_attrib );
       MEMCPY( attr, &ctx->List, sizeof(struct gl_list_attrib) );
-      newnode = new_attrib_node( GL_LIST_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_LIST_BIT, attr);
    }
 
    if (mask & GL_PIXEL_MODE_BIT) {
@@ -404,60 +377,42 @@ _mesa_PushAttrib(GLbitfield mask)
       MEMCPY( attr, &ctx->Pixel, sizeof(struct gl_pixel_attrib) );
       /* push the Read FBO's ReadBuffer state, not ctx->Pixel.ReadBuffer */
       attr->ReadBuffer = ctx->ReadBuffer->ColorReadBuffer;
-      newnode = new_attrib_node( GL_PIXEL_MODE_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_PIXEL_MODE_BIT, attr);
    }
 
    if (mask & GL_POINT_BIT) {
       struct gl_point_attrib *attr;
       attr = MALLOC_STRUCT( gl_point_attrib );
       MEMCPY( attr, &ctx->Point, sizeof(struct gl_point_attrib) );
-      newnode = new_attrib_node( GL_POINT_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_POINT_BIT, attr);
    }
 
    if (mask & GL_POLYGON_BIT) {
       struct gl_polygon_attrib *attr;
       attr = MALLOC_STRUCT( gl_polygon_attrib );
       MEMCPY( attr, &ctx->Polygon, sizeof(struct gl_polygon_attrib) );
-      newnode = new_attrib_node( GL_POLYGON_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_POLYGON_BIT, attr);
    }
 
    if (mask & GL_POLYGON_STIPPLE_BIT) {
       GLuint *stipple;
       stipple = (GLuint *) MALLOC( 32*sizeof(GLuint) );
       MEMCPY( stipple, ctx->PolygonStipple, 32*sizeof(GLuint) );
-      newnode = new_attrib_node( GL_POLYGON_STIPPLE_BIT );
-      newnode->data = stipple;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_POLYGON_STIPPLE_BIT, stipple);
    }
 
    if (mask & GL_SCISSOR_BIT) {
       struct gl_scissor_attrib *attr;
       attr = MALLOC_STRUCT( gl_scissor_attrib );
       MEMCPY( attr, &ctx->Scissor, sizeof(struct gl_scissor_attrib) );
-      newnode = new_attrib_node( GL_SCISSOR_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_SCISSOR_BIT, attr);
    }
 
    if (mask & GL_STENCIL_BUFFER_BIT) {
       struct gl_stencil_attrib *attr;
       attr = MALLOC_STRUCT( gl_stencil_attrib );
       MEMCPY( attr, &ctx->Stencil, sizeof(struct gl_stencil_attrib) );
-      newnode = new_attrib_node( GL_STENCIL_BUFFER_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_STENCIL_BUFFER_BIT, attr);
    }
 
    if (mask & GL_TEXTURE_BIT) {
@@ -494,30 +449,21 @@ _mesa_PushAttrib(GLbitfield mask)
 
       _mesa_unlock_context_textures(ctx);
 
-      newnode = new_attrib_node( GL_TEXTURE_BIT );
-      newnode->data = texstate;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_TEXTURE_BIT, texstate);
    }
 
    if (mask & GL_TRANSFORM_BIT) {
       struct gl_transform_attrib *attr;
       attr = MALLOC_STRUCT( gl_transform_attrib );
       MEMCPY( attr, &ctx->Transform, sizeof(struct gl_transform_attrib) );
-      newnode = new_attrib_node( GL_TRANSFORM_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_TRANSFORM_BIT, attr);
    }
 
    if (mask & GL_VIEWPORT_BIT) {
       struct gl_viewport_attrib *attr;
       attr = MALLOC_STRUCT( gl_viewport_attrib );
       MEMCPY( attr, &ctx->Viewport, sizeof(struct gl_viewport_attrib) );
-      newnode = new_attrib_node( GL_VIEWPORT_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_VIEWPORT_BIT, attr);
    }
 
    /* GL_ARB_multisample */
@@ -525,10 +471,7 @@ _mesa_PushAttrib(GLbitfield mask)
       struct gl_multisample_attrib *attr;
       attr = MALLOC_STRUCT( gl_multisample_attrib );
       MEMCPY( attr, &ctx->Multisample, sizeof(struct gl_multisample_attrib) );
-      newnode = new_attrib_node( GL_MULTISAMPLE_BIT_ARB );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_MULTISAMPLE_BIT_ARB, attr);
    }
 
 end:
@@ -541,6 +484,7 @@ end:
 static void
 pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable)
 {
+   const GLuint curTexUnitSave = ctx->Texture.CurrentUnit;
    GLuint i;
 
 #define TEST_AND_UPDATE(VALUE, NEWVALUE, ENUM)         \
@@ -685,59 +629,51 @@ pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable)
 
    /* texture unit enables */
    for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
-      if (ctx->Texture.Unit[i].Enabled != enable->Texture[i]) {
-         ctx->Texture.Unit[i].Enabled = enable->Texture[i];
-         if (ctx->Driver.Enable) {
-            if (ctx->Driver.ActiveTexture) {
-               (*ctx->Driver.ActiveTexture)(ctx, i);
-            }
-            (*ctx->Driver.Enable)( ctx, GL_TEXTURE_1D,
-                             (GLboolean) (enable->Texture[i] & TEXTURE_1D_BIT) );
-            (*ctx->Driver.Enable)( ctx, GL_TEXTURE_2D,
-                             (GLboolean) (enable->Texture[i] & TEXTURE_2D_BIT) );
-            (*ctx->Driver.Enable)( ctx, GL_TEXTURE_3D,
-                             (GLboolean) (enable->Texture[i] & TEXTURE_3D_BIT) );
-            if (ctx->Extensions.ARB_texture_cube_map)
-               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_CUBE_MAP_ARB,
-                          (GLboolean) (enable->Texture[i] & TEXTURE_CUBE_BIT) );
-            if (ctx->Extensions.NV_texture_rectangle)
-               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_RECTANGLE_NV,
-                          (GLboolean) (enable->Texture[i] & TEXTURE_RECT_BIT) );
+      const GLbitfield enabled = enable->Texture[i];
+      const GLbitfield genEnabled = enable->TexGen[i];
+
+      if (ctx->Texture.Unit[i].Enabled != enabled) {
+         _mesa_ActiveTextureARB(GL_TEXTURE0 + i);
+
+         _mesa_set_enable(ctx, GL_TEXTURE_1D,
+                          (enabled & TEXTURE_1D_BIT) ? GL_TRUE : GL_FALSE);
+         _mesa_set_enable(ctx, GL_TEXTURE_2D,
+                          (enabled & TEXTURE_2D_BIT) ? GL_TRUE : GL_FALSE);
+         _mesa_set_enable(ctx, GL_TEXTURE_3D,
+                          (enabled & TEXTURE_3D_BIT) ? GL_TRUE : GL_FALSE);
+         if (ctx->Extensions.NV_texture_rectangle) {
+            _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE_ARB,
+                             (enabled & TEXTURE_RECT_BIT) ? GL_TRUE : GL_FALSE);
+         }
+         if (ctx->Extensions.ARB_texture_cube_map) {
+            _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP,
+                             (enabled & TEXTURE_CUBE_BIT) ? GL_TRUE : GL_FALSE);
+         }
+         if (ctx->Extensions.MESA_texture_array) {
+            _mesa_set_enable(ctx, GL_TEXTURE_1D_ARRAY_EXT,
+                           (enabled & TEXTURE_1D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
+            _mesa_set_enable(ctx, GL_TEXTURE_2D_ARRAY_EXT,
+                           (enabled & TEXTURE_2D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
          }
       }
 
-      if (ctx->Texture.Unit[i].TexGenEnabled != enable->TexGen[i]) {
-         ctx->Texture.Unit[i].TexGenEnabled = enable->TexGen[i];
-         if (ctx->Driver.Enable) {
-            if (ctx->Driver.ActiveTexture) {
-               (*ctx->Driver.ActiveTexture)(ctx, i);
-            }
-            if (enable->TexGen[i] & S_BIT)
-               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_TRUE);
-            else
-               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_S, GL_FALSE);
-            if (enable->TexGen[i] & T_BIT)
-               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_TRUE);
-            else
-               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_T, GL_FALSE);
-            if (enable->TexGen[i] & R_BIT)
-               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_TRUE);
-            else
-               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_R, GL_FALSE);
-            if (enable->TexGen[i] & Q_BIT)
-               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_TRUE);
-            else
-               (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_FALSE);
-         }
+      if (ctx->Texture.Unit[i].TexGenEnabled != genEnabled) {
+         _mesa_ActiveTextureARB(GL_TEXTURE0 + i);
+         _mesa_set_enable(ctx, GL_TEXTURE_GEN_S,
+                          (genEnabled & S_BIT) ? GL_TRUE : GL_FALSE);
+         _mesa_set_enable(ctx, GL_TEXTURE_GEN_T,
+                          (genEnabled & T_BIT) ? GL_TRUE : GL_FALSE);
+         _mesa_set_enable(ctx, GL_TEXTURE_GEN_R,
+                          (genEnabled & R_BIT) ? GL_TRUE : GL_FALSE);
+         _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q,
+                          (genEnabled & Q_BIT) ? GL_TRUE : GL_FALSE);
       }
 
       /* GL_SGI_texture_color_table */
       ctx->Texture.Unit[i].ColorTableEnabled = enable->TextureColorTable[i];
    }
 
-   if (ctx->Driver.ActiveTexture) {
-      (*ctx->Driver.ActiveTexture)(ctx, ctx->Texture.CurrentUnit);
-   }
+   _mesa_ActiveTextureARB(GL_TEXTURE0 + curTexUnitSave);
 }
 
 
@@ -770,6 +706,13 @@ pop_texture_group(GLcontext *ctx, struct texture_state *texstate)
          _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE_NV,
                      (unit->Enabled & TEXTURE_RECT_BIT) ? GL_TRUE : GL_FALSE);
       }
+      if (ctx->Extensions.MESA_texture_array) {
+         _mesa_set_enable(ctx, GL_TEXTURE_1D_ARRAY_EXT,
+                 (unit->Enabled & TEXTURE_1D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
+         _mesa_set_enable(ctx, GL_TEXTURE_2D_ARRAY_EXT,
+                 (unit->Enabled & TEXTURE_2D_ARRAY_BIT) ? GL_TRUE : GL_FALSE);
+      }
+
       if (ctx->Extensions.SGI_texture_color_table) {
          _mesa_set_enable(ctx, GL_TEXTURE_COLOR_TABLE_SGI,
                           unit->ColorTableEnabled);
@@ -849,7 +792,6 @@ pop_texture_group(GLcontext *ctx, struct texture_state *texstate)
       /* Restore texture object state for each target */
       for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
          const struct gl_texture_object *obj = NULL;
-         GLfloat bordColor[4];
          GLenum target;
 
          obj = &texstate->SavedObj[u][tgt];
@@ -875,12 +817,7 @@ pop_texture_group(GLcontext *ctx, struct texture_state *texstate)
 
          _mesa_BindTexture(target, obj->Name);
 
-         bordColor[0] = CHAN_TO_FLOAT(obj->BorderColor[0]);
-         bordColor[1] = CHAN_TO_FLOAT(obj->BorderColor[1]);
-         bordColor[2] = CHAN_TO_FLOAT(obj->BorderColor[2]);
-         bordColor[3] = CHAN_TO_FLOAT(obj->BorderColor[3]);
-
-         _mesa_TexParameterfv(target, GL_TEXTURE_BORDER_COLOR, bordColor);
+         _mesa_TexParameterfv(target, GL_TEXTURE_BORDER_COLOR, obj->BorderColor);
          _mesa_TexParameterf(target, GL_TEXTURE_PRIORITY, obj->Priority);
          _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, obj->WrapS);
          _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, obj->WrapT);
@@ -1104,7 +1041,7 @@ _mesa_PopAttrib(void)
                  _mesa_light(ctx, i, GL_DIFFUSE, l->Diffuse);
                  _mesa_light(ctx, i, GL_SPECULAR, l->Specular );
                  _mesa_light(ctx, i, GL_POSITION, l->EyePosition);
-                 _mesa_light(ctx, i, GL_SPOT_DIRECTION, l->EyeDirection);
+                 _mesa_light(ctx, i, GL_SPOT_DIRECTION, l->SpotDirection);
                  _mesa_light(ctx, i, GL_SPOT_EXPONENT, &l->SpotExponent);
                  _mesa_light(ctx, i, GL_SPOT_CUTOFF, &l->SpotCutoff);
                  _mesa_light(ctx, i, GL_CONSTANT_ATTENUATION,
@@ -1265,7 +1202,7 @@ _mesa_PopAttrib(void)
 
                /* restore clip planes */
                for (i = 0; i < MAX_CLIP_PLANES; i++) {
-                  const GLuint mask = 1 << 1;
+                  const GLuint mask = 1 << i;
                   const GLfloat *eyePlane = xform->EyeUserPlane[i];
                   COPY_4V(ctx->Transform.EyeUserPlane[i], eyePlane);
                   if (xform->ClipPlanesEnabled & mask) {
@@ -1330,20 +1267,22 @@ _mesa_PopAttrib(void)
  * counts when pushing/popping the GL_CLIENT_VERTEX_ARRAY_BIT attribute group.
  */
 static void
-adjust_buffer_object_ref_counts(struct gl_array_attrib *array, GLint step)
+adjust_buffer_object_ref_counts(struct gl_array_object *arrayObj, GLint step)
 {
    GLuint i;
-   array->ArrayObj->Vertex.BufferObj->RefCount += step;
-   array->ArrayObj->Normal.BufferObj->RefCount += step;
-   array->ArrayObj->Color.BufferObj->RefCount += step;
-   array->ArrayObj->SecondaryColor.BufferObj->RefCount += step;
-   array->ArrayObj->FogCoord.BufferObj->RefCount += step;
-   array->ArrayObj->Index.BufferObj->RefCount += step;
-   array->ArrayObj->EdgeFlag.BufferObj->RefCount += step;
-   for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++)
-      array->ArrayObj->TexCoord[i].BufferObj->RefCount += step;
-   for (i = 0; i < VERT_ATTRIB_MAX; i++)
-      array->ArrayObj->VertexAttrib[i].BufferObj->RefCount += step;
+
+   arrayObj->Vertex.BufferObj->RefCount += step;
+   arrayObj->Weight.BufferObj->RefCount += step;
+   arrayObj->Normal.BufferObj->RefCount += step;
+   arrayObj->Color.BufferObj->RefCount += step;
+   arrayObj->SecondaryColor.BufferObj->RefCount += step;
+   arrayObj->FogCoord.BufferObj->RefCount += step;
+   arrayObj->Index.BufferObj->RefCount += step;
+   arrayObj->EdgeFlag.BufferObj->RefCount += step;
+   for (i = 0; i < Elements(arrayObj->TexCoord); i++)
+      arrayObj->TexCoord[i].BufferObj->RefCount += step;
+   for (i = 0; i < Elements(arrayObj->VertexAttrib); i++)
+      arrayObj->VertexAttrib[i].BufferObj->RefCount += step;
 }
 
 
@@ -1377,7 +1316,6 @@ copy_pixelstore(GLcontext *ctx,
 void GLAPIENTRY
 _mesa_PushClientAttrib(GLbitfield mask)
 {
-   struct gl_attrib_node *newnode;
    struct gl_attrib_node *head;
 
    GET_CURRENT_CONTEXT(ctx);
@@ -1398,17 +1336,11 @@ _mesa_PushClientAttrib(GLbitfield mask)
       /* packing attribs */
       attr = CALLOC_STRUCT( gl_pixelstore_attrib );
       copy_pixelstore(ctx, attr, &ctx->Pack);
-      newnode = new_attrib_node( GL_CLIENT_PACK_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_CLIENT_PACK_BIT, attr);
       /* unpacking attribs */
       attr = CALLOC_STRUCT( gl_pixelstore_attrib );
       copy_pixelstore(ctx, attr, &ctx->Unpack);
-      newnode = new_attrib_node( GL_CLIENT_UNPACK_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_CLIENT_UNPACK_BIT, attr);
    }
 
    if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
@@ -1429,12 +1361,10 @@ _mesa_PushClientAttrib(GLbitfield mask)
 
       attr->ArrayObj = obj;
 
-      newnode = new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT );
-      newnode->data = attr;
-      newnode->next = head;
-      head = newnode;
+      save_attrib_data(&head, GL_CLIENT_VERTEX_ARRAY_BIT, attr);
+
       /* bump reference counts on buffer objects */
-      adjust_buffer_object_ref_counts(&ctx->Array, 1);
+      adjust_buffer_object_ref_counts(ctx->Array.ArrayObj, 1);
    }
 
    ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head;
@@ -1484,7 +1414,7 @@ _mesa_PopClientAttrib(void)
            struct gl_array_attrib * data =
              (struct gl_array_attrib *) node->data;
 
-            adjust_buffer_object_ref_counts(&ctx->Array, -1);
+            adjust_buffer_object_ref_counts(ctx->Array.ArrayObj, -1);
         
             ctx->Array.ActiveTexture = data->ActiveTexture;
            if (data->LockCount != 0)