draw: implement flatshade_first for drawing pipeline
authorBrian Paul <brianp@vmware.com>
Wed, 10 Jun 2009 03:53:34 +0000 (21:53 -0600)
committerBrian Paul <brianp@vmware.com>
Wed, 10 Jun 2009 03:53:34 +0000 (21:53 -0600)
src/gallium/auxiliary/draw/draw_pipe_vbuf.c
src/gallium/auxiliary/draw/draw_pt_decompose.h

index a5d840b96ea84562799aacdb69ebe25a06d0ec43..1a5269c0de9393b126f06855f21290cdc945ccb6 100644 (file)
@@ -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] );
+      }
    }
 }
 
index 3fb0695687892abd977a43e800c7d800683a953e..a86c8d7877f4473bcb54cb0a68d79b676a66f48e 100644 (file)
@@ -47,20 +47,36 @@ static void FUNC( ARGS,
 
    case PIPE_PRIM_TRIANGLES:
       for (i = 0; i+2 < count; i += 3) {
-         TRIANGLE( DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
-                   (i + 0),
-                   (i + 1),
-                   (i + 2 ));
+         if (draw->rasterizer->flatshade_first) {
+            /* put provoking vertex in last pos for clipper */
+            TRIANGLE( DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
+                      (i + 1),
+                      (i + 2),
+                      (i + 0 ));
+         }
+         else {
+            TRIANGLE( DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
+                      (i + 0),
+                      (i + 1),
+                      (i + 2 ));
+         }
       }
       break;
 
    case PIPE_PRIM_TRIANGLE_STRIP:
       if (flatfirst) {
+         printf("%s tri strip %d %d %d\n",
+                __FUNCTION__,
+                (i + 1 + (i&1)),
+                (i + 2 - (i&1)),
+                (i + 0) );
+
+
          for (i = 0; i+2 < count; i++) {
             TRIANGLE( DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
-                      (i + 0),
                       (i + 1 + (i&1)),
-                      (i + 2 - (i&1)));
+                      (i + 2 - (i&1)),
+                      (i + 0) );
          }
       }
       else {
@@ -78,9 +94,9 @@ static void FUNC( ARGS,
          if (flatfirst) {
             for (i = 0; i+2 < count; i++) {
                TRIANGLE( DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
-                         (i + 1),
                          (i + 2),
-                         (0 ));
+                         0,
+                         (i + 1) );
             }
          }
          else {
@@ -96,20 +112,40 @@ static void FUNC( ARGS,
 
 
    case PIPE_PRIM_QUADS:
-      for (i = 0; i+3 < count; i += 4) {
-         QUAD( (i + 0),
-               (i + 1),
-               (i + 2),
-               (i + 3));
+      if (flatfirst) {
+         for (i = 0; i+3 < count; i += 4) {
+            QUAD( (i + 1),
+                  (i + 2),
+                  (i + 3),
+                  (i + 0) );
+         }
+      }
+      else {
+         for (i = 0; i+3 < count; i += 4) {
+            QUAD( (i + 0),
+                  (i + 1),
+                  (i + 2),
+                  (i + 3));
+         }
       }
       break;
 
    case PIPE_PRIM_QUAD_STRIP:
-      for (i = 0; i+3 < count; i += 2) {
-         QUAD( (i + 2),
-               (i + 0),
-               (i + 1),
-               (i + 3));
+      if (flatfirst) {
+         for (i = 0; i+3 < count; i += 2) {
+            QUAD( (i + 1),
+                  (i + 3),
+                  (i + 2),
+                  (i + 0) );
+         }
+      }
+      else {
+         for (i = 0; i+3 < count; i += 2) {
+            QUAD( (i + 2),
+                  (i + 0),
+                  (i + 1),
+                  (i + 3));
+         }
       }
       break;