Merge remote branch 'origin/gallium-0.2' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / sis / sis_fog.c
index 8daa9a0f5e3ea23fbd5b611fdfdf6bd20c9cfefd..517d5722e6a86285bd70d7736c4b3ec7af1a42de 100644 (file)
@@ -18,13 +18,12 @@ Software.
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
-ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 **************************************************************************/
-/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_fog.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ */
 
 /*
  * Authors:
@@ -35,14 +34,17 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "sis_context.h"
 #include "sis_state.h"
 #include "swrast/swrast.h"
-#include "macros.h"
+
+#include "main/macros.h"
 
 static GLint convertFtToFogFt( GLfloat dwInValue );
+static GLint doFPtoFixedNoRound( GLfloat dwInValue, int nFraction );
 
 void
 sisDDFogfv( GLcontext *ctx, GLenum pname, const GLfloat *params )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
+   __GLSiSHardware *prev = &smesa->prev;
    __GLSiSHardware *current = &smesa->current;
 
    float fArg;
@@ -50,35 +52,47 @@ sisDDFogfv( GLcontext *ctx, GLenum pname, const GLfloat *params )
 
    switch (pname)
    {
+   case GL_FOG_COORDINATE_SOURCE_EXT:
+      current->hwFog &= ~MASK_FogMode;
+      switch (ctx->Fog.FogCoordinateSource)
+      {
+      case GL_FOG_COORDINATE_EXT:
+         current->hwFog &= ~MASK_FogZLookup;
+         break;
+      case GL_FRAGMENT_DEPTH_EXT:
+         current->hwFog |= MASK_FogZLookup;
+         break;
+      }
+      if (current->hwFog != prev->hwFog) {
+         prev->hwFog = current->hwFog;
+         smesa->GlobalFlag |= GFLAG_FOGSETTING;
+      }
+      break;
    case GL_FOG_MODE:
       current->hwFog &= ~MASK_FogMode;
       switch (ctx->Fog.Mode)
       {
       case GL_LINEAR:
          current->hwFog |= FOGMODE_LINEAR;
-         _swrast_allow_pixel_fog( ctx, GL_TRUE );
-         _swrast_allow_vertex_fog( ctx, GL_FALSE );
          break;
       case GL_EXP:
-         if (ctx->Hint.Fog == GL_NICEST || smesa->AGPCmdModeEnabled) {
-            current->hwFog |= FOGMODE_EXP;
-            _swrast_allow_pixel_fog( ctx, GL_TRUE );
-            _swrast_allow_vertex_fog( ctx, GL_FALSE );
-         } else { /* GL_DONTCARE or GL_FASTEST */
-            current->hwFog |= FOGMODE_CHEAP;
-            _swrast_allow_pixel_fog( ctx, GL_FALSE );
-            _swrast_allow_vertex_fog( ctx, GL_TRUE );
-         }
+         current->hwFog |= FOGMODE_EXP;
          break;
       case GL_EXP2:
          current->hwFog |= FOGMODE_EXP2;
-         _swrast_allow_pixel_fog( ctx, GL_TRUE );
-         _swrast_allow_vertex_fog( ctx, GL_FALSE );
          break;
       }
+      if (current->hwFog != prev->hwFog) {
+         prev->hwFog = current->hwFog;
+         smesa->GlobalFlag |= GFLAG_FOGSETTING;
+      }
       break;
    case GL_FOG_DENSITY:
       current->hwFogDensity = convertFtToFogFt( ctx->Fog.Density );
+      if (current->hwFogDensity != prev->hwFogDensity) {
+         prev->hwFogDensity = current->hwFogDensity;
+         smesa->GlobalFlag |= GFLAG_FOGSETTING;
+      }
       break;
    case GL_FOG_START:
    case GL_FOG_END:
@@ -91,6 +105,13 @@ sisDDFogfv( GLcontext *ctx, GLenum pname, const GLfloat *params )
          else
             current->hwFogFar = doFPtoFixedNoRound( ctx->Fog.End, 6 );
       }
+      if (current->hwFogFar != prev->hwFogFar ||
+          current->hwFogInverse != prev->hwFogInverse)
+      {
+         prev->hwFogFar = current->hwFogFar;
+         prev->hwFogInverse = current->hwFogInverse;
+         smesa->GlobalFlag |= GFLAG_FOGSETTING;
+      }
       break;
    case GL_FOG_INDEX:
       /* TODO */
@@ -101,11 +122,15 @@ sisDDFogfv( GLcontext *ctx, GLenum pname, const GLfloat *params )
       fogColor |= FLOAT_TO_UBYTE( ctx->Fog.Color[2] );
       current->hwFog &= 0xff000000;
       current->hwFog |= fogColor;
+      if (current->hwFog != prev->hwFog) {
+          prev->hwFog = current->hwFog;
+         smesa->GlobalFlag |= GFLAG_FOGSETTING;
+      }
       break;
    }
 }
 
-GLint
+static GLint
 doFPtoFixedNoRound( GLfloat dwInValue, int nFraction )
 {
    GLint dwMantissa;