fx another place where PRIM_PARITY is calculated
[mesa.git] / src / mesa / tnl / t_vb_fog.c
index 0cffbbb0d15e6be47bed2a23e13c19f7099f93db..6fad9528cda42728feee4f70125b1d771f4fc906 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: t_vb_fog.c,v 1.8 2001/03/12 00:48:44 gareth Exp $ */
+/* $Id: t_vb_fog.c,v 1.12 2001/09/14 21:30:31 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -50,7 +50,7 @@ struct fog_stage_data {
 #define FOG_STAGE_DATA(stage) ((struct fog_stage_data *)stage->privatePtr)
 
 #define FOG_EXP_TABLE_SIZE 256
-#define FOG_MAX (5.0)
+#define FOG_MAX (10.0)
 #define EXP_FOG_MAX .0006595
 #define FOG_INCR (FOG_MAX/FOG_EXP_TABLE_SIZE)
 static GLfloat exp_table[FOG_EXP_TABLE_SIZE];
@@ -59,10 +59,10 @@ static GLfloat inited = 0;
 #if 1
 #define NEG_EXP( result, narg )                                                \
 do {                                                                   \
-   float f = (narg * (1.0/FOG_INCR));                                  \
-   int k = (int) f;                                                    \
+   GLfloat f = (GLfloat) (narg * (1.0/FOG_INCR));                      \
+   GLint k = (GLint) f;                                                        \
    if (k > FOG_EXP_TABLE_SIZE-2)                                       \
-      result = EXP_FOG_MAX;                                            \
+      result = (GLfloat) EXP_FOG_MAX;                                  \
    else                                                                        \
       result = exp_table[k] + (f-k)*(exp_table[k+1]-exp_table[k]);     \
 } while (0)
@@ -76,10 +76,10 @@ do {                                                                \
 
 static void init_static_data( void )
 {
-   float f = 0;
-   int i = 0;
+   GLfloat f = 0.0F;
+   GLint i = 0;
    for ( ; i < FOG_EXP_TABLE_SIZE ; i++, f += FOG_INCR) {
-      exp_table[i] = exp(-f);
+      exp_table[i] = (GLfloat) exp(-f);
    }
    inited = 1;
 }
@@ -112,13 +112,13 @@ static void make_win_fog_coords( GLcontext *ctx, GLvector1f *out,
    case GL_EXP:
       d = ctx->Fog.Density;
       for ( i = 0 ; i < n ; i++, STRIDE_F(v,stride))
-        NEG_EXP( data[i], d*ABSF(*v) );
+         NEG_EXP( data[i], d * ABSF(*v) );
       break;
    case GL_EXP2:
       d = ctx->Fog.Density*ctx->Fog.Density;
       for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride)) {
-        GLfloat z = *v;
-        NEG_EXP( data[i], d*z*z );
+         GLfloat z = *v;
+         NEG_EXP( data[i], d * z * z );
       }
       break;
    default:
@@ -135,12 +135,15 @@ static GLboolean run_fog_stage( GLcontext *ctx,
    struct fog_stage_data *store = FOG_STAGE_DATA(stage);
    GLvector1f *input;
 
-   VB->FogCoordPtr = &store->fogcoord;
-
    if (stage->changed_inputs == 0)
       return GL_TRUE;
 
    if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT) {
+      /* fog computed from Z depth */
+      /* source = VB->ObjPtr or VB->EyePtr coords */
+      /* dest = VB->FogCoordPtr = fog stage private storage */
+      VB->FogCoordPtr = &store->fogcoord;
+
       if (!ctx->_NeedEyeCoords) {
         GLfloat *m = ctx->ModelView.m;
         GLfloat plane[4];
@@ -157,8 +160,9 @@ static GLboolean run_fog_stage( GLcontext *ctx,
         /* Full eye coords weren't required, just calculate the
          * eye Z values.
          */
-        _mesa_dotprod_tab[0][VB->ObjPtr->size](input->data, sizeof(GLfloat),
-                                                VB->ObjPtr, plane, 0 );
+        _mesa_dotprod_tab[VB->ObjPtr->size]( input->data,
+                                             sizeof(GLfloat),
+                                             VB->ObjPtr, plane );
 
         input->count = VB->ObjPtr->count;
       }
@@ -174,8 +178,13 @@ static GLboolean run_fog_stage( GLcontext *ctx,
         input->stride = VB->EyePtr->stride;
         input->count = VB->EyePtr->count;
       }
-   } else
+   } else {
+      /* use glFogCoord() coordinates */
+      /* source = VB->FogCoordPtr */
       input = VB->FogCoordPtr;
+      /* dest = fog stage private storage */
+      VB->FogCoordPtr = &store->fogcoord;
+   }
 
    make_win_fog_coords( ctx, VB->FogCoordPtr, input );
    return GL_TRUE;