diff --git a/glm/gtc/swizzle.hpp b/glm/gtc/swizzle.hpp index a1cf29d1..9cc89d0e 100644 --- a/glm/gtc/swizzle.hpp +++ b/glm/gtc/swizzle.hpp @@ -15,6 +15,7 @@ // Dependency: #include "../glm.hpp" +#include "../gtc/type_precision.hpp" namespace glm { @@ -24,48 +25,323 @@ namespace glm namespace gtc{ //! GLM_GTC_swizzle extension - namespace swizzle{ + namespace swizzle + { + using namespace gtc::half_float; template class vecType> - T swizzle( + T const & swizzle( vecType const & v, comp x); - template - detail::tvec2 swizzle( - detail::tvec4 const & v, + template class vecType> + detail::tvec2 const & swizzle( + vecType const & v, comp x, comp y); - template - detail::tvec3 swizzle( - detail::tvec4 const & v, + template class vecType> + detail::tvec3 const & swizzle( + vecType const & v, comp x, comp y, comp z); - template - detail::tvec4 swizzle( - detail::tvec4 const & v, + template class vecType> + detail::tvec4 const & swizzle( + vecType const & v, comp x, comp y, comp z, comp w); - template - T& swizzle( - detail::tvec4 & v, + template class vecType> + T & swizzle( + vecType & v, comp x); - template + template class vecType> detail::tref2 swizzle( - detail::tvec4 & v, + vecType & v, comp x, comp y); - template + template class vecType> detail::tref3 swizzle( - detail::tvec4 & v, + vecType & v, comp x, comp y, comp z); - template + template class vecType> detail::tref4 swizzle( - detail::tvec4 & v, + vecType & v, comp x, comp y, comp z, comp w); +# define static_swizzle1(TYPE, SIZE) \ + template \ + inline TYPE swizzle(detail::tvec##SIZE const & v) \ + {return v[x];} \ + \ + template \ + inline TYPE& swizzle(detail::tvec##SIZE & v) \ + {return v[x];} + + static_swizzle1(detail::float16, 2) + static_swizzle1(detail::float16, 3) + static_swizzle1(detail::float16, 4) + static_swizzle1(detail::float32, 2) + static_swizzle1(detail::float32, 3) + static_swizzle1(detail::float32, 4) + static_swizzle1(detail::float64, 2) + static_swizzle1(detail::float64, 3) + static_swizzle1(detail::float64, 4) + + static_swizzle1(detail::int8, 2) + static_swizzle1(detail::int8, 3) + static_swizzle1(detail::int8, 4) + static_swizzle1(detail::int16, 2) + static_swizzle1(detail::int16, 3) + static_swizzle1(detail::int16, 4) + static_swizzle1(detail::int32, 2) + static_swizzle1(detail::int32, 3) + static_swizzle1(detail::int32, 4) + static_swizzle1(detail::int64, 2) + static_swizzle1(detail::int64, 3) + static_swizzle1(detail::int64, 4) + + static_swizzle1(detail::uint8, 2) + static_swizzle1(detail::uint8, 3) + static_swizzle1(detail::uint8, 4) + static_swizzle1(detail::uint16, 2) + static_swizzle1(detail::uint16, 3) + static_swizzle1(detail::uint16, 4) + static_swizzle1(detail::uint32, 2) + static_swizzle1(detail::uint32, 3) + static_swizzle1(detail::uint32, 4) + static_swizzle1(detail::uint64, 2) + static_swizzle1(detail::uint64, 3) + static_swizzle1(detail::uint64, 4) + +# define static_swizzle2_const(TYPE) \ + template \ + inline TYPE swizzle(TYPE const & v) \ + {return TYPE(v[x], v[y]);} + +# define static_swizzle3_const(TYPE) \ + template \ + inline TYPE swizzle(TYPE const & v) \ + {return TYPE(v[x], v[y], v[z]);} + +# define static_swizzle4_const(TYPE) \ + template \ + inline TYPE swizzle(TYPE const & v) \ + {return TYPE(v[x], v[y], v[z], v[w]);} +/* +# define static_swizzle2_const(TYPE, SIZE) \ + template \ + inline detail::tvec2 swizzle(detail::tvec##SIZE const & v) \ + {return detail::tvec2(v[x], v[y]);} + +# define static_swizzle3_const(TYPE, SIZE) \ + template \ + inline detail::tvec3 swizzle(detail::tvec##SIZE const & v) \ + {return detail::tvec3(v[x], v[y], v[z]);} + +# define static_swizzle4_const(TYPE, SIZE) \ + template \ + inline detail::tvec4 swizzle(detail::tvec##SIZE const & v) \ + {return detail::tvec4(v[x], v[y], v[z], v[w]);} +*/ + static_swizzle2_const(glm::f16vec2); + static_swizzle2_const(glm::f16vec3); + static_swizzle2_const(glm::f16vec4); + static_swizzle2_const(glm::f32vec2); + static_swizzle2_const(glm::f32vec3); + static_swizzle2_const(glm::f32vec4); + static_swizzle2_const(glm::f64vec2); + static_swizzle2_const(glm::f64vec3); + static_swizzle2_const(glm::f64vec4); + + static_swizzle2_const(glm::i8vec2); + static_swizzle2_const(glm::i8vec3); + static_swizzle2_const(glm::i8vec4); + static_swizzle2_const(glm::i16vec2); + static_swizzle2_const(glm::i16vec3); + static_swizzle2_const(glm::i16vec4); + static_swizzle2_const(glm::i32vec2); + static_swizzle2_const(glm::i32vec3); + static_swizzle2_const(glm::i32vec4); + static_swizzle2_const(glm::i64vec2); + static_swizzle2_const(glm::i64vec3); + static_swizzle2_const(glm::i64vec4); + + static_swizzle2_const(glm::u8vec2); + static_swizzle2_const(glm::u8vec3); + static_swizzle2_const(glm::u8vec4); + static_swizzle2_const(glm::u16vec2); + static_swizzle2_const(glm::u16vec3); + static_swizzle2_const(glm::u16vec4); + static_swizzle2_const(glm::u32vec2); + static_swizzle2_const(glm::u32vec3); + static_swizzle2_const(glm::u32vec4); + static_swizzle2_const(glm::u64vec2); + static_swizzle2_const(glm::u64vec3); + static_swizzle2_const(glm::u64vec4); + + static_swizzle3_const(glm::f16vec2); + static_swizzle3_const(glm::f16vec3); + static_swizzle3_const(glm::f16vec4); + static_swizzle3_const(glm::f32vec2); + static_swizzle3_const(glm::f32vec3); + static_swizzle3_const(glm::f32vec4); + static_swizzle3_const(glm::f64vec2); + static_swizzle3_const(glm::f64vec3); + static_swizzle3_const(glm::f64vec4); + + static_swizzle3_const(glm::i8vec2); + static_swizzle3_const(glm::i8vec3); + static_swizzle3_const(glm::i8vec4); + static_swizzle3_const(glm::i16vec2); + static_swizzle3_const(glm::i16vec3); + static_swizzle3_const(glm::i16vec4); + static_swizzle3_const(glm::i32vec2); + static_swizzle3_const(glm::i32vec3); + static_swizzle3_const(glm::i32vec4); + static_swizzle3_const(glm::i64vec2); + static_swizzle3_const(glm::i64vec3); + static_swizzle3_const(glm::i64vec4); + + static_swizzle3_const(glm::u8vec2); + static_swizzle3_const(glm::u8vec3); + static_swizzle3_const(glm::u8vec4); + static_swizzle3_const(glm::u16vec2); + static_swizzle3_const(glm::u16vec3); + static_swizzle3_const(glm::u16vec4); + static_swizzle3_const(glm::u32vec2); + static_swizzle3_const(glm::u32vec3); + static_swizzle3_const(glm::u32vec4); + static_swizzle3_const(glm::u64vec2); + static_swizzle3_const(glm::u64vec3); + static_swizzle3_const(glm::u64vec4); + + static_swizzle4_const(glm::f16vec2); + static_swizzle4_const(glm::f16vec3); + static_swizzle4_const(glm::f16vec4); + static_swizzle4_const(glm::f32vec2); + static_swizzle4_const(glm::f32vec3); + static_swizzle4_const(glm::f32vec4); + static_swizzle4_const(glm::f64vec2); + static_swizzle4_const(glm::f64vec3); + static_swizzle4_const(glm::f64vec4); + + static_swizzle4_const(glm::i8vec2); + static_swizzle4_const(glm::i8vec3); + static_swizzle4_const(glm::i8vec4); + static_swizzle4_const(glm::i16vec2); + static_swizzle4_const(glm::i16vec3); + static_swizzle4_const(glm::i16vec4); + static_swizzle4_const(glm::i32vec2); + static_swizzle4_const(glm::i32vec3); + static_swizzle4_const(glm::i32vec4); + static_swizzle4_const(glm::i64vec2); + static_swizzle4_const(glm::i64vec3); + static_swizzle4_const(glm::i64vec4); + + static_swizzle4_const(glm::u8vec2); + static_swizzle4_const(glm::u8vec3); + static_swizzle4_const(glm::u8vec4); + static_swizzle4_const(glm::u16vec2); + static_swizzle4_const(glm::u16vec3); + static_swizzle4_const(glm::u16vec4); + static_swizzle4_const(glm::u32vec2); + static_swizzle4_const(glm::u32vec3); + static_swizzle4_const(glm::u32vec4); + static_swizzle4_const(glm::u64vec2); + static_swizzle4_const(glm::u64vec3); + static_swizzle4_const(glm::u64vec4); + +# define static_swizzle2_ref(TYPE) \ + template \ + inline glm::detail::tref2 swizzle(TYPE & v) \ + {return glm::detail::tref2(v[x], v[y]);} + +# define static_swizzle3_ref(TYPE) \ + template \ + inline glm::detail::tref3 swizzle(TYPE & v) \ + {return glm::detail::tref3(v[x], v[y], v[z]);} + +# define static_swizzle4_ref(TYPE) \ + template \ + inline glm::detail::tref4 swizzle(TYPE & v) \ + {return glm::detail::tref4(v[x], v[y], v[z], v[w]);} + + static_swizzle2_ref(glm::f16vec2); + static_swizzle2_ref(glm::f16vec3); + static_swizzle2_ref(glm::f16vec4); + static_swizzle2_ref(glm::f32vec2); + static_swizzle2_ref(glm::f32vec3); + static_swizzle2_ref(glm::f32vec4); + static_swizzle2_ref(glm::f64vec2); + static_swizzle2_ref(glm::f64vec3); + static_swizzle2_ref(glm::f64vec4); + + static_swizzle2_ref(glm::i8vec2); + static_swizzle2_ref(glm::i8vec3); + static_swizzle2_ref(glm::i8vec4); + static_swizzle2_ref(glm::i16vec2); + static_swizzle2_ref(glm::i16vec3); + static_swizzle2_ref(glm::i16vec4); + static_swizzle2_ref(glm::i32vec2); + static_swizzle2_ref(glm::i32vec3); + static_swizzle2_ref(glm::i32vec4); + static_swizzle2_ref(glm::i64vec2); + static_swizzle2_ref(glm::i64vec3); + static_swizzle2_ref(glm::i64vec4); + + static_swizzle2_ref(glm::u8vec2); + static_swizzle2_ref(glm::u8vec3); + static_swizzle2_ref(glm::u8vec4); + static_swizzle2_ref(glm::u16vec2); + static_swizzle2_ref(glm::u16vec3); + static_swizzle2_ref(glm::u16vec4); + static_swizzle2_ref(glm::u32vec2); + static_swizzle2_ref(glm::u32vec3); + static_swizzle2_ref(glm::u32vec4); + static_swizzle2_ref(glm::u64vec2); + static_swizzle2_ref(glm::u64vec3); + static_swizzle2_ref(glm::u64vec4); + + static_swizzle3_ref(glm::f16vec3); + static_swizzle3_ref(glm::f16vec4); + static_swizzle3_ref(glm::f32vec3); + static_swizzle3_ref(glm::f32vec4); + static_swizzle3_ref(glm::f64vec3); + static_swizzle3_ref(glm::f64vec4); + + static_swizzle3_ref(glm::i8vec3); + static_swizzle3_ref(glm::i8vec4); + static_swizzle3_ref(glm::i16vec3); + static_swizzle3_ref(glm::i16vec4); + static_swizzle3_ref(glm::i32vec3); + static_swizzle3_ref(glm::i32vec4); + static_swizzle3_ref(glm::i64vec3); + static_swizzle3_ref(glm::i64vec4); + + static_swizzle3_ref(glm::u8vec3); + static_swizzle3_ref(glm::u8vec4); + static_swizzle3_ref(glm::u16vec3); + static_swizzle3_ref(glm::u16vec4); + static_swizzle3_ref(glm::u32vec3); + static_swizzle3_ref(glm::u32vec4); + static_swizzle3_ref(glm::u64vec3); + static_swizzle3_ref(glm::u64vec4); + + static_swizzle4_ref(glm::f16vec4); + static_swizzle4_ref(glm::f32vec4); + static_swizzle4_ref(glm::f64vec4); + + static_swizzle4_ref(glm::i8vec4); + static_swizzle4_ref(glm::i16vec4); + static_swizzle4_ref(glm::i32vec4); + static_swizzle4_ref(glm::i64vec4); + + static_swizzle4_ref(glm::u8vec4); + static_swizzle4_ref(glm::u16vec4); + static_swizzle4_ref(glm::u32vec4); + static_swizzle4_ref(glm::u64vec4); + }//namespace swizzle }//namespace gtc }//namespace glm diff --git a/glm/gtc/swizzle.inl b/glm/gtc/swizzle.inl index 9a163764..8d9c15c4 100644 --- a/glm/gtc/swizzle.inl +++ b/glm/gtc/swizzle.inl @@ -25,10 +25,10 @@ inline T swizzle return v[x]; } -template +template class vecType> inline detail::tvec2 swizzle ( - detail::tvec4 const & v, + vecType const & v, comp x, comp y ) { @@ -37,10 +37,10 @@ inline detail::tvec2 swizzle v[y]); } -template +template class vecType> inline detail::tvec3 swizzle ( - detail::tvec4 const & v, + vecType const & v, comp x, comp y, comp z ) { @@ -50,89 +50,16 @@ inline detail::tvec3 swizzle v[z]); } -template +template class vecType> inline detail::tvec4 swizzle ( - detail::tvec4 const & v, + vecType const & v, comp x, comp y, comp z, comp w ) { return detail::tvec4(v[x], v[y], v[z], v[w]); } -template -inline int swizzle -( - detail::tvec4 const & v -) -{ - return v[X]; -} - -template -inline float swizzle -( - detail::tvec4 const & v -) -{ - return v[X]; -} - -template -inline detail::tvec2 swizzle -( - detail::tvec4 const & v -) -{ - return detail::tvec2(v[X], v[Y]); -} - -template -inline detail::tvec2 swizzle -( - detail::tvec4 const & v -) -{ - return detail::tvec2(v[X], v[Y]); -} - -template -inline detail::tvec3 swizzle -( - detail::tvec4 const & v -) -{ - return detail::tvec3(v[X], v[Y], v[Z]); -} - -template -inline detail::tvec3 swizzle -( - detail::tvec4 const & v -) -{ - return detail::tvec3(v[X], v[Y], v[Z]); -} - -template -inline detail::tvec4 swizzle -( - detail::tvec4 const & v -) -{ - return detail::tvec4(v[X], v[Y], v[Z], v[W]); -} - -template -inline detail::tvec4 swizzle -( - detail::tvec4 const & v -) -{ - return detail::tvec4(v[X], v[Y], v[Z], v[W]); -} - - template inline T& swizzle ( @@ -172,7 +99,7 @@ inline detail::tref4 swizzle { return detail::tref4(v[x], v[y], v[z], v[w]); } - +/* template inline float& swizzle ( @@ -244,7 +171,7 @@ inline detail::tref4 swizzle { return detail::tref4(v[x], v[y], v[z], v[w]); } - +*/ }//namespace swizzle }//namespace gtc }//namespace glm diff --git a/test/gtc/gtc-swizzle.cpp b/test/gtc/gtc-swizzle.cpp index cae7c61b..d79ba8f5 100644 --- a/test/gtc/gtc-swizzle.cpp +++ b/test/gtc/gtc-swizzle.cpp @@ -38,7 +38,7 @@ int test_swizzle_vec4_ref_dynamic() glm::ivec4 A(0, 1, 2, 3); int B(2); glm::swizzle(A, glm::Z) = B; - assert(A.x == B.x && A.y == B.y); + assert(A.x == B); } return 0; @@ -71,7 +71,7 @@ int test_swizzle_vec4_ref_static() glm::ivec4 A(0, 1, 2, 3); int B(2); glm::swizzle(A) = B; - assert(A.x == B.x && A.y == B.y); + assert(A.x == B); } return 0; @@ -84,12 +84,11 @@ int test_swizzle_vec4_const_dynamic() assert(glm::all(glm::equal(A, B))); glm::ivec3 C = glm::swizzle(A, glm::W, glm::Y, glm::Z); - assert(glm::all(glm::equal(A, C))); + assert(glm::all(glm::equal(glm::ivec3(A), C))); glm::ivec2 D = glm::swizzle(A, glm::W, glm::X); - assert(glm::all(glm::equal(A, D))); + assert(glm::all(glm::equal(glm::ivec2(A), D))); - assert(D.x == A.w && D.y == A.x); int E = glm::swizzle(A, glm::Q); assert(E == A.q); @@ -104,10 +103,10 @@ int test_swizzle_vec4_const_static() assert(glm::all(glm::equal(A, B))); glm::ivec3 C = glm::swizzle(A); - assert(glm::all(glm::equal(A, C))); + assert(glm::all(glm::equal(glm::ivec3(A), C))); glm::ivec2 D = glm::swizzle(A); - assert(glm::all(glm::equal(A, D))); + assert(glm::all(glm::equal(glm::ivec2(A), D))); int E = glm::swizzle(A); assert(E == A.q);