From ec261bd21be8097a2d6d168d94a7b6a86980c26e Mon Sep 17 00:00:00 2001 From: Groove Date: Fri, 6 Jul 2018 22:22:09 +0200 Subject: [PATCH] Added vec1 based constructors to vec4 with tests and fixed build --- glm/detail/type_vec4.hpp | 29 ++++++++ glm/detail/type_vec4.inl | 126 +++++++++++++++++++++++++++++++++++ test/core/core_type_vec4.cpp | 117 +++++++++++++++++++++++++++++++- 3 files changed, 271 insertions(+), 1 deletion(-) diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index 43395ca4..4ecfeee2 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -101,10 +101,39 @@ namespace glm // -- Conversion scalar constructors -- + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit vec(vec<1, U, P> const& v); + /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) template GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec(X _x, Y _y, Z _z, W _w); template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, X, Q> const& _x, Y _y, Z _z, W _w); + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(X _x, vec<1, Y, Q> const& _y, Z _z, W _w); + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, X, Q> const& _x, vec<1, Y, Q> const& _y, Z _z, W _w); + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(X _x, Y _y, vec<1, Z, Q> const& _z, W _w); + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, X, Q> const& _x, Y _y, vec<1, Z, Q> const& _z, W _w); + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(X _x, vec<1, Y, Q> const& _y, vec<1, Z, Q> const& _z, W _w); + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, X, Q> const& _x, vec<1, Y, Q> const& _y, vec<1, Z, Q> const& _z, W _w); + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, X, Q> const& _x, Y _y, Z _z, vec<1, W, Q> const& _w); + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(X _x, vec<1, Y, Q> const& _y, Z _z, vec<1, W, Q> const& _w); + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, X, Q> const& _x, vec<1, Y, Q> const& _y, Z _z, vec<1, W, Q> const& _w); + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(X _x, Y _y, vec<1, Z, Q> const& _z, vec<1, W, Q> const& _w); + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, X, Q> const& _x, Y _y, vec<1, Z, Q> const& _z, vec<1, W, Q> const& _w); + template + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(X _x, vec<1, Y, Q> const& _y, vec<1, Z, Q> const& _z, vec<1, W, Q> const& _w); + template GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, X, Q> const& _x, vec<1, Y, Q> const& _Y, vec<1, Z, Q> const& _z, vec<1, W, Q> const& _w); // -- Conversion vector constructors -- diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index 972cb4e4..7b069f12 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -194,6 +194,15 @@ namespace detail // -- Conversion scalar constructors -- + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(vec<1, U, P> const& v) + : x(static_cast(v.x)) + , y(static_cast(v.x)) + , z(static_cast(v.x)) + , w(static_cast(v.x)) + {} + template template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, T, Q>::vec(X _x, Y _y, Z _z, W _w) @@ -203,6 +212,123 @@ namespace detail , w(static_cast(_w)) {} + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(vec<1, X, Q> const& _x, Y _y, Z _z, W _w) + : x(static_cast(_x.x)) + , y(static_cast(_y)) + , z(static_cast(_z)) + , w(static_cast(_w)) + {} + + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(X _x, vec<1, Y, Q> const& _y, Z _z, W _w) + : x(static_cast(_x)) + , y(static_cast(_y.x)) + , z(static_cast(_z)) + , w(static_cast(_w)) + {} + + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(vec<1, X, Q> const& _x, vec<1, Y, Q> const& _y, Z _z, W _w) + : x(static_cast(_x.x)) + , y(static_cast(_y.x)) + , z(static_cast(_z)) + , w(static_cast(_w)) + {} + + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(X _x, Y _y, vec<1, Z, Q> const& _z, W _w) + : x(static_cast(_x)) + , y(static_cast(_y)) + , z(static_cast(_z.x)) + , w(static_cast(_w)) + {} + + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(vec<1, X, Q> const& _x, Y _y, vec<1, Z, Q> const& _z, W _w) + : x(static_cast(_x.x)) + , y(static_cast(_y)) + , z(static_cast(_z.x)) + , w(static_cast(_w)) + {} + + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(X _x, vec<1, Y, Q> const& _y, vec<1, Z, Q> const& _z, W _w) + : x(static_cast(_x)) + , y(static_cast(_y.x)) + , z(static_cast(_z.x)) + , w(static_cast(_w)) + {} + + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(vec<1, X, Q> const& _x, vec<1, Y, Q> const& _y, vec<1, Z, Q> const& _z, W _w) + : x(static_cast(_x.x)) + , y(static_cast(_y.x)) + , z(static_cast(_z.x)) + , w(static_cast(_w)) + {} + + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(vec<1, X, Q> const& _x, Y _y, Z _z, vec<1, W, Q> const& _w) + : x(static_cast(_x.x)) + , y(static_cast(_y)) + , z(static_cast(_z)) + , w(static_cast(_w.x)) + {} + + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(X _x, vec<1, Y, Q> const& _y, Z _z, vec<1, W, Q> const& _w) + : x(static_cast(_x)) + , y(static_cast(_y.x)) + , z(static_cast(_z)) + , w(static_cast(_w.x)) + {} + + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(vec<1, X, Q> const& _x, vec<1, Y, Q> const& _y, Z _z, vec<1, W, Q> const& _w) + : x(static_cast(_x.x)) + , y(static_cast(_y.x)) + , z(static_cast(_z)) + , w(static_cast(_w.x)) + {} + + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(X _x, Y _y, vec<1, Z, Q> const& _z, vec<1, W, Q> const& _w) + : x(static_cast(_x)) + , y(static_cast(_y)) + , z(static_cast(_z.x)) + , w(static_cast(_w.x)) + {} + + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(vec<1, X, Q> const& _x, Y _y, vec<1, Z, Q> const& _z, vec<1, W, Q> const& _w) + : x(static_cast(_x.x)) + , y(static_cast(_y)) + , z(static_cast(_z.x)) + , w(static_cast(_w.x)) + {} + + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(X _x, vec<1, Y, Q> const& _y, vec<1, Z, Q> const& _z, vec<1, W, Q> const& _w) + : x(static_cast(_x)) + , y(static_cast(_y.x)) + , z(static_cast(_z.x)) + , w(static_cast(_w.x)) + {} + template template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<4, T, Q>::vec(vec<1, X, Q> const& _x, vec<1, Y, Q> const& _y, vec<1, Z, Q> const& _z, vec<1, W, Q> const& _w) diff --git a/test/core/core_type_vec4.cpp b/test/core/core_type_vec4.cpp index 9d272b00..438c1f08 100644 --- a/test/core/core_type_vec4.cpp +++ b/test/core/core_type_vec4.cpp @@ -1,6 +1,7 @@ #define GLM_FORCE_ALIGNED #define GLM_FORCE_SWIZZLE #include +#include #include #include #include @@ -136,7 +137,121 @@ static int test_vec4_ctor() for(std::size_t i = 0; i < Tests.size(); ++i) Error += Tests[i] == glm::vec4(1, 2, 3, 4) ? 0 : 1; } - + + { + glm::vec1 const R(1.0f); + glm::vec1 const S(2.0f); + glm::vec1 const T(3.0f); + glm::vec1 const U(4.0f); + glm::vec4 const O(1.0f, 2.0f, 3.0f, 4.0f); + + glm::vec4 const A(R); + glm::vec4 const B(1.0f); + Error += glm::all(glm::equal(A, B)) ? 0 : 1; + + glm::vec4 const C(R, S, T, U); + Error += glm::all(glm::equal(C, O)) ? 0 : 1; + + glm::vec4 const D(R, 2.0f, 3.0f, 4.0f); + Error += glm::all(glm::equal(D, O)) ? 0 : 1; + + glm::vec4 const E(1.0f, S, 3.0f, 4.0f); + Error += glm::all(glm::equal(E, O)) ? 0 : 1; + + glm::vec4 const F(R, S, 3.0f, 4.0f); + Error += glm::all(glm::equal(F, O)) ? 0 : 1; + + glm::vec4 const G(1.0f, 2.0f, T, 4.0f); + Error += glm::all(glm::equal(G, O)) ? 0 : 1; + + glm::vec4 const H(R, 2.0f, T, 4.0f); + Error += glm::all(glm::equal(H, O)) ? 0 : 1; + + glm::vec4 const I(1.0f, S, T, 4.0f); + Error += glm::all(glm::equal(I, O)) ? 0 : 1; + + glm::vec4 const J(R, S, T, 4.0f); + Error += glm::all(glm::equal(J, O)) ? 0 : 1; + + glm::vec4 const K(R, 2.0f, 3.0f, U); + Error += glm::all(glm::equal(K, O)) ? 0 : 1; + + glm::vec4 const L(1.0f, S, 3.0f, U); + Error += glm::all(glm::equal(L, O)) ? 0 : 1; + + glm::vec4 const M(R, S, 3.0f, U); + Error += glm::all(glm::equal(M, O)) ? 0 : 1; + + glm::vec4 const N(1.0f, 2.0f, T, U); + Error += glm::all(glm::equal(N, O)) ? 0 : 1; + + glm::vec4 const P(R, 2.0f, T, U); + Error += glm::all(glm::equal(P, O)) ? 0 : 1; + + glm::vec4 const Q(1.0f, S, T, U); + Error += glm::all(glm::equal(Q, O)) ? 0 : 1; + + glm::vec4 const V(R, S, T, U); + Error += glm::all(glm::equal(V, O)) ? 0 : 1; + } + + { + glm::vec1 const R(1.0f); + glm::dvec1 const S(2.0f); + glm::vec1 const T(3.0); + glm::dvec1 const U(4.0); + glm::vec4 const O(1.0f, 2.0, 3.0f, 4.0); + + glm::vec4 const A(R); + glm::vec4 const B(1.0); + Error += glm::all(glm::equal(A, B)) ? 0 : 1; + + glm::vec4 const C(R, S, T, U); + Error += glm::all(glm::equal(C, O)) ? 0 : 1; + + glm::vec4 const D(R, 2.0f, 3.0, 4.0f); + Error += glm::all(glm::equal(D, O)) ? 0 : 1; + + glm::vec4 const E(1.0, S, 3.0f, 4.0); + Error += glm::all(glm::equal(E, O)) ? 0 : 1; + + glm::vec4 const F(R, S, 3.0, 4.0f); + Error += glm::all(glm::equal(F, O)) ? 0 : 1; + + glm::vec4 const G(1.0f, 2.0, T, 4.0); + Error += glm::all(glm::equal(G, O)) ? 0 : 1; + + glm::vec4 const H(R, 2.0, T, 4.0); + Error += glm::all(glm::equal(H, O)) ? 0 : 1; + + glm::vec4 const I(1.0, S, T, 4.0f); + Error += glm::all(glm::equal(I, O)) ? 0 : 1; + + glm::vec4 const J(R, S, T, 4.0f); + Error += glm::all(glm::equal(J, O)) ? 0 : 1; + + glm::vec4 const K(R, 2.0f, 3.0, U); + Error += glm::all(glm::equal(K, O)) ? 0 : 1; + + glm::vec4 const L(1.0f, S, 3.0, U); + Error += glm::all(glm::equal(L, O)) ? 0 : 1; + + glm::vec4 const M(R, S, 3.0, U); + Error += glm::all(glm::equal(M, O)) ? 0 : 1; + + glm::vec4 const N(1.0f, 2.0, T, U); + Error += glm::all(glm::equal(N, O)) ? 0 : 1; + + glm::vec4 const P(R, 2.0, T, U); + Error += glm::all(glm::equal(P, O)) ? 0 : 1; + + glm::vec4 const Q(1.0f, S, T, U); + Error += glm::all(glm::equal(Q, O)) ? 0 : 1; + + glm::vec4 const V(R, S, T, U); + Error += glm::all(glm::equal(V, O)) ? 0 : 1; + } + return Error; }