need to copy new 1D/2D array texture objects in _mesa_PushAttrib()
[mesa.git] / src / mesa / main / attrib.c
index b4a587efb04d433a18cc8e6fda44ea895f77cb80..4699546262947cd24366f201a1474f155da512ec 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
+ * Version:  6.5.3
  *
- * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  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"),
@@ -25,6 +25,7 @@
 #include "glheader.h"
 #include "imports.h"
 #include "accum.h"
+#include "arrayobj.h"
 #include "attrib.h"
 #include "blend.h"
 #include "buffers.h"
@@ -137,9 +138,9 @@ _mesa_PushAttrib(GLbitfield mask)
       attr->Blend = ctx->Color.BlendEnabled;
       attr->ClipPlanes = ctx->Transform.ClipPlanesEnabled;
       attr->ColorMaterial = ctx->Light.ColorMaterialEnabled;
-      attr->ColorTable = ctx->Pixel.ColorTableEnabled;
-      attr->PostColorMatrixColorTable = ctx->Pixel.PostColorMatrixColorTableEnabled;
-      attr->PostConvolutionColorTable = ctx->Pixel.PostConvolutionColorTableEnabled;
+      for (i = 0; i < COLORTABLE_MAX; i++) {
+         attr->ColorTable[i] = ctx->Pixel.ColorTableEnabled[i];
+      }
       attr->Convolution1D = ctx->Pixel.Convolution1DEnabled;
       attr->Convolution2D = ctx->Pixel.Convolution2DEnabled;
       attr->Separable2D = ctx->Pixel.Separable2DEnabled;
@@ -179,7 +180,6 @@ _mesa_PushAttrib(GLbitfield mask)
       MEMCPY(attr->Map2Attrib, ctx->Eval.Map2Attrib, sizeof(ctx->Eval.Map2Attrib));
       attr->Normalize = ctx->Transform.Normalize;
       attr->RasterPositionUnclipped = ctx->Transform.RasterPositionUnclipped;
-      attr->PixelTexture = ctx->Pixel.PixelTextureEnabled;
       attr->PointSmooth = ctx->Point.SmoothFlag;
       attr->PointSprite = ctx->Point.PointSprite;
       attr->PolygonOffsetPoint = ctx->Polygon.OffsetPoint;
@@ -276,6 +276,8 @@ _mesa_PushAttrib(GLbitfield mask)
       struct gl_pixel_attrib *attr;
       attr = MALLOC_STRUCT( gl_pixel_attrib );
       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;
@@ -335,6 +337,8 @@ _mesa_PushAttrib(GLbitfield mask)
    if (mask & GL_TEXTURE_BIT) {
       struct gl_texture_attrib *attr;
       GLuint u;
+
+      _mesa_lock_context_textures(ctx);
       /* Bump the texture object reference counts so that they don't
        * inadvertantly get deleted.
        */
@@ -359,7 +363,14 @@ _mesa_PushAttrib(GLbitfield mask)
                                    attr->Unit[u].CurrentCubeMap);
          _mesa_copy_texture_object(&attr->Unit[u].SavedRect,
                                    attr->Unit[u].CurrentRect);
+         _mesa_copy_texture_object(&attr->Unit[u].Saved1DArray,
+                                   attr->Unit[u].Current1DArray);
+         _mesa_copy_texture_object(&attr->Unit[u].Saved2DArray,
+                                   attr->Unit[u].Current2DArray);
       }
+
+      _mesa_unlock_context_textures(ctx);
+
       newnode = new_attrib_node( GL_TEXTURE_BIT );
       newnode->data = attr;
       newnode->next = head;
@@ -425,14 +436,15 @@ pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable)
 
    TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial,
                    GL_COLOR_MATERIAL);
-   TEST_AND_UPDATE(ctx->Pixel.ColorTableEnabled, enable->ColorTable,
+   TEST_AND_UPDATE(ctx->Pixel.ColorTableEnabled[COLORTABLE_PRECONVOLUTION],
+                   enable->ColorTable[COLORTABLE_PRECONVOLUTION],
                    GL_COLOR_TABLE);
-   TEST_AND_UPDATE(ctx->Pixel.PostColorMatrixColorTableEnabled,
-                   enable->PostColorMatrixColorTable,
-                   GL_POST_COLOR_MATRIX_COLOR_TABLE);
-   TEST_AND_UPDATE(ctx->Pixel.PostConvolutionColorTableEnabled,
-                   enable->PostConvolutionColorTable,
+   TEST_AND_UPDATE(ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCONVOLUTION],
+                   enable->ColorTable[COLORTABLE_POSTCONVOLUTION],
                    GL_POST_CONVOLUTION_COLOR_TABLE);
+   TEST_AND_UPDATE(ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCOLORMATRIX],
+                   enable->ColorTable[COLORTABLE_POSTCOLORMATRIX],
+                   GL_POST_COLOR_MATRIX_COLOR_TABLE);
    TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE);
    TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST);
    TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER);
@@ -499,8 +511,6 @@ pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable)
    TEST_AND_UPDATE(ctx->Transform.RasterPositionUnclipped,
                    enable->RasterPositionUnclipped,
                    GL_RASTER_POSITION_UNCLIPPED_IBM);
-   TEST_AND_UPDATE(ctx->Pixel.PixelTextureEnabled, enable->PixelTexture,
-                   GL_POINT_SMOOTH);
    TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth,
                    GL_POINT_SMOOTH);
    if (ctx->Extensions.NV_point_sprite || ctx->Extensions.ARB_point_sprite) {
@@ -536,16 +546,16 @@ pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable)
    TEST_AND_UPDATE(ctx->Multisample.SampleCoverageInvert,
                    enable->SampleCoverageInvert,
                    GL_SAMPLE_COVERAGE_INVERT_ARB);
-   /* GL_NV_vertex_program */
+   /* GL_ARB_vertex_program, GL_NV_vertex_program */
    TEST_AND_UPDATE(ctx->VertexProgram.Enabled,
                    enable->VertexProgram,
-                   GL_VERTEX_PROGRAM_NV);
+                   GL_VERTEX_PROGRAM_ARB);
    TEST_AND_UPDATE(ctx->VertexProgram.PointSizeEnabled,
                    enable->VertexProgramPointSize,
-                   GL_VERTEX_PROGRAM_POINT_SIZE_NV);
+                   GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
    TEST_AND_UPDATE(ctx->VertexProgram.TwoSideEnabled,
                    enable->VertexProgramTwoSide,
-                   GL_VERTEX_PROGRAM_TWO_SIDE_NV);
+                   GL_VERTEX_PROGRAM_TWO_SIDE_ARB);
 
 #undef TEST_AND_UPDATE
 
@@ -738,6 +748,18 @@ pop_texture_group(GLcontext *ctx, const struct gl_texture_attrib *texAttrib)
             target = GL_TEXTURE_RECTANGLE_NV;
             obj = &unit->SavedRect;
             break;
+         case 5:
+            if (!ctx->Extensions.MESA_texture_array)
+               continue;
+            target = GL_TEXTURE_1D_ARRAY_EXT;
+            obj = &unit->Saved1DArray;
+            break;
+         case 6:
+            if (!ctx->Extensions.MESA_texture_array)
+               continue;
+            target = GL_TEXTURE_2D_ARRAY_EXT;
+            obj = &unit->Saved2DArray;
+            break;
          default:
             ; /* silence warnings */
          }
@@ -759,7 +781,8 @@ pop_texture_group(GLcontext *ctx, const struct gl_texture_attrib *texAttrib)
          _mesa_TexParameterf(target, GL_TEXTURE_MIN_LOD, obj->MinLod);
          _mesa_TexParameterf(target, GL_TEXTURE_MAX_LOD, obj->MaxLod);
          _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, obj->BaseLevel);
-         _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, obj->MaxLevel);
+         if (target != GL_TEXTURE_RECTANGLE_ARB)
+            _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, obj->MaxLevel);
          if (ctx->Extensions.EXT_texture_filter_anisotropic) {
             _mesa_TexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
                                 obj->MaxAnisotropy);
@@ -851,8 +874,36 @@ _mesa_PopAttrib(void)
                                (GLboolean) (color->ColorMask[1] != 0),
                                (GLboolean) (color->ColorMask[2] != 0),
                                (GLboolean) (color->ColorMask[3] != 0));
-               _mesa_drawbuffers(ctx, ctx->Const.MaxDrawBuffers,
-                                 color->DrawBuffer, NULL);
+               {
+                  /* Need to determine if more than one color output is
+                   * specified.  If so, call glDrawBuffersARB, else call
+                   * glDrawBuffer().  This is a subtle, but essential point
+                   * since GL_FRONT (for example) is illegal for the former
+                   * function, but legal for the later.
+                   */
+                  GLboolean multipleBuffers = GL_FALSE;
+                  if (ctx->Extensions.ARB_draw_buffers) {
+                     GLuint i;
+                     for (i = 1; i < ctx->Const.MaxDrawBuffers; i++) {
+                        if (color->DrawBuffer[i] != GL_NONE) {
+                           multipleBuffers = GL_TRUE;
+                           break;
+                        }
+                     }
+                  }
+                  /* Call the API_level functions, not _mesa_drawbuffers()
+                   * since we need to do error checking on the pop'd
+                   * GL_DRAW_BUFFER.
+                   * Ex: if GL_FRONT were pushed, but we're popping with a
+                   * user FBO bound, GL_FRONT will be illegal and we'll need
+                   * to record that error.  Per OpenGL ARB decision.
+                   */
+                  if (multipleBuffers)
+                     _mesa_DrawBuffersARB(ctx->Const.MaxDrawBuffers,
+                                          color->DrawBuffer);
+                  else
+                     _mesa_DrawBuffer(color->DrawBuffer[0]);
+               }
                _mesa_set_enable(ctx, GL_ALPHA_TEST, color->AlphaEnabled);
                _mesa_AlphaFunc(color->AlphaFunc, color->AlphaRef);
                _mesa_set_enable(ctx, GL_BLEND, color->BlendEnabled);
@@ -976,9 +1027,6 @@ _mesa_PopAttrib(void)
                                  (GLfloat) light->Model.TwoSide);
                _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL,
                                  (GLfloat) light->Model.ColorControl);
-               /* materials */
-               MEMCPY(&ctx->Light.Material, &light->Material,
-                      sizeof(struct gl_material));
                /* shade model */
                _mesa_ShadeModel(light->ShadeModel);
                /* color material */
@@ -986,6 +1034,9 @@ _mesa_PopAttrib(void)
                                    light->ColorMaterialMode);
                _mesa_set_enable(ctx, GL_COLOR_MATERIAL,
                                 light->ColorMaterialEnabled);
+               /* materials */
+               MEMCPY(&ctx->Light.Material, &light->Material,
+                      sizeof(struct gl_material));
             }
             break;
          case GL_LINE_BIT:
@@ -1185,17 +1236,17 @@ static void
 adjust_buffer_object_ref_counts(struct gl_array_attrib *array, GLint step)
 {
    GLuint i;
-   array->Vertex.BufferObj->RefCount += step;
-   array->Normal.BufferObj->RefCount += step;
-   array->Color.BufferObj->RefCount += step;
-   array->SecondaryColor.BufferObj->RefCount += step;
-   array->FogCoord.BufferObj->RefCount += step;
-   array->Index.BufferObj->RefCount += step;
-   array->EdgeFlag.BufferObj->RefCount += step;
+   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->TexCoord[i].BufferObj->RefCount += step;
+      array->ArrayObj->TexCoord[i].BufferObj->RefCount += step;
    for (i = 0; i < VERT_ATTRIB_MAX; i++)
-      array->VertexAttrib[i].BufferObj->RefCount += step;
+      array->ArrayObj->VertexAttrib[i].BufferObj->RefCount += step;
 
    array->ArrayBufferObj->RefCount += step;
    array->ElementArrayBufferObj->RefCount += step;
@@ -1247,8 +1298,22 @@ _mesa_PushClientAttrib(GLbitfield mask)
    }
    if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
       struct gl_array_attrib *attr;
+      struct gl_array_object *obj;
+
       attr = MALLOC_STRUCT( gl_array_attrib );
+      obj = MALLOC_STRUCT( gl_array_object );
+
+#if FEATURE_ARB_vertex_buffer_object
+      /* increment ref counts since we're copying pointers to these objects */
+      ctx->Array.ArrayBufferObj->RefCount++;
+      ctx->Array.ElementArrayBufferObj->RefCount++;
+#endif
+
       MEMCPY( attr, &ctx->Array, sizeof(struct gl_array_attrib) );
+      MEMCPY( obj, ctx->Array.ArrayObj, sizeof(struct gl_array_object) );
+
+      attr->ArrayObj = obj;
+
       newnode = new_attrib_node( GL_CLIENT_VERTEX_ARRAY_BIT );
       newnode->data = attr;
       newnode->next = head;
@@ -1306,13 +1371,38 @@ _mesa_PopClientAttrib(void)
                     sizeof(struct gl_pixelstore_attrib) );
            ctx->NewState |= _NEW_PACKUNPACK;
             break;
-         case GL_CLIENT_VERTEX_ARRAY_BIT:
+         case GL_CLIENT_VERTEX_ARRAY_BIT: {
+           struct gl_array_attrib * data =
+             (struct gl_array_attrib *) attr->data;
+
             adjust_buffer_object_ref_counts(&ctx->Array, -1);
-            MEMCPY( &ctx->Array, attr->data,
-                   sizeof(struct gl_array_attrib) );
-            /* decrement reference counts on buffer objects */
+        
+            ctx->Array.ActiveTexture = data->ActiveTexture;
+           ctx->Array.LockFirst = data->LockFirst;
+           ctx->Array.LockCount = data->LockCount;
+
+           _mesa_BindVertexArrayAPPLE( data->ArrayObj->Name );
+           
+#if FEATURE_ARB_vertex_buffer_object
+            _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB,
+                                data->ArrayBufferObj->Name);
+            _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
+                                data->ElementArrayBufferObj->Name);
+#endif
+
+           MEMCPY( ctx->Array.ArrayObj, data->ArrayObj,
+                   sizeof( struct gl_array_object ) );
+
+           FREE( data->ArrayObj );
+           
+           /* FIXME: Should some bits in ctx->Array->NewState also be set
+            * FIXME: here?  It seems like it should be set to inclusive-or
+            * FIXME: of the old ArrayObj->_Enabled and the new _Enabled.
+            */
+
            ctx->NewState |= _NEW_ARRAY;
             break;
+        }
          default:
             _mesa_problem( ctx, "Bad attrib flag in PopClientAttrib");
             break;