mesa api_exec: add comment regarding GetPointerv & CORE profiles
[mesa.git] / src / mesa / main / light.c
index 7ebf9bf51cfd37026853a6607bec7d4dbccbb9ef..042ed1cb85894daa66a3de0bbfccd7cc9fd61270 100644 (file)
@@ -54,10 +54,6 @@ _mesa_ShadeModel( GLenum mode )
 
    FLUSH_VERTICES(ctx, _NEW_LIGHT);
    ctx->Light.ShadeModel = mode;
-   if (mode == GL_FLAT)
-      ctx->_TriangleCaps |= DD_FLATSHADE;
-   else
-      ctx->_TriangleCaps &= ~DD_FLATSHADE;
 
    if (ctx->Driver.ShadeModel)
       ctx->Driver.ShadeModel( ctx, mode );
@@ -470,6 +466,8 @@ _mesa_LightModelfv( GLenum pname, const GLfloat *params )
          COPY_4V( ctx->Light.Model.Ambient, params );
          break;
       case GL_LIGHT_MODEL_LOCAL_VIEWER:
+         if (ctx->API != API_OPENGL)
+            goto invalid_pname;
          newbool = (params[0]!=0.0);
         if (ctx->Light.Model.LocalViewer == newbool)
            return;
@@ -488,6 +486,8 @@ _mesa_LightModelfv( GLenum pname, const GLfloat *params )
             ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
          break;
       case GL_LIGHT_MODEL_COLOR_CONTROL:
+         if (ctx->API != API_OPENGL)
+            goto invalid_pname;
          if (params[0] == (GLfloat) GL_SINGLE_COLOR)
            newenum = GL_SINGLE_COLOR;
          else if (params[0] == (GLfloat) GL_SEPARATE_SPECULAR_COLOR)
@@ -503,12 +503,17 @@ _mesa_LightModelfv( GLenum pname, const GLfloat *params )
         ctx->Light.Model.ColorControl = newenum;
          break;
       default:
-         _mesa_error( ctx, GL_INVALID_ENUM, "glLightModel(pname=0x%x)", pname );
-         break;
+         goto invalid_pname;
    }
 
    if (ctx->Driver.LightModelfv)
       ctx->Driver.LightModelfv( ctx, pname, params );
+
+   return;
+
+invalid_pname:
+   _mesa_error( ctx, GL_INVALID_ENUM, "glLightModel(pname=0x%x)", pname );
+   return;
 }
 
 
@@ -621,11 +626,6 @@ _mesa_material_bitmask( struct gl_context *ctx, GLenum face, GLenum pname,
 
 
 
-static void
-invalidate_shine_table( struct gl_context *ctx, GLuint side );
-
-
-
 /* Update derived values following a change in ctx->Light.Material
  */
 void
@@ -697,26 +697,18 @@ _mesa_update_material( struct gl_context *ctx, GLuint bitmask )
                   mat[MAT_ATTRIB_BACK_SPECULAR]);
       }
    }
-
-   if (bitmask & MAT_BIT_FRONT_SHININESS) {
-      invalidate_shine_table( ctx, 0 );
-   }
-
-   if (bitmask & MAT_BIT_BACK_SHININESS) {
-      invalidate_shine_table( ctx, 1 );
-   }
 }
 
 
 /*
  * Update the current materials from the given rgba color
- * according to the bitmask in ColorMaterialBitmask, which is
+ * according to the bitmask in _ColorMaterialBitmask, which is
  * set by glColorMaterial().
  */
 void
 _mesa_update_color_material( struct gl_context *ctx, const GLfloat color[4] )
 {
-   GLuint bitmask = ctx->Light.ColorMaterialBitmask;
+   const GLbitfield bitmask = ctx->Light._ColorMaterialBitmask;
    struct gl_material *mat = &ctx->Light.Material;
    int i;
 
@@ -745,14 +737,16 @@ _mesa_ColorMaterial( GLenum face, GLenum mode )
                   _mesa_lookup_enum_by_nr(mode));
 
    bitmask = _mesa_material_bitmask(ctx, face, mode, legal, "glColorMaterial");
+   if (bitmask == 0)
+      return; /* error was recorded */
 
-   if (ctx->Light.ColorMaterialBitmask == bitmask &&
+   if (ctx->Light._ColorMaterialBitmask == bitmask &&
        ctx->Light.ColorMaterialFace == face &&
        ctx->Light.ColorMaterialMode == mode)
       return;
 
    FLUSH_VERTICES(ctx, _NEW_LIGHT);
-   ctx->Light.ColorMaterialBitmask = bitmask;
+   ctx->Light._ColorMaterialBitmask = bitmask;
    ctx->Light.ColorMaterialFace = face;
    ctx->Light.ColorMaterialMode = mode;
 
@@ -804,6 +798,10 @@ _mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params )
         *params = mat[MAT_ATTRIB_SHININESS(f)][0];
         break;
       case GL_COLOR_INDEXES:
+         if (ctx->API != API_OPENGL) {
+            _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
+            return;
+         }
         params[0] = mat[MAT_ATTRIB_INDEXES(f)][0];
         params[1] = mat[MAT_ATTRIB_INDEXES(f)][1];
         params[2] = mat[MAT_ATTRIB_INDEXES(f)][2];
@@ -822,6 +820,8 @@ _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
    GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */
 
+   ASSERT(ctx->API == API_OPENGL);
+
    FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
 
    if (face==GL_FRONT) {
@@ -874,126 +874,6 @@ _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
 
 
 
-/**********************************************************************/
-/*****                  Lighting computation                      *****/
-/**********************************************************************/
-
-
-/*
- * Notes:
- *   When two-sided lighting is enabled we compute the color (or index)
- *   for both the front and back side of the primitive.  Then, when the
- *   orientation of the facet is later learned, we can determine which
- *   color (or index) to use for rendering.
- *
- *   KW: We now know orientation in advance and only shade for
- *       the side or sides which are actually required.
- *
- * Variables:
- *   n = normal vector
- *   V = vertex position
- *   P = light source position
- *   Pe = (0,0,0,1)
- *
- * Precomputed:
- *   IF P[3]==0 THEN
- *       // light at infinity
- *       IF local_viewer THEN
- *           _VP_inf_norm = unit vector from V to P      // Precompute
- *       ELSE
- *           // eye at infinity
- *           _h_inf_norm = Normalize( VP + <0,0,1> )     // Precompute
- *       ENDIF
- *   ENDIF
- *
- * Functions:
- *   Normalize( v ) = normalized vector v
- *   Magnitude( v ) = length of vector v
- */
-
-
-
-/* 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.
- */
-static void
-invalidate_shine_table( struct gl_context *ctx, GLuint side )
-{
-   ASSERT(side < 2);
-   if (ctx->_ShineTable[side])
-      ctx->_ShineTable[side]->refcount--;
-   ctx->_ShineTable[side] = NULL;
-}
-
-
-static void
-validate_shine_table( struct gl_context *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;
-
-   if (s == list) {
-      GLint j;
-      GLfloat *m;
-
-      foreach(s, list)
-        if (s->refcount == 0)
-           break;
-
-      m = s->tab;
-      m[0] = 0.0;
-      if (shininess == 0.0) {
-        for (j = 1 ; j <= SHINE_TABLE_SIZE ; j++)
-           m[j] = 1.0;
-      }
-      else {
-        for (j = 1 ; j < SHINE_TABLE_SIZE ; j++) {
-            GLdouble t, x = j / (GLfloat) (SHINE_TABLE_SIZE - 1);
-            if (x < 0.005) /* underflow check */
-               x = 0.005;
-            t = pow(x, shininess);
-           if (t > 1e-20)
-              m[j] = (GLfloat) t;
-           else
-              m[j] = 0.0;
-        }
-        m[SHINE_TABLE_SIZE] = 1.0;
-      }
-
-      s->shininess = shininess;
-   }
-
-   if (ctx->_ShineTable[side])
-      ctx->_ShineTable[side]->refcount--;
-
-   ctx->_ShineTable[side] = s;
-   move_to_tail( list, s );
-   s->refcount++;
-}
-
-
-void
-_mesa_validate_all_lighting_tables( struct gl_context *ctx )
-{
-   GLfloat 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.Attrib[MAT_ATTRIB_BACK_SHININESS][0];
-   if (!ctx->_ShineTable[1] || ctx->_ShineTable[1]->shininess != shininess)
-      validate_shine_table( ctx, 1, shininess );
-}
-
-
 /**
  * Examine current lighting parameters to determine if the optimized lighting
  * function can be used.
@@ -1079,9 +959,6 @@ compute_light_positions( struct gl_context *ctx )
       TRANSFORM_NORMAL( ctx->_EyeZDir, eye_z, ctx->ModelviewMatrixStack.Top->m );
    }
 
-   /* Make sure all the light tables are updated before the computation */
-   _mesa_validate_all_lighting_tables(ctx);
-
    foreach (light, &ctx->Light.EnabledList) {
 
       if (ctx->_NeedEyeCoords) {
@@ -1161,7 +1038,7 @@ update_modelview_scale( struct gl_context *ctx )
       if (ctx->_NeedEyeCoords)
         ctx->_ModelViewInvScale = (GLfloat) INV_SQRTF(f);
       else
-        ctx->_ModelViewInvScale = (GLfloat) SQRTF(f);
+        ctx->_ModelViewInvScale = (GLfloat) sqrtf(f);
    }
 }
 
@@ -1326,7 +1203,7 @@ _mesa_init_lighting( struct gl_context *ctx )
    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,
+   ctx->Light._ColorMaterialBitmask = _mesa_material_bitmask( ctx,
                                                GL_FRONT_AND_BACK,
                                                GL_AMBIENT_AND_DIFFUSE, ~0,
                                                NULL );
@@ -1334,17 +1211,6 @@ _mesa_init_lighting( struct gl_context *ctx )
    ctx->Light.ColorMaterialEnabled = GL_FALSE;
    ctx->Light.ClampVertexColor = GL_TRUE;
 
-   /* 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 = GL_FALSE;
    ctx->_NeedEyeCoords = GL_FALSE;
@@ -1359,11 +1225,4 @@ _mesa_init_lighting( struct gl_context *ctx )
 void
 _mesa_free_lighting_data( struct gl_context *ctx )
 {
-   struct gl_shine_tab *s, *tmps;
-
-   /* Free lighting shininess exponentiation table */
-   foreach_s( s, tmps, ctx->_ShineTabList ) {
-      free( s );
-   }
-   free( ctx->_ShineTabList );
 }