Merge branch 'mesa_7_5_branch'
[mesa.git] / src / gallium / auxiliary / draw / draw_pipe_vbuf.c
index b08341145870843c8eb53ac529d958848a7f7024..1a5269c0de9393b126f06855f21290cdc945ccb6 100644 (file)
  * \file
  * Vertex buffer drawing stage.
  * 
- * \author José Fonseca <jrfonsec@tungstengraphics.com>
+ * \author Jose Fonseca <jrfonsec@tungstengraphics.com>
  * \author Keith Whitwell <keith@tungstengraphics.com>
  */
 
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 
@@ -159,8 +159,19 @@ vbuf_tri( struct draw_stage *stage,
 
    check_space( vbuf, 3 );
 
-   for (i = 0; i < 3; i++) {
-      vbuf->indices[vbuf->nr_indices++] = emit_vertex( vbuf, prim->v[i] );
+   if (vbuf->stage.draw->rasterizer->flatshade_first) {
+      /* Put provoking vertex in position expected by the driver.
+       * Emit last provoking vertex in first pos.
+       * Swap verts 0 & 1 to preserve polygon winding.
+       */
+      vbuf->indices[vbuf->nr_indices++] = emit_vertex( vbuf, prim->v[2] );
+      vbuf->indices[vbuf->nr_indices++] = emit_vertex( vbuf, prim->v[0] );
+      vbuf->indices[vbuf->nr_indices++] = emit_vertex( vbuf, prim->v[1] );
+   }
+   else {
+      for (i = 0; i < 3; i++) {
+         vbuf->indices[vbuf->nr_indices++] = emit_vertex( vbuf, prim->v[i] );
+      }
    }
 }
 
@@ -341,7 +352,7 @@ vbuf_flush_vertices( struct vbuf_stage *vbuf )
 {
    if(vbuf->vertices) {
 
-      vbuf->render->unmap_vertices( vbuf->render, 0, vbuf->nr_vertices );
+      vbuf->render->unmap_vertices( vbuf->render, 0, vbuf->nr_vertices - 1 );
 
       if (vbuf->nr_indices) 
       {
@@ -446,6 +457,7 @@ struct draw_stage *draw_vbuf_stage( struct draw_context *draw,
       goto fail;
    
    vbuf->stage.draw = draw;
+   vbuf->stage.name = "vbuf";
    vbuf->stage.point = vbuf_first_point;
    vbuf->stage.line = vbuf_first_line;
    vbuf->stage.tri = vbuf_first_tri;