-
- ctx->NewState |= NEW_FOG;
-}
-
-
-
-
-void
-_mesa_init_fog( void )
-{
-}
-
-static GLvector1f *get_fogcoord_ptr( GLcontext *ctx, GLvector1f *tmp )
-{
- struct vertex_buffer *VB = ctx->VB;
-
- if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT) {
- if (!ctx->NeedEyeCoords) {
- GLfloat *m = ctx->ModelView.m;
- GLfloat plane[4];
-
- plane[0] = m[2];
- plane[1] = m[6];
- plane[2] = m[10];
- plane[3] = m[14];
-
- /* Full eye coords weren't required, just calculate the
- * eye Z values.
- */
- gl_dotprod_tab[0][VB->ObjPtr->size](&VB->Eye, 2,
- VB->ObjPtr, plane, 0 );
-
- tmp->data = &(VB->Eye.data[0][2]);
- tmp->start = VB->Eye.start+2;
- tmp->stride = VB->Eye.stride;
- return tmp;
- }
- else
- {
- if (VB->EyePtr->size < 2)
- gl_vector4f_clean_elem( &VB->Eye, VB->Count, 2 );
-
- tmp->data = &(VB->EyePtr->data[0][2]);
- tmp->start = VB->EyePtr->start+2;
- tmp->stride = VB->EyePtr->stride;
- return tmp;
- }
- } else
- return VB->FogCoordPtr;
-}
-
-
-/* Use lookup table & interpolation?
- */
-static void
-make_win_fog_coords( struct vertex_buffer *VB,
- GLvector1f *fogcoord)
-{
- const GLcontext *ctx = VB->ctx;
- GLfloat end = ctx->Fog.End;
- GLfloat *v = fogcoord->start;
- GLuint stride = fogcoord->stride;
- GLuint n = VB->Count - VB->Start;
- GLfloat *out;
- GLfloat d;
- GLuint i;
-
- VB->FogCoordPtr = VB->store.FogCoord;
- out = VB->FogCoordPtr->data + VB->Start;
-
- switch (ctx->Fog.Mode) {
- case GL_LINEAR:
- d = 1.0F / (ctx->Fog.End - ctx->Fog.Start);
- for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride)) {
- out[i] = (end - ABSF(*v)) * d;
- if (0) fprintf(stderr, "z %f out %f\n", *v, out[i]);
- }
- break;
- case GL_EXP:
- d = -ctx->Fog.Density;
- for ( i = 0 ; i < n ; i++, STRIDE_F(v,stride)) {
- out[i] = exp( d*ABSF(*v) );
- if (0) fprintf(stderr, "z %f out %f\n", *v, out[i]);
- }
- break;
- case GL_EXP2:
- d = -(ctx->Fog.Density*ctx->Fog.Density);
- for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride)) {
- GLfloat z = *v;
- out[i] = exp( d*z*z );
- if (0) fprintf(stderr, "z %f out %f\n", *v, out[i]);
- }
- break;
- default:
- gl_problem(ctx, "Bad fog mode in make_fog_coord");
- return;
- }
-}
-
-
-void
-_mesa_make_win_fog_coords( struct vertex_buffer *VB )
-{
- GLvector1f tmp;
-
- make_win_fog_coords( VB, get_fogcoord_ptr( VB->ctx, &tmp ) );
-}
-
-
-
-/*
- * Apply fog to an array of RGBA pixels.
- * Input: n - number of pixels
- * fog - array of interpolated screen-space fog coordinates in [0..1]
- * red, green, blue, alpha - pixel colors
- * Output: red, green, blue, alpha - fogged pixel colors
- */
-void
-_mesa_fog_rgba_pixels( const GLcontext *ctx,
- GLuint n,
- const GLfixed fog[],
- GLubyte rgba[][4] )
-{
- GLfixed rFog = ctx->Fog.Color[0] * 255.0;
- GLfixed gFog = ctx->Fog.Color[1] * 255.0;
- GLfixed bFog = ctx->Fog.Color[2] * 255.0;
- GLuint i;
-
- for (i=0;i<n;i++) {
- GLfixed f = CLAMP(fog[i], 0, FIXED_ONE);
- GLfixed g = FIXED_ONE - f;
- rgba[i][0] = (f*rgba[i][0] + g*rFog) >> FIXED_SHIFT;
- rgba[i][1] = (f*rgba[i][1] + g*gFog) >> FIXED_SHIFT;
- rgba[i][2] = (f*rgba[i][2] + g*bFog) >> FIXED_SHIFT;
- }