Added state debugging option (SAVAGE_DEBUG=state).
[mesa.git] / src / mesa / main / light.c
index 201938d4aa73b69978c690a2069b9caadabfd907..0cf2635765f112f9639b5d2384f726dccc1b039d 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: light.c,v 1.54 2002/10/25 21:06:29 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  4.1
+ * Version:  6.1
  *
- * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  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"),
 
 #include "glheader.h"
 #include "imports.h"
-#include "colormac.h"
 #include "context.h"
 #include "enums.h"
 #include "light.h"
 #include "macros.h"
-#include "mmath.h"
 #include "simple_list.h"
 #include "mtypes.h"
-#include "math/m_xform.h"
 #include "math/m_matrix.h"
 
 
-/* XXX this is a bit of a hack needed for compilation within XFree86 */
-#ifndef FLT_MIN
-#define FLT_MIN 1e-37
-#endif
-
-
-void
+void GLAPIENTRY
 _mesa_ShadeModel( GLenum mode )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -70,15 +59,14 @@ _mesa_ShadeModel( GLenum mode )
 }
 
 
-
-void
+void GLAPIENTRY
 _mesa_Lightf( GLenum light, GLenum pname, GLfloat param )
 {
    _mesa_Lightfv( light, pname, &param );
 }
 
 
-void
+void GLAPIENTRY
 _mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -137,7 +125,7 @@ _mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params )
       break;
    }
    case GL_SPOT_EXPONENT:
-      if (params[0]<0.0 || params[0]>128.0) {
+      if (params[0]<0.0 || params[0]>ctx->Const.MaxSpotExponent) {
         _mesa_error( ctx, GL_INVALID_VALUE, "glLight" );
         return;
       }
@@ -204,14 +192,14 @@ _mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_Lighti( GLenum light, GLenum pname, GLint param )
 {
    _mesa_Lightiv( light, pname, &param );
 }
 
 
-void
+void GLAPIENTRY
 _mesa_Lightiv( GLenum light, GLenum pname, const GLint *params )
 {
    GLfloat fparam[4];
@@ -253,7 +241,7 @@ _mesa_Lightiv( GLenum light, GLenum pname, const GLint *params )
 
 
 
-void
+void GLAPIENTRY
 _mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -303,8 +291,7 @@ _mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params )
 }
 
 
-
-void
+void GLAPIENTRY
 _mesa_GetLightiv( GLenum light, GLenum pname, GLint *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -374,7 +361,7 @@ _mesa_GetLightiv( GLenum light, GLenum pname, GLint *params )
 /**********************************************************************/
 
 
-void
+void GLAPIENTRY
 _mesa_LightModelfv( GLenum pname, const GLfloat *params )
 {
    GLenum newenum;
@@ -422,14 +409,6 @@ _mesa_LightModelfv( GLenum pname, const GLfloat *params )
            return;
         FLUSH_VERTICES(ctx, _NEW_LIGHT);
         ctx->Light.Model.ColorControl = newenum;
-
-        if ((ctx->Light.Enabled &&
-             ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR)
-            || ctx->Fog.ColorSumEnabled)
-           ctx->_TriangleCaps |= DD_SEPARATE_SPECULAR;
-        else
-           ctx->_TriangleCaps &= ~DD_SEPARATE_SPECULAR;
-
          break;
       default:
          _mesa_error( ctx, GL_INVALID_ENUM, "glLightModel(pname=0x%x)", pname );
@@ -441,7 +420,7 @@ _mesa_LightModelfv( GLenum pname, const GLfloat *params )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_LightModeliv( GLenum pname, const GLint *params )
 {
    GLfloat fparam[4];
@@ -466,14 +445,14 @@ _mesa_LightModeliv( GLenum pname, const GLint *params )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_LightModeli( GLenum pname, GLint param )
 {
    _mesa_LightModeliv( pname, &param );
 }
 
 
-void
+void GLAPIENTRY
 _mesa_LightModelf( GLenum pname, GLfloat param )
 {
    _mesa_LightModelfv( pname, &param );
@@ -497,26 +476,26 @@ _mesa_material_bitmask( GLcontext *ctx, GLenum face, GLenum pname,
    /* Make a bitmask indicating what material attribute(s) we're updating */
    switch (pname) {
       case GL_EMISSION:
-         bitmask |= FRONT_EMISSION_BIT | BACK_EMISSION_BIT;
+         bitmask |= MAT_BIT_FRONT_EMISSION | MAT_BIT_BACK_EMISSION;
          break;
       case GL_AMBIENT:
-         bitmask |= FRONT_AMBIENT_BIT | BACK_AMBIENT_BIT;
+         bitmask |= MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT;
          break;
       case GL_DIFFUSE:
-         bitmask |= FRONT_DIFFUSE_BIT | BACK_DIFFUSE_BIT;
+         bitmask |= MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE;
          break;
       case GL_SPECULAR:
-         bitmask |= FRONT_SPECULAR_BIT | BACK_SPECULAR_BIT;
+         bitmask |= MAT_BIT_FRONT_SPECULAR | MAT_BIT_BACK_SPECULAR;
          break;
       case GL_SHININESS:
-         bitmask |= FRONT_SHININESS_BIT | BACK_SHININESS_BIT;
+         bitmask |= MAT_BIT_FRONT_SHININESS | MAT_BIT_BACK_SHININESS;
          break;
       case GL_AMBIENT_AND_DIFFUSE:
-         bitmask |= FRONT_AMBIENT_BIT | BACK_AMBIENT_BIT;
-         bitmask |= FRONT_DIFFUSE_BIT | BACK_DIFFUSE_BIT;
+         bitmask |= MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT;
+         bitmask |= MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE;
          break;
       case GL_COLOR_INDEXES:
-         bitmask |= FRONT_INDEXES_BIT  | BACK_INDEXES_BIT;
+         bitmask |= MAT_BIT_FRONT_INDEXES  | MAT_BIT_BACK_INDEXES;
          break;
       default:
          _mesa_error( ctx, GL_INVALID_ENUM, where );
@@ -543,306 +522,134 @@ _mesa_material_bitmask( GLcontext *ctx, GLenum face, GLenum pname,
 }
 
 
-/* Perform a straight copy between pairs of materials.
+
+/* Perform a straight copy between materials.
  */
-void _mesa_copy_material_pairs( struct gl_material dst[2],
-                            const struct gl_material src[2],
-                            GLuint bitmask )
+void
+_mesa_copy_materials( struct gl_material *dst,
+                      const struct gl_material *src,
+                      GLuint bitmask )
 {
-   if (bitmask & FRONT_EMISSION_BIT) {
-      COPY_4FV( dst[0].Emission, src[0].Emission );
-   }
-   if (bitmask & BACK_EMISSION_BIT) {
-      COPY_4FV( dst[1].Emission, src[1].Emission );
-   }
-   if (bitmask & FRONT_AMBIENT_BIT) {
-      COPY_4FV( dst[0].Ambient, src[0].Ambient );
-   }
-   if (bitmask & BACK_AMBIENT_BIT) {
-      COPY_4FV( dst[1].Ambient, src[1].Ambient );
-   }
-   if (bitmask & FRONT_DIFFUSE_BIT) {
-      COPY_4FV( dst[0].Diffuse, src[0].Diffuse );
-   }
-   if (bitmask & BACK_DIFFUSE_BIT) {
-      COPY_4FV( dst[1].Diffuse, src[1].Diffuse );
-   }
-   if (bitmask & FRONT_SPECULAR_BIT) {
-      COPY_4FV( dst[0].Specular, src[0].Specular );
-   }
-   if (bitmask & BACK_SPECULAR_BIT) {
-      COPY_4FV( dst[1].Specular, src[1].Specular );
-   }
-   if (bitmask & FRONT_SHININESS_BIT) {
-      dst[0].Shininess = src[0].Shininess;
-   }
-   if (bitmask & BACK_SHININESS_BIT) {
-      dst[1].Shininess = src[1].Shininess;
-   }
-   if (bitmask & FRONT_INDEXES_BIT) {
-      dst[0].AmbientIndex = src[0].AmbientIndex;
-      dst[0].DiffuseIndex = src[0].DiffuseIndex;
-      dst[0].SpecularIndex = src[0].SpecularIndex;
-   }
-   if (bitmask & BACK_INDEXES_BIT) {
-      dst[1].AmbientIndex = src[1].AmbientIndex;
-      dst[1].DiffuseIndex = src[1].DiffuseIndex;
-      dst[1].SpecularIndex = src[1].SpecularIndex;
-   }
+   int i;
+
+   for (i = 0 ; i < MAT_ATTRIB_MAX ; i++) 
+      if (bitmask & (1<<i))
+        COPY_4FV( dst->Attrib[i], src->Attrib[i] );
 }
 
 
-/*
- * Check if the global material has to be updated with info that was
- * associated with a vertex via glMaterial.
- * This function is used when any material values get changed between
- * glBegin/glEnd either by calling glMaterial() or by calling glColor()
- * when GL_COLOR_MATERIAL is enabled.
- *
- * src[0] is front material, src[1] is back material
- *
- * Additionally keeps the precomputed lighting state uptodate.
+
+/* Update derived values following a change in ctx->Light.Material
  */
-void _mesa_update_material( GLcontext *ctx,
-                        const struct gl_material src[2],
-                        GLuint bitmask )
+void
+_mesa_update_material( GLcontext *ctx, GLuint bitmask )
 {
    struct gl_light *light, *list = &ctx->Light.EnabledList;
+   GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
 
-   if (ctx->Light.ColorMaterialEnabled)
-      bitmask &= ~ctx->Light.ColorMaterialBitmask;
-
-   if (MESA_VERBOSE&VERBOSE_IMMEDIATE)
+   if (MESA_VERBOSE&VERBOSE_IMMEDIATE) 
       _mesa_debug(ctx, "_mesa_update_material, mask 0x%x\n", bitmask);
 
    if (!bitmask)
       return;
 
-   /* update material emission */
-   if (bitmask & FRONT_EMISSION_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[0];
-      COPY_4FV( mat->Emission, src[0].Emission );
-   }
-   if (bitmask & BACK_EMISSION_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[1];
-      COPY_4FV( mat->Emission, src[1].Emission );
-   }
-
    /* update material ambience */
-   if (bitmask & FRONT_AMBIENT_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[0];
-      COPY_4FV( mat->Ambient, src[0].Ambient );
+   if (bitmask & MAT_BIT_FRONT_AMBIENT) {
       foreach (light, list) {
-         SCALE_3V( light->_MatAmbient[0], light->Ambient, src[0].Ambient);
+         SCALE_3V( light->_MatAmbient[0], light->Ambient, 
+                  mat[MAT_ATTRIB_FRONT_AMBIENT]);
       }
    }
-   if (bitmask & BACK_AMBIENT_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[1];
-      COPY_4FV( mat->Ambient, src[1].Ambient );
+
+   if (bitmask & MAT_BIT_BACK_AMBIENT) {
       foreach (light, list) {
-         SCALE_3V( light->_MatAmbient[1], light->Ambient, src[1].Ambient);
+         SCALE_3V( light->_MatAmbient[1], light->Ambient, 
+                  mat[MAT_ATTRIB_BACK_AMBIENT]);
       }
    }
 
    /* update BaseColor = emission + scene's ambience * material's ambience */
-   if (bitmask & (FRONT_EMISSION_BIT | FRONT_AMBIENT_BIT)) {
-      struct gl_material *mat = &ctx->Light.Material[0];
-      COPY_3V( ctx->Light._BaseColor[0], mat->Emission );
-      ACC_SCALE_3V( ctx->Light._BaseColor[0], mat->Ambient,
+   if (bitmask & (MAT_BIT_FRONT_EMISSION | MAT_BIT_FRONT_AMBIENT)) {
+      COPY_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_EMISSION] );
+      ACC_SCALE_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_AMBIENT],
                    ctx->Light.Model.Ambient );
    }
-   if (bitmask & (BACK_EMISSION_BIT | BACK_AMBIENT_BIT)) {
-      struct gl_material *mat = &ctx->Light.Material[1];
-      COPY_3V( ctx->Light._BaseColor[1], mat->Emission );
-      ACC_SCALE_3V( ctx->Light._BaseColor[1], mat->Ambient,
+
+   if (bitmask & (MAT_BIT_BACK_EMISSION | MAT_BIT_BACK_AMBIENT)) {
+      COPY_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_EMISSION] );
+      ACC_SCALE_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_AMBIENT],
                    ctx->Light.Model.Ambient );
    }
 
    /* update material diffuse values */
-   if (bitmask & FRONT_DIFFUSE_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[0];
-      COPY_4FV( mat->Diffuse, src[0].Diffuse );
+   if (bitmask & MAT_BIT_FRONT_DIFFUSE) {
       foreach (light, list) {
-        SCALE_3V( light->_MatDiffuse[0], light->Diffuse, mat->Diffuse );
+        SCALE_3V( light->_MatDiffuse[0], light->Diffuse, 
+                  mat[MAT_ATTRIB_FRONT_DIFFUSE] );
       }
    }
-   if (bitmask & BACK_DIFFUSE_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[1];
-      COPY_4FV( mat->Diffuse, src[1].Diffuse );
+
+   if (bitmask & MAT_BIT_BACK_DIFFUSE) {
       foreach (light, list) {
-        SCALE_3V( light->_MatDiffuse[1], light->Diffuse, mat->Diffuse );
+        SCALE_3V( light->_MatDiffuse[1], light->Diffuse, 
+                  mat[MAT_ATTRIB_BACK_DIFFUSE] );
       }
    }
 
    /* update material specular values */
-   if (bitmask & FRONT_SPECULAR_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[0];
-      COPY_4FV( mat->Specular, src[0].Specular );
+   if (bitmask & MAT_BIT_FRONT_SPECULAR) {
       foreach (light, list) {
-        SCALE_3V( light->_MatSpecular[0], light->Specular, mat->Specular);
+        SCALE_3V( light->_MatSpecular[0], light->Specular, 
+                  mat[MAT_ATTRIB_FRONT_SPECULAR]);
       }
    }
-   if (bitmask & BACK_SPECULAR_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[1];
-      COPY_4FV( mat->Specular, src[1].Specular );
+
+   if (bitmask & MAT_BIT_BACK_SPECULAR) {
       foreach (light, list) {
-        SCALE_3V( light->_MatSpecular[1], light->Specular, mat->Specular);
+        SCALE_3V( light->_MatSpecular[1], light->Specular,
+                  mat[MAT_ATTRIB_BACK_SPECULAR]);
       }
    }
 
-   if (bitmask & FRONT_SHININESS_BIT) {
-      ctx->Light.Material[0].Shininess = src[0].Shininess;
+   if (bitmask & MAT_BIT_FRONT_SHININESS) {
       _mesa_invalidate_shine_table( ctx, 0 );
    }
-   if (bitmask & BACK_SHININESS_BIT) {
-      ctx->Light.Material[1].Shininess = src[1].Shininess;
-      _mesa_invalidate_shine_table( ctx, 1 );
-   }
-
-   if (bitmask & FRONT_INDEXES_BIT) {
-      ctx->Light.Material[0].AmbientIndex = src[0].AmbientIndex;
-      ctx->Light.Material[0].DiffuseIndex = src[0].DiffuseIndex;
-      ctx->Light.Material[0].SpecularIndex = src[0].SpecularIndex;
-   }
-   if (bitmask & BACK_INDEXES_BIT) {
-      ctx->Light.Material[1].AmbientIndex = src[1].AmbientIndex;
-      ctx->Light.Material[1].DiffuseIndex = src[1].DiffuseIndex;
-      ctx->Light.Material[1].SpecularIndex = src[1].SpecularIndex;
-   }
 
-   if (0) {
-      struct gl_material *mat = &ctx->Light.Material[0];
-      _mesa_debug(ctx, "update_mat  emission : %f %f %f\n",
-                  mat->Emission[0], mat->Emission[1], mat->Emission[2]);
-      _mesa_debug(ctx, "update_mat  specular : %f %f %f\n",
-                  mat->Specular[0], mat->Specular[1], mat->Specular[2]);
-      _mesa_debug(ctx, "update_mat  diffuse : %f %f %f\n",
-                  mat->Diffuse[0], mat->Diffuse[1], mat->Diffuse[2]);
-      _mesa_debug(ctx, "update_mat  ambient : %f %f %f\n",
-                  mat->Ambient[0], mat->Ambient[1], mat->Ambient[2]);
+   if (bitmask & MAT_BIT_BACK_SHININESS) {
+      _mesa_invalidate_shine_table( ctx, 1 );
    }
 }
 
 
-
-
-
-
-
 /*
  * Update the current materials from the given rgba color
  * according to the bitmask in ColorMaterialBitmask, which is
  * set by glColorMaterial().
  */
-void _mesa_update_color_material( GLcontext *ctx,
-                                 const GLfloat color[4] )
+void
+_mesa_update_color_material( GLcontext *ctx, const GLfloat color[4] )
 {
-   struct gl_light *light, *list = &ctx->Light.EnabledList;
    GLuint bitmask = ctx->Light.ColorMaterialBitmask;
+   struct gl_material *mat = &ctx->Light.Material;
+   int i;
 
-   if (MESA_VERBOSE&VERBOSE_IMMEDIATE)
-      _mesa_debug(ctx, "_mesa_update_color_material, mask 0x%x\n", bitmask);
-
-   /* update emissive colors */
-   if (bitmask & FRONT_EMISSION_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[0];
-      COPY_4FV( mat->Emission, color );
-   }
-
-   if (bitmask & BACK_EMISSION_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[1];
-      COPY_4FV( mat->Emission, color );
-   }
-
-   /* update light->_MatAmbient = light's ambient * material's ambient */
-   if (bitmask & FRONT_AMBIENT_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[0];
-      foreach (light, list) {
-         SCALE_3V( light->_MatAmbient[0], light->Ambient, color);
-      }
-      COPY_4FV( mat->Ambient, color );
-   }
-
-   if (bitmask & BACK_AMBIENT_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[1];
-      foreach (light, list) {
-         SCALE_3V( light->_MatAmbient[1], light->Ambient, color);
-      }
-      COPY_4FV( mat->Ambient, color );
-   }
+   for (i = 0 ; i < MAT_ATTRIB_MAX ; i++) 
+      if (bitmask & (1<<i))
+        COPY_4FV( mat->Attrib[i], color );
 
-   /* update BaseColor = emission + scene's ambience * material's ambience */
-   if (bitmask & (FRONT_EMISSION_BIT | FRONT_AMBIENT_BIT)) {
-      struct gl_material *mat = &ctx->Light.Material[0];
-      COPY_3V( ctx->Light._BaseColor[0], mat->Emission );
-      ACC_SCALE_3V( ctx->Light._BaseColor[0], mat->Ambient, ctx->Light.Model.Ambient );
-   }
-
-   if (bitmask & (BACK_EMISSION_BIT | BACK_AMBIENT_BIT)) {
-      struct gl_material *mat = &ctx->Light.Material[1];
-      COPY_3V( ctx->Light._BaseColor[1], mat->Emission );
-      ACC_SCALE_3V( ctx->Light._BaseColor[1], mat->Ambient, ctx->Light.Model.Ambient );
-   }
-
-   /* update light->_MatDiffuse = light's diffuse * material's diffuse */
-   if (bitmask & FRONT_DIFFUSE_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[0];
-      COPY_4FV( mat->Diffuse, color );
-      foreach (light, list) {
-        SCALE_3V( light->_MatDiffuse[0], light->Diffuse, mat->Diffuse );
-      }
-   }
-
-   if (bitmask & BACK_DIFFUSE_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[1];
-      COPY_4FV( mat->Diffuse, color );
-      foreach (light, list) {
-        SCALE_3V( light->_MatDiffuse[1], light->Diffuse, mat->Diffuse );
-      }
-   }
-
-   /* update light->_MatSpecular = light's specular * material's specular */
-   if (bitmask & FRONT_SPECULAR_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[0];
-      COPY_4FV( mat->Specular, color );
-      foreach (light, list) {
-        ACC_SCALE_3V( light->_MatSpecular[0], light->Specular, mat->Specular);
-      }
-   }
-
-   if (bitmask & BACK_SPECULAR_BIT) {
-      struct gl_material *mat = &ctx->Light.Material[1];
-      COPY_4FV( mat->Specular, color );
-      foreach (light, list) {
-        ACC_SCALE_3V( light->_MatSpecular[1], light->Specular, mat->Specular);
-      }
-   }
-
-   if (0) {
-      struct gl_material *mat = &ctx->Light.Material[0];
-      _mesa_debug(ctx, "update_color_mat  emission : %f %f %f\n",
-                  mat->Emission[0], mat->Emission[1], mat->Emission[2]);
-      _mesa_debug(ctx, "update_color_mat  specular : %f %f %f\n",
-                  mat->Specular[0], mat->Specular[1], mat->Specular[2]);
-      _mesa_debug(ctx, "update_color_mat  diffuse : %f %f %f\n",
-                  mat->Diffuse[0], mat->Diffuse[1], mat->Diffuse[2]);
-      _mesa_debug(ctx, "update_color_mat  ambient : %f %f %f\n",
-                  mat->Ambient[0], mat->Ambient[1], mat->Ambient[2]);
-   }
+   _mesa_update_material( ctx, bitmask );
 }
 
 
-
-
-void
+void GLAPIENTRY
 _mesa_ColorMaterial( GLenum face, GLenum mode )
 {
    GET_CURRENT_CONTEXT(ctx);
    GLuint bitmask;
-   GLuint legal = (FRONT_EMISSION_BIT | BACK_EMISSION_BIT |
-                  FRONT_SPECULAR_BIT | BACK_SPECULAR_BIT |
-                  FRONT_DIFFUSE_BIT  | BACK_DIFFUSE_BIT  |
-                  FRONT_AMBIENT_BIT  | BACK_AMBIENT_BIT);
+   GLuint legal = (MAT_BIT_FRONT_EMISSION | MAT_BIT_BACK_EMISSION |
+                  MAT_BIT_FRONT_SPECULAR | MAT_BIT_BACK_SPECULAR |
+                  MAT_BIT_FRONT_DIFFUSE  | MAT_BIT_BACK_DIFFUSE  |
+                  MAT_BIT_FRONT_AMBIENT  | MAT_BIT_BACK_AMBIENT);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE&VERBOSE_API)
@@ -872,16 +679,16 @@ _mesa_ColorMaterial( GLenum face, GLenum mode )
 }
 
 
-
-
-
-void
+void GLAPIENTRY
 _mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
    GLuint f;
+   GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */
 
+   FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
+
    if (face==GL_FRONT) {
       f = 0;
    }
@@ -892,26 +699,27 @@ _mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params )
       _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(face)" );
       return;
    }
+
    switch (pname) {
       case GL_AMBIENT:
-         COPY_4FV( params, ctx->Light.Material[f].Ambient );
+         COPY_4FV( params, mat[MAT_ATTRIB_AMBIENT(f)] );
          break;
       case GL_DIFFUSE:
-         COPY_4FV( params, ctx->Light.Material[f].Diffuse );
+         COPY_4FV( params, mat[MAT_ATTRIB_DIFFUSE(f)] );
         break;
       case GL_SPECULAR:
-         COPY_4FV( params, ctx->Light.Material[f].Specular );
+         COPY_4FV( params, mat[MAT_ATTRIB_SPECULAR(f)] );
         break;
       case GL_EMISSION:
-        COPY_4FV( params, ctx->Light.Material[f].Emission );
+        COPY_4FV( params, mat[MAT_ATTRIB_EMISSION(f)] );
         break;
       case GL_SHININESS:
-        *params = ctx->Light.Material[f].Shininess;
+        *params = mat[MAT_ATTRIB_SHININESS(f)][0];
         break;
       case GL_COLOR_INDEXES:
-        params[0] = ctx->Light.Material[f].AmbientIndex;
-        params[1] = ctx->Light.Material[f].DiffuseIndex;
-        params[2] = ctx->Light.Material[f].SpecularIndex;
+        params[0] = mat[MAT_ATTRIB_INDEXES(f)][0];
+        params[1] = mat[MAT_ATTRIB_INDEXES(f)][1];
+        params[2] = mat[MAT_ATTRIB_INDEXES(f)][2];
         break;
       default:
          _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
@@ -919,14 +727,16 @@ _mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params )
 }
 
 
-
-void
+void GLAPIENTRY
 _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
 {
    GET_CURRENT_CONTEXT(ctx);
    GLuint f;
+   GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */
 
+   FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
+
    if (face==GL_FRONT) {
       f = 0;
    }
@@ -939,36 +749,36 @@ _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
    }
    switch (pname) {
       case GL_AMBIENT:
-         params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Ambient[0] );
-         params[1] = FLOAT_TO_INT( ctx->Light.Material[f].Ambient[1] );
-         params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Ambient[2] );
-         params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Ambient[3] );
+         params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][0] );
+         params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][1] );
+         params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][2] );
+         params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][3] );
          break;
       case GL_DIFFUSE:
-         params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[0] );
-         params[1] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[1] );
-         params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[2] );
-         params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[3] );
+         params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][0] );
+         params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][1] );
+         params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][2] );
+         params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][3] );
         break;
       case GL_SPECULAR:
-         params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[0] );
-         params[1] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[1] );
-         params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[2] );
-         params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[3] );
+         params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][0] );
+         params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][1] );
+         params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][2] );
+         params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][3] );
         break;
       case GL_EMISSION:
-         params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[0] );
-         params[1] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[1] );
-         params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[2] );
-         params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[3] );
+         params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][0] );
+         params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][1] );
+         params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][2] );
+         params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][3] );
         break;
       case GL_SHININESS:
-         *params = ROUNDF( ctx->Light.Material[f].Shininess );
+         *params = IROUND( mat[MAT_ATTRIB_SHININESS(f)][0] );
         break;
       case GL_COLOR_INDEXES:
-        params[0] = ROUNDF( ctx->Light.Material[f].AmbientIndex );
-        params[1] = ROUNDF( ctx->Light.Material[f].DiffuseIndex );
-        params[2] = ROUNDF( ctx->Light.Material[f].SpecularIndex );
+        params[0] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][0] );
+        params[1] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][1] );
+        params[2] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][2] );
         break;
       default:
          _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
@@ -977,7 +787,6 @@ _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
 
 
 
-
 /**********************************************************************/
 /*****                  Lighting computation                      *****/
 /**********************************************************************/
@@ -1027,7 +836,9 @@ _mesa_invalidate_spot_exp_table( struct gl_light *l )
    l->_SpotExpTable[0][0] = -1;
 }
 
-static void validate_spot_exp_table( struct gl_light *l )
+
+static void
+validate_spot_exp_table( struct gl_light *l )
 {
    GLint i;
    GLdouble exponent = l->SpotExponent;
@@ -1055,24 +866,28 @@ static void validate_spot_exp_table( struct gl_light *l )
 
 
 
-
 /* Calculate a new shine table.  Doing this here saves a branch in
  * lighting, and the cost of doing it early may be partially offset
  * by keeping a MRU cache of shine tables for various shine values.
  */
 void
-_mesa_invalidate_shine_table( GLcontext *ctx, GLuint i )
+_mesa_invalidate_shine_table( GLcontext *ctx, GLuint side )
 {
-   if (ctx->_ShineTable[i])
-      ctx->_ShineTable[i]->refcount--;
-   ctx->_ShineTable[i] = 0;
+   ASSERT(side < 2);
+   if (ctx->_ShineTable[side])
+      ctx->_ShineTable[side]->refcount--;
+   ctx->_ShineTable[side] = 0;
 }
 
-static void validate_shine_table( GLcontext *ctx, GLuint i, GLfloat shininess )
+
+static void
+validate_shine_table( GLcontext *ctx, GLuint side, GLfloat shininess )
 {
    struct gl_shine_tab *list = ctx->_ShineTabList;
    struct gl_shine_tab *s;
 
+   ASSERT(side < 2);
+
    foreach(s, list)
       if ( s->shininess == shininess )
         break;
@@ -1108,25 +923,26 @@ static void validate_shine_table( GLcontext *ctx, GLuint i, GLfloat shininess )
       s->shininess = shininess;
    }
 
-   if (ctx->_ShineTable[i])
-      ctx->_ShineTable[i]->refcount--;
+   if (ctx->_ShineTable[side])
+      ctx->_ShineTable[side]->refcount--;
 
-   ctx->_ShineTable[i] = s;
+   ctx->_ShineTable[side] = s;
    move_to_tail( list, s );
    s->refcount++;
 }
 
+
 void
 _mesa_validate_all_lighting_tables( GLcontext *ctx )
 {
-   GLint i;
+   GLuint i;
    GLfloat shininess;
-
-   shininess = ctx->Light.Material[0].Shininess;
+   
+   shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0];
    if (!ctx->_ShineTable[0] || ctx->_ShineTable[0]->shininess != shininess)
       validate_shine_table( ctx, 0, shininess );
 
-   shininess = ctx->Light.Material[1].Shininess;
+   shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_SHININESS][0];
    if (!ctx->_ShineTable[1] || ctx->_ShineTable[1]->shininess != shininess)
       validate_shine_table( ctx, 1, shininess );
 
@@ -1137,7 +953,6 @@ _mesa_validate_all_lighting_tables( GLcontext *ctx )
 
 
 
-
 /*
  * Examine current lighting parameters to determine if the optimized lighting
  * function can be used.
@@ -1148,15 +963,12 @@ void
 _mesa_update_lighting( GLcontext *ctx )
 {
    struct gl_light *light;
-   ctx->_NeedEyeCoords &= ~NEED_EYE_LIGHT;
-   ctx->_NeedNormals &= ~NEED_NORMALS_LIGHT;
+   ctx->Light._NeedEyeCoords = 0;
    ctx->Light._Flags = 0;
 
    if (!ctx->Light.Enabled)
       return;
 
-   ctx->_NeedNormals |= NEED_NORMALS_LIGHT;
-
    foreach(light, &ctx->Light.EnabledList) {
       ctx->Light._Flags |= light->_Flags;
    }
@@ -1166,9 +978,9 @@ _mesa_update_lighting( GLcontext *ctx )
        ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR ||
        ctx->Light.Model.LocalViewer);
 
-   if ((ctx->Light._Flags & LIGHT_POSITIONAL) ||
-       ctx->Light.Model.LocalViewer)
-      ctx->_NeedEyeCoords |= NEED_EYE_LIGHT;
+   ctx->Light._NeedEyeCoords = ((ctx->Light._Flags & LIGHT_POSITIONAL) ||
+                               ctx->Light.Model.LocalViewer);
+
 
 
    /* XXX: This test is overkill & needs to be fixed both for software and
@@ -1176,7 +988,7 @@ _mesa_update_lighting( GLcontext *ctx )
     * be tested to verify this.
     */
    if (ctx->Light._NeedVertices)
-      ctx->_NeedEyeCoords |= NEED_EYE_LIGHT;
+      ctx->Light._NeedEyeCoords = GL_TRUE;
 
 
    /* Precompute some shading values.  Although we reference
@@ -1185,26 +997,22 @@ _mesa_update_lighting( GLcontext *ctx )
     * are flushed, they will update the derived state at that time.
     */
    if (ctx->Visual.rgbMode) {
-      GLuint sides = ctx->Light.Model.TwoSide ? 2 : 1;
-      GLuint side;
-      for (side=0; side < sides; side++) {
-        struct gl_material *mat = &ctx->Light.Material[side];
-
-        COPY_3V(ctx->Light._BaseColor[side], mat->Emission);
-        ACC_SCALE_3V(ctx->Light._BaseColor[side],
-                     ctx->Light.Model.Ambient,
-                     mat->Ambient);
-      }
-
-      foreach (light, &ctx->Light.EnabledList) {
-        for (side=0; side< sides; side++) {
-           const struct gl_material *mat = &ctx->Light.Material[side];
-           SCALE_3V( light->_MatDiffuse[side], light->Diffuse, mat->Diffuse );
-           SCALE_3V( light->_MatAmbient[side], light->Ambient, mat->Ambient );
-           SCALE_3V( light->_MatSpecular[side], light->Specular,
-                     mat->Specular);
-        }
-      }
+      if (ctx->Light.Model.TwoSide)
+        _mesa_update_material( ctx, 
+                               MAT_BIT_FRONT_EMISSION |
+                               MAT_BIT_FRONT_AMBIENT |
+                               MAT_BIT_FRONT_DIFFUSE | 
+                               MAT_BIT_FRONT_SPECULAR |
+                               MAT_BIT_BACK_EMISSION |
+                               MAT_BIT_BACK_AMBIENT |
+                               MAT_BIT_BACK_DIFFUSE | 
+                               MAT_BIT_BACK_SPECULAR);
+      else
+        _mesa_update_material( ctx, 
+                               MAT_BIT_FRONT_EMISSION |
+                               MAT_BIT_FRONT_AMBIENT |
+                               MAT_BIT_FRONT_DIFFUSE | 
+                               MAT_BIT_FRONT_SPECULAR);
    }
    else {
       static const GLfloat ci[3] = { .30F, .59F, .11F };
@@ -1223,8 +1031,8 @@ _mesa_update_lighting( GLcontext *ctx )
  * Update on (_NEW_MODELVIEW | _NEW_LIGHT) when lighting is enabled.
  * Also update on lighting space changes.
  */
-void
-_mesa_compute_light_positions( GLcontext *ctx )
+static void
+compute_light_positions( GLcontext *ctx )
 {
    struct gl_light *light;
    static const GLfloat eye_z[3] = { 0, 0, 1 };
@@ -1292,3 +1100,217 @@ _mesa_compute_light_positions( GLcontext *ctx )
       }
    }
 }
+
+
+
+static void
+update_modelview_scale( GLcontext *ctx )
+{
+   ctx->_ModelViewInvScale = 1.0F;
+   if (ctx->ModelviewMatrixStack.Top->flags & (MAT_FLAG_UNIFORM_SCALE |
+                              MAT_FLAG_GENERAL_SCALE |
+                              MAT_FLAG_GENERAL_3D |
+                              MAT_FLAG_GENERAL) ) {
+      const GLfloat *m = ctx->ModelviewMatrixStack.Top->inv;
+      GLfloat f = m[2] * m[2] + m[6] * m[6] + m[10] * m[10];
+      if (f < 1e-12) f = 1.0;
+      if (ctx->_NeedEyeCoords)
+        ctx->_ModelViewInvScale = (GLfloat) INV_SQRTF(f);
+      else
+        ctx->_ModelViewInvScale = (GLfloat) SQRTF(f);
+   }
+}
+
+
+/* Bring uptodate any state that relies on _NeedEyeCoords.
+ */
+void
+_mesa_update_tnl_spaces( GLcontext *ctx, GLuint new_state )
+{
+   const GLuint oldneedeyecoords = ctx->_NeedEyeCoords;
+
+   (void) new_state;
+   ctx->_NeedEyeCoords = 0;
+
+   if (ctx->_ForceEyeCoords ||
+       (ctx->Texture._GenFlags & TEXGEN_NEED_EYE_COORD) ||
+       ctx->Point._Attenuated ||
+       ctx->Light._NeedEyeCoords)
+      ctx->_NeedEyeCoords = 1;
+
+   if (ctx->Light.Enabled &&
+       !TEST_MAT_FLAGS( ctx->ModelviewMatrixStack.Top, 
+                       MAT_FLAGS_LENGTH_PRESERVING))
+      ctx->_NeedEyeCoords = 1;
+
+
+   /* Check if the truth-value interpretations of the bitfields have
+    * changed:
+    */
+   if (oldneedeyecoords != ctx->_NeedEyeCoords) {
+      /* Recalculate all state that depends on _NeedEyeCoords.
+       */
+      update_modelview_scale(ctx);
+      compute_light_positions( ctx );
+
+      if (ctx->Driver.LightingSpaceChange)
+        ctx->Driver.LightingSpaceChange( ctx );
+   }
+   else {
+      GLuint new_state = ctx->NewState;
+
+      /* Recalculate that same state only if it has been invalidated
+       * by other statechanges.
+       */
+      if (new_state & _NEW_MODELVIEW)
+        update_modelview_scale(ctx);
+
+      if (new_state & (_NEW_LIGHT|_NEW_MODELVIEW))
+        compute_light_positions( ctx );
+   }
+}
+
+
+/* Drivers may need this if the hardware tnl unit doesn't support the
+ * light-in-modelspace optimization.  It's also useful for debugging.
+ */
+void
+_mesa_allow_light_in_model( GLcontext *ctx, GLboolean flag )
+{
+   ctx->_ForceEyeCoords = !flag;
+   ctx->NewState |= _NEW_POINT;        /* one of the bits from
+                                * _MESA_NEW_NEED_EYE_COORDS.
+                                */
+}
+
+
+
+/**********************************************************************/
+/*****                      Initialization                        *****/
+/**********************************************************************/
+
+/**
+ * Initialize the n-th light data structure.
+ *
+ * \param l pointer to the gl_light structure to be initialized.
+ * \param n number of the light. 
+ * \note The defaults for light 0 are different than the other lights.
+ */
+static void
+init_light( struct gl_light *l, GLuint n )
+{
+   make_empty_list( l );
+
+   ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
+   if (n==0) {
+      ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
+      ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
+   }
+   else {
+      ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
+      ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
+   }
+   ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
+   ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
+   l->SpotExponent = 0.0;
+   _mesa_invalidate_spot_exp_table( l );
+   l->SpotCutoff = 180.0;
+   l->_CosCutoff = 0.0;                /* KW: -ve values not admitted */
+   l->ConstantAttenuation = 1.0;
+   l->LinearAttenuation = 0.0;
+   l->QuadraticAttenuation = 0.0;
+   l->Enabled = GL_FALSE;
+}
+
+
+/**
+ * Initialize the light model data structure.
+ *
+ * \param lm pointer to the gl_lightmodel structure to be initialized.
+ */
+static void
+init_lightmodel( struct gl_lightmodel *lm )
+{
+   ASSIGN_4V( lm->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
+   lm->LocalViewer = GL_FALSE;
+   lm->TwoSide = GL_FALSE;
+   lm->ColorControl = GL_SINGLE_COLOR;
+}
+
+
+/**
+ * Initialize the material data structure.
+ * 
+ * \param m pointer to the gl_material structure to be initialized.
+ */
+static void
+init_material( struct gl_material *m )
+{
+   ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_AMBIENT],  0.2F, 0.2F, 0.2F, 1.0F );
+   ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_DIFFUSE],  0.8F, 0.8F, 0.8F, 1.0F );
+   ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_SPECULAR], 0.0F, 0.0F, 0.0F, 1.0F );
+   ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_EMISSION], 0.0F, 0.0F, 0.0F, 1.0F );
+   ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_SHININESS], 0.0F, 0.0F, 0.0F, 0.0F );
+   ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_INDEXES], 0.0F, 1.0F, 1.0F, 0.0F );
+   ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_AMBIENT],  0.2F, 0.2F, 0.2F, 1.0F );
+   ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_DIFFUSE],  0.8F, 0.8F, 0.8F, 1.0F );
+   ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_SPECULAR], 0.0F, 0.0F, 0.0F, 1.0F );
+   ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_EMISSION], 0.0F, 0.0F, 0.0F, 1.0F );
+   ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_SHININESS], 0.0F, 0.0F, 0.0F, 0.0F );
+   ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_INDEXES], 0.0F, 1.0F, 1.0F, 0.0F );
+}
+
+
+void
+_mesa_init_lighting( GLcontext *ctx )
+{
+   GLuint i;
+
+   /* Lighting group */
+   for (i = 0; i < MAX_LIGHTS; i++) {
+      init_light( &ctx->Light.Light[i], i );
+   }
+   make_empty_list( &ctx->Light.EnabledList );
+
+   init_lightmodel( &ctx->Light.Model );
+   init_material( &ctx->Light.Material );
+   ctx->Light.ShadeModel = GL_SMOOTH;
+   ctx->Light.Enabled = GL_FALSE;
+   ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
+   ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
+   ctx->Light.ColorMaterialBitmask = _mesa_material_bitmask( ctx,
+                                               GL_FRONT_AND_BACK,
+                                               GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
+
+   ctx->Light.ColorMaterialEnabled = GL_FALSE;
+
+   /* Lighting miscellaneous */
+   ctx->_ShineTabList = MALLOC_STRUCT( gl_shine_tab );
+   make_empty_list( ctx->_ShineTabList );
+   /* Allocate 10 (arbitrary) shininess lookup tables */
+   for (i = 0 ; i < 10 ; i++) {
+      struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
+      s->shininess = -1;
+      s->refcount = 0;
+      insert_at_tail( ctx->_ShineTabList, s );
+   }
+
+   /* Miscellaneous */
+   ctx->Light._NeedEyeCoords = 0;
+   ctx->_NeedEyeCoords = 0;
+   ctx->_ModelViewInvScale = 1.0;
+}
+
+
+void
+_mesa_free_lighting_data( GLcontext *ctx )
+{
+   struct gl_shine_tab *s, *tmps;
+
+   /* Free lighting shininess exponentiation table */
+   foreach_s( s, tmps, ctx->_ShineTabList ) {
+      FREE( s );
+   }
+   FREE( ctx->_ShineTabList );
+}