Minor tweaks to help out at a driver level.
[mesa.git] / src / mesa / main / attrib.c
index aabea8c066a9659a3ed1cc79c72777c6d582656e..62d968a32faf2c696abf5f24fafffc999dc160be 100644 (file)
@@ -1,10 +1,9 @@
-/* $Id: attrib.c,v 1.75 2002/10/24 23:57:19 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  4.1
+ * Version:  5.1
  *
- * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2003  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"),
@@ -31,6 +30,7 @@
 #include "blend.h"
 #include "buffers.h"
 #include "colormac.h"
+#include "colortab.h"
 #include "context.h"
 #include "depth.h"
 #include "enable.h"
@@ -65,7 +65,7 @@ new_attrib_node( GLbitfield kind )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_PushAttrib(GLbitfield mask)
 {
    struct gl_attrib_node *newnode;
@@ -137,6 +137,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;
       attr->Convolution1D = ctx->Pixel.Convolution1DEnabled;
       attr->Convolution2D = ctx->Pixel.Convolution2DEnabled;
       attr->Separable2D = ctx->Pixel.Separable2DEnabled;
@@ -195,6 +198,7 @@ _mesa_PushAttrib(GLbitfield mask)
       for (i=0; i<MAX_TEXTURE_UNITS; i++) {
          attr->Texture[i] = ctx->Texture.Unit[i].Enabled;
          attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled;
+         attr->TextureColorTable[i] = ctx->Texture.Unit[i].ColorTableEnabled;
       }
       /* GL_NV_vertex_program */
       attr->VertexProgram = ctx->VertexProgram.Enabled;
@@ -420,6 +424,14 @@ 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,
+                   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,
+                   GL_POST_CONVOLUTION_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);
@@ -490,7 +502,7 @@ pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable)
                    GL_POINT_SMOOTH);
    TEST_AND_UPDATE(ctx->Point.SmoothFlag, enable->PointSmooth,
                    GL_POINT_SMOOTH);
-   if (ctx->Extensions.NV_point_sprite) {
+   if (ctx->Extensions.NV_point_sprite || ctx->Extensions.ARB_point_sprite) {
       TEST_AND_UPDATE(ctx->Point.PointSprite, enable->PointSprite,
                       GL_POINT_SPRITE_NV);
    }
@@ -581,6 +593,9 @@ pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable)
                (*ctx->Driver.Enable)( ctx, GL_TEXTURE_GEN_Q, GL_FALSE);
          }
       }
+
+      /* GL_SGI_texture_color_table */
+      ctx->Texture.Unit[i].ColorTableEnabled = enable->TextureColorTable[i];
    }
 
    if (ctx->Driver.ActiveTexture) {
@@ -613,6 +628,10 @@ pop_texture_group(GLcontext *ctx, const struct gl_texture_attrib *texAttrib)
          _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE_NV,
              (GLboolean) (unit->Enabled & TEXTURE_RECT_BIT ? GL_TRUE : GL_FALSE));
       }
+      if (ctx->Extensions.SGI_texture_color_table) {
+         _mesa_set_enable(ctx, GL_TEXTURE_COLOR_TABLE_SGI,
+                          unit->ColorTableEnabled);
+      }
       _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->EnvMode);
       _mesa_TexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, unit->EnvColor);
       _mesa_TexGeni(GL_S, GL_TEXTURE_GEN_MODE, unit->GenModeS);
@@ -764,7 +783,7 @@ pop_texture_group(GLcontext *ctx, const struct gl_texture_attrib *texAttrib)
  * We could at least check if the value to restore equals the current value
  * and then skip the Mesa call.
  */
-void
+void GLAPIENTRY
 _mesa_PopAttrib(void)
 {
    struct gl_attrib_node *attr, *next;
@@ -935,8 +954,8 @@ _mesa_PopAttrib(void)
                _mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL,
                                  (GLfloat) light->Model.ColorControl);
                /* materials */
-               MEMCPY(ctx->Light.Material, light->Material,
-                      2 * sizeof(struct gl_material));
+               MEMCPY(&ctx->Light.Material, &light->Material,
+                      sizeof(struct gl_material));
                /* shade model */
                _mesa_ShadeModel(light->ShadeModel);
                /* color material */
@@ -979,7 +998,8 @@ _mesa_PopAttrib(void)
                   _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT,
                                            point->Threshold);
                }
-               if (ctx->Extensions.NV_point_sprite) {
+               if (ctx->Extensions.NV_point_sprite
+                  || ctx->Extensions.ARB_point_sprite) {
                   GLuint u;
                   for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
                      _mesa_TexEnvi(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV,
@@ -1118,7 +1138,7 @@ _mesa_PopAttrib(void)
 #define GL_CLIENT_UNPACK_BIT (1<<21)
 
 
-void
+void GLAPIENTRY
 _mesa_PushClientAttrib(GLbitfield mask)
 {
    struct gl_attrib_node *newnode;
@@ -1170,7 +1190,7 @@ _mesa_PushClientAttrib(GLbitfield mask)
 
 
 
-void
+void GLAPIENTRY
 _mesa_PopClientAttrib(void)
 {
    struct gl_attrib_node *attr, *next;
@@ -1214,3 +1234,11 @@ _mesa_PopClientAttrib(void)
       attr = next;
    }
 }
+
+
+void _mesa_init_attrib( GLcontext *ctx )
+{
+   /* Renderer and client attribute stacks */
+   ctx->AttribStackDepth = 0;
+   ctx->ClientAttribStackDepth = 0;
+}