Mesa (gallium-0.2): mesa: clamp luminance if needed.

Alan Hourihane alanh at kemper.freedesktop.org
Thu Nov 20 13:44:23 UTC 2008


Module: Mesa
Branch: gallium-0.2
Commit: 2f9ceb158afffe5ea390b909261988267e663e36
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2f9ceb158afffe5ea390b909261988267e663e36

Author: Xiang, Haihao <haihao.xiang at intel.com>
Date:   Wed Nov 19 11:22:35 2008 +0800

mesa: clamp luminance if needed.

This fixes glReadPixels(GL_LUMINANCE, GL_FLOAT)/glGetTexImage(GL_LUMINANCE, GL_FLOAT) issue
on fixed-point color buffers.

---

 src/mesa/main/image.c    |    2 +-
 src/mesa/main/texstore.c |   10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index 1a6e864..4551b4a 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -1689,7 +1689,7 @@ _mesa_pack_rgba_span_float(GLcontext *ctx, GLuint n, GLfloat rgba[][4],
 
    if (dstFormat == GL_LUMINANCE || dstFormat == GL_LUMINANCE_ALPHA) {
       /* compute luminance values */
-      if (dstType != GL_FLOAT || ctx->Color.ClampReadColor == GL_TRUE) {
+      if (transferOps & IMAGE_CLAMP_BIT) {
          for (i = 0; i < n; i++) {
             GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
             luminance[i] = CLAMP(sum, 0.0F, 1.0F);
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index abeed3b..4b2b129 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -3719,6 +3719,14 @@ _mesa_get_teximage(GLcontext *ctx, GLenum target, GLint level,
                /* general case:  convert row to RGBA format */
                GLfloat rgba[MAX_WIDTH][4];
                GLint col;
+               GLbitfield transferOps = 0x0;
+
+               if (type == GL_FLOAT && 
+                   ((ctx->Color.ClampReadColor == GL_TRUE) ||
+                    (ctx->Color.ClampReadColor == GL_FIXED_ONLY_ARB &&
+                     texImage->TexFormat->DataType != GL_FLOAT)))
+                  transferOps |= IMAGE_CLAMP_BIT;
+
                for (col = 0; col < width; col++) {
                   (*texImage->FetchTexelf)(texImage, col, row, img, rgba[col]);
                   if (texImage->TexFormat->BaseFormat == GL_ALPHA) {
@@ -3743,7 +3751,7 @@ _mesa_get_teximage(GLcontext *ctx, GLenum target, GLint level,
                }
                _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
                                           format, type, dest,
-                                          &ctx->Pack, 0x0 /*image xfer ops*/);
+                                          &ctx->Pack, transferOps /*image xfer ops*/);
             } /* format */
          } /* row */
       } /* img */




More information about the mesa-commit mailing list