[Mesa-dev] [PATCH 1/4] meta: fix GetTexImage() for compressed luminance, l/a, intensity formats
Brian Paul
brian.e.paul at gmail.com
Thu Sep 29 13:24:45 PDT 2011
From: Brian Paul <brianp at vmware.com>
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 b6e80d7..b47eb2c 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 = _mesa_get_format_base_format(texImage->TexFormat);
+
+ /* 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 c87f5e0..e73c5a4 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 6f04eb6..558b106 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)
{
--
1.7.3.4
More information about the mesa-dev
mailing list