Optimize Color32 to use packed bits for quick comparisons

This commit is contained in:
Wojtek Figat
2024-10-08 12:15:01 +02:00
parent 735b573705
commit 9694446fca

View File

@@ -80,12 +80,12 @@ public:
public: public:
bool operator==(const Color32& other) const bool operator==(const Color32& other) const
{ {
return R == other.R && G == other.G && B == other.B && A == other.A; return Raw == other.Raw;
} }
bool operator!=(const Color32& other) const bool operator!=(const Color32& other) const
{ {
return R != other.R || G != other.G || B != other.B || A != other.A; return Raw != other.Raw;
} }
Color32 operator+(const Color32& b) const Color32 operator+(const Color32& b) const
@@ -138,7 +138,7 @@ public:
// Returns true if color is fully transparent (all components are equal zero). // Returns true if color is fully transparent (all components are equal zero).
bool IsTransparent() const bool IsTransparent() const
{ {
return R + G + B + A == 0; return Raw == 0;
} }
// Returns true if color has opacity channel in use (different from 255). // Returns true if color has opacity channel in use (different from 255).
@@ -222,7 +222,7 @@ namespace Math
{ {
FORCE_INLINE static bool NearEqual(const Color32& a, const Color32& b) FORCE_INLINE static bool NearEqual(const Color32& a, const Color32& b)
{ {
return a == b; return a.Raw == b.Raw;
} }
} }