From 94eff6f642127f6b404c19be46f928f8ad9a28cf Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Thu, 1 Oct 2015 21:48:36 -0400 Subject: [PATCH] Add metaprogramming helper constructors for tvec4 and fvec4SIMD - Tests, too - Also, removed a line from the simdVec4 test (there's no operator+, apparently) --- glm/detail/type_vec4.hpp | 5 +++++ glm/detail/type_vec4.inl | 8 ++++++++ glm/gtx/simd_vec4.hpp | 5 +++++ glm/gtx/simd_vec4.inl | 6 ++++++ test/core/core_type_vec4.cpp | 10 ++++++++++ test/gtx/gtx_simd_vec4.cpp | 14 ++++++++++++-- 6 files changed, 46 insertions(+), 2 deletions(-) diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index 2d110c31..4ab19924 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -225,6 +225,11 @@ namespace detail template GLM_FUNC_DECL GLM_EXPLICIT tvec4(tvec4 const & v); +# ifdef GLM_META_PROG_HELPERS + template + GLM_FUNC_DECL tvec4(X const& x, Y const& y, Z const& z = Z(0)); +# endif + // -- Swizzle constructors -- # if GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE) diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index 80c75945..b5168952 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -202,6 +202,14 @@ namespace glm w(static_cast(v.w)) {} +# ifdef GLM_META_PROG_HELPERS + template + template + GLM_FUNC_QUALIFIER tvec4::tvec4(X const& x, Y const& y, Z const& z) + : x(static_cast(x)), y(static_cast(y)), z(static_cast(z)), w(static_cast(0)) + {} +# endif + // -- Component accesses -- # ifdef GLM_FORCE_SIZE_FUNC diff --git a/glm/gtx/simd_vec4.hpp b/glm/gtx/simd_vec4.hpp index cb084852..d49b75bf 100644 --- a/glm/gtx/simd_vec4.hpp +++ b/glm/gtx/simd_vec4.hpp @@ -136,6 +136,11 @@ namespace detail explicit fvec4SIMD( vec4 const & v); +# ifdef GLM_META_PROG_HELPERS + template + GLM_FUNC_DECL fvec4SIMD(X const& x, Y const& y, Z const& z = Z(0)); +# endif + //////////////////////////////////////// //// Conversion vector constructors diff --git a/glm/gtx/simd_vec4.inl b/glm/gtx/simd_vec4.inl index e375073f..13d77ff8 100644 --- a/glm/gtx/simd_vec4.inl +++ b/glm/gtx/simd_vec4.inl @@ -89,6 +89,12 @@ GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(vec2 const & v1, vec2 const & v2) : Data(_mm_set_ps(v2.y, v2.x, v1.y, v1.x)) {} +# ifdef GLM_META_PROG_HELPERS + template + GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(X const& x, Y const& y, Z const& z) + : fvec4SIMD(static_cast(x), static_cast(y), static_cast(z), 0.0f) + {} +# endif //GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(ivec4SIMD const & v) : // Data(_mm_cvtepi32_ps(v.Data)) //{} diff --git a/test/core/core_type_vec4.cpp b/test/core/core_type_vec4.cpp index cc72ddaa..ba1bfd4b 100644 --- a/test/core/core_type_vec4.cpp +++ b/test/core/core_type_vec4.cpp @@ -73,6 +73,16 @@ int test_vec4_ctor() Error += glm::all(glm::equal(A, B)) ? 0 : 1; } +# ifdef GLM_META_PROG_HELPERS + { + glm::vec4 a(1, 2, 0, 0), b(1, 2), c(1, 2, 0); + + Error += (a == b) ? 0 : 1; + Error += (b == c) ? 0 : 1; + Error += (a == c) ? 0 : 1; + } +# endif + # if GLM_HAS_TRIVIAL_QUERIES // Error += std::is_trivially_default_constructible::value ? 0 : 1; // Error += std::is_trivially_copy_assignable::value ? 0 : 1; diff --git a/test/gtx/gtx_simd_vec4.cpp b/test/gtx/gtx_simd_vec4.cpp index b86eb272..d0f08ed5 100644 --- a/test/gtx/gtx_simd_vec4.cpp +++ b/test/gtx/gtx_simd_vec4.cpp @@ -29,22 +29,32 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#define GLM_META_PROG_HELPERS #include #include #include + #if(GLM_ARCH != GLM_ARCH_PURE) int main() { + int Error = 0; #ifdef GLM_META_PROG_HELPERS assert(glm::simdVec4::components == glm::simdVec4::pure_type::components); + { + glm::simdVec4 a(1, 2, 0, 0), b(1, 2), c(1, 2, 0); + + Error += (glm::vec4_cast(a) == glm::vec4_cast(b)) ? 0 : 1; + Error += (glm::vec4_cast(b) == glm::vec4_cast(c)) ? 0 : 1; + Error += (glm::vec4_cast(c) == glm::vec4_cast(a)) ? 0 : 1; + } #endif glm::simdVec4 A1(0.0f, 0.1f, 0.2f, 0.3f); glm::simdVec4 B1(0.4f, 0.5f, 0.6f, 0.7f); - glm::simdVec4 C1 = A1 + B1; + //glm::simdVec4 C1 = A1 + B1; glm::simdVec4 D1 = A1.swizzle(); glm::simdVec4 E1(glm::vec4(1.0f)); glm::vec4 F1 = glm::vec4_cast(E1); @@ -61,7 +71,7 @@ int main() glm::simdVec4 GNI(add0); - return 0; + return Error; } #else