-/* $Id: s_fog.c,v 1.16 2001/12/18 04:06:46 brianp Exp $ */
+/* $Id: s_fog.c,v 1.17 2002/01/21 18:12:34 brianp Exp $ */
/*
* Mesa 3-D graphics library
-/*
+/**
* Used to convert current raster distance to a fog factor in [0,1].
*/
GLfloat
-/*
+/**
* Apply fog to a span of RGBA pixels.
* Input: ctx -
* span - where span->fog and span->fogStep have to be set.
}
}
-/*
+
+/**
+ * Apply fog given in an array to RGBA pixels.
+ * Input: ctx -
+ * span -
+ * fog - array of fog factors in [0,1]
+ * red, green, blue, alpha - pixel colors
+ * Output: red, green, blue, alpha - fogged pixel colors
+ */
+void
+_mesa_fog_rgba_pixels_with_array( const GLcontext *ctx, struct sw_span *span,
+ const GLfloat fog[], GLchan rgba[][4] )
+{
+ GLuint i;
+ GLchan rFog, gFog, bFog;
+
+ ASSERT(fog != NULL);
+ ASSERT(ctx->Fog.Enabled);
+ ASSERT(span->filledColor == GL_TRUE);
+
+ 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]);
+
+ for (i = span->start; i < span->end; i++) {
+ const GLfloat f = fog[i];
+ const GLfloat g = 1.0F - f;
+ rgba[i][RCOMP] = (GLchan) (f * rgba[i][RCOMP] + g * rFog);
+ rgba[i][GCOMP] = (GLchan) (f * rgba[i][GCOMP] + g * gFog);
+ rgba[i][BCOMP] = (GLchan) (f * rgba[i][BCOMP] + g * bFog);
+ }
+}
+
+/**
* Apply fog to an array of RGBA pixels.
* Input: n - number of pixels
* fog - array of fog factors in [0,1]
}
-/*
+/**
* Apply fog to a span of color index pixels.
* Input: ctx -
* span - where span->fog and span->fogStep have to be set.
}
}
-/*
+
+/**
+ * Apply fog given in an array to a span of color index pixels.
+ * Input: ctx -
+ * span -
+ * fog - array of fog factors in [0,1]
+ * index - pixel color indexes
+ * Output: index - fogged pixel color indexes
+ */
+void
+_mesa_fog_ci_pixels_with_array( const GLcontext *ctx, struct sw_span *span,
+ const GLfloat fog[], GLuint index[] )
+{
+ GLuint idx = (GLuint) ctx->Fog.Index;
+ GLuint i;
+
+ ASSERT(fog != NULL);
+ ASSERT(ctx->Fog.Enabled);
+ ASSERT(span->filledColor == GL_TRUE);
+
+ for (i = span->start; i < span->end; i++) {
+ const GLfloat f = CLAMP(fog[i], 0.0F, 1.0F);
+ index[i] = (GLuint) ((GLfloat) index[i] + (1.0F - f) * idx);
+ }
+}
+
+/**
* Apply fog to an array of color index pixels.
* Input: n - number of pixels
* fog - array of fog factors in [0,1]
-/*
+/**
* Calculate fog factors (in [0,1]) from window z values
* Input: n - number of pixels
* z - array of integer depth values
}
-/*
+/**
* Apply fog to a span of RGBA pixels.
* Input: ctx -
* span - where span->depth has to be filled.
ASSERT(span->filledColor == GL_TRUE);
compute_fog_factors_from_z(ctx, span->end, span->depth, fogFact );
- _old_fog_rgba_pixels( ctx, span->end, fogFact, rgba );
+ _mesa_fog_rgba_pixels_with_array( ctx, span, fogFact, rgba );
}
-/*
+
+/**
* Apply fog to an array of RGBA pixels.
* Input: n - number of pixels
* z - array of integer depth values
}
-/*
+/**
* Apply fog to a span of color index pixels.
* Input: ctx -
* span - where span->depth has to be filled.
ASSERT(span->filledColor == GL_TRUE);
compute_fog_factors_from_z(ctx, span->end, span->depth, fogFact );
- _old_fog_ci_pixels( ctx, span->end, fogFact, index );
+ _mesa_fog_ci_pixels_with_array( ctx, span, fogFact, index );
}
-/*
+/**
* Apply fog to an array of color index pixels.
* Input: n - number of pixels
* z - array of integer depth values