r300g: implement MSAA
[mesa.git] / src / gallium / auxiliary / util / u_format_r11g11b10f.h
index 000a5c25bfca71c8bf3e4421b40f014cb44c55f7..b883b318e03601f5cbfa68fb6644445f5a42167d 100644 (file)
@@ -60,13 +60,23 @@ static INLINE unsigned f32_to_uf11(float val)
    int exponent = ((f32.ui >> 23) & 0xff) - 127;
    int mantissa = f32.ui & 0x007fffff;
 
-   if (sign) return 0;
-
    if (exponent == 128) { /* Infinity or NaN */
+      /* From the GL_EXT_packed_float spec:
+       *
+       *     "Additionally: negative infinity is converted to zero; positive
+       *      infinity is converted to positive infinity; and both positive and
+       *      negative NaN are converted to positive NaN."
+       */
       uf11 = UF11_MAX_EXPONENT;
-      if (mantissa) uf11 |= (mantissa & UF11_MANTISSA_BITS);
-   }
-   else if (val > 65024.0f) {
+      if (mantissa) {
+        uf11 |= 1; /* NaN */
+      } else {
+        if (sign)
+           uf11 = 0; /* 0.0 */
+      }
+   } else if (sign) {
+      return 0;
+   } else if (val > 65024.0f) {
       /* From the GL_EXT_packed_float spec:
        *
        *     "Likewise, finite positive values greater than 65024 (the maximum
@@ -109,12 +119,12 @@ static INLINE float uf11_to_f32(uint16_t val)
       float scale, decimal;
       exponent -= 15;
       if (exponent < 0) {
-         scale = 1.0 / (1 << -exponent);
+         scale = 1.0f / (1 << -exponent);
       }
       else {
-         scale = 1 << exponent;
+         scale = (float) (1 << exponent);
       }
-      decimal = 1.0 + (float) mantissa / 64;
+      decimal = 1.0f + (float) mantissa / 64;
       f32.f = scale * decimal;
    }
 
@@ -136,13 +146,23 @@ static INLINE unsigned f32_to_uf10(float val)
    int exponent = ((f32.ui >> 23) & 0xff) - 127;
    int mantissa = f32.ui & 0x007fffff;
 
-   if (sign) return 0;
-
-   if (exponent == 128) { /* Infinity or NaN */
+   if (exponent == 128) {
+      /* From the GL_EXT_packed_float spec:
+       *
+       *     "Additionally: negative infinity is converted to zero; positive
+       *      infinity is converted to positive infinity; and both positive and
+       *      negative NaN are converted to positive NaN."
+       */
       uf10 = UF10_MAX_EXPONENT;
-      if (mantissa) uf10 |= (mantissa & UF10_MANTISSA_BITS);
-   }
-   else if (val > 64512.0f) { /* Overflow - flush to Infinity */
+      if (mantissa) {
+        uf10 |= 1; /* NaN */
+      } else {
+        if (sign)
+           uf10 = 0; /* 0.0 */
+      }
+   } else if (sign) {
+      return 0;
+   } else if (val > 64512.0f) { /* Overflow - flush to Infinity */
       /* From the GL_EXT_packed_float spec:
        *
        *     "Likewise, finite positive values greater than 64512 (the maximum
@@ -185,12 +205,12 @@ static INLINE float uf10_to_f32(uint16_t val)
       float scale, decimal;
       exponent -= 15;
       if (exponent < 0) {
-         scale = 1.0 / (1 << -exponent);
+         scale = 1.0f / (1 << -exponent);
       }
       else {
-         scale = 1 << exponent;
+         scale = (float) (1 << exponent);
       }
-      decimal = 1.0 + (float) mantissa / 32;
+      decimal = 1.0f + (float) mantissa / 32;
       f32.f = scale * decimal;
    }