various pipeline bugs
diff --git a/src/mesa/drivers/glide/fxapi.c b/src/mesa/drivers/glide/fxapi.c
index fbc586e..82084e7 100644
--- a/src/mesa/drivers/glide/fxapi.c
+++ b/src/mesa/drivers/glide/fxapi.c
@@ -948,6 +948,7 @@
     fxMesa->haveTwoTMUs=GL_FALSE;
 
   if (getenv("FX_EMULATE_SINGLE_TMU")) {
+     fprint(stderr, "stadnnadna;lskdjf");
      if (MESA_VERBOSE&VERBOSE_DRIVER) 
        fprintf(stderr, "\n\nEmulating single tmu\n\n");
      fxMesa->haveTwoTMUs = GL_FALSE;
diff --git a/src/mesa/drivers/glide/fxdd.c b/src/mesa/drivers/glide/fxdd.c
index b2f3a7a..8fe8d80 100644
--- a/src/mesa/drivers/glide/fxdd.c
+++ b/src/mesa/drivers/glide/fxdd.c
@@ -513,6 +513,10 @@
     if(new_state & INTERESTED) {
       fxDDChooseRenderState( ctx );
       fxMesa->RenderVBTables=fxDDChooseRenderVBTables(ctx);
+      fxMesa->RenderVBClippedTab=fxMesa->RenderVBTables[0];
+      fxMesa->RenderVBCulledTab=fxMesa->RenderVBTables[1];
+      fxMesa->RenderVBRawTab=fxMesa->RenderVBTables[2];
+
       ctx->Driver.RasterSetup=fxDDChooseSetupFunction(ctx);
     }
       
@@ -520,10 +524,6 @@
     ctx->Driver.LineFunc=fxMesa->LineFunc;
     ctx->Driver.TriangleFunc=fxMesa->TriangleFunc;
     ctx->Driver.QuadFunc=fxMesa->QuadFunc;
-    ctx->Driver.RenderVBClippedTab=fxMesa->RenderVBTables[0];
-    ctx->Driver.RenderVBCulledTab=fxMesa->RenderVBTables[1];
-    ctx->Driver.RenderVBRawTab=fxMesa->RenderVBTables[2];
-
   }
 
   ctx->Driver.AllocDepthBuffer=fxAllocDepthBuffer;
diff --git a/src/mesa/drivers/glide/fxdrv.h b/src/mesa/drivers/glide/fxdrv.h
index bb8f5b8..435d4ce 100644
--- a/src/mesa/drivers/glide/fxdrv.h
+++ b/src/mesa/drivers/glide/fxdrv.h
@@ -420,6 +420,11 @@
 
   render_func **RenderVBTables;
 
+  render_func *RenderVBClippedTab;
+  render_func *RenderVBCulledTab;
+  render_func *RenderVBRawTab;
+
+
   tfxStats stats;
 
   void *state;
@@ -570,7 +575,10 @@
 extern void fxDDCullFace(GLcontext *ctx, GLenum mode);
 extern void fxDDFrontFace(GLcontext *ctx, GLenum mode);
 
+extern void fxPrintRenderState( const char *msg, GLuint state );
+extern void fxPrintHintState( const char *msg, GLuint state );
 
+extern void fxDDDoRenderVB( struct vertex_buffer *VB );
 
 
 #endif
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 55c7467..61c1641 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1,4 +1,4 @@
-/* $Id: context.c,v 1.1 1999/08/19 00:55:41 jtg Exp $ */
+/* $Id: context.c,v 1.2 1999/08/26 14:50:49 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -764,7 +764,7 @@
       /* Extensions */
       gl_extensions_ctr( ctx );
 
-      ctx->AllowVertexCull = 0;
+      ctx->AllowVertexCull = CLIP_CULLED_BIT;
 
       /* Lighting group */
       for (i=0;i<MAX_LIGHTS;i++) {
@@ -1919,6 +1919,8 @@
 
 static void update_fog_mode( GLcontext *ctx )
 {
+   int old_mode = ctx->FogMode;
+
    if (ctx->Fog.Enabled) {
       if (ctx->Texture.Enabled)
          ctx->FogMode = FOG_FRAGMENT;
@@ -1934,6 +1936,9 @@
    else {
       ctx->FogMode = FOG_NONE;
    }
+   
+   if (old_mode != ctx->FogMode)
+      ctx->NewState |= NEW_FOG;
 }
 
 
@@ -2121,7 +2126,9 @@
       ctx->NeedNormals = (ctx->Light.Enabled || ctx->Texture.NeedNormals);
    }
 
-   if (ctx->NewState & (NEW_RASTER_OPS | NEW_LIGHTING)) {
+   if (ctx->NewState & (NEW_RASTER_OPS | NEW_LIGHTING | NEW_FOG)) {
+
+
       if (ctx->NewState & NEW_RASTER_OPS) {
 	 update_pixel_logic(ctx);
 	 update_pixel_masking(ctx);
@@ -2192,10 +2199,10 @@
       }
 
       if (ctx->NewState & NEW_LIGHTING) {
-	 ctx->TriangleCaps &= ~(DD_TRI_LIGHT_TWOSIDE|DD_EARLY_CULL);
+	 ctx->TriangleCaps &= ~(DD_TRI_LIGHT_TWOSIDE|DD_LIGHTING_CULL);
 	 if (ctx->Light.Enabled) {
 	    if (ctx->Light.Model.TwoSide)
-	       ctx->TriangleCaps |= (DD_TRI_LIGHT_TWOSIDE|DD_EARLY_CULL);
+	       ctx->TriangleCaps |= (DD_TRI_LIGHT_TWOSIDE|DD_LIGHTING_CULL);
 	    gl_update_lighting(ctx);
 	 }
       }
@@ -2207,21 +2214,29 @@
       if (ctx->NewState & NEW_POLYGON) {
 	 /* Setup CullBits bitmask */
 	 if (ctx->Polygon.CullFlag) {
+	    ctx->backface_sign = 1;
 	    switch(ctx->Polygon.CullFaceMode) {
-	    case GL_FRONT:
-	       ctx->Polygon.CullBits = 2;
-	       break;
 	    case GL_BACK:
+	       if(ctx->Polygon.FrontFace==GL_CCW)
+		  ctx->backface_sign = -1;
 	       ctx->Polygon.CullBits = 1;
 	       break;
+	    case GL_FRONT:
+	       if(ctx->Polygon.FrontFace!=GL_CCW)
+		  ctx->backface_sign = -1;
+	       ctx->Polygon.CullBits = 2;
+	       break;
 	    default:
 	    case GL_FRONT_AND_BACK:
+	       ctx->backface_sign = 0;
 	       ctx->Polygon.CullBits = 3;
 	       break;
 	    }
 	 }
-	 else
+	 else {
 	    ctx->Polygon.CullBits = 3;
+	    ctx->backface_sign = 0;
+	 }
 
 	 /* Any Polygon offsets enabled? */
 	 ctx->TriangleCaps &= ~DD_TRI_OFFSET;
@@ -2257,6 +2272,9 @@
       ctx->IndirectTriangles = ctx->TriangleCaps & ~ctx->Driver.TriangleCaps;
       ctx->IndirectTriangles |= DD_SW_RASTERIZE;
 
+      if (MESA_VERBOSE&VERBOSE_CULL)
+	 gl_print_tri_caps("initial indirect tris", ctx->IndirectTriangles);
+
       ctx->Driver.PointsFunc = NULL;
       ctx->Driver.LineFunc = NULL;
       ctx->Driver.TriangleFunc = NULL;
@@ -2272,6 +2290,9 @@
        */
       ctx->Driver.UpdateState(ctx);
 
+      if (MESA_VERBOSE&VERBOSE_CULL)
+	 gl_print_tri_caps("indirect tris", ctx->IndirectTriangles);
+
       /*
        * In case the driver didn't hook in an optimized point, line or
        * triangle function we'll now select "core/fallback" point, line
@@ -2282,8 +2303,16 @@
 	 gl_set_line_function(ctx);
 	 gl_set_triangle_function(ctx);
 	 gl_set_quad_function(ctx);
+
+	 if ((ctx->IndirectTriangles & 
+	      (DD_TRI_SW_RASTERIZE|DD_QUAD_SW_RASTERIZE|DD_TRI_CULL)) ==
+	     (DD_TRI_SW_RASTERIZE|DD_QUAD_SW_RASTERIZE|DD_TRI_CULL)) 
+	    ctx->IndirectTriangles &= ~DD_TRI_CULL;
       }
 
+      if (MESA_VERBOSE&VERBOSE_CULL)
+	 gl_print_tri_caps("indirect tris 2", ctx->IndirectTriangles);
+
       gl_set_render_vb_function(ctx);
    }
 
@@ -2311,9 +2340,10 @@
    /* Figure out whether we can light in object space or not.  If we
     * can, find the current positions of the lights in object space
     */
-   if ((ctx->Enabled & (ENABLE_POINT_ATTEN | ENABLE_LIGHT | 
+   if ((ctx->Enabled & (ENABLE_POINT_ATTEN | ENABLE_LIGHT | ENABLE_FOG |
 			ENABLE_TEXGEN0 | ENABLE_TEXGEN1)) &&
        (ctx->NewState & (NEW_LIGHTING | 
+                         NEW_FOG |
 			 NEW_MODELVIEW | 
 			 NEW_PROJECTION |
 			 NEW_TEXTURING |
diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c
index 001de03..24266e3 100644
--- a/src/mesa/main/dlist.c
+++ b/src/mesa/main/dlist.c
@@ -1,4 +1,4 @@
-/* $Id: dlist.c,v 1.1 1999/08/19 00:55:41 jtg Exp $ */
+/* $Id: dlist.c,v 1.2 1999/08/26 14:50:49 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -2454,6 +2454,10 @@
          case OPCODE_VERTEX_CASSETTE:
 	    if (ctx->NewState)
 	       gl_update_state(ctx);
+	    if (ctx->CompileCVAFlag) {
+	       ctx->CompileCVAFlag = 0;
+	       ctx->CVA.elt.pipeline_valid = 0;
+	    }
 	    if (!ctx->CVA.elt.pipeline_valid)
 	       gl_build_immediate_pipeline( ctx );
 	    gl_fixup_cassette( ctx, (struct immediate *) n[1].data ); 
diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c
index b79a907..429a7b1 100644
--- a/src/mesa/main/enable.c
+++ b/src/mesa/main/enable.c
@@ -1,4 +1,4 @@
-/* $Id: enable.c,v 1.2 1999/08/19 13:24:27 brianp Exp $ */
+/* $Id: enable.c,v 1.3 1999/08/26 14:50:49 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -56,7 +56,7 @@
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx, "gl_enable/disable" );
 
    if (MESA_VERBOSE & VERBOSE_API) 
-      fprintf(stderr, "%s %s (%x)\n", 
+      fprintf(stderr, "%s %s (newstate is %x)\n", 
 	      state ? "glEnable" : "glDisable",
 	      gl_lookup_enum_by_nr(cap),
 	      ctx->NewState);
@@ -153,7 +153,7 @@
 	 if (ctx->Fog.Enabled!=state) {
             ctx->Fog.Enabled = state;
 	    ctx->Enabled ^= ENABLE_FOG;
-            ctx->NewState |= NEW_FOG;
+            ctx->NewState |= NEW_FOG|NEW_RASTER_OPS;
          }
 	 break;
       case GL_LIGHT0:
diff --git a/src/mesa/main/polygon.c b/src/mesa/main/polygon.c
index 8369003..09399da 100644
--- a/src/mesa/main/polygon.c
+++ b/src/mesa/main/polygon.c
@@ -1,4 +1,4 @@
-/* $Id: polygon.c,v 1.1 1999/08/19 00:55:41 jtg Exp $ */
+/* $Id: polygon.c,v 1.2 1999/08/26 14:50:49 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -119,9 +119,6 @@
       ctx->Polygon.Unfilled = GL_TRUE;
       ctx->TriangleCaps |= DD_TRI_UNFILLED;
    }
-   else {
-      ctx->Polygon.Unfilled = GL_FALSE;
-   }
 
    ctx->NewState |= (NEW_POLYGON | NEW_RASTER_OPS);
 
diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c
index b63d6a7..aab630c 100644
--- a/src/mesa/main/varray.c
+++ b/src/mesa/main/varray.c
@@ -1,4 +1,4 @@
-/* $Id: varray.c,v 1.1 1999/08/19 00:55:41 jtg Exp $ */
+/* $Id: varray.c,v 1.2 1999/08/26 14:50:49 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -407,7 +407,7 @@
    if (translate & VERT_OBJ_ANY) 
       (ctx->Array.VertexEltFunc)( IM->Obj, 
 				  &ctx->Array.Vertex, 
-				  flags, elts, VERT_ELT,
+				  flags, elts, (VERT_ELT|VERT_OBJ_ANY),
 				  start, count);
    
    if (translate & VERT_NORM) 
@@ -830,11 +830,10 @@
       GLuint nr = MIN2( VB_MAX, count - j + VB_START );	\
       struct immediate *IM = ctx->input;		\
       GLuint sf = IM->Flag[VB_START];			\
-      GLuint flags = IM->ArrayOrFlags;			\
 							\
       for (i = VB_START ; i < nr ; i++) {		\
 	 IM->Elt[i] = (GLuint) *indices++;		\
-	 IM->Flag[i] = flags;				\
+	 IM->Flag[i] = VERT_ELT;			\
       }							\
 							\
       if (j == 0) IM->Flag[VB_START] |= sf;		\
@@ -1251,8 +1250,6 @@
    /* Not really important any more:
     */
    ctx->Array.Summary = ctx->Array.Flags & VERT_DATA;
-
-   ctx->input->ArrayOrFlags = (ctx->Array.Flags & VERT_OBJ_234) | VERT_ELT;
    ctx->input->ArrayAndFlags = ~ctx->Array.Flags;
    ctx->input->ArrayEltFlush = !(ctx->CompileCVAFlag);
 }
diff --git a/src/mesa/x86/common_x86.c b/src/mesa/x86/common_x86.c
index 7d30be9..b5dc202 100644
--- a/src/mesa/x86/common_x86.c
+++ b/src/mesa/x86/common_x86.c
@@ -32,6 +32,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 #include "common_x86asm.h"
 
 int gl_x86_cpu_features = 0;
@@ -43,7 +44,7 @@
    gl_x86_cpu_features = gl_identify_x86_cpu_features ();
 
    if (gl_x86_cpu_features & GL_CPU_GenuineIntel) {
-      printf ("GenuineIntel cpu detected.\n");
+      fprintf (stderr, "GenuineIntel cpu detected.\n");
    }
    gl_init_x86_asm_transforms ();
 
@@ -52,7 +53,7 @@
    if (gl_x86_cpu_features & GL_CPU_MMX) {
       char *s = getenv( "MESA_NO_MMX" );
       if (s == NULL) { 
-         printf ("MMX cpu detected.\n");
+         fprintf (stderr, "MMX cpu detected.\n");
       } else {
          gl_x86_cpu_features &= (!GL_CPU_MMX); 
       }
@@ -64,7 +65,7 @@
    if (gl_x86_cpu_features & GL_CPU_3Dnow) {
       char *s = getenv( "MESA_NO_3DNOW" );
       if (s == NULL) {
-         printf ("3Dnow cpu detected.\n");
+         fprintf (stderr, "3Dnow cpu detected.\n");
          gl_init_3dnow_asm_transforms ();
       } else {
          gl_x86_cpu_features &= (!GL_CPU_3Dnow);