-/* $Id: t_vb_fog.c,v 1.10 2001/03/30 14:44:44 gareth Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 3.5
+ * Version: 5.1
*
- * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2003 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"),
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Authors:
- * Keith Whitwell <keithw@valinux.com>
+ * Keith Whitwell <keith@tungstengraphics.com>
*/
#include "colormac.h"
#include "context.h"
#include "macros.h"
-#include "mem.h"
-#include "mmath.h"
+#include "imports.h"
#include "mtypes.h"
#include "math/m_xform.h"
struct fog_stage_data {
- GLvector1f fogcoord; /* has actual storage allocated */
- GLvector1f input; /* points into VB->EyePtr Z values */
+ 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)
#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];
#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)
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;
}
-static void make_win_fog_coords( GLcontext *ctx, GLvector1f *out,
- const GLvector1f *in )
+static void make_win_fog_coords( GLcontext *ctx, GLvector4f *out,
+ const GLvector4f *in )
{
GLfloat end = ctx->Fog.End;
GLfloat *v = in->start;
GLuint stride = in->stride;
GLuint n = in->count;
- GLfloat *data = out->data;
+ GLfloat (*data)[4] = out->data;
GLfloat d;
GLuint i;
else
d = 1.0F / (ctx->Fog.End - ctx->Fog.Start);
for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride)) {
- GLfloat f = (end - ABSF(*v)) * d;
- data[i] = CLAMP(f, 0.0F, 1.0F);
+ GLfloat f = (end - FABSF(*v)) * d;
+ data[i][0] = CLAMP(f, 0.0F, 1.0F);
}
break;
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][0], d * FABSF(*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][0], d * z * z );
}
break;
default:
static GLboolean run_fog_stage( GLcontext *ctx,
- struct gl_pipeline_stage *stage )
+ struct tnl_pipeline_stage *stage )
{
struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
struct fog_stage_data *store = FOG_STAGE_DATA(stage);
- GLvector1f *input;
+ GLvector4f *input;
if (stage->changed_inputs == 0)
return GL_TRUE;
VB->FogCoordPtr = &store->fogcoord;
if (!ctx->_NeedEyeCoords) {
- GLfloat *m = ctx->ModelView.m;
+ const GLfloat *m = ctx->ModelviewMatrixStack.Top->m;
GLfloat plane[4];
/* Use this to store calculated eye z values:
/* Full eye coords weren't required, just calculate the
* eye Z values.
*/
- _mesa_dotprod_tab[VB->ObjPtr->size]( input->data,
- sizeof(GLfloat),
+ _mesa_dotprod_tab[VB->ObjPtr->size]( (GLfloat *) input->data,
+ 4 * sizeof(GLfloat),
VB->ObjPtr, plane );
input->count = VB->ObjPtr->count;
}
- else
- {
+ else {
input = &store->input;
if (VB->EyePtr->size < 2)
_mesa_vector4f_clean_elem( VB->EyePtr, VB->Count, 2 );
- input->data = &(VB->EyePtr->data[0][2]);
+ input->data = (GLfloat (*)[4]) &(VB->EyePtr->data[0][2]);
input->start = VB->EyePtr->start+2;
input->stride = VB->EyePtr->stride;
input->count = VB->EyePtr->count;
}
- } else {
+ }
+ else {
/* use glFogCoord() coordinates */
/* source = VB->FogCoordPtr */
input = VB->FogCoordPtr;
}
make_win_fog_coords( ctx, VB->FogCoordPtr, input );
+
+ VB->AttribPtr[_TNL_ATTRIB_FOG] = VB->FogCoordPtr;
return GL_TRUE;
}
-static void check_fog_stage( GLcontext *ctx, struct gl_pipeline_stage *stage )
+
+static void check_fog_stage( GLcontext *ctx, struct tnl_pipeline_stage *stage )
{
- stage->active = ctx->Fog.Enabled;
+ stage->active = ctx->Fog.Enabled && !ctx->VertexProgram.Enabled;
if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT)
- stage->inputs = VERT_EYE;
+ stage->inputs = _TNL_BIT_POS;
else
- stage->inputs = VERT_FOG_COORD;
+ stage->inputs = _TNL_BIT_FOG;
}
/* Called the first time stage->run() is invoked.
*/
static GLboolean alloc_fog_data( GLcontext *ctx,
- struct gl_pipeline_stage *stage )
+ struct tnl_pipeline_stage *stage )
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
struct fog_stage_data *store;
if (!store)
return GL_FALSE;
- _mesa_vector1f_alloc( &store->fogcoord, 0, tnl->vb.Size, 32 );
- _mesa_vector1f_init( &store->input, 0, 0 );
+ _mesa_vector4f_alloc( &store->fogcoord, 0, tnl->vb.Size, 32 );
+ _mesa_vector4f_init( &store->input, 0, 0 );
if (!inited)
init_static_data();
}
-static void free_fog_data( struct gl_pipeline_stage *stage )
+static void free_fog_data( struct tnl_pipeline_stage *stage )
{
struct fog_stage_data *store = FOG_STAGE_DATA(stage);
if (store) {
- _mesa_vector1f_free( &store->fogcoord );
+ _mesa_vector4f_free( &store->fogcoord );
FREE( store );
stage->privatePtr = NULL;
}
}
-const struct gl_pipeline_stage _tnl_fog_coordinate_stage =
+const struct tnl_pipeline_stage _tnl_fog_coordinate_stage =
{
- "build fog coordinates",
- _NEW_FOG,
- _NEW_FOG,
- 0, 0, VERT_FOG_COORD, /* active, inputs, outputs */
- 0, 0, /* changed_inputs, private_data */
+ "build fog coordinates", /* name */
+ _NEW_FOG, /* check_state */
+ _NEW_FOG, /* run_state */
+ GL_FALSE, /* active? */
+ 0, /* inputs */
+ _TNL_BIT_FOG, /* outputs */
+ 0, /* changed_inputs */
+ NULL, /* private_data */
free_fog_data, /* dtr */
check_fog_stage, /* check */
alloc_fog_data /* run -- initially set to init. */