diff --git a/include/CColor.hpp b/include/CColor.hpp index 8d98c06..4892afb 100644 --- a/include/CColor.hpp +++ b/include/CColor.hpp @@ -1,7 +1,8 @@ #ifndef CCOLOR_HPP #define CCOLOR_HPP -#include "MathLib.hpp" +#include "Math.hpp" +#include "TVectorUnion.hpp" #include #if BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ @@ -25,6 +26,8 @@ typedef union typedef uint8_t Comp8; typedef uint32_t Comp32; +class CVector4f; + class alignas(16) CColor { public: @@ -54,6 +57,9 @@ public: CColor(Comp32 rgba) { fromRGBA32(rgba); } CColor(const Comp8* rgba) { fromRGBA8(rgba[0], rgba[1], rgba[2], rgba[3]); } + CColor(const CVector4f& other); + CColor& operator=(const CVector4f& other); + #if ZE_ATHENA_TYPES inline void readRGBA(Athena::io::IStreamReader& reader) { @@ -195,12 +201,16 @@ public: } inline float magSquared() const { -#if __SSE4_1__ - TVectorUnion result; - result.mVec128 = _mm_dp_ps(mVec128, mVec128, 0xF1); - return result.v[0]; -#elif __SSE__ +#if __SSE__ TVectorUnion result; +#if __SSE4_1__ || __SSE4_2__ + if (cpuFeatures().SSE41 || cpuFeatures().SSE42) + { + result.mVec128 = _mm_dp_ps(mVec128, mVec128, 0xF1); + return result.v[0]; + } +#endif + result.mVec128 = _mm_mul_ps(mVec128, mVec128); return result.v[0] + result.v[1] + result.v[2] + result.v[3]; #else diff --git a/include/CVector4f.hpp b/include/CVector4f.hpp index ba9bfb9..3116e79 100644 --- a/include/CVector4f.hpp +++ b/include/CVector4f.hpp @@ -13,6 +13,7 @@ namespace Zeus { +class CColor; class alignas(16) CVector4f { public: @@ -35,6 +36,7 @@ class alignas(16) CVector4f CVector4f(float xyzw) {splat(xyzw);} CVector4f(float x, float y, float z, float w) {v[0] = x; v[1] = y; v[2] = z; v[3] = w;} + CVector4f(const CColor& other); #if ZE_ATHENA_TYPES CVector4f(Athena::io::IStreamReader& input) { @@ -53,6 +55,7 @@ class alignas(16) CVector4f w = 1.0f; } + CVector4f& operator=(const CColor& other); inline bool operator ==(const CVector4f& rhs) const { #if __SSE__ diff --git a/src/CColor.cpp b/src/CColor.cpp index 997d0ad..0d3d3b7 100644 --- a/src/CColor.cpp +++ b/src/CColor.cpp @@ -1,4 +1,5 @@ #include "CColor.hpp" +#include "CVector4f.hpp" namespace Zeus { @@ -27,6 +28,18 @@ float hueToRgb(float p, float q, float t) return p; } +CColor::CColor(const CVector4f& other) +{ r = other.x; g = other.y; b = other.z; a = other.w; } + +CColor& CColor::operator=(const CVector4f& other) +{ + r = other.x; + g = other.y; + b = other.z; + a = other.w; + + return *this; +} void CColor::fromHSV(float h, float s, float v, float _a) { int i = int(h * 6); diff --git a/src/CVector4f.cpp b/src/CVector4f.cpp index afaccbe..5dbef01 100644 --- a/src/CVector4f.cpp +++ b/src/CVector4f.cpp @@ -1,2 +1,20 @@ #include "CVector4f.hpp" +#include "CColor.hpp" +namespace Zeus +{ +CVector4f::CVector4f(const Zeus::CColor& other) + : x(other.r), y(other.g), z(other.b), w(other.a) +{ +} + +CVector4f& CVector4f::operator=(const CColor& other) +{ + x = other.r; + y = other.g; + z = other.b; + w = other.a; + + return *this; +} +}