Mesa (master): swrast: When reading from a 0-bits r,g,b channel, return 0 not 1.

Eric Anholt anholt at kemper.freedesktop.org
Wed Jun 9 16:00:20 PDT 2010


Module: Mesa
Branch: master
Commit: ceba688cb54016a9f6ff70761b2c459698bfd7f0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ceba688cb54016a9f6ff70761b2c459698bfd7f0

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jun 10 00:15:48 2010 -0700

swrast: When reading from a 0-bits r,g,b channel, return 0 not 1.

It looks like we were reading a fractional value, multiplying by an
enormous negative value, then stuffing that value into a bitfield
assuming it was already clamped.  This becomes relevant for GL_ALPHA
or R/RG FBOs.

---

 src/mesa/swrast/s_readpix.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/mesa/swrast/s_readpix.c b/src/mesa/swrast/s_readpix.c
index 368311e..6ad9ace 100644
--- a/src/mesa/swrast/s_readpix.c
+++ b/src/mesa/swrast/s_readpix.c
@@ -265,10 +265,18 @@ adjust_colors(const struct gl_framebuffer *fb, GLuint n, GLfloat rgba[][4])
    const GLuint rShift = 8 - fb->Visual.redBits;
    const GLuint gShift = 8 - fb->Visual.greenBits;
    const GLuint bShift = 8 - fb->Visual.blueBits;
-   const GLfloat rScale = 1.0F / (GLfloat) ((1 << fb->Visual.redBits  ) - 1);
-   const GLfloat gScale = 1.0F / (GLfloat) ((1 << fb->Visual.greenBits) - 1);
-   const GLfloat bScale = 1.0F / (GLfloat) ((1 << fb->Visual.blueBits ) - 1);
+   GLfloat rScale = 1.0F / (GLfloat) ((1 << fb->Visual.redBits  ) - 1);
+   GLfloat gScale = 1.0F / (GLfloat) ((1 << fb->Visual.greenBits) - 1);
+   GLfloat bScale = 1.0F / (GLfloat) ((1 << fb->Visual.blueBits ) - 1);
    GLuint i;
+
+   if (fb->Visual.redBits == 0)
+      rScale = 0;
+   if (fb->Visual.greenBits == 0)
+      gScale = 0;
+   if (fb->Visual.blueBits == 0)
+      bScale = 0;
+
    for (i = 0; i < n; i++) {
       GLint r, g, b;
       /* convert float back to ubyte */



More information about the mesa-commit mailing list