summaryrefslogtreecommitdiffstats
path: root/src/mesa/swrast/s_context.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2004-02-17 21:03:03 +0000
committerBrian Paul <[email protected]>2004-02-17 21:03:03 +0000
commit09da0b8e6621a831e3eeb9381430f2bed18a22ad (patch)
treee7e307c3a5ddd773b469cf17d0331822388b466e /src/mesa/swrast/s_context.c
parent9a389d4bdb8026063034767e1599be975cb4e2f2 (diff)
A bit of an overhaul of the fog code.
glFogCoord didn't always work reliably. ARB fragment program fog options work now. Per-fragment fog computations are now perspective corrected.
Diffstat (limited to 'src/mesa/swrast/s_context.c')
-rw-r--r--src/mesa/swrast/s_context.c47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index c69d4cfd5d4..800f79080f8 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 5.1
+ * Version: 6.1
*
- * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 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"),
@@ -28,6 +28,7 @@
#include "imports.h"
#include "context.h"
+#include "colormac.h"
#include "mtypes.h"
#include "texobj.h"
#include "nvfragprog.h"
@@ -141,15 +142,17 @@ _swrast_update_polygon( GLcontext *ctx )
static void
-_swrast_update_hint( GLcontext *ctx )
+_swrast_update_fog_hint( GLcontext *ctx )
{
SWcontext *swrast = SWRAST_CONTEXT(ctx);
swrast->_PreferPixelFog = (!swrast->AllowVertexFog ||
+ ctx->FragmentProgram.Enabled ||
(ctx->Hint.Fog == GL_NICEST &&
swrast->AllowPixelFog));
}
+
/*
* Update the swrast->_AnyTextureCombine flag.
*/
@@ -169,6 +172,36 @@ _swrast_update_texture_env( GLcontext *ctx )
}
+/*
+ * Update swrast->_FogColor and swrast->_FogEnable values.
+ */
+static void
+_swrast_update_fog_state( GLcontext *ctx )
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+
+ /* convert fog color to GLchan values */
+ CLAMPED_FLOAT_TO_CHAN(swrast->_FogColor[RCOMP], ctx->Fog.Color[RCOMP]);
+ CLAMPED_FLOAT_TO_CHAN(swrast->_FogColor[GCOMP], ctx->Fog.Color[GCOMP]);
+ CLAMPED_FLOAT_TO_CHAN(swrast->_FogColor[BCOMP], ctx->Fog.Color[BCOMP]);
+
+ /* determine if fog is needed */
+ swrast->_FogEnabled = GL_FALSE;
+ if (ctx->Fog.Enabled) {
+ swrast->_FogEnabled = GL_TRUE;
+ }
+ else if (ctx->FragmentProgram.Enabled &&
+ ctx->FragmentProgram.Current->Base.Target == GL_FRAGMENT_PROGRAM_ARB) {
+ const struct fragment_program *p;
+ p = (struct fragment_program *) ctx->FragmentProgram.Current;
+ if (p->FogOption != GL_NONE) {
+ swrast->_FogEnabled = GL_TRUE;
+ }
+ }
+}
+
+
+
#define _SWRAST_NEW_DERIVED (_SWRAST_NEW_RASTERMASK | \
_NEW_TEXTURE | \
_NEW_HINT | \
@@ -393,12 +426,16 @@ _swrast_validate_derived( GLcontext *ctx )
if (swrast->NewState & _NEW_POLYGON)
_swrast_update_polygon( ctx );
- if (swrast->NewState & _NEW_HINT)
- _swrast_update_hint( ctx );
+ if (swrast->NewState & (_NEW_HINT | _NEW_PROGRAM))
+ _swrast_update_fog_hint( ctx );
if (swrast->NewState & _SWRAST_NEW_TEXTURE_ENV_MODE)
_swrast_update_texture_env( ctx );
+ if (swrast->NewState & _NEW_FOG) {
+ _swrast_update_fog_state( ctx );
+ }
+
swrast->NewState = 0;
swrast->StateChanges = 0;
swrast->InvalidateState = _swrast_invalidate_state;