draw: Take flatshade_first rasterizer bit into account.
authorMichal Krol <michal@tungstengraphics.com>
Tue, 25 Mar 2008 22:49:11 +0000 (23:49 +0100)
committerMichal Krol <michal@tungstengraphics.com>
Tue, 25 Mar 2008 22:51:52 +0000 (23:51 +0100)
src/gallium/auxiliary/draw/draw_prim.c

index 75b2f79babb048017104a03fdfdeddbd8caecb32..f589d0c0173860f6692f5622f8007a97a63184a8 100644 (file)
@@ -330,6 +330,8 @@ draw_prim( struct draw_context *draw,
    unsigned i;
    boolean unfilled = (draw->rasterizer->fill_cw != PIPE_POLYGON_MODE_FILL ||
                       draw->rasterizer->fill_ccw != PIPE_POLYGON_MODE_FILL);
+   boolean flatfirst =
+      (draw->rasterizer->flatshade & draw->rasterizer->flatshade_first) ? TRUE : FALSE;
 
 //   debug_printf("%s (%d) %d/%d\n", __FUNCTION__, draw->prim, start, count );
 
@@ -342,11 +344,21 @@ draw_prim( struct draw_context *draw,
       break;
 
    case PIPE_PRIM_LINES:
-      for (i = 0; i+1 < count; i += 2) {
-        do_line( draw, 
-                 TRUE,
-                 start + i + 0,
-                 start + i + 1);
+      if (flatfirst) {
+         for (i = 0; i+1 < count; i += 2) {
+            do_line( draw, 
+               TRUE,
+               start + i + 1,
+               start + i + 0);
+         }
+      }
+      else {
+         for (i = 0; i+1 < count; i += 2) {
+            do_line( draw, 
+               TRUE,
+               start + i + 0,
+               start + i + 1);
+         }
       }
       break;
 
@@ -367,60 +379,120 @@ draw_prim( struct draw_context *draw,
       break;
 
    case PIPE_PRIM_LINE_STRIP:
-      for (i = 1; i < count; i++) {
-        do_line( draw,
-                 i == 1,
-                 start + i - 1,
-                 start + i );
+      if (flatfirst) {
+         for (i = 1; i < count; i++) {
+            do_line( draw,
+               i == 1,
+               start + i,
+               start + i - 1 );
+         }
+      }
+      else {
+         for (i = 1; i < count; i++) {
+            do_line( draw,
+               i == 1,
+               start + i - 1,
+               start + i );
+         }
       }
       break;
 
    case PIPE_PRIM_TRIANGLES:
-      if (unfilled) {
-        for (i = 0; i+2 < count; i += 3) {
-           do_ef_triangle( draw,
-                           1, 
-                           ~0,
-                           start + i + 0,
-                           start + i + 1,
-                           start + i + 2 );
-        }
-      } 
+      if (flatfirst) {
+         if (unfilled) {
+            for (i = 0; i+2 < count; i += 3) {
+               do_ef_triangle( draw,
+                  1, 
+                  ~0,
+                  start + i + 1,
+                  start + i + 2,
+                  start + i + 0 );
+            }
+         } 
+         else {
+            for (i = 0; i+2 < count; i += 3) {
+               do_triangle( draw,
+                  start + i + 1,
+                  start + i + 2,
+                  start + i + 0 );
+            }
+         }
+      }
       else {
-        for (i = 0; i+2 < count; i += 3) {
-           do_triangle( draw,
-                        start + i + 0,
-                        start + i + 1,
-                        start + i + 2 );
-        }
+         if (unfilled) {
+            for (i = 0; i+2 < count; i += 3) {
+               do_ef_triangle( draw,
+                  1, 
+                  ~0,
+                  start + i + 0,
+                  start + i + 1,
+                  start + i + 2 );
+            }
+         } 
+         else {
+            for (i = 0; i+2 < count; i += 3) {
+               do_triangle( draw,
+                  start + i + 0,
+                  start + i + 1,
+                  start + i + 2 );
+            }
+         }
       }
       break;
 
    case PIPE_PRIM_TRIANGLE_STRIP:
-      for (i = 0; i+2 < count; i++) {
-        if (i & 1) {
-           do_triangle( draw,
-                        start + i + 1,
-                        start + i + 0,
-                        start + i + 2 );
-        }
-        else {
-           do_triangle( draw,
-                        start + i + 0,
-                        start + i + 1,
-                        start + i + 2 );
-        }
+      if (flatfirst) {
+         for (i = 0; i+2 < count; i++) {
+            if (i & 1) {
+               do_triangle( draw,
+                  start + i + 2,
+                  start + i + 1,
+                  start + i + 0 );
+            }
+            else {
+               do_triangle( draw,
+                  start + i + 1,
+                  start + i + 2,
+                  start + i + 0 );
+            }
+         }
+      }
+      else {
+         for (i = 0; i+2 < count; i++) {
+            if (i & 1) {
+               do_triangle( draw,
+                  start + i + 1,
+                  start + i + 0,
+                  start + i + 2 );
+            }
+            else {
+               do_triangle( draw,
+                  start + i + 0,
+                  start + i + 1,
+                  start + i + 2 );
+            }
+         }
       }
       break;
 
    case PIPE_PRIM_TRIANGLE_FAN:
       if (count >= 3) {
-        for (i = 0; i+2 < count; i++) {
-           do_triangle( draw,
-                        start + 0,
-                        start + i + 1,
-                        start + i + 2 );
-        }
+         if (flatfirst) {
+            for (i = 0; i+2 < count; i++) {
+               do_triangle( draw,
+                  start + i + 2,
+                  start + 0,
+                  start + i + 1 );
+            }
+         }
+         else {
+            for (i = 0; i+2 < count; i++) {
+               do_triangle( draw,
+                  start + 0,
+                  start + i + 1,
+                  start + i + 2 );
+            }
+         }
       }
       break;