diff options
author | Keith Whitwell <[email protected]> | 2001-02-06 04:06:34 +0000 |
---|---|---|
committer | Keith Whitwell <[email protected]> | 2001-02-06 04:06:34 +0000 |
commit | d1baa05439c7157eeca42ec191d5375821725bdd (patch) | |
tree | bfd3ff31b803f177d678ab3b6783b876c1938fec /src | |
parent | 8fd9f1748d12751683cf8039401a7f7f66ab73fa (diff) |
Use a lookup table to compute exponents in tnl fogging code. Slightly
clean up the shine table lookup macro.
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/drivers/x11/xm_tri.c | 4 | ||||
-rw-r--r-- | src/mesa/main/dd.h | 10 | ||||
-rw-r--r-- | src/mesa/main/imports.c | 4 | ||||
-rw-r--r-- | src/mesa/main/light.h | 11 | ||||
-rw-r--r-- | src/mesa/tnl/t_vb_fog.c | 49 |
5 files changed, 56 insertions, 22 deletions
diff --git a/src/mesa/drivers/x11/xm_tri.c b/src/mesa/drivers/x11/xm_tri.c index 4bb33ce66e3..9f152265f75 100644 --- a/src/mesa/drivers/x11/xm_tri.c +++ b/src/mesa/drivers/x11/xm_tri.c @@ -1,4 +1,4 @@ -/* $Id: xm_tri.c,v 1.17 2001/01/23 23:39:37 brianp Exp $ */ +/* $Id: xm_tri.c,v 1.18 2001/02/06 04:06:36 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -1521,7 +1521,7 @@ do { \ #endif - + static swrast_tri_func get_triangle_func( GLcontext *ctx ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index 542f866ff67..417beed91d1 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -1,4 +1,4 @@ -/* $Id: dd.h,v 1.49 2001/01/29 20:47:39 keithw Exp $ */ +/* $Id: dd.h,v 1.50 2001/02/06 04:06:34 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -900,12 +900,13 @@ struct dd_function_table { #define PRIM_UNKNOWN GL_POLYGON+3 GLuint CurrentExecPrimitive; - /* Set by the driver-supplied t&l engine. Set to GL_POLYGON+1 when - * outside begin/end. + /* Set by the driver-supplied t&l engine. Set to + * PRIM_OUTSIDE_BEGIN_END when outside begin/end. */ GLuint CurrentSavePrimitive; - /* Current state of an inprogress compilation. + /* Current state of an in-progress compilation. May take on any of + * the additional values defined above. */ @@ -926,7 +927,6 @@ struct dd_function_table { * if (flags & FLUSH_STORED_VERTICES) flushes any buffered vertices, * if (flags & FLUSH_UPDATE_CURRENT) updates ctx->Current * and ctx->Light.Material - * returns GL_TRUE. * * Note that the default t&l engine never clears the * FLUSH_UPDATE_CURRENT bit, even after performing the update. diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index 93fb906f35f..e36f7a24b02 100644 --- a/src/mesa/main/imports.c +++ b/src/mesa/main/imports.c @@ -1,4 +1,4 @@ -/* $Id: imports.c,v 1.4 2001/01/08 04:09:41 keithw Exp $ */ +/* $Id: imports.c,v 1.5 2001/02/06 04:06:35 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -158,7 +158,7 @@ _mesa_InitDefaultImports(__GLimports *imports, void *driverCtx, void *other) imports->warning = _mesa_warning; imports->fatal = _mesa_fatal; imports->getenv = _mesa_getenv; -/* imports->atoi = _mesa_atoi; */ + imports->atoi = _mesa_atoi; imports->sprintf = _mesa_sprintf; imports->fopen = _mesa_fopen; imports->fclose = _mesa_fclose; diff --git a/src/mesa/main/light.h b/src/mesa/main/light.h index f737abf4e45..b39aa002d87 100644 --- a/src/mesa/main/light.h +++ b/src/mesa/main/light.h @@ -1,4 +1,4 @@ -/* $Id: light.h,v 1.8 2000/12/26 05:09:29 keithw Exp $ */ +/* $Id: light.h,v 1.9 2001/02/06 04:06:35 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -82,13 +82,12 @@ _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params ); #define GET_SHINE_TAB_ENTRY( table, dp, result ) \ do { \ struct gl_shine_tab *_tab = table; \ - if (dp>1.0) \ + float f = (dp * (SHINE_TABLE_SIZE-1)); \ + int k = (int) f; \ + if (k > SHINE_TABLE_SIZE-2) \ result = pow( dp, _tab->shininess ); \ - else { \ - float f = (dp * (SHINE_TABLE_SIZE-1)); \ - int k = (int) f; \ + else \ result = _tab->tab[k] + (f-k)*(_tab->tab[k+1]-_tab->tab[k]); \ - } \ } while (0) diff --git a/src/mesa/tnl/t_vb_fog.c b/src/mesa/tnl/t_vb_fog.c index 2adb8d18500..e7f740dfa3c 100644 --- a/src/mesa/tnl/t_vb_fog.c +++ b/src/mesa/tnl/t_vb_fog.c @@ -1,4 +1,4 @@ -/* $Id: t_vb_fog.c,v 1.2 2001/01/03 22:56:23 brianp Exp $ */ +/* $Id: t_vb_fog.c,v 1.3 2001/02/06 04:06:36 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -49,10 +49,42 @@ struct fog_stage_data { #define FOG_STAGE_DATA(stage) ((struct fog_stage_data *)stage->private) +#define FOG_EXP_TABLE_SIZE 256 +#define FOG_MAX (5.0) +#define EXP_FOG_MAX .0006595 +#define FOG_INCR (FOG_MAX/FOG_EXP_TABLE_SIZE) +static GLfloat exp_table[FOG_EXP_TABLE_SIZE]; +static GLfloat inited = 0; + +#if 1 +#define NEG_EXP( result, narg ) \ +do { \ + float f = (narg * (1.0/FOG_INCR)); \ + int k = (int) f; \ + if (k > FOG_EXP_TABLE_SIZE-2) \ + result = EXP_FOG_MAX; \ + else \ + result = exp_table[k] + (f-k)*(exp_table[k+1]-exp_table[k]); \ +} while (0) +#else +#define NEG_EXP( result, narg ) \ +do { \ + result = exp(-narg); \ +} while (0) +#endif + + +static void init_static_data( void ) +{ + float f = 0; + int i = 0; + for ( ; i < FOG_EXP_TABLE_SIZE ; i++, f += FOG_INCR) { + exp_table[i] = exp(-f); + } + inited = 1; +} -/* Use lookup table & interpolation? - */ static void make_win_fog_coords( GLcontext *ctx, GLvector1f *out, const GLvector1f *in ) { @@ -76,15 +108,15 @@ static void make_win_fog_coords( GLcontext *ctx, GLvector1f *out, data[i] = (end - ABSF(*v)) * d; break; case GL_EXP: - d = -ctx->Fog.Density; + d = ctx->Fog.Density; for ( i = 0 ; i < n ; i++, STRIDE_F(v,stride)) - data[i] = exp( d*ABSF(*v) ); + NEG_EXP( data[i], d*ABSF(*v) ); break; case GL_EXP2: - d = -(ctx->Fog.Density*ctx->Fog.Density); + d = ctx->Fog.Density*ctx->Fog.Density; for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride)) { GLfloat z = *v; - data[i] = exp( d*z*z ); + NEG_EXP( data[i], d*z*z ); } break; default: @@ -173,6 +205,9 @@ static GLboolean alloc_fog_data( GLcontext *ctx, gl_vector1f_alloc( &store->fogcoord, 0, tnl->vb.Size, 32 ); gl_vector1f_init( &store->input, 0, 0 ); + if (!inited) + init_static_data(); + /* Now run the stage. */ stage->run = run_fog_stage; |