From 9aa5e5829e58fddea5de453a8ec522002456ba43 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Sun, 26 Feb 2012 01:33:40 +0000 Subject: [PATCH] readpix: Don't disable fast path for normalized types Mesa has a fast path for the generic fallback when using glReadPixels for RGBA data which uses memcpy. However it was really difficult to hit this case because it would not be used if any transferOps are enabled. Any type apart from floating point or non-normalized integer types (so any of the common types) would force enabling clamping so the fast path could not be used. This patch makes it ignore clamping when determining whether to use the fast path if the data type of the buffer is an unsigned normalized type because in that case clamping will not have any effect anyway. This patch additionally makes it explicitly ignore luminance types because in that case the conversion to and from RGB does not end up with exactly the same values. https://bugs.freedesktop.org/show_bug.cgi?id=46631 --- src/mesa/main/readpix.c | 32 +++++++++++++++++++++++++------- 1 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c index 0f429ab..dd438f9 100644 --- a/src/mesa/main/readpix.c +++ b/src/mesa/main/readpix.c @@ -225,6 +225,26 @@ fast_read_rgba_pixels_memcpy( struct gl_context *ctx, ctx->Pack.SwapBytes)) return GL_FALSE; + /* If the format is unsigned normalized then we can ignore clamping + because the values are already in the range 0->1 so it won't + have any effect anyway */ + if (_mesa_get_format_datatype (rb->Format) == GL_UNSIGNED_NORMALIZED) + transferOps &= ~IMAGE_CLAMP_BIT; + + if (transferOps) + return GL_FALSE; + + /* This can't handle luminance buffers because it would effectively + need to multiply the luminance values by 3. The spec says it + should convert to RGB by setting all of the components to the + luminance value and then convert back to luminance by adding all + of the components together. */ + switch (_mesa_get_format_base_format(rb->Format)) { + case GL_LUMINANCE: + case GL_LUMINANCE_ALPHA: + return GL_FALSE; + } + dstStride = _mesa_image_row_stride(packing, width, format, type); dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height, format, type, 0, 0); @@ -320,13 +340,11 @@ read_rgba_pixels( struct gl_context *ctx, transferOps |= IMAGE_CLAMP_BIT; } - if (!transferOps) { - /* Try the optimized paths first. */ - if (fast_read_rgba_pixels_memcpy(ctx, x, y, width, height, - format, type, pixels, packing, - transferOps)) { - return; - } + /* Try the optimized paths first. */ + if (fast_read_rgba_pixels_memcpy(ctx, x, y, width, height, + format, type, pixels, packing, + transferOps)) { + return; } slow_read_rgba_pixels(ctx, x, y, width, height, -- 1.7.3.16.g9464b