aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/swrast/s_depth.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-04-12 09:53:17 +0000
committermarha <marha@users.sourceforge.net>2010-04-12 09:53:17 +0000
commit29b86f9852b2b7ecc31cdfee56679537e40bc6e2 (patch)
tree1e6ec8ccf2dbf773260a1953b8e13c49f9b7c5f5 /mesalib/src/mesa/swrast/s_depth.c
parent529236591df7366479a6fac30b387667678fd1ba (diff)
downloadvcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.tar.gz
vcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.tar.bz2
vcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.zip
svn merge -r524:HEAD "^/branches/released" .
Diffstat (limited to 'mesalib/src/mesa/swrast/s_depth.c')
-rw-r--r--mesalib/src/mesa/swrast/s_depth.c60
1 files changed, 36 insertions, 24 deletions
diff --git a/mesalib/src/mesa/swrast/s_depth.c b/mesalib/src/mesa/swrast/s_depth.c
index c37a54eb3..ed637cac1 100644
--- a/mesalib/src/mesa/swrast/s_depth.c
+++ b/mesalib/src/mesa/swrast/s_depth.c
@@ -28,7 +28,6 @@
#include "main/formats.h"
#include "main/macros.h"
#include "main/imports.h"
-#include "main/fbobject.h"
#include "s_depth.h"
#include "s_context.h"
@@ -260,7 +259,7 @@ depth_test_span16( GLcontext *ctx, GLuint n,
}
break;
case GL_NEVER:
- _mesa_bzero(mask, n * sizeof(GLubyte));
+ memset(mask, 0, n * sizeof(GLubyte));
break;
default:
_mesa_problem(ctx, "Bad depth func in depth_test_span16");
@@ -489,7 +488,7 @@ depth_test_span32( GLcontext *ctx, GLuint n,
}
break;
case GL_NEVER:
- _mesa_bzero(mask, n * sizeof(GLubyte));
+ memset(mask, 0, n * sizeof(GLubyte));
break;
default:
_mesa_problem(ctx, "Bad depth func in depth_test_span32");
@@ -498,17 +497,24 @@ depth_test_span32( GLcontext *ctx, GLuint n,
return passed;
}
-/* Apply ARB_depth_clamp to span of fragments. */
+
+
+/**
+ * Clamp fragment Z values to the depth near/far range (glDepthRange()).
+ * This is used when GL_ARB_depth_clamp/GL_DEPTH_CLAMP is turned on.
+ * In that case, vertexes are not clipped against the near/far planes
+ * so rasterization will produce fragment Z values outside the usual
+ * [0,1] range.
+ */
void
_swrast_depth_clamp_span( GLcontext *ctx, SWspan *span )
{
struct gl_framebuffer *fb = ctx->DrawBuffer;
- struct gl_renderbuffer *rb = fb->_DepthBuffer;
const GLuint count = span->end;
- GLuint *zValues = span->array->z;
- GLuint min, max;
+ GLint *zValues = (GLint *) span->array->z; /* sign change */
+ GLint min, max;
GLfloat min_f, max_f;
- int i;
+ GLuint i;
if (ctx->Viewport.Near < ctx->Viewport.Far) {
min_f = ctx->Viewport.Near;
@@ -518,15 +524,21 @@ _swrast_depth_clamp_span( GLcontext *ctx, SWspan *span )
max_f = ctx->Viewport.Near;
}
- if (rb->DataType == GL_UNSIGNED_SHORT) {
- CLAMPED_FLOAT_TO_USHORT(min, min_f);
- CLAMPED_FLOAT_TO_USHORT(max, max_f);
- } else {
- assert(rb->DataType == GL_UNSIGNED_INT);
- min = FLOAT_TO_UINT(min_f);
- max = FLOAT_TO_UINT(max_f);
- }
-
+ /* Convert floating point values in [0,1] to device Z coordinates in
+ * [0, DepthMax].
+ * ex: If the Z buffer has 24 bits, DepthMax = 0xffffff.
+ *
+ * XXX this all falls apart if we have 31 or more bits of Z because
+ * the triangle rasterization code produces unsigned Z values. Negative
+ * vertex Z values come out as large fragment Z uints.
+ */
+ min = (GLint) (min_f * fb->_DepthMaxF);
+ max = (GLint) (max_f * fb->_DepthMaxF);
+ if (max < 0)
+ max = 0x7fffffff; /* catch over flow for 30-bit z */
+
+ /* Note that we do the comparisons here using signed integers.
+ */
for (i = 0; i < count; i++) {
if (zValues[i] < min)
zValues[i] = min;
@@ -832,7 +844,7 @@ direct_depth_test_pixels16(GLcontext *ctx, GLushort *zStart, GLuint stride,
break;
case GL_NEVER:
/* depth test never passes */
- _mesa_bzero(mask, n * sizeof(GLubyte));
+ memset(mask, 0, n * sizeof(GLubyte));
break;
default:
_mesa_problem(ctx, "Bad depth func in direct_depth_test_pixels");
@@ -1078,7 +1090,7 @@ direct_depth_test_pixels32(GLcontext *ctx, GLuint *zStart, GLuint stride,
break;
case GL_NEVER:
/* depth test never passes */
- _mesa_bzero(mask, n * sizeof(GLubyte));
+ memset(mask, 0, n * sizeof(GLubyte));
break;
default:
_mesa_problem(ctx, "Bad depth func in direct_depth_test_pixels");
@@ -1248,7 +1260,7 @@ _swrast_read_depth_span_float( GLcontext *ctx, struct gl_renderbuffer *rb,
if (!rb) {
/* really only doing this to prevent FP exceptions later */
- _mesa_bzero(depth, n * sizeof(GLfloat));
+ memset(depth, 0, n * sizeof(GLfloat));
return;
}
@@ -1257,7 +1269,7 @@ _swrast_read_depth_span_float( GLcontext *ctx, struct gl_renderbuffer *rb,
if (y < 0 || y >= (GLint) rb->Height ||
x + n <= 0 || x >= (GLint) rb->Width) {
/* span is completely outside framebuffer */
- _mesa_bzero(depth, n * sizeof(GLfloat));
+ memset(depth, 0, n * sizeof(GLfloat));
return;
}
@@ -1314,7 +1326,7 @@ _swrast_read_depth_span_uint( GLcontext *ctx, struct gl_renderbuffer *rb,
if (!rb) {
/* really only doing this to prevent FP exceptions later */
- _mesa_bzero(depth, n * sizeof(GLuint));
+ memset(depth, 0, n * sizeof(GLuint));
return;
}
@@ -1325,7 +1337,7 @@ _swrast_read_depth_span_uint( GLcontext *ctx, struct gl_renderbuffer *rb,
if (y < 0 || y >= (GLint) rb->Height ||
x + n <= 0 || x >= (GLint) rb->Width) {
/* span is completely outside framebuffer */
- _mesa_bzero(depth, n * sizeof(GLfloat));
+ memset(depth, 0, n * sizeof(GLfloat));
return;
}
@@ -1426,7 +1438,7 @@ _swrast_clear_depth_buffer( GLcontext *ctx, struct gl_renderbuffer *rb )
/* optimized case */
GLushort *dst = (GLushort *) rb->GetPointer(ctx, rb, x, y);
GLuint len = width * height * sizeof(GLushort);
- _mesa_memset(dst, (clearValue & 0xff), len);
+ memset(dst, (clearValue & 0xff), len);
}
else {
/* general case */