From a8a299c2e33e41efd47190abd455fe888c65a9cc Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 18 Mar 2014 22:56:27 -0700 Subject: [PATCH] Fix ToRGB/ToRGBA possible accuracy loss. It was always like this, but not used as much before. Shifts are fast and it eneds to sum anyway, there should not be any benefit to multiplying as floats, and it will probably lose accuracy. --- GPU/Math3D.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/GPU/Math3D.h b/GPU/Math3D.h index 2b1a5c575d..aca12ddb78 100644 --- a/GPU/Math3D.h +++ b/GPU/Math3D.h @@ -927,9 +927,9 @@ inline unsigned int Vec3::ToRGB() const __m128i c16 = _mm_packs_epi32(c, c); return _mm_cvtsi128_si32(_mm_packus_epi16(c16, c16)) & 0x00FFFFFF; #else - return ((unsigned int)(r()*255.f)) + - ((unsigned int)(g()*255.f*256.f)) + - ((unsigned int)(b()*255.f*256.f*256.f)); + return ((unsigned int)(r()*255.f) << 0) | + ((unsigned int)(g()*255.f) << 8) | + ((unsigned int)(b()*255.f) << 16); #endif } @@ -981,10 +981,10 @@ inline unsigned int Vec4::ToRGBA() const __m128i c16 = _mm_packs_epi32(c, c); return _mm_cvtsi128_si32(_mm_packus_epi16(c16, c16)); #else - return ((unsigned int)(r()*255.f)) + - ((unsigned int)(g()*255.f*256.f)) + - ((unsigned int)(b()*255.f*256.f*256.f)) + - ((unsigned int)(a()*255.f*256.f*256.f*256.f)); + return ((unsigned int)(r()*255.f) << 0) | + ((unsigned int)(g()*255.f) << 8) | + ((unsigned int)(b()*255.f) << 16) | + ((unsigned int)(a()*255.f) << 24); #endif }