/*
* Mesa 3-D graphics library
- * Version: 6.1
+ * Version: 6.5
*
- * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
*/
-#include "glheader.h"
-#include "colormac.h"
-#include "context.h"
-#include "macros.h"
-#include "imports.h"
-#include "mtypes.h"
+#include "main/glheader.h"
+#include "main/colormac.h"
+#include "main/context.h"
+#include "main/macros.h"
+#include "main/imports.h"
+#include "main/mtypes.h"
#include "math/m_xform.h"
struct fog_stage_data {
GLvector4f fogcoord; /* has actual storage allocated */
- GLvector4f input; /* points into VB->EyePtr Z values */
};
#define FOG_STAGE_DATA(stage) ((struct fog_stage_data *)stage->privatePtr)
GLfloat f = 0.0F;
GLint i = 0;
for ( ; i < FOG_EXP_TABLE_SIZE ; i++, f += FOG_INCR) {
- exp_table[i] = (GLfloat) exp(-f);
+ exp_table[i] = EXPF(-f);
}
inited = 1;
}
* evaluating the GL_LINEAR, GL_EXP or GL_EXP2 fog function.
* Fog coordinates are distances from the eye (typically between the
* near and far clip plane distances).
+ * Note that fogcoords may be negative, if eye z is source absolute
+ * value must be taken earlier.
* Fog blend factors are in the range [0,1].
*/
static void
struct fog_stage_data *store = FOG_STAGE_DATA(stage);
GLvector4f *input;
- if (stage->changed_inputs == 0)
+
+ if (!ctx->Fog.Enabled)
return GL_TRUE;
- if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT) {
+ if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT && !ctx->VertexProgram._Current) {
+ GLuint i;
+ GLfloat *coord;
/* Fog is computed from vertex or fragment Z values */
/* source = VB->ObjPtr or VB->EyePtr coords */
- /* dest = VB->FogCoordPtr = fog stage private storage */
- VB->FogCoordPtr = &store->fogcoord;
+ /* dest = VB->AttribPtr[_TNL_ATTRIB_FOG] = fog stage private storage */
+ VB->AttribPtr[_TNL_ATTRIB_FOG] = &store->fogcoord;
if (!ctx->_NeedEyeCoords) {
/* compute fog coords from object coords */
*/
input = &store->fogcoord;
- /* NOTE: negate plane here so we get positive fog coords! */
- plane[0] = -m[2];
- plane[1] = -m[6];
- plane[2] = -m[10];
- plane[3] = -m[14];
-
+ 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.
*/
VB->ObjPtr, plane );
input->count = VB->ObjPtr->count;
+
+ /* make sure coords are really positive
+ NOTE should avoid going through array twice */
+ coord = input->start;
+ for (i = 0; i < input->count; i++) {
+ *coord = FABSF(*coord);
+ STRIDE_F(coord, input->stride);
+ }
}
else {
- /* fog coordinates = eye Z coordinates (use ABS later) */
- input = &store->input;
+ /* fog coordinates = eye Z coordinates - need to copy for ABS */
+ input = &store->fogcoord;
if (VB->EyePtr->size < 2)
_mesa_vector4f_clean_elem( VB->EyePtr, VB->Count, 2 );
- input->data = (GLfloat (*)[4]) &(VB->EyePtr->data[0][2]);
- input->start = VB->EyePtr->start+2;
- input->stride = VB->EyePtr->stride;
+ input->stride = 4 * sizeof(GLfloat);
input->count = VB->EyePtr->count;
+ coord = VB->EyePtr->start;
+ for (i = 0 ; i < VB->EyePtr->count; i++) {
+ input->data[i][0] = FABSF(coord[2]);
+ STRIDE_F(coord, VB->EyePtr->stride);
+ }
}
}
else {
/* use glFogCoord() coordinates */
- input = VB->FogCoordPtr; /* source data */
- VB->FogCoordPtr = &store->fogcoord; /* dest data */
+ input = VB->AttribPtr[_TNL_ATTRIB_FOG]; /* source data */
+
+ /* input->count may be one if glFogCoord was only called once
+ * before glBegin. But we need to compute fog for all vertices.
+ */
+ input->count = VB->ObjPtr->count;
+
+ VB->AttribPtr[_TNL_ATTRIB_FOG] = &store->fogcoord; /* dest data */
}
if (tnl->_DoVertexFog) {
/* compute blend factors from fog coordinates */
- compute_fog_blend_factors( ctx, VB->FogCoordPtr, input );
+ compute_fog_blend_factors( ctx, VB->AttribPtr[_TNL_ATTRIB_FOG], input );
}
else {
/* results = incoming fog coords (compute fog per-fragment later) */
- VB->FogCoordPtr = input;
+ VB->AttribPtr[_TNL_ATTRIB_FOG] = input;
}
- VB->AttribPtr[_TNL_ATTRIB_FOG] = VB->FogCoordPtr;
+ VB->FogCoordPtr = VB->AttribPtr[_TNL_ATTRIB_FOG];
return GL_TRUE;
}
-static void
-check_fog_stage(GLcontext *ctx, struct tnl_pipeline_stage *stage)
-{
- stage->active = ctx->Fog.Enabled && !ctx->VertexProgram.Enabled;
-
- if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT)
- stage->inputs = _TNL_BIT_POS;
- else
- stage->inputs = _TNL_BIT_FOG;
-}
-
/* Called the first time stage->run() is invoked.
*/
return GL_FALSE;
_mesa_vector4f_alloc( &store->fogcoord, 0, tnl->vb.Size, 32 );
- _mesa_vector4f_init( &store->input, 0, 0 );
if (!inited)
init_static_data();
- /* Now run the stage.
- */
- stage->run = run_fog_stage;
- return stage->run( ctx, stage );
+ return GL_TRUE;
}
const struct tnl_pipeline_stage _tnl_fog_coordinate_stage =
{
"build fog coordinates", /* name */
- _NEW_FOG|_NEW_PROGRAM, /* check_state */
- _NEW_FOG, /* run_state */
- GL_FALSE, /* active? */
- 0, /* inputs */
- _TNL_BIT_FOG, /* outputs */
- 0, /* changed_inputs */
NULL, /* private_data */
+ alloc_fog_data, /* dtr */
free_fog_data, /* dtr */
- check_fog_stage, /* check */
- alloc_fog_data /* run -- initially set to init. */
+ NULL, /* check */
+ run_fog_stage /* run -- initially set to init. */
};