X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fswrast%2Fs_depth.c;h=58440cb97bd68203a41023b094fd7b620f6528ed;hb=12d69fca096facf0ddb4642faaed4d5f02d76848;hp=c37a54eb3eb4fd85bef03a742774dabf23b69955;hpb=32ec3f26731ac998b6fda7ce596ec568d6f76eeb;p=mesa.git diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c index c37a54eb3eb..58440cb97bd 100644 --- a/src/mesa/swrast/s_depth.c +++ b/src/mesa/swrast/s_depth.c @@ -28,10 +28,8 @@ #include "main/formats.h" #include "main/macros.h" #include "main/imports.h" -#include "main/fbobject.h" #include "s_depth.h" -#include "s_context.h" #include "s_span.h" @@ -42,7 +40,7 @@ * Return: number of fragments which pass the test. */ static GLuint -depth_test_span16( GLcontext *ctx, GLuint n, +depth_test_span16( struct gl_context *ctx, GLuint n, GLushort zbuffer[], const GLuint z[], GLubyte mask[] ) { GLuint passed = 0; @@ -260,7 +258,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"); @@ -271,7 +269,7 @@ depth_test_span16( GLcontext *ctx, GLuint n, static GLuint -depth_test_span32( GLcontext *ctx, GLuint n, +depth_test_span32( struct gl_context *ctx, GLuint n, GLuint zbuffer[], const GLuint z[], GLubyte mask[] ) { GLuint passed = 0; @@ -489,7 +487,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 +496,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 ) +_swrast_depth_clamp_span( struct gl_context *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 +523,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; @@ -541,7 +552,7 @@ _swrast_depth_clamp_span( GLcontext *ctx, SWspan *span ) * Apply depth test to span of fragments. */ static GLuint -depth_test_span( GLcontext *ctx, SWspan *span) +depth_test_span( struct gl_context *ctx, SWspan *span) { struct gl_framebuffer *fb = ctx->DrawBuffer; struct gl_renderbuffer *rb = fb->_DepthBuffer; @@ -599,7 +610,7 @@ depth_test_span( GLcontext *ctx, SWspan *span) * Do depth testing for an array of fragments at assorted locations. */ static void -direct_depth_test_pixels16(GLcontext *ctx, GLushort *zStart, GLuint stride, +direct_depth_test_pixels16(struct gl_context *ctx, GLushort *zStart, GLuint stride, GLuint n, const GLint x[], const GLint y[], const GLuint z[], GLubyte mask[] ) { @@ -832,7 +843,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"); @@ -845,7 +856,7 @@ direct_depth_test_pixels16(GLcontext *ctx, GLushort *zStart, GLuint stride, * Do depth testing for an array of fragments with direct access to zbuffer. */ static void -direct_depth_test_pixels32(GLcontext *ctx, GLuint *zStart, GLuint stride, +direct_depth_test_pixels32(struct gl_context *ctx, GLuint *zStart, GLuint stride, GLuint n, const GLint x[], const GLint y[], const GLuint z[], GLubyte mask[] ) { @@ -1078,7 +1089,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"); @@ -1089,7 +1100,7 @@ direct_depth_test_pixels32(GLcontext *ctx, GLuint *zStart, GLuint stride, static GLuint -depth_test_pixels( GLcontext *ctx, SWspan *span ) +depth_test_pixels( struct gl_context *ctx, SWspan *span ) { struct gl_framebuffer *fb = ctx->DrawBuffer; struct gl_renderbuffer *rb = fb->_DepthBuffer; @@ -1139,7 +1150,7 @@ depth_test_pixels( GLcontext *ctx, SWspan *span ) * \return approx number of pixels that passed (only zero is reliable) */ GLuint -_swrast_depth_test_span( GLcontext *ctx, SWspan *span) +_swrast_depth_test_span( struct gl_context *ctx, SWspan *span) { if (span->arrayMask & SPAN_XY) return depth_test_pixels(ctx, span); @@ -1156,7 +1167,7 @@ _swrast_depth_test_span( GLcontext *ctx, SWspan *span) * \return GL_TRUE if any fragments pass, GL_FALSE if no fragments pass */ GLboolean -_swrast_depth_bounds_test( GLcontext *ctx, SWspan *span ) +_swrast_depth_bounds_test( struct gl_context *ctx, SWspan *span ) { struct gl_framebuffer *fb = ctx->DrawBuffer; struct gl_renderbuffer *rb = fb->_DepthBuffer; @@ -1241,14 +1252,14 @@ _swrast_depth_bounds_test( GLcontext *ctx, SWspan *span ) * _swrast_ReadPixels. */ void -_swrast_read_depth_span_float( GLcontext *ctx, struct gl_renderbuffer *rb, +_swrast_read_depth_span_float( struct gl_context *ctx, struct gl_renderbuffer *rb, GLint n, GLint x, GLint y, GLfloat depth[] ) { const GLfloat scale = 1.0F / ctx->DrawBuffer->_DepthMaxF; 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 +1268,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; } @@ -1307,14 +1318,14 @@ _swrast_read_depth_span_float( GLcontext *ctx, struct gl_renderbuffer *rb, * As above, but return 32-bit GLuint values. */ void -_swrast_read_depth_span_uint( GLcontext *ctx, struct gl_renderbuffer *rb, +_swrast_read_depth_span_uint( struct gl_context *ctx, struct gl_renderbuffer *rb, GLint n, GLint x, GLint y, GLuint depth[] ) { GLuint depthBits; 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 +1336,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; } @@ -1389,7 +1400,7 @@ _swrast_read_depth_span_uint( GLcontext *ctx, struct gl_renderbuffer *rb, * Clear the given z/depth renderbuffer. */ void -_swrast_clear_depth_buffer( GLcontext *ctx, struct gl_renderbuffer *rb ) +_swrast_clear_depth_buffer( struct gl_context *ctx, struct gl_renderbuffer *rb ) { GLuint clearValue; GLint x, y, width, height; @@ -1426,7 +1437,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 */