Use a lookup table to compute exponents in tnl fogging code. Slightly
authorKeith Whitwell <keith@tungstengraphics.com>
Tue, 6 Feb 2001 04:06:34 +0000 (04:06 +0000)
committerKeith Whitwell <keith@tungstengraphics.com>
Tue, 6 Feb 2001 04:06:34 +0000 (04:06 +0000)
clean up the shine table lookup macro.

src/mesa/drivers/x11/xm_tri.c
src/mesa/main/dd.h
src/mesa/main/imports.c
src/mesa/main/light.h
src/mesa/tnl/t_vb_fog.c

index 4bb33ce66e3938a679c9ee8941f6762fc89fc76a..9f152265f753c60163e585e6d305b6d1be4e4734 100644 (file)
@@ -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);
index 542f866ff6755f25affb50abe6ee79334ad159a8..417beed91d1a59f6630206e6aa5a101e0be05a89 100644 (file)
@@ -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.
index 93fb906f35f15d1ed6fed387fecb7d32f657abfb..e36f7a24b025cc3300d25edbe7a9bfa77a823278 100644 (file)
@@ -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;
index f737abf4e45dd1f400c036a50586c9ee06943baa..b39aa002d879067de9361b1f77d7d7716eea4688 100644 (file)
@@ -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)
 
 
index 2adb8d1850006b5c6f7904f5834291956dbdcb37..e7f740dfa3c2d0d59b2ac3e47f678b8df3732ee9 100644 (file)
@@ -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;