mesa: remove gl_light::_SpotExpTable field

Just use pow() instead.  Spot lights aren't too common and fixed-function
lighting isn't as important as it used to me.

This saves 32KB per context.  Each table was 4KB and there's 8 lights.
This commit is contained in:
Brian Paul 2012-02-08 20:11:58 -07:00
parent 4dacf793c8
commit ae509f88a5
6 changed files with 4 additions and 68 deletions

View file

@ -154,7 +154,6 @@ _mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *pa
return;
FLUSH_VERTICES(ctx, _NEW_LIGHT);
light->SpotExponent = params[0];
_mesa_invalidate_spot_exp_table(light);
break;
case GL_SPOT_CUTOFF:
ASSERT(params[0] == 180.0 || (params[0] >= 0.0 && params[0] <= 90.0));
@ -911,46 +910,6 @@ _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
/*
* Whenever the spotlight exponent for a light changes we must call
* this function to recompute the exponent lookup table.
*/
void
_mesa_invalidate_spot_exp_table( struct gl_light *l )
{
l->_SpotExpTable[0][0] = -1;
}
static void
validate_spot_exp_table( struct gl_light *l )
{
GLint i;
GLdouble exponent = l->SpotExponent;
GLdouble tmp = 0;
GLint clamp = 0;
l->_SpotExpTable[0][0] = 0.0;
for (i = EXP_TABLE_SIZE - 1; i > 0 ;i--) {
if (clamp == 0) {
tmp = pow(i / (GLdouble) (EXP_TABLE_SIZE - 1), exponent);
if (tmp < FLT_MIN * 100.0) {
tmp = 0.0;
clamp = 1;
}
}
l->_SpotExpTable[i][0] = (GLfloat) tmp;
}
for (i = 0; i < EXP_TABLE_SIZE - 1; i++) {
l->_SpotExpTable[i][1] = (l->_SpotExpTable[i+1][0] -
l->_SpotExpTable[i][0]);
}
l->_SpotExpTable[EXP_TABLE_SIZE-1][1] = 0.0;
}
/* 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.
@ -1020,7 +979,6 @@ validate_shine_table( struct gl_context *ctx, GLuint side, GLfloat shininess )
void
_mesa_validate_all_lighting_tables( struct gl_context *ctx )
{
GLuint i;
GLfloat shininess;
shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0];
@ -1030,10 +988,6 @@ _mesa_validate_all_lighting_tables( struct gl_context *ctx )
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 );
for (i = 0; i < ctx->Const.MaxLights; i++)
if (ctx->Light.Light[i]._SpotExpTable[0][0] == -1)
validate_spot_exp_table( &ctx->Light.Light[i] );
}
@ -1180,11 +1134,8 @@ compute_light_positions( struct gl_context *ctx )
light->_NormSpotDirection);
if (PV_dot_dir > light->_CosCutoff) {
double x = PV_dot_dir * (EXP_TABLE_SIZE-1);
int k = (int) x;
light->_VP_inf_spot_attenuation =
(GLfloat) (light->_SpotExpTable[k][0] +
(x-k)*light->_SpotExpTable[k][1]);
powf(PV_dot_dir, light->SpotExponent);
}
else {
light->_VP_inf_spot_attenuation = 0;
@ -1303,7 +1254,6 @@ init_light( struct gl_light *l, GLuint n )
ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
ASSIGN_3V( l->SpotDirection, 0.0, 0.0, -1.0 );
l->SpotExponent = 0.0;
_mesa_invalidate_spot_exp_table( l );
l->SpotCutoff = 180.0;
l->_CosCutoffNeg = -1.0f;
l->_CosCutoff = 0.0; /* KW: -ve values not admitted */

View file

@ -110,8 +110,6 @@ extern GLuint _mesa_material_bitmask( struct gl_context *ctx,
GLuint legal,
const char * );
extern void _mesa_invalidate_spot_exp_table( struct gl_light *l );
extern void _mesa_invalidate_shine_table( struct gl_context *ctx, GLuint i );
extern void _mesa_validate_all_lighting_tables( struct gl_context *ctx );
@ -135,7 +133,6 @@ extern void _mesa_allow_light_in_model( struct gl_context *ctx, GLboolean flag )
#else
#define _mesa_update_color_material( c, r ) ((void)0)
#define _mesa_validate_all_lighting_tables( c ) ((void)0)
#define _mesa_invalidate_spot_exp_table( l ) ((void)0)
#define _mesa_material_bitmask( c, f, p, l, s ) 0
#define _mesa_init_lighting( c ) ((void)0)
#define _mesa_free_lighting_data( c ) ((void)0)

View file

@ -689,7 +689,6 @@ struct gl_light
GLfloat _NormSpotDirection[4]; /**< normalized spotlight direction */
GLfloat _VP_inf_spot_attenuation;
GLfloat _SpotExpTable[EXP_TABLE_SIZE][2]; /**< to replace a pow() call */
GLfloat _MatAmbient[2][3]; /**< material ambient * light ambient */
GLfloat _MatDiffuse[2][3]; /**< material diffuse * light diffuse */
GLfloat _MatSpecular[2][3]; /**< material spec * light specular */

View file

@ -167,10 +167,7 @@ shade_rastpos(struct gl_context *ctx,
continue;
}
else {
double x = PV_dot_dir * (EXP_TABLE_SIZE-1);
int k = (int) x;
GLfloat spot = (GLfloat) (light->_SpotExpTable[k][0]
+ (x-k)*light->_SpotExpTable[k][1]);
GLfloat spot = powf(PV_dot_dir, light->SpotExponent);
attenuation *= spot;
}
}

View file

@ -147,10 +147,7 @@ static void TAG(light_rgba_spec)( struct gl_context *ctx,
continue; /* this light makes no contribution */
}
else {
GLdouble x = PV_dot_dir * (EXP_TABLE_SIZE-1);
GLint k = (GLint) x;
GLfloat spot = (GLfloat) (light->_SpotExpTable[k][0]
+ (x-k)*light->_SpotExpTable[k][1]);
GLfloat spot = powf(PV_dot_dir, light->SpotExponent);
attenuation *= spot;
}
}
@ -331,10 +328,7 @@ static void TAG(light_rgba)( struct gl_context *ctx,
continue; /* this light makes no contribution */
}
else {
GLdouble x = PV_dot_dir * (EXP_TABLE_SIZE-1);
GLint k = (GLint) x;
GLfloat spot = (GLfloat) (light->_SpotExpTable[k][0]
+ (x-k)*light->_SpotExpTable[k][1]);
GLfloat spot = powf(PV_dot_dir, light->SpotExponent);
attenuation *= spot;
}
}

View file

@ -209,7 +209,6 @@ int main( int argc, char **argv )
OFFSET( "LIGHT_NORM_DIRECTION ", struct gl_light, _NormSpotDirection );
OFFSET( "LIGHT_VP_INF_SPOT_ATTEN ", struct gl_light, _VP_inf_spot_attenuation );
printf( "\n" );
OFFSET( "LIGHT_SPOT_EXP_TABLE ", struct gl_light, _SpotExpTable );
OFFSET( "LIGHT_MAT_AMBIENT ", struct gl_light, _MatAmbient );
OFFSET( "LIGHT_MAT_DIFFUSE ", struct gl_light, _MatDiffuse );
OFFSET( "LIGHT_MAT_SPECULAR ", struct gl_light, _MatSpecular );