Fix typo
[mesa.git] / src / mesa / swrast / s_fog.c
index 0e65f784f8e88dbb74498db2bb7f630cce727dc5..7c2d519173b32fdd736ee3ce9b4b8e5d1cee1edc 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: s_fog.c,v 1.6 2001/01/02 21:09:50 brianp Exp $ */
+/* $Id: s_fog.c,v 1.9 2001/03/03 20:33:30 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -49,10 +49,12 @@ _mesa_fog_rgba_pixels( const GLcontext *ctx,
                       const GLfixed fog[], 
                       GLchan rgba[][4] )
 {
-   const GLchan rFog = FLOAT_TO_CHAN(ctx->Fog.Color[RCOMP]);
-   const GLchan gFog = FLOAT_TO_CHAN(ctx->Fog.Color[GCOMP]);
-   const GLchan bFog = FLOAT_TO_CHAN(ctx->Fog.Color[BCOMP]);
    GLuint i;
+   GLchan rFog, gFog, bFog;
+
+   UNCLAMPED_FLOAT_TO_CHAN(rFog, ctx->Fog.Color[RCOMP]);
+   UNCLAMPED_FLOAT_TO_CHAN(gFog, ctx->Fog.Color[GCOMP]);
+   UNCLAMPED_FLOAT_TO_CHAN(bFog, ctx->Fog.Color[BCOMP]);
 
 #if CHAN_TYPE == GL_FLOAT
    for (i = 0; i < n; i++) {
@@ -117,9 +119,14 @@ _mesa_win_fog_coords_from_z( const GLcontext *ctx,
    const GLfloat p10 = ctx->ProjectionMatrix.m[10];
    const GLfloat p14 = ctx->ProjectionMatrix.m[14];
    const GLfloat tz = ctx->Viewport._WindowMap.m[MAT_TZ];
-   const GLfloat szInv = 1.0F / ctx->Viewport._WindowMap.m[MAT_SZ];
+   GLfloat szInv;
    GLuint i;
 
+   if (ctx->Viewport._WindowMap.m[MAT_SZ] == 0.0)
+      szInv = 1.0F;
+   else
+      szInv = 1.0F / ctx->Viewport._WindowMap.m[MAT_SZ];
+
    /*
     * Note: to compute eyeZ from the ndcZ we have to solve the following:
     *
@@ -147,7 +154,11 @@ _mesa_win_fog_coords_from_z( const GLcontext *ctx,
       case GL_LINEAR:
          {
             GLfloat fogEnd = ctx->Fog.End;
-            GLfloat fogScale = 1.0F / (ctx->Fog.End - ctx->Fog.Start);
+            GLfloat fogScale;
+            if (ctx->Fog.Start == ctx->Fog.End)
+               fogScale = 1.0;
+            else
+               fogScale = 1.0F / (ctx->Fog.End - ctx->Fog.Start);
             if (ortho) {
                for (i=0;i<n;i++) {
                   GLfloat ndcz = ((GLfloat) z[i] - tz) * szInv;
@@ -223,7 +234,7 @@ _mesa_win_fog_coords_from_z( const GLcontext *ctx,
          }
         break;
       default:
-         gl_problem(ctx, "Bad fog mode in _mesa_win_fog_coords_from_z");
+         _mesa_problem(ctx, "Bad fog mode in _mesa_win_fog_coords_from_z");
          return;
    }
 }