diff options
Diffstat (limited to 'src/mesa/state_tracker/st_cb_readpixels.c')
-rw-r--r-- | src/mesa/state_tracker/st_cb_readpixels.c | 55 |
1 files changed, 45 insertions, 10 deletions
diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index f8da2a4..2a63799 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -198,27 +198,39 @@ 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, - A8R8G8B8_UNORM_TO_BGRA_UINT + A8R8G8B8_UNORM_TO_BGRA_UINT, + A8R8G8B8_UNORM_TO_RGBA_UINT } combo; 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 (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8) { + combo = A8R8G8B8_UNORM_TO_RGBA_UINT; + } else { return GL_FALSE; } @@ -278,7 +290,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; @@ -301,6 +313,26 @@ 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) { + assert(alphaORoperand == 0xff); + for (col = 0; col < width; col++) { + dst[col*4+3] = 0xff; + } + } + dst += dstStride; + y += dy; + } + break; + case A8R8G8B8_UNORM_TO_RGBA_UINT: + for (row = 0; row < height; row++) { + 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) | alphaORoperand; + dst[col*4+1] = (pixel >> 0) & 0xff; + dst[col*4+2] = (pixel >> 8) & 0xff; + dst[col*4+3] = (pixel >> 16) & 0xff; + } dst += dstStride; y += dy; } @@ -331,7 +363,7 @@ st_readpixels(struct gl_context *ctx, GLint x, GLint y, GLsizei width, GLsizei h struct st_context *st = st_context(ctx); struct pipe_context *pipe = st->pipe; GLfloat (*temp)[4]; - const GLbitfield transferOps = ctx->_ImageTransferState; + GLbitfield transferOps = ctx->_ImageTransferState; GLsizei i, j; GLint yStep, dfStride; GLfloat *df; @@ -391,7 +423,10 @@ st_readpixels(struct gl_context *ctx, GLint x, GLint y, GLsizei width, GLsizei h return; } - if (format == GL_RGBA && type == GL_FLOAT) { + if(ctx->Color._ClampReadColor) + transferOps |= IMAGE_CLAMP_BIT; + + if (format == GL_RGBA && type == GL_FLOAT && !transferOps) { /* write tile(row) directly into user's buffer */ df = (GLfloat *) _mesa_image_address2d(&clippedPacking, dest, width, height, format, type, 0, 0); |