added GL_SGIX/SGIS_pixel_texture
[mesa.git] / src / mesa / main / fog.c
index 9a2520d60665946ebe5cf28d962a19a1e355ff6a..998c9bdac56043c7a57d10a3160712897265ffc4 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: fog.c,v 1.6 2000/02/02 22:22:59 brianp Exp $ */
+/* $Id: fog.c,v 1.8 2000/03/07 17:40:34 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -34,6 +34,7 @@
 #include "macros.h"
 #include "mmath.h"
 #include "types.h"
+#include "xform.h"
 #endif
 
 
@@ -106,23 +107,9 @@ _mesa_Fogfv( GLenum pname, const GLfloat *params )
         }
         break;
       case GL_FOG_START:
-#if 0
-         /* Prior to OpenGL 1.1, this was an error */
-         if (*params<0.0F) {
-            gl_error( ctx, GL_INVALID_VALUE, "glFog(GL_FOG_START)" );
-            return;
-         }
-#endif
         ctx->Fog.Start = *params;
         break;
       case GL_FOG_END:
-#if 0
-         /* Prior to OpenGL 1.1, this was an error */
-         if (*params<0.0F) {
-            gl_error( ctx, GL_INVALID_VALUE, "glFog(GL_FOG_END)" );
-            return;
-         }
-#endif
         ctx->Fog.End = *params;
         break;
       case GL_FOG_INDEX:
@@ -150,9 +137,13 @@ _mesa_Fogfv( GLenum pname, const GLfloat *params )
 typedef void (*fog_func)( struct vertex_buffer *VB, GLuint side, 
                          GLubyte flag );
 
+typedef void (*fog_coord_func)( struct vertex_buffer *VB, 
+                               const GLvector4f *from,
+                               GLubyte flag );
 
 static fog_func fog_ci_tab[2];
 static fog_func fog_rgba_tab[2];
+static fog_coord_func make_fog_coord_tab[2];
 
 /*
  * Compute the fogged color for an array of vertices.
@@ -210,6 +201,71 @@ _mesa_fog_vertices( struct vertex_buffer *VB )
    }
 }
 
+
+static void check_fog_coords( GLcontext *ctx, struct gl_pipeline_stage *d )
+{
+   d->type = 0;
+
+   if (ctx->FogMode==FOG_FRAGMENT)
+   {
+      d->type = PIPE_IMMEDIATE|PIPE_PRECALC;
+      d->inputs = VERT_OBJ_ANY;
+      d->outputs = VERT_FOG_COORD;
+   }
+}
+
+
+static void gl_make_fog_coords( struct vertex_buffer *VB )
+{
+   GLcontext *ctx = VB->ctx;
+
+   /* If full eye coords weren't required, just calculate the eye Z
+    * values.  
+    */
+   if (!ctx->NeedEyeCoords) {
+      GLfloat *m = ctx->ModelView.m;
+      GLfloat plane[4];
+
+      plane[0] = m[2];
+      plane[1] = m[6];
+      plane[2] = m[10];
+      plane[3] = m[14];
+
+      gl_dotprod_tab[0][VB->ObjPtr->size](&VB->Eye,
+                                         2, /* fill z coordinates */
+                                         VB->ObjPtr,
+                                         plane,
+                                         0 );
+
+      make_fog_coord_tab[0]( VB, &VB->Eye, 0 );
+   }
+   else
+   {
+      make_fog_coord_tab[0]( VB, VB->EyePtr, 0 );
+   }
+}
+
+
+/* Drivers that want fog coordinates in VB->Spec[0] alpha, can substitute this
+ * stage for the default PIPE_OP_FOG pipeline stage.
+ */
+struct gl_pipeline_stage gl_fog_coord_stage = {
+   "build fog coordinates",
+   PIPE_OP_FOG,
+   PIPE_PRECALC|PIPE_IMMEDIATE,
+   0,
+   NEW_FOG,
+   NEW_LIGHTING|NEW_RASTER_OPS|NEW_FOG|NEW_MODELVIEW,
+   0, 0,
+   0, 0, 0,
+   check_fog_coords,
+   gl_make_fog_coords 
+};
+
+
+
+
+
 /*
  * Apply fog to an array of RGBA pixels.
  * Input:  n - number of pixels