From 17956988dd179268e1c168f48536a77c3ecc58fb Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Thu, 30 Apr 2015 23:31:59 -0700 Subject: [PATCH] * Fix CVector3f SSE4.1 * Add CColor --- CColor.hpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ CVector3f.hpp | 2 +- MathLib.hpp | 1 + MathLib.pri | 1 + 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 CColor.hpp diff --git a/CColor.hpp b/CColor.hpp new file mode 100644 index 0000000..cec8445 --- /dev/null +++ b/CColor.hpp @@ -0,0 +1,70 @@ +#ifndef CCOLOR_HPP +#define CCOLOR_HPP + +#include "MathLib.hpp" +#include + +class CColor +{ +public: + ZE_DECLARE_ALIGNED_ALLOCATOR(); + + CColor() : r(1.0f), g(1.0f), b(1.0f), a(1.0f) {} + CColor(float r, float g, float b, float a = 1.0f) + : r(r), g(g), b(b), a(a) + { + } + + CColor(Athena::io::IStreamReader& reader) {readRGBA(reader);} + + inline void readRGBA(Athena::io::IStreamReader& reader) + { + r = reader.readFloat(); + g = reader.readFloat(); + b = reader.readFloat(); + a = reader.readFloat(); + } + + inline void readBGRA(Athena::io::IStreamReader& reader) + { + b = reader.readFloat(); + g = reader.readFloat(); + r = reader.readFloat(); + a = reader.readFloat(); + } + + inline float operator[](const int& idx) { return (&r)[idx]; } + + union + { + struct + { + float r, g, b, a; + }; +#if __SSE__ + __m128 mVec128; +#endif + }; + + void fromRGBA32(unsigned int rgba) + { + union + { + struct + { + unsigned char r, g, b, a; + }; + unsigned int rgba; + } tmp = + { + .rgba = rgba + }; + + r = tmp.r / 255.f; + g = tmp.g / 255.f; + b = tmp.b / 255.f; + a = tmp.a / 255.f; + } +}; + +#endif // CCOLOR_HPP diff --git a/CVector3f.hpp b/CVector3f.hpp index df3497a..a12fd81 100644 --- a/CVector3f.hpp +++ b/CVector3f.hpp @@ -185,7 +185,7 @@ public: { #if __SSE4_1__ TVectorUnion result; - result.mVec128 = _mm_dp_ps(mVec128, rhs.mVec128, 0x71); + result.mVec128 = _mm_dp_ps(mVec128, mVec128, 0x71); return result.v[0]; #elif __SSE__ TVectorUnion result; diff --git a/MathLib.hpp b/MathLib.hpp index c7500cb..f1020f1 100644 --- a/MathLib.hpp +++ b/MathLib.hpp @@ -9,6 +9,7 @@ #include "CVector3d.hpp" #include "CVector3f.hpp" #include "CPlane.hpp" +#include "CColor.hpp" #include "Global.hpp" #include "Math.hpp" diff --git a/MathLib.pri b/MathLib.pri index eef3ef8..588e95d 100644 --- a/MathLib.pri +++ b/MathLib.pri @@ -18,6 +18,7 @@ HEADERS += \ $$PWD/CAxisAngle.hpp \ $$PWD/CPlane.hpp \ $$PWD/CTransform.hpp \ + $$PWD/CColor.hpp \ $$PWD/Global.hpp \ $$PWD/MathLib.hpp