From f850b72e36061168370770204b75d638989a5c2e Mon Sep 17 00:00:00 2001 From: arcum42 Date: Wed, 22 Sep 2010 12:39:39 +0000 Subject: [PATCH] GregMiscellaneous: zzogl-pg: Try out using modifications of some of GSdx's code for ZZoglMath.h. git-svn-id: http://pcsx2.googlecode.com/svn/branches/GregMiscellaneous@3818 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/zzogl-pg/opengl/ZZoglMath.h | 296 ++++++++++++++++++++++++++++ 1 file changed, 296 insertions(+) diff --git a/plugins/zzogl-pg/opengl/ZZoglMath.h b/plugins/zzogl-pg/opengl/ZZoglMath.h index 006a62a3c3..1754a9ae8c 100644 --- a/plugins/zzogl-pg/opengl/ZZoglMath.h +++ b/plugins/zzogl-pg/opengl/ZZoglMath.h @@ -27,6 +27,10 @@ #include +//#define ZZ_MMATH + +#ifndef ZZ_MMATH + template class Vector4 { @@ -194,4 +198,296 @@ class Vector4 typedef Vector4 float4; +#else + +// Reimplement, swiping a bunch of code from GSdx and adapting it. (specifically GSVector.h) +// This doesn't include more then half of the functions in there, as well as some of the structs... +#include + +#include "Pcsx2Types.h" + +class float4 +{ + public: + union + { + struct {float x, y, z, w;}; + struct {float r, g, b, a;}; + struct {float left, top, right, bottom;}; + float v[4]; + float f32[4]; + s8 _s8[16]; + s16 _s16[8]; + s32 _s32[4]; + s64 _s64[2]; + u8 _u8[16]; + u16 _u16[8]; + u32 _u32[4]; + u64 _u64[2]; + __m128 m; + }; + + float4() + { + m = _mm_setzero_ps(); + } + + float4(float x, float y, float z, float w = 0) + { + m = _mm_set_ps(w, z, y, x); + } + + float4(float4 &f) + { + m = f.m; + } + + float4(float x, float y) + { + m = _mm_unpacklo_ps(_mm_load_ss(&x), _mm_load_ss(&y)); + } + + float4(int x, int y) + { + m = _mm_cvtepi32_ps(_mm_unpacklo_epi32(_mm_cvtsi32_si128(x), _mm_cvtsi32_si128(y))); + } + + explicit float4(float f) + { + m = _mm_set1_ps(f); + } + + explicit float4(__m128 m) + { + this->m = m; + } + + float4(float* f) + { + x = f[0]; + y = f[1]; + z = f[2]; + w = f[3]; // For some reason, the old code set this to 0. + } + + float& operator[](int i) + { + switch(i) + { + case 0: return x; + case 1: return y; + case 2: return z; + case 3: return w; + default: assert(0); + } + } + + operator float*() + { + return (float*) this; + } + + operator const float*() const + { + return (const float*) this; + } + + void operator = (float f) + { + m = _mm_set1_ps(f); + } + + void operator = (__m128 m) + { + this->m = m; + } + + + void operator += (const float4& v) + { + m = _mm_add_ps(m, v.m); + } + + void operator -= (const float4& v) + { + m = _mm_sub_ps(m, v.m); + } + + void operator *= (const float4& v) + { + m = _mm_mul_ps(m, v.m); + } + + void operator /= (const float4& v) + { + m = _mm_div_ps(m, v.m); + } + + void operator += (float f) + { + *this += float4(f); + } + + void operator -= (float f) + { + *this -= float4(f); + } + + void operator *= (float f) + { + *this *= float4(f); + } + + void operator /= (float f) + { + *this /= float4(f); + } + + void operator &= (const float4& v) + { + m = _mm_and_ps(m, v.m); + } + + void operator |= (const float4& v) + { + m = _mm_or_ps(m, v.m); + } + + void operator ^= (const float4& v) + { + m = _mm_xor_ps(m, v.m); + } + + friend float4 operator + (const float4& v1, const float4& v2) + { + return float4(_mm_add_ps(v1.m, v2.m)); + } + + friend float4 operator - (const float4& v1, const float4& v2) + { + return float4(_mm_sub_ps(v1.m, v2.m)); + } + + friend float4 operator * (const float4& v1, const float4& v2) + { + return float4(_mm_mul_ps(v1.m, v2.m)); + } + + friend float4 operator / (const float4& v1, const float4& v2) + { + return float4(_mm_div_ps(v1.m, v2.m)); + } + + friend float4 operator + (const float4& v, float f) + { + return v + float4(f); + } + + friend float4 operator - (const float4& v, float f) + { + return v - float4(f); + } + + friend float4 operator * (const float4& v, float f) + { + return v * float4(f); + } + + friend float4 operator / (const float4& v, float f) + { + return v / float4(f); + } + + friend float4 operator & (const float4& v1, const float4& v2) + { + return float4(_mm_and_ps(v1.m, v2.m)); + } + + friend float4 operator | (const float4& v1, const float4& v2) + { + return float4(_mm_or_ps(v1.m, v2.m)); + } + + friend float4 operator ^ (const float4& v1, const float4& v2) + { + return float4(_mm_xor_ps(v1.m, v2.m)); + } + + friend float4 operator == (const float4& v1, const float4& v2) + { + return float4(_mm_cmpeq_ps(v1.m, v2.m)); + } + + friend float4 operator != (const float4& v1, const float4& v2) + { + return float4(_mm_cmpneq_ps(v1.m, v2.m)); + } + + friend float4 operator > (const float4& v1, const float4& v2) + { + return float4(_mm_cmpgt_ps(v1.m, v2.m)); + } + + friend float4 operator < (const float4& v1, const float4& v2) + { + return float4(_mm_cmplt_ps(v1.m, v2.m)); + } + + friend float4 operator >= (const float4& v1, const float4& v2) + { + return float4(_mm_cmpge_ps(v1.m, v2.m)); + } + + friend float4 operator <= (const float4& v1, const float4& v2) + { + return float4(_mm_cmple_ps(v1.m, v2.m)); + } + + // This looked interesting, so I thought I'd include it... + + template float4 shuffle() const + { + return float4(_mm_shuffle_ps(m, m, _MM_SHUFFLE(i, i, i, i))); + } + + #define VECTOR4_SHUFFLE_4(xs, xn, ys, yn, zs, zn, ws, wn) \ + float4 xs##ys##zs##ws() const {return float4(_mm_shuffle_ps(m, m, _MM_SHUFFLE(wn, zn, yn, xn)));} \ + float4 xs##ys##zs##ws(const float4& v) const {return float4(_mm_shuffle_ps(m, v.m, _MM_SHUFFLE(wn, zn, yn, xn)));} \ + + #define VECTOR4_SHUFFLE_3(xs, xn, ys, yn, zs, zn) \ + VECTOR4_SHUFFLE_4(xs, xn, ys, yn, zs, zn, x, 0) \ + VECTOR4_SHUFFLE_4(xs, xn, ys, yn, zs, zn, y, 1) \ + VECTOR4_SHUFFLE_4(xs, xn, ys, yn, zs, zn, z, 2) \ + VECTOR4_SHUFFLE_4(xs, xn, ys, yn, zs, zn, w, 3) \ + + #define VECTOR4_SHUFFLE_2(xs, xn, ys, yn) \ + VECTOR4_SHUFFLE_3(xs, xn, ys, yn, x, 0) \ + VECTOR4_SHUFFLE_3(xs, xn, ys, yn, y, 1) \ + VECTOR4_SHUFFLE_3(xs, xn, ys, yn, z, 2) \ + VECTOR4_SHUFFLE_3(xs, xn, ys, yn, w, 3) \ + + #define VECTOR4_SHUFFLE_1(xs, xn) \ + float4 xs##4() const {return float4(_mm_shuffle_ps(m, m, _MM_SHUFFLE(xn, xn, xn, xn)));} \ + float4 xs##4(const float4& v) const {return float4(_mm_shuffle_ps(m, v.m, _MM_SHUFFLE(xn, xn, xn, xn)));} \ + VECTOR4_SHUFFLE_2(xs, xn, x, 0) \ + VECTOR4_SHUFFLE_2(xs, xn, y, 1) \ + VECTOR4_SHUFFLE_2(xs, xn, z, 2) \ + VECTOR4_SHUFFLE_2(xs, xn, w, 3) \ + + VECTOR4_SHUFFLE_1(x, 0) + VECTOR4_SHUFFLE_1(y, 1) + VECTOR4_SHUFFLE_1(z, 2) + VECTOR4_SHUFFLE_1(w, 3) + + // Probably doesn't belong here, but I'll leave it in for the moment. + void SetColor(u32 color) + { + x = (color & 0xff) / 255.0f; + y = ((color >> 8) & 0xff) / 255.0f; + z = ((color >> 16) & 0xff) / 255.0f; + } +}; + +#endif + #endif