Merge branch 'gallium-front-ccw'
[mesa.git] / src / gallium / drivers / llvmpipe / lp_setup_tri.c
index ce689d3d568ca7c3794764a139ae8fffe74e1a5b..306cb6e27d2895dcb8a667ae332a4441549fbd54 100644 (file)
@@ -163,12 +163,17 @@ setup_fragcoord_coef(struct lp_setup_context *setup,
 }
 
 
+/**
+ * Setup the fragment input attribute with the front-facing value.
+ * \param frontface  is the triangle front facing?
+ */
 static void setup_facing_coef( struct lp_setup_context *setup,
                                struct lp_rast_triangle *tri,
                                unsigned slot,
                                boolean frontface )
 {
-   constant_coef( setup, tri, slot, 1.0f - frontface, 0 );
+   /* convert TRUE to 1.0 and FALSE to -1.0 */
+   constant_coef( setup, tri, slot, 2.0f * frontface - 1.0f, 0 );
    constant_coef( setup, tri, slot, 0.0f, 1 ); /* wasted */
    constant_coef( setup, tri, slot, 0.0f, 2 ); /* wasted */
    constant_coef( setup, tri, slot, 0.0f, 3 ); /* wasted */
@@ -200,8 +205,14 @@ static void setup_tri_coefficients( struct lp_setup_context *setup,
 
       switch (setup->fs.input[slot].interp) {
       case LP_INTERP_CONSTANT:
-         for (i = 0; i < NUM_CHANNELS; i++)
-            constant_coef(setup, tri, slot+1, v3[vert_attr][i], i);
+         if (setup->flatshade_first) {
+            for (i = 0; i < NUM_CHANNELS; i++)
+               constant_coef(setup, tri, slot+1, v1[vert_attr][i], i);
+         }
+         else {
+            for (i = 0; i < NUM_CHANNELS; i++)
+               constant_coef(setup, tri, slot+1, v3[vert_attr][i], i);
+         }
          break;
 
       case LP_INTERP_LINEAR:
@@ -272,6 +283,32 @@ alloc_triangle(struct lp_scene *scene, unsigned nr_inputs, unsigned *tri_size)
 }
 
 
+/**
+ * Print triangle vertex attribs (for debug).
+ */
+static void
+print_triangle(struct lp_setup_context *setup,
+               const float (*v1)[4],
+               const float (*v2)[4],
+               const float (*v3)[4])
+{
+   uint i;
+
+   debug_printf("llvmpipe triangle\n");
+   for (i = 0; i < setup->fs.nr_inputs; i++) {
+      debug_printf("  v1[%d]:  %f %f %f %f\n", i,
+                   v1[i][0], v1[i][1], v1[i][2], v1[i][3]);
+   }
+   for (i = 0; i < setup->fs.nr_inputs; i++) {
+      debug_printf("  v2[%d]:  %f %f %f %f\n", i,
+                   v2[i][0], v2[i][1], v2[i][2], v2[i][3]);
+   }
+   for (i = 0; i < setup->fs.nr_inputs; i++) {
+      debug_printf("  v3[%d]:  %f %f %f %f\n", i,
+                   v3[i][0], v3[i][1], v3[i][2], v3[i][3]);
+   }
+}
+
 
 /**
  * Do basic setup for triangle rasterization and determine which
@@ -300,6 +337,9 @@ do_triangle_ccw(struct lp_setup_context *setup,
    int minx, maxx, miny, maxy;
    unsigned tri_bytes;
 
+   if (0)
+      print_triangle(setup, v1, v2, v3);
+
    tri = alloc_triangle(scene, setup->fs.nr_inputs, &tri_bytes);
 
 #ifdef DEBUG
@@ -572,6 +612,9 @@ do_triangle_ccw(struct lp_setup_context *setup,
 }
 
 
+/**
+ * Draw triangle if it's CW, cull otherwise.
+ */
 static void triangle_cw( struct lp_setup_context *setup,
                         const float (*v0)[4],
                         const float (*v1)[4],
@@ -581,6 +624,9 @@ static void triangle_cw( struct lp_setup_context *setup,
 }
 
 
+/**
+ * Draw triangle if it's CCW, cull otherwise.
+ */
 static void triangle_ccw( struct lp_setup_context *setup,
                         const float (*v0)[4],
                         const float (*v1)[4],
@@ -590,6 +636,10 @@ static void triangle_ccw( struct lp_setup_context *setup,
 }
 
 
+
+/**
+ * Draw triangle whether it's CW or CCW.
+ */
 static void triangle_both( struct lp_setup_context *setup,
                           const float (*v0)[4],
                           const float (*v1)[4],
@@ -621,14 +671,14 @@ void
 lp_setup_choose_triangle( struct lp_setup_context *setup )
 {
    switch (setup->cullmode) {
-   case PIPE_WINDING_NONE:
+   case PIPE_FACE_NONE:
       setup->triangle = triangle_both;
       break;
-   case PIPE_WINDING_CCW:
-      setup->triangle = triangle_cw;
+   case PIPE_FACE_BACK:
+      setup->triangle = setup->ccw_is_frontface ? triangle_ccw : triangle_cw;
       break;
-   case PIPE_WINDING_CW:
-      setup->triangle = triangle_ccw;
+   case PIPE_FACE_FRONT:
+      setup->triangle = setup->ccw_is_frontface ? triangle_cw : triangle_ccw;
       break;
    default:
       setup->triangle = triangle_nop;