From 21c1fa14a77ed11591726d8fa4a26915ffcc773a Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 14 Jan 2011 19:35:39 +0000 Subject: [PATCH] Updated GLM_GTC_swizzle extension + tests --- glm/gtc/swizzle.hpp | 7 +++- glm/gtc/swizzle.inl | 88 ++++++++++++++++++++++++++++++++++++++-- test/gtc/CMakeLists.txt | 1 + test/gtc/gtc-swizzle.cpp | 46 +++++++++++++++++++++ 4 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 test/gtc/gtc-swizzle.cpp diff --git a/glm/gtc/swizzle.hpp b/glm/gtc/swizzle.hpp index e71210eb..7af4b4f6 100644 --- a/glm/gtc/swizzle.hpp +++ b/glm/gtc/swizzle.hpp @@ -42,10 +42,15 @@ namespace glm comp x, comp y, comp z); template - inline detail::tref4 swizzle( + detail::tvec4 swizzle( detail::tvec4 const & v, comp x, comp y, comp z, comp w); + template + detail::tref4 swizzle( + detail::tvec4 & v, + comp x, comp y, comp z, comp w); + }//namespace swizzle }//namespace gtc }//namespace glm diff --git a/glm/gtc/swizzle.inl b/glm/gtc/swizzle.inl index b072df20..79519df1 100644 --- a/glm/gtc/swizzle.inl +++ b/glm/gtc/swizzle.inl @@ -1,6 +1,6 @@ namespace glm{ namespace gtc{ -namespace glm_gtc_swizzle +namespace swizzle { template inline T swizzle @@ -38,15 +38,97 @@ namespace glm_gtc_swizzle } template - inline detail::tref4 swizzle + inline detail::tvec4 swizzle ( detail::tvec4 const & v, comp x, comp y, comp z, comp w ) + { + return detail::tvec4(v[x], v[y], v[z], v[w]); + } + + template + inline detail::tref4 swizzle + ( + detail::tvec4 & v, + comp x, comp y, comp z, comp w + ) { return detail::tref4(v[x], v[y], v[z], v[w]); } -}//namespace glm_gtc_swizzle + 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]); + } + +}//namespace swizzle }//namespace gtc }//namespace glm diff --git a/test/gtc/CMakeLists.txt b/test/gtc/CMakeLists.txt index e69de29b..3cbcd7fa 100644 --- a/test/gtc/CMakeLists.txt +++ b/test/gtc/CMakeLists.txt @@ -0,0 +1 @@ +glmCreateTestGTC(gtc-swizzle) \ No newline at end of file diff --git a/test/gtc/gtc-swizzle.cpp b/test/gtc/gtc-swizzle.cpp new file mode 100644 index 00000000..c2d51d99 --- /dev/null +++ b/test/gtc/gtc-swizzle.cpp @@ -0,0 +1,46 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////// +// OpenGL Mathematics Copyright (c) 2005 - 2010 G-Truc Creation (www.g-truc.net) +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Created : 2010-09-16 +// Updated : 2010-09-16 +// Licence : This source is under MIT licence +// File : test/gtx/simd-mat4.cpp +/////////////////////////////////////////////////////////////////////////////////////////////////// + +#define GLM_INSTRUCTION_SET GLM_PLATFORM_SSE3 | GLM_PLATFORM_SSE2 +#include +#include + +int test_swizzle_vec4_dynamic() +{ + glm::ivec4 A(0, 1, 2, 3); + glm::ivec4 B = glm::swizzle(A, glm::B, glm::G, glm::R, glm::A); + glm::ivec3 C = glm::swizzle(A, glm::W, glm::Y, glm::Z); + glm::ivec2 D = glm::swizzle(A, glm::W, glm::X); + assert(D.x == A.w && D.y == A.x); + int E = glm::swizzle(A, glm::Q); + assert(E == A.q); + + return 0; +} + +int test_swizzle_vec4_static() +{ + glm::ivec4 A(0, 1, 2, 3); + glm::ivec4 B = glm::swizzle(A); + glm::ivec3 C = glm::swizzle(A); + glm::ivec2 D = glm::swizzle(A); + int E = glm::swizzle(A); + assert(E == A.q); + + return 0; +} + +int main(int argc, void* argv[]) +{ + int Failed = 0; + Failed += test_swizzle_vec4_dynamic(); + Failed += test_swizzle_vec4_static(); + + return Failed; +}