fix perspective-interpolated attribs for points, liens
authorBrian <brian.paul@tungstengraphics.com>
Tue, 16 Oct 2007 18:04:16 +0000 (12:04 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Tue, 16 Oct 2007 18:04:16 +0000 (12:04 -0600)
src/mesa/pipe/softpipe/sp_prim_setup.c

index 2e27d00acfb02c4fec960caa3fbe63a67e38fd09..7c81faf9df5bd7a76f09e179bd151132f5587a1c 100644 (file)
@@ -659,9 +659,9 @@ static void setup_tri( struct draw_stage *stage,
 static void
 line_linear_coeff(struct setup_stage *setup, unsigned slot, unsigned i)
 {
-   const float dz = setup->vmax->data[slot][i] - setup->vmin->data[slot][i];
-   const float dadx = dz * setup->emaj.dx * setup->oneoverarea;
-   const float dady = dz * setup->emaj.dy * setup->oneoverarea;
+   const float da = setup->vmax->data[slot][i] - setup->vmin->data[slot][i];
+   const float dadx = da * setup->emaj.dx * setup->oneoverarea;
+   const float dady = da * setup->emaj.dy * setup->oneoverarea;
    setup->coef[slot].dadx[i] = dadx;
    setup->coef[slot].dady[i] = dady;
    setup->coef[slot].a0[i]
@@ -678,8 +678,19 @@ line_linear_coeff(struct setup_stage *setup, unsigned slot, unsigned i)
 static void
 line_persp_coeff(struct setup_stage *setup, unsigned slot, unsigned i)
 {
-   /* XXX to do */
-   line_linear_coeff(setup, slot, i); /* XXX temporary */
+   /* XXX double-check/verify this arithmetic */
+   const float a0 = setup->vmin->data[slot][i] * setup->vmin->data[0][3];
+   const float a1 = setup->vmax->data[slot][i] * setup->vmin->data[0][3];
+   const float da = a1 - a0;
+   const float dadx = da * setup->emaj.dx * setup->oneoverarea;
+   const float dady = da * setup->emaj.dy * setup->oneoverarea;
+   setup->coef[slot].dadx[i] = dadx;
+   setup->coef[slot].dady[i] = dady;
+   setup->coef[slot].a0[i]
+      = (setup->vmin->data[slot][i] - 
+         (dadx * (setup->vmin->data[0][0] - 0.5f) + 
+          dady * (setup->vmin->data[0][1] - 0.5f)));
+
 }
 
 
@@ -895,6 +906,18 @@ setup_line(struct draw_stage *stage, struct prim_header *prim)
 }
 
 
+static void
+point_persp_coeff(struct setup_stage *setup, const struct vertex_header *vert,
+                  uint slot, uint i)
+{
+   assert(slot < PIPE_MAX_SHADER_INPUTS);
+   assert(i <= 3);
+   setup->coef[slot].dadx[i] = 0.0F;
+   setup->coef[slot].dady[i] = 0.0F;
+   setup->coef[slot].a0[i] = vert->data[slot][i] * vert->data[0][3];
+}
+
+
 /**
  * Do setup for point rasterization, then render the point.
  * Round or square points...
@@ -904,6 +927,7 @@ static void
 setup_point(struct draw_stage *stage, struct prim_header *prim)
 {
    struct setup_stage *setup = setup_stage( stage );
+   const interp_mode *interp = setup->softpipe->vertex_info.interp_mode;
    const struct vertex_header *v0 = prim->v[0];
    const int sizeAttr = setup->softpipe->psize_slot;
    const float halfSize
@@ -934,8 +958,20 @@ setup_point(struct draw_stage *stage, struct prim_header *prim)
    const_coeff(setup, 0, 2);
    const_coeff(setup, 0, 3);
    for (slot = 1; slot < setup->quad.nr_attrs; slot++) {
-      for (j = 0; j < NUM_CHANNELS; j++)
-         const_coeff(setup, slot, j);
+      switch (interp[slot]) {
+      case INTERP_CONSTANT:
+         /* fall-through */
+      case INTERP_LINEAR:
+         for (j = 0; j < NUM_CHANNELS; j++)
+            const_coeff(setup, slot, j);
+         break;
+      case INTERP_PERSPECTIVE:
+         for (j = 0; j < NUM_CHANNELS; j++)
+            point_persp_coeff(setup, v0, slot, j);
+         break;
+      default:
+         assert(0);
+      }
    }
 
    setup->quad.prim = PRIM_POINT;