gallium: additional fixes to ensure even number of vertices per buffer
authorBrian Paul <brian.paul@tungstengraphics.com>
Wed, 18 Jun 2008 21:08:19 +0000 (15:08 -0600)
committerBrian Paul <brian.paul@tungstengraphics.com>
Wed, 18 Jun 2008 21:08:19 +0000 (15:08 -0600)
src/gallium/auxiliary/draw/draw_pipe_vbuf.c
src/gallium/auxiliary/draw/draw_pt_emit.c
src/gallium/auxiliary/draw/draw_pt_fetch_emit.c
src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c

index 10a1f7df7990377bd05bee26033c37dccc843f06..a6fde77a0edd2247cc3b82b3f58f304fe40679aa 100644 (file)
@@ -390,6 +390,9 @@ vbuf_alloc_vertices( struct vbuf_stage *vbuf )
    /* Allocate a new vertex buffer */
    vbuf->max_vertices = vbuf->render->max_vertex_buffer_bytes / vbuf->vertex_size;
 
+   /* even number */
+   vbuf->max_vertices = vbuf->max_vertices & ~1;
+
    /* Must always succeed -- driver gives us a
     * 'max_vertex_buffer_bytes' which it guarantees it can allocate,
     * and it will flush itself if necessary to do so.  If this does
index a02f1f46fed951f0183c6b0f8159beb5a5d331c2..40f05cb9e0b851389877f45b88a578333c541c09 100644 (file)
@@ -143,6 +143,9 @@ void draw_pt_emit_prepare( struct pt_emit *emit,
 
    *max_vertices = (draw->render->max_vertex_buffer_bytes / 
                     (vinfo->size * 4));
+
+   /* even number */
+   *max_vertices = *max_vertices & ~1;
 }
 
 
index 083ce105bfd5d40dae1c50bff4587cca742549f4..4a1f3b095361e6046d64678796837fc36bfaebc5 100644 (file)
@@ -200,6 +200,15 @@ static void fetch_emit_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;
 }
 
 
index 25118712a6645070d11d81f984e3a572774c4701..0aec4b71baf99cbfd081ae2dee6bf0c3bf252db2 100644 (file)
@@ -99,6 +99,9 @@ static void fetch_pipeline_prepare( struct draw_pt_middle_end *middle,
       *max_vertices = DRAW_PIPE_MAX_VERTICES; 
    }
 
+   /* return even number */
+   *max_vertices = *max_vertices & ~1;
+
    /* No need to prepare the shader.
     */
    vs->prepare(vs, draw);