Minor tweaks to help out at a driver level.
[mesa.git] / src / mesa / main / attrib.c
index 2ebaaf734148c8f270d21a9b07cd60f860a9a3cb..62d968a32faf2c696abf5f24fafffc999dc160be 100644 (file)
@@ -1,10 +1,9 @@
-/* $Id: attrib.c,v 1.71 2002/09/06 02:56:08 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"),
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
-
-#ifdef PC_HEADER
-#include "all.h"
-#else
 #include "glheader.h"
+#include "imports.h"
 #include "accum.h"
 #include "attrib.h"
 #include "blend.h"
 #include "buffers.h"
 #include "colormac.h"
+#include "colortab.h"
 #include "context.h"
 #include "depth.h"
 #include "enable.h"
@@ -43,7 +40,6 @@
 #include "light.h"
 #include "lines.h"
 #include "matrix.h"
-#include "mem.h"
 #include "points.h"
 #include "polygon.h"
 #include "simple_list.h"
@@ -52,9 +48,6 @@
 #include "texstate.h"
 #include "mtypes.h"
 #include "math/m_xform.h"
-#endif
-
-
 
 
 /*
@@ -72,7 +65,7 @@ new_attrib_node( GLbitfield kind )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_PushAttrib(GLbitfield mask)
 {
    struct gl_attrib_node *newnode;
@@ -144,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;
@@ -202,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;
@@ -421,12 +418,20 @@ pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable)
    for (i=0;i<MAX_CLIP_PLANES;i++) {
       const GLuint mask = 1 << i;
       if ((ctx->Transform.ClipPlanesEnabled & mask) != (enable->ClipPlanes & mask))
-         _mesa_set_enable(ctx, (GLenum) (GL_CLIP_PLANE0 + i),
-                          (enable->ClipPlanes & mask) ? GL_TRUE : GL_FALSE);
+         _mesa_set_enable(ctx, (GLenum) (GL_CLIP_PLANE0 + i),
+                          (GLboolean) ((enable->ClipPlanes & mask) ? GL_TRUE : GL_FALSE));
    }
 
    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);
@@ -497,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);
    }
@@ -588,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) {
@@ -620,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);
@@ -739,7 +751,7 @@ pop_texture_group(GLcontext *ctx, const struct gl_texture_attrib *texAttrib)
          }
          if (ctx->Extensions.SGIX_shadow_ambient) {
             _mesa_TexParameterf(target, GL_SHADOW_AMBIENT_SGIX,
-                                CHAN_TO_FLOAT(obj->ShadowAmbient));
+                                obj->ShadowAmbient);
          }
 
       }
@@ -771,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;
@@ -809,10 +821,10 @@ _mesa_PopAttrib(void)
                const struct gl_colorbuffer_attrib *color;
                color = (const struct gl_colorbuffer_attrib *) attr->data;
                _mesa_ClearIndex((GLfloat) color->ClearIndex);
-               _mesa_ClearColor(CHAN_TO_FLOAT(color->ClearColor[0]),
-                                CHAN_TO_FLOAT(color->ClearColor[1]),
-                                CHAN_TO_FLOAT(color->ClearColor[2]),
-                                CHAN_TO_FLOAT(color->ClearColor[3]));
+               _mesa_ClearColor(color->ClearColor[0],
+                                color->ClearColor[1],
+                                color->ClearColor[2],
+                                color->ClearColor[3]);
                _mesa_IndexMask(color->IndexMask);
                _mesa_ColorMask((GLboolean) (color->ColorMask[0] != 0),
                                (GLboolean) (color->ColorMask[1] != 0),
@@ -820,8 +832,7 @@ _mesa_PopAttrib(void)
                                (GLboolean) (color->ColorMask[3] != 0));
                _mesa_DrawBuffer(color->DrawBuffer);
                _mesa_set_enable(ctx, GL_ALPHA_TEST, color->AlphaEnabled);
-               _mesa_AlphaFunc(color->AlphaFunc,
-                               CHAN_TO_FLOAT(color->AlphaRef));
+               _mesa_AlphaFunc(color->AlphaFunc, color->AlphaRef);
                _mesa_set_enable(ctx, GL_BLEND, color->BlendEnabled);
                _mesa_BlendFuncSeparateEXT(color->BlendSrcRGB,
                                           color->BlendDstRGB,
@@ -943,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 */
@@ -977,13 +988,18 @@ _mesa_PopAttrib(void)
                point = (const struct gl_point_attrib *) attr->data;
                _mesa_PointSize(point->Size);
                _mesa_set_enable(ctx, GL_POINT_SMOOTH, point->SmoothFlag);
-               _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT,
-                                         point->Params);
-               _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT, point->MinSize);
-               _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT, point->MaxSize);
-               _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT,
-                                        point->Threshold);
-               if (ctx->Extensions.NV_point_sprite) {
+               if (ctx->Extensions.EXT_point_parameters) {
+                  _mesa_PointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT,
+                                            point->Params);
+                  _mesa_PointParameterfEXT(GL_POINT_SIZE_MIN_EXT,
+                                           point->MinSize);
+                  _mesa_PointParameterfEXT(GL_POINT_SIZE_MAX_EXT,
+                                           point->MaxSize);
+                  _mesa_PointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT,
+                                           point->Threshold);
+               }
+               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,
@@ -1122,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;
@@ -1174,7 +1190,7 @@ _mesa_PushClientAttrib(GLbitfield mask)
 
 
 
-void
+void GLAPIENTRY
 _mesa_PopClientAttrib(void)
 {
    struct gl_attrib_node *attr, *next;
@@ -1218,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;
+}