From ae509f88a54b9cc32f16099109330f2792593c83 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 8 Feb 2012 20:11:58 -0700 Subject: [PATCH] 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. --- src/mesa/main/light.c | 52 +----------------------------------- src/mesa/main/light.h | 3 --- src/mesa/main/mtypes.h | 1 - src/mesa/tnl/t_rasterpos.c | 5 +--- src/mesa/tnl/t_vb_lighttmp.h | 10 ++----- src/mesa/x86/gen_matypes.c | 1 - 6 files changed, 4 insertions(+), 68 deletions(-) diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c index bf4bee3d696..39a984b1f19 100644 --- a/src/mesa/main/light.c +++ b/src/mesa/main/light.c @@ -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 */ diff --git a/src/mesa/main/light.h b/src/mesa/main/light.h index 9b66c7ed853..8b19e63a9c1 100644 --- a/src/mesa/main/light.h +++ b/src/mesa/main/light.h @@ -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) diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index ce302ca0b6a..521bb39f992 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -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 */ diff --git a/src/mesa/tnl/t_rasterpos.c b/src/mesa/tnl/t_rasterpos.c index a7e4397b660..bdd6129e727 100644 --- a/src/mesa/tnl/t_rasterpos.c +++ b/src/mesa/tnl/t_rasterpos.c @@ -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; } } diff --git a/src/mesa/tnl/t_vb_lighttmp.h b/src/mesa/tnl/t_vb_lighttmp.h index aae1d18ff7f..0b8c314685e 100644 --- a/src/mesa/tnl/t_vb_lighttmp.h +++ b/src/mesa/tnl/t_vb_lighttmp.h @@ -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; } } diff --git a/src/mesa/x86/gen_matypes.c b/src/mesa/x86/gen_matypes.c index 97f71f92cea..7af82b4aea6 100644 --- a/src/mesa/x86/gen_matypes.c +++ b/src/mesa/x86/gen_matypes.c @@ -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 ); -- 2.30.2