Merge branch 'mesa_7_5_branch' into dlist-statechange-shortcircuit
[mesa.git] / src / mesa / main / fog.c
index 79f480db37b01e18054e39cda92a577ed5d86125..50a61bd84bff8bfac1cdfc7306be2a7a3b92062e 100644 (file)
 
 
 
-void
+void GLAPIENTRY
 _mesa_Fogf(GLenum pname, GLfloat param)
 {
    _mesa_Fogfv(pname, &param);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_Fogi(GLenum pname, GLint param )
 {
    GLfloat fparam = (GLfloat) param;
@@ -46,7 +46,7 @@ _mesa_Fogi(GLenum pname, GLint param )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_Fogiv(GLenum pname, const GLint *params )
 {
    GLfloat p[4];
@@ -73,7 +73,15 @@ _mesa_Fogiv(GLenum pname, const GLint *params )
 }
 
 
-void
+#define UPDATE_FOG_SCALE(ctx) do {\
+      if (ctx->Fog.End == ctx->Fog.Start)\
+         ctx->Fog._Scale = 1.0f;\
+      else\
+         ctx->Fog._Scale = 1.0f / (ctx->Fog.End - ctx->Fog.Start);\
+   } while(0)
+
+
+void GLAPIENTRY
 _mesa_Fogfv( GLenum pname, const GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -108,17 +116,19 @@ _mesa_Fogfv( GLenum pname, const GLfloat *params )
         ctx->Fog.Density = *params;
         break;
       case GL_FOG_START:
-        if (ctx->Fog.Start == *params)
-           return;
-        FLUSH_VERTICES(ctx, _NEW_FOG);
-        ctx->Fog.Start = *params;
-        break;
+         if (ctx->Fog.Start == *params)
+            return;
+         FLUSH_VERTICES(ctx, _NEW_FOG);
+         ctx->Fog.Start = *params;
+         UPDATE_FOG_SCALE(ctx);
+         break;
       case GL_FOG_END:
-        if (ctx->Fog.End == *params)
-           return;
-        FLUSH_VERTICES(ctx, _NEW_FOG);
-        ctx->Fog.End = *params;
-        break;
+         if (ctx->Fog.End == *params)
+            return;
+         FLUSH_VERTICES(ctx, _NEW_FOG);
+         ctx->Fog.End = *params;
+         UPDATE_FOG_SCALE(ctx);
+         break;
       case GL_FOG_INDEX:
         if (ctx->Fog.Index == *params)
            return;
@@ -156,3 +166,23 @@ _mesa_Fogfv( GLenum pname, const GLfloat *params )
       (*ctx->Driver.Fogfv)( ctx, pname, params );
    }
 }
+
+
+/**********************************************************************/
+/*****                      Initialization                        *****/
+/**********************************************************************/
+
+void _mesa_init_fog( GLcontext * ctx )
+{
+   /* Fog group */
+   ctx->Fog.Enabled = GL_FALSE;
+   ctx->Fog.Mode = GL_EXP;
+   ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
+   ctx->Fog.Index = 0.0;
+   ctx->Fog.Density = 1.0;
+   ctx->Fog.Start = 0.0;
+   ctx->Fog.End = 1.0;
+   ctx->Fog.ColorSumEnabled = GL_FALSE;
+   ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
+   ctx->Fog._Scale = 1.0f;
+}