summaryrefslogtreecommitdiff
path: root/src/mesa/swrast_setup
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2004-03-03 15:50:28 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2004-03-03 15:50:28 +0000
commit7c6a04f6d8ef3c8a47a708a76bb4f4ac65c6b20f (patch)
treef67c42f75a303691cf7a6e2a4272ad09cde98766 /src/mesa/swrast_setup
parent9a20a72cdcab2a6c1678b83c782b61c047e765e3 (diff)
added clamping to polygon offset to prevent potential negative Z values and FP exceptions
Diffstat (limited to 'src/mesa/swrast_setup')
-rw-r--r--src/mesa/swrast_setup/ss_tritmp.h31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/mesa/swrast_setup/ss_tritmp.h b/src/mesa/swrast_setup/ss_tritmp.h
index cc02a992ee..e1c2565c73 100644
--- a/src/mesa/swrast_setup/ss_tritmp.h
+++ b/src/mesa/swrast_setup/ss_tritmp.h
@@ -1,9 +1,8 @@
-
/*
* Mesa 3-D graphics library
- * Version: 5.0
+ * Version: 6.1
*
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -102,24 +101,24 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
if (IND & SS_OFFSET_BIT)
{
- offset = ctx->Polygon.OffsetUnits;
+ offset = ctx->Polygon.OffsetUnits * ctx->MRD;
z[0] = v[0]->win[2];
z[1] = v[1]->win[2];
z[2] = v[2]->win[2];
if (cc * cc > 1e-16) {
- GLfloat ez = z[0] - z[2];
- GLfloat fz = z[1] - z[2];
- GLfloat a = ey*fz - ez*fy;
- GLfloat b = ez*fx - ex*fz;
- GLfloat ic = 1.0F / cc;
- GLfloat ac = a * ic;
- GLfloat bc = b * ic;
- if (ac < 0.0F) ac = -ac;
- if (bc < 0.0F) bc = -bc;
- offset += MAX2(ac, bc) * ctx->Polygon.OffsetFactor;
+ const GLfloat ez = z[0] - z[2];
+ const GLfloat fz = z[1] - z[2];
+ const GLfloat oneOverArea = 1.0F / cc;
+ const GLfloat dzdx = FABSF((ey * fz - ez * fy) * oneOverArea);
+ const GLfloat dzdy = FABSF((ez * fx - ex * fz) * oneOverArea);
+ offset += MAX2(dzdx, dzdy) * ctx->Polygon.OffsetFactor;
+ /* Unfortunately, we need to clamp to prevent negative Zs below.
+ * Technically, we should do the clamping per-fragment.
+ */
+ offset = MAX2(offset, -v[0]->win[2]);
+ offset = MAX2(offset, -v[1]->win[2]);
+ offset = MAX2(offset, -v[2]->win[2]);
}
- offset *= ctx->MRD;
- /*printf("offset %g\n", offset);*/
}
}