diff --git a/glm/core/type_vec3.hpp b/glm/core/type_vec3.hpp index 497722ca..2b5d9ab6 100644 --- a/glm/core/type_vec3.hpp +++ b/glm/core/type_vec3.hpp @@ -101,11 +101,6 @@ namespace detail value_type const & s2, value_type const & s3); - ////////////////////////////////////// - // Swizzle constructors - - GLM_FUNC_DECL tvec3(tref3 const & r); - ////////////////////////////////////// // Convertion scalar constructors @@ -136,6 +131,17 @@ namespace detail template GLM_FUNC_DECL explicit tvec3(tvec4 const & v); + ////////////////////////////////////// + // Swizzle constructors + + GLM_FUNC_DECL tvec3(tref3 const & r); + + template + GLM_FUNC_DECL explicit tvec3(tref2 const & v, B const & s); + + template + GLM_FUNC_DECL explicit tvec3(A const & s, tref2 const & v); + ////////////////////////////////////// // Unary arithmetic operators diff --git a/glm/core/type_vec3.inl b/glm/core/type_vec3.inl index 08940e53..84bf3a44 100644 --- a/glm/core/type_vec3.inl +++ b/glm/core/type_vec3.inl @@ -131,6 +131,30 @@ namespace detail z(r.z) {} + template + template + GLM_FUNC_QUALIFIER tvec3::tvec3 + ( + tref2 const & v, + B const & s + ) : + x(value_type(v.x)), + y(value_type(v.y)), + z(value_type(s)) + {} + + template + template + GLM_FUNC_QUALIFIER tvec3::tvec3 + ( + A const & s, + tref2 const & v + ) : + x(value_type(s)), + y(value_type(v.x)), + z(value_type(v.y)) + {} + ////////////////////////////////////// // Convertion scalar constructors diff --git a/glm/core/type_vec4.hpp b/glm/core/type_vec4.hpp index 35923366..5c9283b7 100644 --- a/glm/core/type_vec4.hpp +++ b/glm/core/type_vec4.hpp @@ -103,11 +103,6 @@ namespace detail value_type const & s2, value_type const & s3); - ////////////////////////////////////// - // Swizzle constructors - - GLM_FUNC_DECL tvec4(tref4 const & r); - ////////////////////////////////////// // Convertion scalar constructors @@ -148,6 +143,36 @@ namespace detail template GLM_FUNC_DECL explicit tvec4(tvec4 const & v); + ////////////////////////////////////// + // Swizzle constructors + + GLM_FUNC_DECL tvec4(tref4 const & r); + + //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) + template + GLM_FUNC_DECL explicit tvec4(tref2 const & v, B const & s1, C const & s2); + //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) + template + GLM_FUNC_DECL explicit tvec4(A const & s1, tref2 const & v, C const & s2); + //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) + template + GLM_FUNC_DECL explicit tvec4(A const & s1, B const & s2, tref2 const & v); + //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) + template + GLM_FUNC_DECL explicit tvec4(tref3 const & v, B const & s); + //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) + template + GLM_FUNC_DECL explicit tvec4(A const & s, tref3 const & v); + //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) + template + GLM_FUNC_DECL explicit tvec4(tref2 const & v1, tref2 const & v2); + //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) + template + GLM_FUNC_DECL explicit tvec4(tvec2 const & v1, tref2 const & v2); + //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) + template + GLM_FUNC_DECL explicit tvec4(tref2 const & v1, tvec2 const & v2); + ////////////////////////////////////// // Unary arithmetic operators diff --git a/glm/core/type_vec4.inl b/glm/core/type_vec4.inl index 8196862a..363ada1f 100644 --- a/glm/core/type_vec4.inl +++ b/glm/core/type_vec4.inl @@ -137,6 +137,113 @@ namespace detail w(r.w) {} + template + template + GLM_FUNC_QUALIFIER tvec4::tvec4 + ( + tref2 const & v, + B const & s1, + C const & s2 + ) : + x(value_type(v.x)), + y(value_type(v.y)), + z(value_type(s1)), + w(value_type(s2)) + {} + + template + template + GLM_FUNC_QUALIFIER tvec4::tvec4 + ( + A const & s1, + tref2 const & v, + C const & s2 + ) : + x(value_type(s1)), + y(value_type(v.x)), + z(value_type(v.y)), + w(value_type(s2)) + {} + + template + template + GLM_FUNC_QUALIFIER tvec4::tvec4 + ( + A const & s1, + B const & s2, + tref2 const & v + ) : + x(value_type(s1)), + y(value_type(s2)), + z(value_type(v.x)), + w(value_type(v.y)) + {} + + template + template + GLM_FUNC_QUALIFIER tvec4::tvec4 + ( + tref3 const & v, + B const & s + ) : + x(value_type(v.x)), + y(value_type(v.y)), + z(value_type(v.z)), + w(value_type(s)) + {} + + template + template + GLM_FUNC_QUALIFIER tvec4::tvec4 + ( + A const & s, + tref3 const & v + ) : + x(value_type(s)), + y(value_type(v.x)), + z(value_type(v.y)), + w(value_type(v.z)) + {} + + template + template + GLM_FUNC_QUALIFIER tvec4::tvec4 + ( + tref2 const & v1, + tref2 const & v2 + ) : + x(value_type(v1.x)), + y(value_type(v1.y)), + z(value_type(v2.x)), + w(value_type(v2.y)) + {} + + template + template + GLM_FUNC_QUALIFIER tvec4::tvec4 + ( + tvec2 const & v1, + tref2 const & v2 + ) : + x(value_type(v1.x)), + y(value_type(v1.y)), + z(value_type(v2.x)), + w(value_type(v2.y)) + {} + + template + template + GLM_FUNC_QUALIFIER tvec4::tvec4 + ( + tref2 const & v1, + tvec2 const & v2 + ) : + x(value_type(v1.x)), + y(value_type(v1.y)), + z(value_type(v2.x)), + w(value_type(v2.y)) + {} + ////////////////////////////////////// // Convertion scalar constructors diff --git a/readme.txt b/readme.txt index c2f6a97e..af4d0901 100644 --- a/readme.txt +++ b/readme.txt @@ -48,6 +48,11 @@ generation distribution. - Removed many unused namespaces - Fixed half based type contructors +================================================================================ +GLM 0.9.2.7: 2011-1X-XX +-------------------------------------------------------------------------------- +- Added more swizzling constructors + ================================================================================ GLM 0.9.2.6: 2011-10-01 -------------------------------------------------------------------------------- diff --git a/test/gtc/gtc_swizzle.cpp b/test/gtc/gtc_swizzle.cpp index 5ed77ae1..2520243b 100644 --- a/test/gtc/gtc_swizzle.cpp +++ b/test/gtc/gtc_swizzle.cpp @@ -121,13 +121,83 @@ int test_swizzle_vec4_const_static() return Error; } +int test_swizzle_vec3_partial() +{ + int Error = 0; + + glm::ivec3 A(0, 1, 2); + + { + glm::ivec3 B(A.swizzle(glm::R, glm::G, glm::B)); + Error += (A == B) ? 0 : 1; + } + + { + glm::ivec3 B(A.swizzle(glm::R, glm::G), 2); + Error += (A == B) ? 0 : 1; + } + + { + glm::ivec3 B(0, A.swizzle(glm::G, glm::B)); + Error += (A == B) ? 0 : 1; + } + + return Error; +} + +int test_swizzle_vec4_partial() +{ + int Error = 0; + + glm::ivec4 A(0, 1, 2, 3); + + { + glm::ivec4 B(A.swizzle(glm::R, glm::G, glm::B), 3); + Error += (A == B) ? 0 : 1; + } + + { + glm::ivec4 B(A.swizzle(glm::R, glm::G), 2, 3); + Error += (A == B) ? 0 : 1; + } + + { + glm::ivec4 B(0, A.swizzle(glm::G, glm::B), 3); + Error += (A == B) ? 0 : 1; + } + + { + glm::ivec4 B(0, 1, A.swizzle(glm::B, glm::A)); + Error += (A == B) ? 0 : 1; + } + + { + glm::ivec4 B(A.swizzle(glm::X, glm::Y), A.swizzle(glm::Z, glm::W)); + Error += (A == B) ? 0 : 1; + } + + { + glm::ivec4 B(A.swizzle(glm::X, glm::Y), glm::vec2(2, 3)); + Error += (A == B) ? 0 : 1; + } + + { + glm::ivec4 B(glm::vec2(0, 1), A.swizzle(glm::Z, glm::W)); + Error += (A == B) ? 0 : 1; + } + + return Error; +} + int main() { int Error = 0; + Error += test_swizzle_vec3_partial(); Error += test_swizzle_vec4_ref_dynamic(); Error += test_swizzle_vec4_ref_static(); Error += test_swizzle_vec4_const_dynamic(); Error += test_swizzle_vec4_const_static(); + Error += test_swizzle_vec4_partial(); return Error; }