From a8ca786ba69f6af0120a24f473b2ae7e6a41495d Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 30 Sep 2011 08:15:30 -0600 Subject: [PATCH] meta: fix GetTexImage() for luminance, l/a, intensity formats The GL spec says that luminance values are returned as (l, 0, 0, 1), L/A values as (l, 0, 0, a) and intensity values as (i, 0, 0, 1). Use the pixel transfer scale controls to implement that. This fixes a few failures in the new piglit getteximage-formats test when getting a compressed L or L/A image. --- src/mesa/drivers/common/meta.c | 24 ++++++++++++++++++++++-- src/mesa/main/pixel.c | 2 +- src/mesa/main/pixel.h | 9 +++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index 02913685e66..4d645e20083 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -49,6 +49,7 @@ #include "main/macros.h" #include "main/matrix.h" #include "main/mipmap.h" +#include "main/pixel.h" #include "main/pbo.h" #include "main/polygon.h" #include "main/readpix.h" @@ -3235,8 +3236,27 @@ decompress_texture_image(struct gl_context *ctx, } /* read pixels from renderbuffer */ - ctx->Pack.RowLength = destRowLength; - _mesa_ReadPixels(0, 0, width, height, destFormat, destType, dest); + { + GLenum baseTexFormat = texImage->_BaseFormat; + + /* The pixel transfer state will be set to default values at this point + * (see MESA_META_PIXEL_TRANSFER) so pixel transfer ops are effectively + * turned off (as required by glGetTexImage) but we need to handle some + * special cases. In particular, single-channel texture values are + * returned as red and two-channel texture values are returned as + * red/alpha. + */ + if (baseTexFormat == GL_LUMINANCE || + baseTexFormat == GL_LUMINANCE_ALPHA || + baseTexFormat == GL_INTENSITY) { + /* Green and blue must be zero */ + _mesa_PixelTransferf(GL_GREEN_SCALE, 0.0f); + _mesa_PixelTransferf(GL_BLUE_SCALE, 0.0f); + } + + ctx->Pack.RowLength = destRowLength; + _mesa_ReadPixels(0, 0, width, height, destFormat, destType, dest); + } /* disable texture unit */ _mesa_set_enable(ctx, target, GL_FALSE); diff --git a/src/mesa/main/pixel.c b/src/mesa/main/pixel.c index c87f5e0e9f7..e73c5a49a4a 100644 --- a/src/mesa/main/pixel.c +++ b/src/mesa/main/pixel.c @@ -506,7 +506,7 @@ _mesa_GetPixelMapusv( GLenum map, GLushort *values ) * Implements glPixelTransfer[fi] whether called immediately or from a * display list. */ -static void GLAPIENTRY +void GLAPIENTRY _mesa_PixelTransferf( GLenum pname, GLfloat param ) { GET_CURRENT_CONTEXT(ctx); diff --git a/src/mesa/main/pixel.h b/src/mesa/main/pixel.h index 6f04eb62724..558b106d78c 100644 --- a/src/mesa/main/pixel.h +++ b/src/mesa/main/pixel.h @@ -43,6 +43,9 @@ struct gl_context; #if FEATURE_pixel_transfer +extern void GLAPIENTRY +_mesa_PixelTransferf(GLenum pname, GLfloat param); + extern void _mesa_update_pixel( struct gl_context *ctx, GLuint newstate ); @@ -51,6 +54,12 @@ _mesa_init_pixel_dispatch( struct _glapi_table * disp ); #else /* FEATURE_pixel_transfer */ +static inline void GLAPIENTRY +_mesa_PixelTransferf(GLenum pname, GLfloat param) +{ +} + + static INLINE void _mesa_update_pixel(struct gl_context *ctx, GLuint newstate) { -- 2.30.2