keeping things safe: sanity check back
[mesa.git] / src / mesa / tnl / t_vb_render.c
index 5ccec25cb28ea91a82ab67a9574eb4eb838c4661..1c5016896833c50ceaec8780027a1c4b53d41430 100644 (file)
@@ -1,10 +1,9 @@
-/* $Id: t_vb_render.c,v 1.27 2002/01/22 14:35:17 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  4.0.1
+ * Version:  5.1
  *
- * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -24,7 +23,7 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *    Keith Whitwell <keithw@valinux.com>
+ *    Keith Whitwell <keith@tungstengraphics.com>
  */
 
 
 
 #include "glheader.h"
 #include "context.h"
+#include "enums.h"
 #include "macros.h"
-#include "mem.h"
+#include "imports.h"
 #include "mtypes.h"
-#include "mmath.h"
-
+#include "nvfragprog.h"
 #include "math/m_matrix.h"
 #include "math/m_xform.h"
 
 /**********************************************************************/
 
 
-#if defined(USE_IEEE)
-#define NEGATIVE(x) (GET_FLOAT_BITS(x) & (1<<31))
-#define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31))
-#else
-#define NEGATIVE(x) (x < 0)
-#define DIFFERENT_SIGNS(x,y) (x * y <= 0 && x - y != 0)
-/* Could just use (x*y<0) except for the flatshading requirements.
- * Maybe there's a better way?
- */
-#endif
-
-
 #define W(i) coord[i][3]
 #define Z(i) coord[i][2]
 #define Y(i) coord[i][1]
@@ -85,7 +72,7 @@
 /*              Clip and render whole begin/end objects               */
 /**********************************************************************/
 
-#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED)
+#define NEED_EDGEFLAG_SETUP (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL)
 #define EDGEFLAG_GET(idx) VB->EdgeFlag[idx]
 #define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val
 
@@ -142,7 +129,7 @@ do {                                                        \
 
 #define TAG(x) clip_##x##_verts
 #define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x )
-#define RESET_STIPPLE tnl->Driver.Render.ResetLineStipple( ctx )
+#define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx )
 #define RESET_OCCLUSION ctx->OcclusionResult = GL_TRUE
 #define PRESERVE_VB_DEFS
 #include "t_vb_rendertmp.h"
@@ -197,7 +184,7 @@ static void clip_elt_triangles( GLcontext *ctx,
 /*                  Render whole begin/end objects                    */
 /**********************************************************************/
 
-#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED)
+#define NEED_EDGEFLAG_SETUP (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL)
 #define EDGEFLAG_GET(idx) VB->EdgeFlag[idx]
 #define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val
 
@@ -229,7 +216,7 @@ static void clip_elt_triangles( GLcontext *ctx,
    (void) (LineFunc && TriangleFunc && QuadFunc);              \
    (void) elt; (void) stipple
 
-#define RESET_STIPPLE tnl->Driver.Render.ResetLineStipple( ctx )
+#define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx )
 #define RESET_OCCLUSION ctx->OcclusionResult = GL_TRUE
 #define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x )
 #define RENDER_TAB_QUALIFIER
@@ -274,7 +261,7 @@ void _tnl_RenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj )
 
 
 static GLboolean run_render( GLcontext *ctx,
-                            struct gl_pipeline_stage *stage )
+                            struct tnl_pipeline_stage *stage )
 {
    TNLcontext *tnl = TNL_CONTEXT(ctx);
    struct vertex_buffer *VB = &tnl->vb;
@@ -317,23 +304,29 @@ static GLboolean run_render( GLcontext *ctx,
 
    do
    {
-      GLuint i, length, flags = 0;
-      for (i = VB->FirstPrimitive ; !(flags & PRIM_LAST) ; i += length)
+      GLuint i;
+
+      for (i = 0 ; i < VB->PrimitiveCount ; i++)
       {
-        flags = VB->Primitive[i];
-        length= VB->PrimitiveLength[i];
-        ASSERT(length || (flags & PRIM_LAST));
-        ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1);
+        GLuint prim = VB->Primitive[i].mode;
+        GLuint start = VB->Primitive[i].start;
+        GLuint length = VB->Primitive[i].count;
+
+        assert((prim & PRIM_MODE_MASK) < GL_POLYGON+1);
+
+        if (MESA_VERBOSE & VERBOSE_PRIMS) 
+           _mesa_debug(NULL, "MESA prim %s %d..%d\n", 
+                       _mesa_lookup_enum_by_nr(prim & PRIM_MODE_MASK), 
+                       start, start+length);
+
         if (length)
-           tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags );
+           tab[prim & PRIM_MODE_MASK]( ctx, start, start + length, prim );
       }
    } while (tnl->Driver.Render.Multipass &&
            tnl->Driver.Render.Multipass( ctx, ++pass ));
 
-
    tnl->Driver.Render.Finish( ctx );
-/*     _swrast_flush(ctx); */
-/*     usleep(1000000); */
+
    return GL_FALSE;            /* finished the pipe */
 }
 
@@ -347,54 +340,20 @@ static GLboolean run_render( GLcontext *ctx,
 /* Quite a bit of work involved in finding out the inputs for the
  * render stage.
  */
-static void check_render( GLcontext *ctx, struct gl_pipeline_stage *stage )
+static void check_render( GLcontext *ctx, struct tnl_pipeline_stage *stage )
 {
-   GLuint inputs = VERT_BIT_CLIP;
-   GLuint i;
-
-   if (ctx->Visual.rgbMode) {
-      inputs |= VERT_BIT_COLOR0;
-
-      if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)
-        inputs |= VERT_BIT_COLOR1;
-
-      if (ctx->Texture._ReallyEnabled) {
-        for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) {
-           if (ctx->Texture.Unit[i]._ReallyEnabled)
-              inputs |= VERT_BIT_TEX(i);
-        }
-      }
-   }
-   else {
-      inputs |= VERT_BIT_INDEX;
-   }
-
-   if (ctx->Point._Attenuated)
-      inputs |= VERT_BIT_POINT_SIZE;
-
-   /* How do drivers turn this off?
-    */
-   if (ctx->Fog.Enabled)
-      inputs |= VERT_BIT_FOG;
-
-   if (ctx->_TriangleCaps & DD_TRI_UNFILLED)
-      inputs |= VERT_BIT_EDGEFLAG;
-
-   if (ctx->RenderMode==GL_FEEDBACK)
-      inputs |= VERT_BITS_TEX_ANY;
-
-   stage->inputs = inputs;
+   stage->inputs = TNL_CONTEXT(ctx)->render_inputs;
 }
 
 
 
 
-static void dtr( struct gl_pipeline_stage *stage )
+static void dtr( struct tnl_pipeline_stage *stage )
 {
 }
 
 
-const struct gl_pipeline_stage _tnl_render_stage =
+const struct tnl_pipeline_stage _tnl_render_stage =
 {
    "render",                   /* name */
    (_NEW_BUFFERS |