diff options
author | Nicky <sl.nicky.ml@googlemail.com> | 2016-04-22 14:58:25 +0200 |
---|---|---|
committer | Nicky <sl.nicky.ml@googlemail.com> | 2016-04-22 14:58:25 +0200 |
commit | e8aa2dd71fff7a39f2b03039b23afa8bdf804fcb (patch) | |
tree | f97958ed6d53fe9ba6c6eeab5583eb2f733f92c2 /indra/llmath | |
parent | 30dcad4b95d355e07f0807360f2e5f65b0460fe3 (diff) |
x64: Do not use a union of LLColor4U. Especially having the two pointer in there will blow up the struct to at least 8 byte, which will break VBO packing as this class needs to be 4 byte in size.
(transplanted from 847df86d6b5daa69dcfc428df18876a9c1e8bef6)
Diffstat (limited to 'indra/llmath')
-rw-r--r-- | indra/llmath/v4coloru.h | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/indra/llmath/v4coloru.h b/indra/llmath/v4coloru.h index fddad34978..31ae3e3c1a 100644 --- a/indra/llmath/v4coloru.h +++ b/indra/llmath/v4coloru.h @@ -47,14 +47,7 @@ class LLColor4U { public: - union - { - U8 mV[LENGTHOFCOLOR4U]; - U32 mAll; - LLColor4* mSources; - LLColor4U* mSourcesU; - }; - + U8 mV[LENGTHOFCOLOR4U]; LLColor4U(); // Initializes LLColor4U to (0, 0, 0, 1) LLColor4U(U8 r, U8 g, U8 b); // Initializes LLColor4U to (r, g, b, 1) @@ -132,6 +125,9 @@ public: return LLColor4(*this); } + U32 asRGBA() const; + void fromRGBA( U32 aVal ); + static LLColor4U white; static LLColor4U black; static LLColor4U red; @@ -565,6 +561,36 @@ void LLColor4U::setVecScaleClamp(const LLColor3& color) mV[3] = 255; } +inline U32 LLColor4U::asRGBA() const +{ + U32 nRet( 0 ); + + // Little endian: values are swapped in memory. The original code access the array like a U32, so we need to swap here + + nRet |= mV[ 3 ]; + nRet <<= 8; + nRet |= mV[ 2 ]; + nRet <<= 8; + nRet |= mV[ 1 ]; + nRet <<= 8; + nRet |= mV[ 0 ]; + + return nRet; +} + +inline void LLColor4U::fromRGBA( U32 aVal ) +{ + // Little endian: values are swapped in memory. The original code access the array like a U32, so we need to swap here + + mV[ 0 ] = aVal & 0xFF; + aVal >>= 8; + mV[ 1 ] = aVal & 0xFF; + aVal >>= 8; + mV[ 2 ] = aVal & 0xFF; + aVal >>= 8; + mV[ 3 ] = aVal & 0xFF; +} + #endif |