From d72834dd0ba471bbd7fe16aedc800f290ea46651 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 14 May 2004 14:39:59 +0000 Subject: Minor fixes/optimizations to type conversions in draw_depth_pixels(). Fix off by one errors in a few assertions. --- src/mesa/swrast/s_drawpix.c | 68 +++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 27 deletions(-) (limited to 'src/mesa') diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c index a93a605a97..d12ea359c7 100644 --- a/src/mesa/swrast/s_drawpix.c +++ b/src/mesa/swrast/s_drawpix.c @@ -289,7 +289,7 @@ fast_draw_pixels(GLcontext *ctx, GLint x, GLint y, if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) { /* no zooming */ GLint row; - ASSERT(drawWidth < MAX_WIDTH); + ASSERT(drawWidth <= MAX_WIDTH); for (row=0; rowPixel.ZoomX==1.0F && ctx->Pixel.ZoomY==-1.0F) { /* upside-down */ GLint row; - ASSERT(drawWidth < MAX_WIDTH); + ASSERT(drawWidth <= MAX_WIDTH); for (row=0; rowPixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) { /* no zooming */ GLint row; - ASSERT(drawWidth < MAX_WIDTH); + ASSERT(drawWidth <= MAX_WIDTH); for (row=0; rowPixel.ZoomX==1.0F && ctx->Pixel.ZoomY==-1.0F) { /* upside-down */ GLint row; - ASSERT(drawWidth < MAX_WIDTH); + ASSERT(drawWidth <= MAX_WIDTH); for (row=0; rowrgba); (*swrast->Driver.WriteRGBASpan)(ctx, drawWidth, destX, destY, (const GLchan (*)[4]) span.array->rgba, NULL); @@ -432,7 +432,7 @@ fast_draw_pixels(GLcontext *ctx, GLint x, GLint y, /* upside-down */ GLint row; for (row=0; rowrgba); destY--; (*swrast->Driver.WriteRGBASpan)(ctx, drawWidth, destX, destY, @@ -445,7 +445,7 @@ fast_draw_pixels(GLcontext *ctx, GLint x, GLint y, /* with zooming */ GLint row; for (row=0; rowrgba); span.x = destX; span.y = destY; @@ -645,37 +645,51 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y, if (ctx->Texture._EnabledCoordUnits) _swrast_span_default_texcoords(ctx, &span); - if (type == GL_UNSIGNED_SHORT && ctx->Visual.depthBits == 16 - && !bias_or_scale && !zoom && ctx->Visual.rgbMode - && width < MAX_WIDTH) { + if (type == GL_UNSIGNED_SHORT + && ctx->Visual.depthBits == 16 + && !bias_or_scale + && !zoom + && ctx->Visual.rgbMode + && width <= MAX_WIDTH) { /* Special case: directly write 16-bit depth values */ GLint row; span.x = x; span.y = y; span.end = width; for (row = 0; row < height; row++, span.y++) { - const GLushort *zptr = (const GLushort *) + const GLushort *zSrc = (const GLushort *) _mesa_image_address(&ctx->Unpack, pixels, width, height, GL_DEPTH_COMPONENT, type, 0, row, 0); GLint i; for (i = 0; i < width; i++) - span.array->z[i] = zptr[i]; + span.array->z[i] = zSrc[i]; _swrast_write_rgba_span(ctx, &span); } } - else if (type == GL_UNSIGNED_INT && ctx->Visual.depthBits == 32 - && !bias_or_scale && !zoom && ctx->Visual.rgbMode - && width < MAX_WIDTH) { - /* Special case: directly write 32-bit depth values */ + else if (type == GL_UNSIGNED_INT + && sizeof(GLdepth) == 4 + && !bias_or_scale + && !zoom + && ctx->Visual.rgbMode + && width <= MAX_WIDTH) { + /* Special case: shift 32-bit values down to ctx->Visual.depthBits */ + const GLint shift = 32 - ctx->Visual.depthBits; GLint row; span.x = x; span.y = y; span.end = width; for (row = 0; row < height; row++, span.y++) { - const GLuint *zptr = (const GLuint *) + const GLuint *zSrc = (const GLuint *) _mesa_image_address(&ctx->Unpack, pixels, width, height, GL_DEPTH_COMPONENT, type, 0, row, 0); - MEMCPY(span.array->z, zptr, width * sizeof(GLdepth)); + if (shift == 0) { + MEMCPY(span.array->z, zSrc, width * sizeof(GLdepth)); + } + else { + GLint col; + for (col = 0; col < width; col++) + span.array->z[col] = zSrc[col] >> shift; + } _swrast_write_rgba_span(ctx, &span); } } @@ -692,10 +706,10 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y, ASSERT(span.end <= MAX_WIDTH); for (row = 0; row < height; row++, spanY++) { GLfloat floatSpan[MAX_WIDTH]; - const GLvoid *src = _mesa_image_address(&ctx->Unpack, - pixels, width, height, - GL_DEPTH_COMPONENT, type, - 0, row, skipPixels); + const GLvoid *zSrc = _mesa_image_address(&ctx->Unpack, + pixels, width, height, + GL_DEPTH_COMPONENT, type, + 0, row, skipPixels); /* Set these for each row since the _swrast_write_* function may * change them while clipping. @@ -705,13 +719,13 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y, span.end = spanEnd; _mesa_unpack_depth_span(ctx, span.end, floatSpan, type, - src, &ctx->Unpack); + zSrc, &ctx->Unpack); /* clamp depth values to [0,1] and convert from floats to ints */ { - const GLfloat zs = ctx->DepthMaxF; + const GLfloat zScale = ctx->DepthMaxF; GLuint i; for (i = 0; i < span.end; i++) { - span.array->z[i] = (GLdepth) (floatSpan[i] * zs + 0.5F); + span.array->z[i] = (GLdepth) (floatSpan[i] * zScale); } } if (zoom) { -- cgit v1.2.3