mesa: Change "BRIAN PAUL" to "THE AUTHORS" in license text.
[mesa.git] / src / mesa / tnl_dd / t_dd_dmatmp.h
index 44eaeaf76b004438f4ffd447b9e018b599e2359b..614a9ec3bfa34742f81c5f517a115fa7b55d319f 100644 (file)
@@ -1,9 +1,8 @@
-
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
+ * Version:  6.5.1
  *
- * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2006  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"),
@@ -18,7 +17,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
@@ -27,7 +26,9 @@
  */
 
 
-/* Template for render stages which build and emit vertices directly
+/**
+ * \file t_dd_dmatmp.h
+ * Template for render stages which build and emit vertices directly
  * to fixed-size dma buffers.  Useful for rendering strips and other
  * native primitives where clipping and per-vertex tweaks such as
  * those in t_dd_tritmp.h are not required.
@@ -36,8 +37,6 @@
  * Where various primitive types are unaccelerated by hardware, the
  * code attempts to fallback to other primitive types (quadstrips to
  * tristrips, lineloops to linestrips), or to indexed vertices.
- * Ultimately, a FALLBACK() macro is invoked if there is no way to
- * render the primitive natively.
  */
 
 #if !defined(HAVE_TRIANGLES)
@@ -74,7 +73,7 @@ do {                                          \
 
 
 #if (HAVE_ELTS)
-static void *TAG(emit_elts)( GLcontext *ctx, GLuint *elts, GLuint nr,
+static void *TAG(emit_elts)( struct gl_context *ctx, GLuint *elts, GLuint nr,
                             void *buf)
 {
    GLint i;
@@ -95,7 +94,7 @@ static void *TAG(emit_elts)( GLcontext *ctx, GLuint *elts, GLuint nr,
 }
 #endif
 
-static __inline void *TAG(emit_verts)( GLcontext *ctx, GLuint start, 
+static __inline void *TAG(emit_verts)( struct gl_context *ctx, GLuint start, 
                                     GLuint count, void *buf )
 {
    return EMIT_VERTS(ctx, start, count, buf);
@@ -105,7 +104,7 @@ static __inline void *TAG(emit_verts)( GLcontext *ctx, GLuint start,
  *                    Render non-indexed primitives.
  ***********************************************************************/
 
-static void TAG(render_points_verts)( GLcontext *ctx,
+static void TAG(render_points_verts)( struct gl_context *ctx,
                                      GLuint start,
                                      GLuint count,
                                      GLuint flags )
@@ -113,11 +112,12 @@ static void TAG(render_points_verts)( GLcontext *ctx,
    if (HAVE_POINTS) {
       LOCAL_VARS;
       int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
-      int currentsz = GET_CURRENT_VB_MAX_VERTS();
+      int currentsz;
       GLuint j, nr;
 
       INIT( GL_POINTS );
 
+      currentsz = GET_CURRENT_VB_MAX_VERTS();
       if (currentsz < 8)
         currentsz = dmasz;
 
@@ -133,7 +133,7 @@ static void TAG(render_points_verts)( GLcontext *ctx,
    }
 }
 
-static void TAG(render_lines_verts)( GLcontext *ctx,
+static void TAG(render_lines_verts)( struct gl_context *ctx,
                                     GLuint start,
                                     GLuint count,
                                     GLuint flags )
@@ -141,7 +141,7 @@ static void TAG(render_lines_verts)( GLcontext *ctx,
    if (HAVE_LINES) {
       LOCAL_VARS;
       int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
-      int currentsz = GET_CURRENT_VB_MAX_VERTS();
+      int currentsz;
       GLuint j, nr;
 
       INIT( GL_LINES );
@@ -149,6 +149,7 @@ static void TAG(render_lines_verts)( GLcontext *ctx,
       /* Emit whole number of lines in total and in each buffer:
        */
       count -= (count-start) & 1;
+      currentsz = GET_CURRENT_VB_MAX_VERTS();
       currentsz -= currentsz & 1;
       dmasz -= dmasz & 1;
 
@@ -168,7 +169,7 @@ static void TAG(render_lines_verts)( GLcontext *ctx,
 }
 
 
-static void TAG(render_line_strip_verts)( GLcontext *ctx,
+static void TAG(render_line_strip_verts)( struct gl_context *ctx,
                                          GLuint start,
                                          GLuint count,
                                          GLuint flags )
@@ -176,11 +177,12 @@ static void TAG(render_line_strip_verts)( GLcontext *ctx,
    if (HAVE_LINE_STRIPS) {
       LOCAL_VARS;
       int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
-      int currentsz = GET_CURRENT_VB_MAX_VERTS();
+      int currentsz;
       GLuint j, nr;
 
       INIT( GL_LINE_STRIP );
 
+      currentsz = GET_CURRENT_VB_MAX_VERTS();
       if (currentsz < 8)
         currentsz = dmasz;
 
@@ -199,7 +201,7 @@ static void TAG(render_line_strip_verts)( GLcontext *ctx,
 }
 
 
-static void TAG(render_line_loop_verts)( GLcontext *ctx,
+static void TAG(render_line_loop_verts)( struct gl_context *ctx,
                                         GLuint start,
                                         GLuint count,
                                         GLuint flags )
@@ -207,7 +209,7 @@ static void TAG(render_line_loop_verts)( GLcontext *ctx,
    if (HAVE_LINE_STRIPS) {
       LOCAL_VARS;
       int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
-      int currentsz = GET_CURRENT_VB_MAX_VERTS();
+      int currentsz;
       GLuint j, nr;
 
       INIT( GL_LINE_STRIP );
@@ -219,6 +221,7 @@ static void TAG(render_line_loop_verts)( GLcontext *ctx,
 
       /* Ensure last vertex won't wrap buffers:
        */
+      currentsz = GET_CURRENT_VB_MAX_VERTS();
       currentsz--;
       dmasz--;
 
@@ -238,6 +241,7 @@ static void TAG(render_line_loop_verts)( GLcontext *ctx,
               tmp = ALLOC_VERTS(nr+1);
               tmp = TAG(emit_verts)( ctx, j, nr, tmp );
               tmp = TAG(emit_verts)( ctx, start, 1, tmp );
+              (void) tmp;
            }
            else {
               TAG(emit_verts)( ctx, j, nr, ALLOC_VERTS(nr) );
@@ -251,6 +255,7 @@ static void TAG(render_line_loop_verts)( GLcontext *ctx,
         tmp = ALLOC_VERTS(2);
         tmp = TAG(emit_verts)( ctx, start+1, 1, tmp );
         tmp = TAG(emit_verts)( ctx, start, 1, tmp );
+        (void) tmp;
       }
 
       FLUSH();
@@ -262,18 +267,20 @@ static void TAG(render_line_loop_verts)( GLcontext *ctx,
 }
 
 
-static void TAG(render_triangles_verts)( GLcontext *ctx,
+static void TAG(render_triangles_verts)( struct gl_context *ctx,
                                         GLuint start,
                                         GLuint count,
                                         GLuint flags )
 {
    LOCAL_VARS;
    int dmasz = (GET_SUBSEQUENT_VB_MAX_VERTS()/3) * 3;
-   int currentsz = (GET_CURRENT_VB_MAX_VERTS()/3) * 3;
+   int currentsz;
    GLuint j, nr;
 
    INIT(GL_TRIANGLES);
 
+   currentsz = (GET_CURRENT_VB_MAX_VERTS()/3) * 3;
+
    /* Emit whole number of tris in total.  dmasz is already a multiple
     * of 3.
     */
@@ -291,7 +298,7 @@ static void TAG(render_triangles_verts)( GLcontext *ctx,
 
 
 
-static void TAG(render_tri_strip_verts)( GLcontext *ctx,
+static void TAG(render_tri_strip_verts)( struct gl_context *ctx,
                                         GLuint start,
                                         GLuint count,
                                         GLuint flags )
@@ -329,7 +336,7 @@ static void TAG(render_tri_strip_verts)( GLcontext *ctx,
    }
 }
 
-static void TAG(render_tri_fan_verts)( GLcontext *ctx,
+static void TAG(render_tri_fan_verts)( struct gl_context *ctx,
                                       GLuint start,
                                       GLuint count,
                                       GLuint flags )
@@ -338,20 +345,22 @@ static void TAG(render_tri_fan_verts)( GLcontext *ctx,
       LOCAL_VARS;
       GLuint j, nr;
       int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
-      int currentsz = GET_CURRENT_VB_MAX_VERTS();
+      int currentsz;
 
       INIT(GL_TRIANGLE_FAN);
 
+      currentsz = GET_CURRENT_VB_MAX_VERTS();
       if (currentsz < 8) {
         currentsz = dmasz;
       }
 
-      for (j = start + 1 ; j + 1 < count; j += nr - 1 ) {
+      for (j = start + 1 ; j + 1 < count; j += nr - 2 ) {
         void *tmp;
         nr = MIN2( currentsz, count - j + 1 );
         tmp = ALLOC_VERTS( nr );
         tmp = TAG(emit_verts)( ctx, start, 1, tmp );
         tmp = TAG(emit_verts)( ctx, j, nr - 1, tmp );
+        (void) tmp;
         currentsz = dmasz;
       }
 
@@ -367,7 +376,7 @@ static void TAG(render_tri_fan_verts)( GLcontext *ctx,
 }
 
 
-static void TAG(render_poly_verts)( GLcontext *ctx,
+static void TAG(render_poly_verts)( struct gl_context *ctx,
                                    GLuint start,
                                    GLuint count,
                                    GLuint flags )
@@ -376,26 +385,28 @@ static void TAG(render_poly_verts)( GLcontext *ctx,
       LOCAL_VARS;
       GLuint j, nr;
       int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
-      int currentsz = GET_CURRENT_VB_MAX_VERTS();
+      int currentsz;
 
       INIT(GL_POLYGON);
 
+      currentsz = GET_CURRENT_VB_MAX_VERTS();
       if (currentsz < 8) {
         currentsz = dmasz;
       }
 
-      for (j = start + 1 ; j + 1 < count ; j += nr - 1 ) {
+      for (j = start + 1 ; j + 1 < count ; j += nr - 2 ) {
         void *tmp;
         nr = MIN2( currentsz, count - j + 1 );
         tmp = ALLOC_VERTS( nr );
         tmp = TAG(emit_verts)( ctx, start, 1, tmp );
         tmp = TAG(emit_verts)( ctx, j, nr - 1, tmp );
+        (void) tmp;
         currentsz = dmasz;
       }
 
       FLUSH();
    }
-   else if (HAVE_TRI_FANS && !(ctx->_TriangleCaps & DD_FLATSHADE)) {
+   else if (HAVE_TRI_FANS && ctx->Light.ShadeModel == GL_SMOOTH) {
       TAG(render_tri_fan_verts)( ctx, start, count, flags );
    } else {
       fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
@@ -403,7 +414,7 @@ static void TAG(render_poly_verts)( GLcontext *ctx,
    }
 }
 
-static void TAG(render_quad_strip_verts)( GLcontext *ctx,
+static void TAG(render_quad_strip_verts)( struct gl_context *ctx,
                                          GLuint start,
                                          GLuint count,
                                          GLuint flags )
@@ -419,7 +430,6 @@ static void TAG(render_quad_strip_verts)( GLcontext *ctx,
       INIT(GL_QUAD_STRIP);
 
       currentsz = GET_CURRENT_VB_MAX_VERTS();
-
       if (currentsz < 8) {
         currentsz = dmasz;
       }
@@ -435,7 +445,9 @@ static void TAG(render_quad_strip_verts)( GLcontext *ctx,
 
       FLUSH();
 
-   } else if (HAVE_TRI_STRIPS && (ctx->_TriangleCaps & DD_FLATSHADE)) {
+   } else if (HAVE_TRI_STRIPS && 
+             ctx->Light.ShadeModel == GL_FLAT &&
+             TNL_CONTEXT(ctx)->vb.AttribPtr[_TNL_ATTRIB_COLOR0]->stride) {
       if (HAVE_ELTS) {
         LOCAL_VARS;
         int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
@@ -485,8 +497,8 @@ static void TAG(render_quad_strip_verts)( GLcontext *ctx,
         FLUSH();
       }
       else {
-        /* Vertices won't fit in a single buffer or elts not available,
-         * VERT_FALLBACK.
+        /* Vertices won't fit in a single buffer or elts not
+         * available - should never happen.
          */
         fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
         return;
@@ -495,7 +507,7 @@ static void TAG(render_quad_strip_verts)( GLcontext *ctx,
    else if (HAVE_TRI_STRIPS) {
       LOCAL_VARS;
       int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
-      int currentsz = GET_CURRENT_VB_MAX_VERTS();
+      int currentsz;
 
       /* Emit smooth-shaded quadstrips as tristrips:
        */
@@ -505,6 +517,7 @@ static void TAG(render_quad_strip_verts)( GLcontext *ctx,
       /* Emit whole number of quads in total, and in each buffer.
        */
       dmasz -= dmasz & 1;
+      currentsz = GET_CURRENT_VB_MAX_VERTS();
       currentsz -= currentsz & 1;
       count -= (count-start) & 1;
 
@@ -527,7 +540,7 @@ static void TAG(render_quad_strip_verts)( GLcontext *ctx,
 }
 
 
-static void TAG(render_quads_verts)( GLcontext *ctx,
+static void TAG(render_quads_verts)( struct gl_context *ctx,
                                     GLuint start,
                                     GLuint count,
                                     GLuint flags )
@@ -535,7 +548,7 @@ static void TAG(render_quads_verts)( GLcontext *ctx,
    if (HAVE_QUADS) {
       LOCAL_VARS;
       int dmasz = (GET_SUBSEQUENT_VB_MAX_VERTS()/4) * 4;
-      int currentsz = (GET_CURRENT_VB_MAX_VERTS()/4) * 4;
+      int currentsz;
       GLuint j, nr;
 
       INIT(GL_QUADS);
@@ -545,6 +558,7 @@ static void TAG(render_quads_verts)( GLcontext *ctx,
        */
       count -= (count-start)%4;
 
+      currentsz = (GET_CURRENT_VB_MAX_VERTS()/4) * 4;
       if (currentsz < 8)
          currentsz = dmasz;
 
@@ -553,9 +567,8 @@ static void TAG(render_quads_verts)( GLcontext *ctx,
          TAG(emit_verts)( ctx, j, nr, ALLOC_VERTS(nr) );
          currentsz = dmasz;
       }
-
-
-   } else if (HAVE_ELTS) {
+   }
+   else if (HAVE_ELTS) {
       /* Hardware doesn't have a quad primitive type -- try to
        * simulate it using indexed vertices and the triangle
        * primitive:
@@ -606,15 +619,37 @@ static void TAG(render_quads_verts)( GLcontext *ctx,
 
       RELEASE_ELT_VERTS();
    }
+   else if (HAVE_TRIANGLES) {
+      /* Hardware doesn't have a quad primitive type -- try to
+       * simulate it using triangle primitive.  This is a win for
+       * gears, but is it useful in the broader world?
+       */
+      LOCAL_VARS;
+      GLuint j;
+
+      INIT(GL_TRIANGLES);
+
+      for (j = start; j < count-3; j += 4) {
+        void *tmp = ALLOC_VERTS( 6 );
+        /* Send v0, v1, v3
+         */
+        tmp = EMIT_VERTS(ctx, j,     2, tmp);
+        tmp = EMIT_VERTS(ctx, j + 3, 1, tmp);
+        /* Send v1, v2, v3
+         */
+        tmp = EMIT_VERTS(ctx, j + 1, 3, tmp);
+        (void) tmp;
+      }
+   }
    else {
-      /* Vertices won't fit in a single buffer, fallback.
+      /* Vertices won't fit in a single buffer, should never happen.
        */
       fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
       return;
    }
 }
 
-static void TAG(render_noop)( GLcontext *ctx,
+static void TAG(render_noop)( struct gl_context *ctx,
                              GLuint start,
                              GLuint count,
                              GLuint flags )
@@ -624,7 +659,7 @@ static void TAG(render_noop)( GLcontext *ctx,
 
 
 
-static render_func TAG(render_tab_verts)[GL_POLYGON+2] =
+static tnl_render_func TAG(render_tab_verts)[GL_POLYGON+2] =
 {
    TAG(render_points_verts),
    TAG(render_lines_verts),
@@ -645,7 +680,7 @@ static render_func TAG(render_tab_verts)[GL_POLYGON+2] =
  ****************************************************************************/
 
 #if (HAVE_ELTS)
-static void TAG(render_points_elts)( GLcontext *ctx,
+static void TAG(render_points_elts)( struct gl_context *ctx,
                                     GLuint start,
                                     GLuint count,
                                     GLuint flags )
@@ -677,7 +712,7 @@ static void TAG(render_points_elts)( GLcontext *ctx,
 
 
 
-static void TAG(render_lines_elts)( GLcontext *ctx,
+static void TAG(render_lines_elts)( struct gl_context *ctx,
                                    GLuint start,
                                    GLuint count,
                                    GLuint flags )
@@ -714,7 +749,7 @@ static void TAG(render_lines_elts)( GLcontext *ctx,
 }
 
 
-static void TAG(render_line_strip_elts)( GLcontext *ctx,
+static void TAG(render_line_strip_elts)( struct gl_context *ctx,
                                         GLuint start,
                                         GLuint count,
                                         GLuint flags )
@@ -748,7 +783,7 @@ static void TAG(render_line_strip_elts)( GLcontext *ctx,
 }
 
 
-static void TAG(render_line_loop_elts)( GLcontext *ctx,
+static void TAG(render_line_loop_elts)( struct gl_context *ctx,
                                        GLuint start,
                                        GLuint count,
                                        GLuint flags )
@@ -790,6 +825,7 @@ static void TAG(render_line_loop_elts)( GLcontext *ctx,
               tmp = ALLOC_ELTS(nr+1);
               tmp = TAG(emit_elts)( ctx, elts+j, nr, tmp );
               tmp = TAG(emit_elts)( ctx, elts+start, 1, tmp );
+              (void) tmp;
            }
            else {
               TAG(emit_elts)( ctx, elts+j, nr, ALLOC_ELTS(nr) );
@@ -803,6 +839,7 @@ static void TAG(render_line_loop_elts)( GLcontext *ctx,
         tmp = ALLOC_ELTS(2);
         tmp = TAG(emit_elts)( ctx, elts+start+1, 1, tmp );
         tmp = TAG(emit_elts)( ctx, elts+start, 1, tmp );
+        (void) tmp;
       }
 
       FLUSH();
@@ -818,7 +855,7 @@ static void TAG(render_line_loop_elts)( GLcontext *ctx,
  * buffers.  For elts, this is probably no better (worse?) than the
  * standard path.
  */
-static void TAG(render_triangles_elts)( GLcontext *ctx,
+static void TAG(render_triangles_elts)( struct gl_context *ctx,
                                        GLuint start,
                                        GLuint count,
                                        GLuint flags )
@@ -852,7 +889,7 @@ static void TAG(render_triangles_elts)( GLcontext *ctx,
 
 
 
-static void TAG(render_tri_strip_elts)( GLcontext *ctx,
+static void TAG(render_tri_strip_elts)( struct gl_context *ctx,
                                        GLuint start,
                                        GLuint count,
                                        GLuint flags )
@@ -890,7 +927,7 @@ static void TAG(render_tri_strip_elts)( GLcontext *ctx,
    }
 }
 
-static void TAG(render_tri_fan_elts)( GLcontext *ctx,
+static void TAG(render_tri_fan_elts)( struct gl_context *ctx,
                                      GLuint start,
                                      GLuint count,
                                      GLuint flags )
@@ -910,12 +947,13 @@ static void TAG(render_tri_fan_elts)( GLcontext *ctx,
         currentsz = dmasz;
       }
 
-      for (j = start + 1 ; j + 1 < count; j += nr - 1 ) {
+      for (j = start + 1 ; j + 1 < count; j += nr - 2 ) {
         void *tmp;
         nr = MIN2( currentsz, count - j + 1 );
         tmp = ALLOC_ELTS( nr );
         tmp = TAG(emit_elts)( ctx, elts+start, 1, tmp );
         tmp = TAG(emit_elts)( ctx, elts+j, nr - 1, tmp );
+        (void) tmp;
         FLUSH();
         currentsz = dmasz;
       }
@@ -927,7 +965,7 @@ static void TAG(render_tri_fan_elts)( GLcontext *ctx,
 }
 
 
-static void TAG(render_poly_elts)( GLcontext *ctx,
+static void TAG(render_poly_elts)( struct gl_context *ctx,
                                   GLuint start,
                                   GLuint count,
                                   GLuint flags )
@@ -947,16 +985,17 @@ static void TAG(render_poly_elts)( GLcontext *ctx,
         currentsz = dmasz;
       }
 
-      for (j = start + 1 ; j + 1 < count; j += nr - 1 ) {
+      for (j = start + 1 ; j + 1 < count; j += nr - 2 ) {
         void *tmp;
         nr = MIN2( currentsz, count - j + 1 );
         tmp = ALLOC_ELTS( nr );
         tmp = TAG(emit_elts)( ctx, elts+start, 1, tmp );
         tmp = TAG(emit_elts)( ctx, elts+j, nr - 1, tmp );
+        (void) tmp;
         FLUSH();
         currentsz = dmasz;
       }
-   } else if (HAVE_TRI_FANS && !(ctx->_TriangleCaps & DD_FLATSHADE)) {
+   } else if (HAVE_TRI_FANS && ctx->Light.ShadeModel == GL_SMOOTH) {
       TAG(render_tri_fan_verts)( ctx, start, count, flags );
    } else {
       fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
@@ -964,7 +1003,7 @@ static void TAG(render_poly_elts)( GLcontext *ctx,
    }
 }
 
-static void TAG(render_quad_strip_elts)( GLcontext *ctx,
+static void TAG(render_quad_strip_elts)( struct gl_context *ctx,
                                         GLuint start,
                                         GLuint count,
                                         GLuint flags )
@@ -990,7 +1029,7 @@ static void TAG(render_quad_strip_elts)( GLcontext *ctx,
       if (currentsz < 12)
         currentsz = dmasz;
 
-      if (ctx->_TriangleCaps & DD_FLATSHADE) {
+      if (ctx->Light.ShadeModel == GL_FLAT) {
         ELT_INIT( GL_TRIANGLES );
 
         currentsz = currentsz/6*2;
@@ -1003,8 +1042,7 @@ static void TAG(render_quad_strip_elts)( GLcontext *ctx,
            {
               GLint i;
               GLint quads = (nr/2)-1;
-              void *buf = ALLOC_ELTS( quads*6 );
-              ELTS_VARS( buf );
+              ELTS_VARS( ALLOC_ELTS( quads*6 ) );
 
               for ( i = j-start ; i < j-start+quads ; i++, elts += 2 ) {
                  EMIT_TWO_ELTS( 0, elts[0], elts[1] );
@@ -1033,7 +1071,7 @@ static void TAG(render_quad_strip_elts)( GLcontext *ctx,
 }
 
 
-static void TAG(render_quads_elts)( GLcontext *ctx,
+static void TAG(render_quads_elts)( struct gl_context *ctx,
                                    GLuint start,
                                    GLuint count,
                                    GLuint flags )
@@ -1092,8 +1130,7 @@ static void TAG(render_quads_elts)( GLcontext *ctx,
         {
            GLint quads = nr/4;
            GLint i;
-           void *buf = ALLOC_ELTS( quads * 6 );
-           ELTS_VARS(buf);
+           ELTS_VARS( ALLOC_ELTS( quads * 6 ) );
 
            for ( i = j-start ; i < j-start+quads ; i++, elts += 4 ) {
               EMIT_TWO_ELTS( 0, elts[0], elts[1] );
@@ -1112,7 +1149,7 @@ static void TAG(render_quads_elts)( GLcontext *ctx,
 
 
 
-static render_func TAG(render_tab_elts)[GL_POLYGON+2] =
+static tnl_render_func TAG(render_tab_elts)[GL_POLYGON+2] =
 {
    TAG(render_points_elts),
    TAG(render_lines_elts),
@@ -1133,17 +1170,15 @@ static render_func TAG(render_tab_elts)[GL_POLYGON+2] =
 
 
 
-
-
-
-/* Prevent fallbacks later on.
+/* Pre-check the primitives in the VB to prevent the need for
+ * fallbacks later on.
  */
-static GLboolean TAG(validate_render)( GLcontext *ctx,
+static GLboolean TAG(validate_render)( struct gl_context *ctx,
                                       struct vertex_buffer *VB )
 {
    GLint i;
 
-   if (VB->ClipOrMask)
+   if (VB->ClipOrMask & ~CLIP_CULL_BIT)
       return GL_FALSE;
 
    if (VB->Elts && !HAVE_ELTS)
@@ -1183,8 +1218,9 @@ static GLboolean TAG(validate_render)( GLcontext *ctx,
         if (HAVE_POLYGONS) {
            ok = GL_TRUE;
         }
-        else 
-           ok =  (HAVE_TRI_FANS && !(ctx->_TriangleCaps & DD_FLATSHADE));
+        else {
+           ok = (HAVE_TRI_FANS && ctx->Light.ShadeModel == GL_SMOOTH);
+         }
         break;
       case GL_QUAD_STRIP:
         if (VB->Elts) {
@@ -1192,9 +1228,11 @@ static GLboolean TAG(validate_render)( GLcontext *ctx,
         }
         else if (HAVE_QUAD_STRIPS) {
            ok = GL_TRUE;
-        } else if (HAVE_TRI_STRIPS && (ctx->_TriangleCaps & DD_FLATSHADE)) {
+        } else if (HAVE_TRI_STRIPS && 
+                   ctx->Light.ShadeModel == GL_FLAT &&
+                   VB->AttribPtr[_TNL_ATTRIB_COLOR0]->stride != 0) {
            if (HAVE_ELTS) {
-              ok = count < GET_SUBSEQUENT_VB_MAX_ELTS();
+              ok = (GLint) count < GET_SUBSEQUENT_VB_MAX_ELTS();
            }
            else {
               ok = GL_FALSE;
@@ -1207,17 +1245,20 @@ static GLboolean TAG(validate_render)( GLcontext *ctx,
         if (HAVE_QUADS) {
            ok = GL_TRUE;
         } else if (HAVE_ELTS) {
-           ok = count < GET_SUBSEQUENT_VB_MAX_ELTS();
+           ok = (GLint) count < GET_SUBSEQUENT_VB_MAX_ELTS();
         }
         else {
-           ok = GL_FALSE;
+           ok = HAVE_TRIANGLES; /* flatshading is ok. */
         }
         break;
       default:
         break;
       }
       
-      if (!ok) return GL_FALSE;
+      if (!ok) {
+/*      fprintf(stderr, "not ok %s\n", _mesa_lookup_enum_by_nr(prim & PRIM_MODE_MASK)); */
+        return GL_FALSE;
+      }
    }
 
    return GL_TRUE;