draw: Preserve the provoking vertex both when decomposing and clipping.
authorJosé Fonseca <jfonseca@vmware.com>
Tue, 4 May 2010 23:40:56 +0000 (00:40 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Tue, 4 May 2010 23:46:13 +0000 (00:46 +0100)
Based on John Lawless' feedback.

src/gallium/auxiliary/draw/draw_pipe_clip.c
src/gallium/auxiliary/draw/draw_pt_decompose.h

index 51a6115ebf5e9e06a8e1c488abb8c80ca0424933..428ef4ef67ad0f1597170097fcddd7631c17c50a 100644 (file)
@@ -175,9 +175,17 @@ static void emit_poly( struct draw_stage *stage,
    header.pad = 0;
 
    for (i = 2; i < n; i++, header.flags = edge_middle) {
-      header.v[0] = inlist[i-1];
-      header.v[1] = inlist[i];
-      header.v[2] = inlist[0]; /* keep in v[2] for flatshading */
+      /* keep in provoking vertex for flatshading */
+      if (stage->draw->rasterizer->flatshade_first) {
+         header.v[0] = inlist[0];
+         header.v[1] = inlist[i-1];
+         header.v[2] = inlist[i];
+      }
+      else {
+         header.v[0] = inlist[i-1];
+         header.v[1] = inlist[i];
+         header.v[2] = inlist[0];
+      }
 
       if (i == n-1)
          header.flags |= edge_last;
@@ -293,12 +301,21 @@ do_clip_tri( struct draw_stage *stage,
 
    /* If flat-shading, copy color to new provoking vertex.
     */
-   if (clipper->flat && inlist[0] != header->v[2]) {
-      inlist[0] = dup_vert(stage, inlist[0], tmpnr++);
+   if (stage->draw->rasterizer->flatshade_first) {
+      if (clipper->flat && inlist[0] != header->v[0]) {
+         inlist[0] = dup_vert(stage, inlist[0], tmpnr++);
+
+         copy_colors(stage, inlist[0], header->v[0]);
+      }
+   } else {
+      if (clipper->flat && inlist[0] != header->v[2]) {
+         inlist[0] = dup_vert(stage, inlist[0], tmpnr++);
 
-      copy_colors(stage, inlist[0], header->v[2]);
+         copy_colors(stage, inlist[0], header->v[2]);
+      }
    }
 
+
    /* Emit the polygon as triangles to the setup stage:
     */
    if (n >= 3)
index 3c44f7c11eec0c216fa9c1217ea87dd95f0cbe89..02567d97f266ddaa10d9ff22f7930961d4a2f1b0 100644 (file)
@@ -47,19 +47,10 @@ static void FUNC( ARGS,
 
    case PIPE_PRIM_TRIANGLES:
       for (i = 0; i+2 < count; i += 3) {
-         if (flatfirst) {
-            /* 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 ));
-         }
+         TRIANGLE( DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL,
+                   (i + 0),
+                   (i + 1),
+                   (i + 2 ));
       }
       break;
 
@@ -67,9 +58,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 + 0),
                       (i + 1 + (i&1)),
-                      (i + 2 - (i&1)),
-                      (i + 0) );
+                      (i + 2 - (i&1)) );
          }
       }
       else {
@@ -87,9 +78,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,
-                         (i + 1) );
+                         0 );
             }
          }
          else {