X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Ftnl%2Ft_vb_lighttmp.h;h=ac88095a969b96e0ee39a5316fb43c4b4f4b8de8;hb=d94bec5c49d926069f97a4b12fb2532611a9080c;hp=aae1d18ff7f51b66e4db8e24ed7c4b8ecf272b0b;hpb=0072acd447dc6be652e63752e50215c3105322c8;p=mesa.git diff --git a/src/mesa/tnl/t_vb_lighttmp.h b/src/mesa/tnl/t_vb_lighttmp.h index aae1d18ff7f..ac88095a969 100644 --- a/src/mesa/tnl/t_vb_lighttmp.h +++ b/src/mesa/tnl/t_vb_lighttmp.h @@ -1,6 +1,5 @@ /* * Mesa 3-D graphics library - * Version: 5.1 * * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. * @@ -17,14 +16,14 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. * * * Authors: - * Brian Paul - * Keith Whitwell + * Brian Paul Keith Whitwell */ @@ -69,7 +68,7 @@ static void TAG(light_rgba_spec)( struct gl_context *ctx, const GLuint nr = VB->Count; #ifdef TRACE - fprintf(stderr, "%s\n", __FUNCTION__ ); + fprintf(stderr, "%s\n", __func__ ); #endif VB->AttribPtr[_TNL_ATTRIB_COLOR0] = &store->LitColor[0]; @@ -88,7 +87,7 @@ static void TAG(light_rgba_spec)( struct gl_context *ctx, for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) { GLfloat sum[2][3], spec[2][3]; - struct gl_light *light; + GLbitfield mask; #if IDX & LIGHT_MATERIAL update_materials( ctx, store ); @@ -107,13 +106,16 @@ static void TAG(light_rgba_spec)( struct gl_context *ctx, #endif /* Add contribution from each enabled light source */ - foreach (light, &ctx->Light.EnabledList) { + mask = ctx->Light._EnabledLights; + while (mask) { + const int l = u_bit_scan(&mask); + struct gl_light *light = &ctx->Light.Light[l]; GLfloat n_dot_h; GLfloat correction; GLint side; GLfloat contrib[3]; GLfloat attenuation; - GLfloat VP[3]; /* unit vector from vertex to light */ + GLfloat VP[3]; /* unit vector from vertex to light */ GLfloat n_dot_VP; /* n dot VP */ GLfloat *h; @@ -130,7 +132,7 @@ static void TAG(light_rgba_spec)( struct gl_context *ctx, d = (GLfloat) LEN_3FV( VP ); - if (d > 1e-6) { + if (d > 1e-6F) { GLfloat invd = 1.0F / d; SELF_SCALE_SCALAR_3V(VP, invd); } @@ -147,16 +149,13 @@ 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; } } } - if (attenuation < 1e-3) + if (attenuation < 1e-3F) continue; /* this light makes no contribution */ /* Compute dot product or normal and vector from V to light pos */ @@ -207,11 +206,8 @@ 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 ); - - if (spec_coef > 1.0e-10) { + GLfloat spec_coef = lookup_shininess(ctx, side, n_dot_h); + if (spec_coef > 1.0e-10F) { spec_coef *= attenuation; ACC_SCALE_SCALAR_3V( spec[side], spec_coef, light->_MatSpecular[side]); @@ -256,7 +252,7 @@ static void TAG(light_rgba)( struct gl_context *ctx, const GLuint nr = VB->Count; #ifdef TRACE - fprintf(stderr, "%s\n", __FUNCTION__ ); + fprintf(stderr, "%s\n", __func__ ); #endif VB->AttribPtr[_TNL_ATTRIB_COLOR0] = &store->LitColor[0]; @@ -272,7 +268,7 @@ static void TAG(light_rgba)( struct gl_context *ctx, for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) { GLfloat sum[2][3]; - struct gl_light *light; + GLbitfield mask; #if IDX & LIGHT_MATERIAL update_materials( ctx, store ); @@ -289,13 +285,15 @@ static void TAG(light_rgba)( struct gl_context *ctx, #endif /* Add contribution from each enabled light source */ - foreach (light, &ctx->Light.EnabledList) { - + mask = ctx->Light._EnabledLights; + while (mask) { + const int l = u_bit_scan(&mask); + struct gl_light *light = &ctx->Light.Light[l]; GLfloat n_dot_h; GLfloat correction; GLint side; GLfloat contrib[3]; - GLfloat attenuation = 1.0; + GLfloat attenuation; GLfloat VP[3]; /* unit vector from vertex to light */ GLfloat n_dot_VP; /* n dot VP */ GLfloat *h; @@ -309,12 +307,11 @@ static void TAG(light_rgba)( struct gl_context *ctx, else { GLfloat d; /* distance from vertex to light */ - SUB_3V(VP, light->_Position, vertex); d = (GLfloat) LEN_3FV( VP ); - if ( d > 1e-6) { + if (d > 1e-6F) { GLfloat invd = 1.0F / d; SELF_SCALE_SCALAR_3V(VP, invd); } @@ -331,16 +328,13 @@ 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; } } } - if (attenuation < 1e-3) + if (attenuation < 1e-3F) continue; /* this light makes no contribution */ /* Compute dot product or normal and vector from V to light pos */ @@ -391,13 +385,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 = lookup_shininess(ctx, side, n_dot_h); ACC_SCALE_SCALAR_3V( contrib, spec_coef, light->_MatSpecular[side]); } @@ -434,7 +423,8 @@ static void TAG(light_fast_rgba_single)( struct gl_context *ctx, #if IDX & LIGHT_TWOSIDE GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data; #endif - const struct gl_light *light = ctx->Light.EnabledList.next; + const struct gl_light *light = + &ctx->Light.Light[ffs(ctx->Light._EnabledLights) - 1]; GLuint j = 0; GLfloat base[2][4]; #if IDX & LIGHT_MATERIAL @@ -444,7 +434,7 @@ static void TAG(light_fast_rgba_single)( struct gl_context *ctx, #endif #ifdef TRACE - fprintf(stderr, "%s\n", __FUNCTION__ ); + fprintf(stderr, "%s\n", __func__ ); #endif (void) input; /* doesn't refer to Eye or Obj */ @@ -497,8 +487,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 = lookup_shininess(ctx, 1, n_dot_h); ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[1]); } COPY_3V(Bcolor[j], sum ); @@ -512,10 +501,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 = 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]; @@ -548,10 +535,9 @@ static void TAG(light_fast_rgba)( struct gl_context *ctx, #else const GLuint nr = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->count; #endif - const struct gl_light *light; #ifdef TRACE - fprintf(stderr, "%s %d\n", __FUNCTION__, nr ); + fprintf(stderr, "%s %d\n", __func__, nr ); #endif (void) input; @@ -576,6 +562,7 @@ static void TAG(light_fast_rgba)( struct gl_context *ctx, for (j = 0; j < nr; j++, STRIDE_F(normal,nstride)) { GLfloat sum[2][3]; + GLbitfield mask; #if IDX & LIGHT_MATERIAL update_materials( ctx, store ); @@ -592,7 +579,10 @@ static void TAG(light_fast_rgba)( struct gl_context *ctx, COPY_3V(sum[1], ctx->Light._BaseColor[1]); #endif - foreach (light, &ctx->Light.EnabledList) { + mask = ctx->Light._EnabledLights; + while (mask) { + const int l = u_bit_scan(&mask); + const struct gl_light *light = &ctx->Light.Light[l]; GLfloat n_dot_h, n_dot_VP, spec; ACC_3V(sum[0], light->_MatAmbient[0]); @@ -606,8 +596,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 = lookup_shininess(ctx, 0, n_dot_h); ACC_SCALE_SCALAR_3V( sum[0], spec, light->_MatSpecular[0]); } } @@ -616,8 +605,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 = lookup_shininess(ctx, 1, n_dot_h); ACC_SCALE_SCALAR_3V( sum[1], spec, light->_MatSpecular[1]); } }