From: Brian Paul Date: Thu, 9 Feb 2012 03:11:58 +0000 (-0700) Subject: mesa: replace GET_SHINE_TAB_ENTRY() macro with an inline function X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9d9111108eadd65708899284b1cfa9ca425f3ac8;p=mesa.git mesa: replace GET_SHINE_TAB_ENTRY() macro with an inline function --- diff --git a/src/mesa/main/light.h b/src/mesa/main/light.h index 26e604bc523..996698793f5 100644 --- a/src/mesa/main/light.h +++ b/src/mesa/main/light.h @@ -87,22 +87,24 @@ extern void _mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *params); -/* Lerp between adjacent values in the f(x) lookup table, giving a - * continuous function, with adequeate overall accuracy. (Though - * still pretty good compared to a straight lookup). - * Result should be a GLfloat. +/* + * Compute dp ^ SpecularExponent. + * Lerp between adjacent values in the f(x) lookup table, giving a + * continuous function, with adequate overall accuracy. (Though still + * pretty good compared to a straight lookup). */ -#define GET_SHINE_TAB_ENTRY( table, dp, result ) \ -do { \ - struct gl_shine_tab *_tab = table; \ - float f = (dp * (SHINE_TABLE_SIZE-1)); \ - int k = (int) f; \ - if (k < 0 /* gcc may cast an overflow float value to negative int value*/ \ - || k > SHINE_TABLE_SIZE-2) \ - result = (GLfloat) pow( dp, _tab->shininess ); \ - else \ - result = _tab->tab[k] + (f-k)*(_tab->tab[k+1]-_tab->tab[k]); \ -} while (0) +static inline GLfloat +_mesa_lookup_shininess(const struct gl_context *ctx, GLuint face, GLfloat dp) +{ + const struct gl_shine_tab *tab = ctx->_ShineTable[face]; + float f = dp * (SHINE_TABLE_SIZE - 1); + int k = (int) f; + if (k < 0 /* gcc may cast an overflow float value to negative int value */ + || k > SHINE_TABLE_SIZE - 2) + return powf(dp, tab->shininess); + else + return tab->tab[k] + (f - k) * (tab->tab[k+1] - tab->tab[k]); +} extern GLuint _mesa_material_bitmask( struct gl_context *ctx, diff --git a/src/mesa/tnl/t_rasterpos.c b/src/mesa/tnl/t_rasterpos.c index bdd6129e727..17611cd216a 100644 --- a/src/mesa/tnl/t_rasterpos.c +++ b/src/mesa/tnl/t_rasterpos.c @@ -214,8 +214,7 @@ shade_rastpos(struct gl_context *ctx, n_dot_h = DOT3(normal, h); if (n_dot_h > 0.0F) { - GLfloat spec_coef; - GET_SHINE_TAB_ENTRY( ctx->_ShineTable[0], n_dot_h, spec_coef ); + GLfloat spec_coef = _mesa_lookup_shininess(ctx, 0, n_dot_h); if (spec_coef > 1.0e-10) { if (ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR) { diff --git a/src/mesa/tnl/t_vb_lighttmp.h b/src/mesa/tnl/t_vb_lighttmp.h index 0b8c314685e..1041a24e761 100644 --- a/src/mesa/tnl/t_vb_lighttmp.h +++ b/src/mesa/tnl/t_vb_lighttmp.h @@ -204,10 +204,7 @@ static void TAG(light_rgba_spec)( struct gl_context *ctx, n_dot_h = correction * DOT3(normal, h); if (n_dot_h > 0.0F) { - GLfloat spec_coef; - struct gl_shine_tab *tab = ctx->_ShineTable[side]; - GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef ); - + GLfloat spec_coef = _mesa_lookup_shininess(ctx, side, n_dot_h); if (spec_coef > 1.0e-10) { spec_coef *= attenuation; ACC_SCALE_SCALAR_3V( spec[side], spec_coef, @@ -385,13 +382,8 @@ static void TAG(light_rgba)( struct gl_context *ctx, n_dot_h = correction * DOT3(normal, h); - if (n_dot_h > 0.0F) - { - GLfloat spec_coef; - struct gl_shine_tab *tab = ctx->_ShineTable[side]; - - GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef ); - + if (n_dot_h > 0.0F) { + GLfloat spec_coef = _mesa_lookup_shininess(ctx, side, n_dot_h); ACC_SCALE_SCALAR_3V( contrib, spec_coef, light->_MatSpecular[side]); } @@ -491,8 +483,7 @@ static void TAG(light_fast_rgba_single)( struct gl_context *ctx, COPY_3V(sum, base[1]); ACC_SCALE_SCALAR_3V(sum, -n_dot_VP, light->_MatDiffuse[1]); if (n_dot_h > 0.0F) { - GLfloat spec; - GET_SHINE_TAB_ENTRY( ctx->_ShineTable[1], n_dot_h, spec ); + GLfloat spec = _mesa_lookup_shininess(ctx, 1, n_dot_h); ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[1]); } COPY_3V(Bcolor[j], sum ); @@ -506,10 +497,8 @@ static void TAG(light_fast_rgba_single)( struct gl_context *ctx, COPY_3V(sum, base[0]); ACC_SCALE_SCALAR_3V(sum, n_dot_VP, light->_MatDiffuse[0]); if (n_dot_h > 0.0F) { - GLfloat spec; - GET_SHINE_TAB_ENTRY( ctx->_ShineTable[0], n_dot_h, spec ); + GLfloat spec = _mesa_lookup_shininess(ctx, 0, n_dot_h); ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[0]); - } COPY_3V(Fcolor[j], sum ); Fcolor[j][3] = base[0][3]; @@ -600,8 +589,7 @@ static void TAG(light_fast_rgba)( struct gl_context *ctx, ACC_SCALE_SCALAR_3V(sum[0], n_dot_VP, light->_MatDiffuse[0]); n_dot_h = DOT3(normal, light->_h_inf_norm); if (n_dot_h > 0.0F) { - struct gl_shine_tab *tab = ctx->_ShineTable[0]; - GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec ); + spec = _mesa_lookup_shininess(ctx, 0, n_dot_h); ACC_SCALE_SCALAR_3V( sum[0], spec, light->_MatSpecular[0]); } } @@ -610,8 +598,7 @@ static void TAG(light_fast_rgba)( struct gl_context *ctx, ACC_SCALE_SCALAR_3V(sum[1], -n_dot_VP, light->_MatDiffuse[1]); n_dot_h = -DOT3(normal, light->_h_inf_norm); if (n_dot_h > 0.0F) { - struct gl_shine_tab *tab = ctx->_ShineTable[1]; - GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec ); + spec = _mesa_lookup_shininess(ctx, 1, n_dot_h); ACC_SCALE_SCALAR_3V( sum[1], spec, light->_MatSpecular[1]); } }