diff options
author | Brian Paul <brian.paul@tungstengraphics.com> | 2004-03-03 15:50:28 +0000 |
---|---|---|
committer | Brian Paul <brian.paul@tungstengraphics.com> | 2004-03-03 15:50:28 +0000 |
commit | 7c6a04f6d8ef3c8a47a708a76bb4f4ac65c6b20f (patch) | |
tree | f67c42f75a303691cf7a6e2a4272ad09cde98766 /src/mesa/swrast_setup/ss_tritmp.h | |
parent | 9a20a72cdcab2a6c1678b83c782b61c047e765e3 (diff) | |
download | external_mesa3d-7c6a04f6d8ef3c8a47a708a76bb4f4ac65c6b20f.zip external_mesa3d-7c6a04f6d8ef3c8a47a708a76bb4f4ac65c6b20f.tar.gz external_mesa3d-7c6a04f6d8ef3c8a47a708a76bb4f4ac65c6b20f.tar.bz2 |
added clamping to polygon offset to prevent potential negative Z values and FP exceptions
Diffstat (limited to 'src/mesa/swrast_setup/ss_tritmp.h')
-rw-r--r-- | src/mesa/swrast_setup/ss_tritmp.h | 31 |
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 cc02a99..e1c2565 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);*/ } } |