gallium: split long prims into chunks with an even number of vertices
authorBrian Paul <brian.paul@tungstengraphics.com>
Wed, 18 Jun 2008 20:50:35 +0000 (14:50 -0600)
committerBrian Paul <brian.paul@tungstengraphics.com>
Wed, 18 Jun 2008 20:55:12 +0000 (14:55 -0600)
This fixes culling "parity" errors when splitting long tri strips.  Splitting
strips into chunks with an odd number of vertices causes front/back-face
orientation to get reversed and upsets culling.

src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c
src/gallium/auxiliary/draw/draw_pt_varray.c

index 5ce3aba2a2de2acfe995e3e47cafa40f61ea0a51..fdf9b6fe6a8462190224554b399739552204ea92 100644 (file)
@@ -193,6 +193,15 @@ static void fse_prepare( struct draw_pt_middle_end *middle,
    *max_vertices = (draw->render->max_vertex_buffer_bytes / 
                     (vinfo->size * 4));
 
+   /* Return an even number of verts.
+    * This prevents "parity" errors when splitting long triangle strips which
+    * can lead to front/back culling mix-ups.
+    * Every other triangle in a strip has an alternate front/back orientation
+    * so splitting at an odd position can cause the orientation of subsequent
+    * triangles to get reversed.
+    */
+   *max_vertices = *max_vertices & ~1;
+
    /* Probably need to do this somewhere (or fix exec shader not to
     * need it):
     */
index 4479963db177198162ca11ed5c2e8c0df344ad2f..2cc08a9e9393c2fcb17bb7fd5f5eaad964af2490 100644 (file)
@@ -147,6 +147,10 @@ static void varray_prepare(struct draw_pt_front_end *frontend,
 
    varray->middle = middle;
    middle->prepare(middle, varray->output_prim, opt, &varray->driver_fetch_max );
+
+   /* check that the max is even */
+   assert((varray->driver_fetch_max & 1) == 0);
+
    varray->fetch_max = MIN2(FETCH_MAX, varray->driver_fetch_max);
 }