The glean exactRGBA test has always failed with Mesa (with sw rendering at least). The failures come from a sequence of int->float->int conversions which don't meet the GL spec.

In particular, when glColor4us() or glColor4ui() are used to set the drawing color, the N-bit integer frame buffer values should match the upper N bits of the GLushort or GLuint value originally passed in.

Because of int->float->int conversions it's a little tricky to maintain the N-bit identity requirement.

The attached patch fixes the exactRGBA failures. I haven't seen any regressions but some additional eyes should take a look.

There are two parts:

1. Convert float->ubyte with floor(x*255.999) instead of iround(x*255.0)

2. Convert uint->float with floor((u >> 16) / 65535.0) instead of floor(u / 4294967295.0) This effectively converts the GLuint to a GLushort. This isn't ideal but I think it's "good enough" until we find otherwise.

-Brian
diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h
index 7b61e22..70fde6b 100644
--- a/src/mesa/main/imports.h
+++ b/src/mesa/main/imports.h
@@ -423,21 +423,21 @@ _mesa_is_pow_two(int x)
            else if (__tmp.i >= IEEE_0996)                              \
               UB = (GLubyte) 255;                                      \
            else {                                                      \
-              __tmp.f = __tmp.f * (255.0F/256.0F) + 32768.0F;          \
-              UB = (GLubyte) __tmp.i;                                  \
+              __tmp.f = __tmp.f * 255.999F + 256.0F;                   \
+              UB = (GLubyte) ((__tmp.i & 0x7fffff) >> 15);             \
            }                                                           \
         } while (0)
 #define CLAMPED_FLOAT_TO_UBYTE(UB, F)                                  \
         do {                                                           \
            fi_type __tmp;                                              \
-           __tmp.f = (F) * (255.0F/256.0F) + 32768.0F;                 \
-           UB = (GLubyte) __tmp.i;                                     \
+           __tmp.f = (F) * 255.999F + 256.0F;                          \
+           UB = (GLubyte) ((__tmp.i & 0x7fffff) >> 15);                        
\
         } while (0)
 #else
 #define UNCLAMPED_FLOAT_TO_UBYTE(ub, f) \
-       ub = ((GLubyte) IROUND(CLAMP((f), 0.0F, 1.0F) * 255.0F))
+       ub = ((GLubyte) IFLOOR(CLAMP((f), 0.0F, 1.0F) * 255.999F))
 #define CLAMPED_FLOAT_TO_UBYTE(ub, f) \
-       ub = ((GLubyte) IROUND((f) * 255.0F))
+       ub = ((GLubyte) IFLOOR((f) * 255.999F))
 #endif
 
 
diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h
index 4ca7957..90013e7 100644
--- a/src/mesa/main/macros.h
+++ b/src/mesa/main/macros.h
@@ -83,7 +83,7 @@ extern GLfloat _mesa_ubyte_to_float_color_tab[256];
 
 
 /** Convert GLuint in [0,4294967295] to GLfloat in [0.0,1.0] */
-#define UINT_TO_FLOAT(U)    ((GLfloat) (U) * (1.0F / 4294967295.0))
+#define UINT_TO_FLOAT(U)    ((GLfloat) ((U) >> 16) * (1.0F / 65535.0F))
 
 /** Convert GLfloat in [0.0,1.0] to GLuint in [0,4294967295] */
 #define FLOAT_TO_UINT(X)    ((GLuint) ((X) * 4294967295.0))
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to