Add a 'RenderPrimitive' callback to t_vb_render.c. Helps out drivers
[mesa.git] / src / mesa / main / state.c
index 5c4dda99e8d97db0e8c131f087bf6424368c9608..43e4872d66ff183ad491d8d57c4df5038e072a9a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: state.c,v 1.50 2000/11/28 00:07:51 brianp Exp $ */
+/* $Id: state.c,v 1.53 2000/12/26 05:09:29 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -26,8 +26,7 @@
 
 
 /*
- * This file initializes the immediate-mode dispatch table (which may
- * be state-dependant) and manages internal Mesa state update.
+ * This file manages internal Mesa state update.
  */
 
 
 #include "varray.h"
 #include "winpos.h"
 
-#include "swrast/swrast.h"
 #include "math/m_matrix.h"
 #include "math/m_xform.h"
 #endif
 
 
-
 static int
 generic_noop(void)
 {
@@ -112,6 +109,7 @@ _mesa_init_no_op_table(struct _glapi_table *table, GLuint tableSize)
 }
 
 
+
 /*
  * Initialize the given dispatch table with pointers to Mesa's
  * immediate-mode commands.
@@ -501,35 +499,21 @@ _mesa_init_exec_table(struct _glapi_table *exec, GLuint tableSize)
 static void
 update_polygon( GLcontext *ctx )
 {
-   ctx->_TriangleCaps &= ~DD_TRI_CULL_FRONT_BACK;
-
-   /* Setup CullBits bitmask */
-   if (ctx->Polygon.CullFlag) {
-      switch(ctx->Polygon.CullFaceMode) {
-      case GL_BACK:
-        ctx->Polygon._CullBits = 1;
-        break;
-      case GL_FRONT:
-        ctx->Polygon._CullBits = 2;
-        break;
-      default:
-      case GL_FRONT_AND_BACK:
-        ctx->Polygon._CullBits = 0;
-        ctx->_TriangleCaps |= DD_TRI_CULL_FRONT_BACK;
-        break;
-      }
-   }
-   else {
-      ctx->Polygon._CullBits = 3;
-   }
+   ctx->_TriangleCaps &= ~(DD_TRI_CULL_FRONT_BACK | DD_TRI_OFFSET);
+
+/*     if (ctx->Polygon.CullFlag && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) */
+/*        ctx->_TriangleCaps |= DD_TRI_CULL_FRONT_BACK; */
 
    /* Any Polygon offsets enabled? */
+   ctx->Polygon._OffsetAny = GL_FALSE;
    ctx->_TriangleCaps &= ~DD_TRI_OFFSET;
 
    if (ctx->Polygon.OffsetPoint ||
        ctx->Polygon.OffsetLine ||
-       ctx->Polygon.OffsetFill)
+       ctx->Polygon.OffsetFill) {
       ctx->_TriangleCaps |= DD_TRI_OFFSET;
+      ctx->Polygon._OffsetAny = GL_TRUE;
+   }
 }
 
 static void
@@ -584,8 +568,8 @@ update_tnl_spaces( GLcontext *ctx, GLuint oldneedeyecoords )
    else {
       GLuint new_state = ctx->NewState;
 
-      /* Recalculate that same state if and only if it has been
-       * invalidated by other statechanges.
+      /* Recalculate that same state only if it has been invalidated
+       * by other statechanges. 
        */
       if (new_state & _NEW_MODELVIEW)
         update_modelview_scale(ctx);
@@ -649,7 +633,6 @@ update_projection( GLcontext *ctx )
 }
 
 
-
 /*
  * Return a bitmask of IMAGE_*_BIT flags which to indicate which
  * pixel transfer operations are enabled.
@@ -722,13 +705,17 @@ update_image_transfer_state(GLcontext *ctx)
  * rendering any primitive.  Basically, function pointers and miscellaneous
  * flags are updated to reflect the current state of the state machine.
  *
- * Special care is taken with the derived value _NeedEyeCoords.  These
+ * The above constraint is now maintained largely by the two Exec
+ * dispatch tables, which trigger the appropriate flush on transition
+ * between State and Geometry modes.
+ *
+ * Special care is taken with the derived value _NeedEyeCoords.  This
  * is a bitflag which is updated with information from a number of
  * attribute groups (MODELVIEW, LIGHT, TEXTURE).  A lot of derived
  * state references this value, and must be treated with care to
  * ensure that updates are done correctly.  All state dependent on
  * _NeedEyeCoords is calculated from within _mesa_update_tnl_spaces(),
- * and from nowhere else.
+ * and from nowhere else.  
  */
 void gl_update_state( GLcontext *ctx )
 {
@@ -752,7 +739,7 @@ void gl_update_state( GLcontext *ctx )
 
    /* References ColorMatrix.type (derived above).
     */
-   if (new_state & (_NEW_PIXEL|_NEW_COLOR_MATRIX))
+   if (new_state & _IMAGE_NEW_TRANSFER_STATE)
       update_image_transfer_state(ctx);
 
    /* Contributes to NeedEyeCoords, NeedNormals.
@@ -781,20 +768,20 @@ void gl_update_state( GLcontext *ctx )
            ctx->_NeedEyeCoords |= NEED_EYE_LIGHT_MODELVIEW;
    }
 
-   /* ctx->_NeedEyeCoords and ctx->_NeedEyeNormals are now uptodate.
+
+   /* ctx->_NeedEyeCoords is now uptodate.
     *
-    * If the truth value of either has changed, update for the new
-    * lighting space and recompute the positions of lights and the
+    * If the truth value of this variable has changed, update for the
+    * new lighting space and recompute the positions of lights and the
     * normal transform.
     *
     * If the lighting space hasn't changed, may still need to recompute
-    * light positions & normal transforms for other reasons.
+    * light positions & normal transforms for other reasons. 
     */
    if (new_state & (_NEW_MODELVIEW |
                    _NEW_PROJECTION |
-                   _TNL_NEW_NORMAL_TRANSFORM |
                    _NEW_LIGHT |
-                   _TNL_NEW_NEED_EYE_COORDS))
+                   _MESA_NEW_NEED_EYE_COORDS))
       update_tnl_spaces( ctx, oldneedeyecoords );
 
    /*
@@ -802,7 +789,12 @@ void gl_update_state( GLcontext *ctx )
     * to it's specific, private functions, and performs any
     * internal state management necessary, including invalidating
     * state of active modules.
+    *
+    * Set ctx->NewState to zero to avoid recursion if
+    * Driver.UpdateState() has to call FLUSH_VERTICES().  (fixed?)
     */
-   ctx->Driver.UpdateState(ctx);
    ctx->NewState = 0;
+   ctx->Driver.UpdateState(ctx, new_state);
+   
+   ctx->Array.NewState = 0;
 }