Updated patch as I was told that "an X component is supposed to result in 1.0".
On Thu, Apr 14, 2011 at 5:10 PM, Pierre-Eric Pelloux-Prayer <pell...@gmail.com> wrote: > Another similar patch proposal : handling of > PIPE_FORMAT_B8G8R8X8_UNORM format in st_fast_readpixels. > > If I'm correct the 'X' of B8G8R8X8 in stands for 'whatever value' so I > think we could use the same code path for both > PIPE_FORMAT_B8G8R8A8_UNORM and PIPE_FORMAT_B8G8R8X8_UNORM. > > (Blender uses glReadPixels + PIPE_FORMAT_B8G8R8X8_UNORM when right > mouse clicking in Edit-Mode) > > > On Thu, Apr 14, 2011 at 3:52 PM, Brian Paul <bri...@vmware.com> wrote: >> On 04/13/2011 05:29 AM, Pierre-Eric wrote: >>> >>> As Lightsmark seems to make use of glReadPixels with {GL_RGBA + >>> GL_UNSIGNED_INT_8_8_8_8} parameters, >>> I built a short patch to allow 'st_fast_readpixels' to handle this >>> combination. >>> >>> It's been tested using piglit's pixelFormat test + a custom app. >>> >>> Best regards, >>> --Pierre-Eric >> >> Thanks. I'll commit it soon. >> >> -Brian >> >> >
From 803c59d0cbaf6cb30b08947f07e8d9aaed6c1aad Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer <pell...@gmail.com> Date: Thu, 14 Apr 2011 18:17:28 +0200 Subject: [PATCH] Add handling for 'PIPE_FORMAT_B8G8R8X8_UNORM' in st_fast_readpixels --- src/mesa/state_tracker/st_cb_readpixels.c | 30 +++++++++++++++++++--------- 1 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index fdb7770..1b57e9b 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -198,6 +198,7 @@ st_fast_readpixels(struct gl_context *ctx, struct st_renderbuffer *strb, const struct gl_pixelstore_attrib *pack, GLvoid *dest) { + GLubyte alphaORoperand; enum combination { A8R8G8B8_UNORM_TO_RGBA_UBYTE, A8R8G8B8_UNORM_TO_RGB_UBYTE, @@ -208,20 +209,24 @@ st_fast_readpixels(struct gl_context *ctx, struct st_renderbuffer *strb, if (ctx->_ImageTransferState) return GL_FALSE; - if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM && - format == GL_RGBA && type == GL_UNSIGNED_BYTE) { + if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM) { + alphaORoperand = 0; + } else if (strb->format == PIPE_FORMAT_B8G8R8X8_UNORM ) { + alphaORoperand = 0xff; + } else { + return GL_FALSE; + } + + if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) { combo = A8R8G8B8_UNORM_TO_RGBA_UBYTE; } - else if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM && - format == GL_RGB && type == GL_UNSIGNED_BYTE) { + else if (format == GL_RGB && type == GL_UNSIGNED_BYTE) { combo = A8R8G8B8_UNORM_TO_RGB_UBYTE; } - else if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM && - format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV) { + else if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV) { combo = A8R8G8B8_UNORM_TO_BGRA_UINT; } - else if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM && - format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8) { + else if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8) { combo = A8R8G8B8_UNORM_TO_RGBA_UINT; } else { @@ -283,7 +288,7 @@ st_fast_readpixels(struct gl_context *ctx, struct st_renderbuffer *strb, dst[col*4+0] = (pixel >> 16) & 0xff; dst[col*4+1] = (pixel >> 8) & 0xff; dst[col*4+2] = (pixel >> 0) & 0xff; - dst[col*4+3] = (pixel >> 24) & 0xff; + dst[col*4+3] = ((pixel >> 24) & 0xff) | alphaORoperand; } dst += dstStride; y += dy; @@ -306,6 +311,11 @@ st_fast_readpixels(struct gl_context *ctx, struct st_renderbuffer *strb, for (row = 0; row < height; row++) { const GLubyte *src = map + y * trans->stride; memcpy(dst, src, 4 * width); + if (alphaORoperand) { + for (col = 0; col < width; col++) { + dst[col*4+3] |= alphaORoperand; + } + } dst += dstStride; y += dy; } @@ -315,7 +325,7 @@ st_fast_readpixels(struct gl_context *ctx, struct st_renderbuffer *strb, const GLubyte *src = map + y * trans->stride; for (col = 0; col < width; col++) { GLuint pixel = ((GLuint *) src)[col]; - dst[col*4+0] = (pixel >> 24) & 0xff; + dst[col*4+0] = ((pixel >> 24) & 0xff) | alphaORoperand; dst[col*4+1] = (pixel >> 0) & 0xff; dst[col*4+2] = (pixel >> 8) & 0xff; dst[col*4+3] = (pixel >> 16) & 0xff; -- 1.7.4.1
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev