summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian <brian.paul@tungstengraphics.com>2007-07-10 14:38:10 -0600
committerBrian <brian.paul@tungstengraphics.com>2007-07-10 14:38:10 -0600
commit13aa51de41a93fff1aa5050cebec2a6e0985b45a (patch)
treedcafec873daf0eeecbf0d344d2721580750bacff
parent6aa9c8ebc19ffa4425669862caeb99b22c079090 (diff)
clamp after offsetting, new comments
-rw-r--r--src/mesa/pipe/draw/draw_offset.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/mesa/pipe/draw/draw_offset.c b/src/mesa/pipe/draw/draw_offset.c
index 0fa8cf29d3..62ab2e4643 100644
--- a/src/mesa/pipe/draw/draw_offset.c
+++ b/src/mesa/pipe/draw/draw_offset.c
@@ -74,32 +74,34 @@ static void do_offset_tri( struct prim_stage *stage,
/* Window coords:
*/
- GLfloat *v0 = (GLfloat *)&(header->v[0]->data[0]);
- GLfloat *v1 = (GLfloat *)&(header->v[1]->data[0]);
- GLfloat *v2 = (GLfloat *)&(header->v[2]->data[0]);
-
+ GLfloat *v0 = header->v[0]->data[0];
+ GLfloat *v1 = header->v[1]->data[0];
+ GLfloat *v2 = header->v[2]->data[0];
+
+ /* edge vectors e = v0 - v2, f = v1 - v2 */
GLfloat ex = v0[0] - v2[2];
- GLfloat fx = v1[0] - v2[2];
GLfloat ey = v0[1] - v2[2];
- GLfloat fy = v1[1] - v2[2];
GLfloat ez = v0[2] - v2[2];
+ GLfloat fx = v1[0] - v2[2];
+ GLfloat fy = v1[1] - v2[2];
GLfloat fz = v1[2] - v2[2];
+ /* (a,b) = cross(e,f).xy */
GLfloat a = ey*fz - ez*fy;
GLfloat b = ez*fx - ex*fz;
- GLfloat ac = a * inv_det;
- GLfloat bc = b * inv_det;
- GLfloat zoffset;
-
- ac = FABSF(ac);
- bc = FABSF(bc);
+ GLfloat dzdx = FABSF(a * inv_det);
+ GLfloat dzdy = FABSF(b * inv_det);
- zoffset = offset->units + MAX2( ac, bc ) * offset->scale;
+ GLfloat zoffset = offset->units + MAX2(dzdx, dzdy) * offset->scale;
- v0[2] += zoffset;
- v1[2] += zoffset;
- v2[2] += zoffset;
+ /*
+ * Note: we're applying the offset and clamping per-vertex.
+ * Ideally, the offset is applied per-fragment prior to fragment shading.
+ */
+ v0[2] = CLAMP(v0[2] + zoffset, 0.0, 1.0);
+ v1[2] = CLAMP(v1[2] + zoffset, 0.0, 1.0);
+ v2[2] = CLAMP(v2[2] + zoffset, 0.0, 1.0);
stage->next->tri( stage->next, header );
}