diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c index 4918549..3dd3384 100644 --- a/src/mesa/main/readpix.c +++ b/src/mesa/main/readpix.c @@ -220,9 +220,16 @@ fast_read_rgba_pixels_memcpy( struct gl_context *ctx, struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer; GLubyte *dst, *map; int dstStride, stride, j, texelBytes; + GLboolean swizzle_rb = GL_FALSE; - if (!_mesa_format_matches_format_and_type(rb->Format, format, type, - ctx->Pack.SwapBytes)) + if (rb->Format == MESA_FORMAT_RGBA8888_REV && + format == GL_BGRA && + type == GL_UNSIGNED_INT_8_8_8_8_REV && + !ctx->Pack.SwapBytes) { + swizzle_rb = GL_TRUE; + } + else if (!_mesa_format_matches_format_and_type(rb->Format, format, type, + ctx->Pack.SwapBytes)) return GL_FALSE; /* If the format is unsigned normalized then we can ignore clamping @@ -247,10 +254,28 @@ fast_read_rgba_pixels_memcpy( struct gl_context *ctx, } texelBytes = _mesa_get_format_bytes(rb->Format); - for (j = 0; j < height; j++) { - memcpy(dst, map, width * texelBytes); - dst += dstStride; - map += stride; + + if (swizzle_rb) { + /* swap R/B */ + for (j = 0; j < height; j++) { + int i; + for (i = 0; i < width; i++) { + dst[i*4+0] = map[i*4+2]; + dst[i*4+1] = map[i*4+1]; + dst[i*4+2] = map[i*4+0]; + dst[i*4+3] = map[i*4+3]; + } + dst += dstStride; + map += stride; + } + + } else { + /* just memcpy */ + for (j = 0; j < height; j++) { + memcpy(dst, map, width * texelBytes); + dst += dstStride; + map += stride; + } } ctx->Driver.UnmapRenderbuffer(ctx, rb);