From d4abbe37d24b15bc002033ce15bb942a39133de2 Mon Sep 17 00:00:00 2001 From: badlogicgames Date: Sun, 28 Nov 2010 14:27:23 +0000 Subject: [PATCH] [fixed] Color.toFloatBits() methods. Will half the precision of the alpha channel of 32-bit rgba colors. Nothing i can do about it. Problem is that Java only has a single canonical NaN value. Using Float.intBitsToFloat() will convert any signaling NaN to that canonical value, transforming colors like 0xfeaaeb3c to 0xfeeaeb3c. The fix just masks the 32-bit int via 0xfeffffff before it is passed ot Color.toFloatBits() effectively making it impossible to return canonical NaNs. This of course means that the least significant bit of the alpha component is always 0, so you only have 128 alpha values really :p. Darn Java. Darn FPUs. --- gdx/src/com/badlogic/gdx/graphics/Color.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gdx/src/com/badlogic/gdx/graphics/Color.java b/gdx/src/com/badlogic/gdx/graphics/Color.java index ece817354..29a606191 100644 --- a/gdx/src/com/badlogic/gdx/graphics/Color.java +++ b/gdx/src/com/badlogic/gdx/graphics/Color.java @@ -218,7 +218,7 @@ public class Color { */ public static float toFloatBits(int r, int g, int b, int a) { int color = (a << 24) | (b << 16) | (g << 8) | r; - float floatColor = Float.intBitsToFloat(color); + float floatColor = Float.intBitsToFloat(color & 0xfeffffff); return floatColor; } @@ -250,7 +250,7 @@ public class Color { public float toFloatBits() { int color = ((int) (255 * a) << 24) | ((int) (255 * b) << 16) | ((int) (255 * g) << 8) | ((int) (255 * r)); - return Float.intBitsToFloat(color); + return Float.intBitsToFloat(color & 0xfeffffff); } /** @@ -273,6 +273,6 @@ public class Color { public static float toFloatBits(float r, float g, float b, float a) { int color = ((int) (255 * a) << 24) | ((int) (255 * b) << 16) | ((int) (255 * g) << 8) | ((int) (255 * r)); - return Float.intBitsToFloat(color); + return Float.intBitsToFloat(color & 0xfeffffff); } } -- 2.11.0