Browse Source

Updated GLM_GTC_swizzle extension + tests

Christophe Riccio 15 years ago
parent
commit
21c1fa14a7
4 changed files with 138 additions and 4 deletions
  1. 6 1
      glm/gtc/swizzle.hpp
  2. 85 3
      glm/gtc/swizzle.inl
  3. 1 0
      test/gtc/CMakeLists.txt
  4. 46 0
      test/gtc/gtc-swizzle.cpp

+ 6 - 1
glm/gtc/swizzle.hpp

@@ -42,10 +42,15 @@ namespace glm
 			comp x, comp y, comp z);
 			comp x, comp y, comp z);
 
 
 		template <typename T>
 		template <typename T>
-		inline detail::tref4<T> swizzle(
+		detail::tvec4<T> swizzle(
 			detail::tvec4<T> const & v,
 			detail::tvec4<T> const & v,
 			comp x, comp y, comp z, comp w);
 			comp x, comp y, comp z, comp w);
 
 
+		template <typename T>
+		detail::tref4<T> swizzle(
+			detail::tvec4<T> & v,
+			comp x, comp y, comp z, comp w);
+
 	}//namespace swizzle
 	}//namespace swizzle
 	}//namespace gtc
 	}//namespace gtc
 }//namespace glm
 }//namespace glm

+ 85 - 3
glm/gtc/swizzle.inl

@@ -1,6 +1,6 @@
 namespace glm{
 namespace glm{
 namespace gtc{
 namespace gtc{
-namespace glm_gtc_swizzle
+namespace swizzle
 {
 {
 	template <typename T>
 	template <typename T>
 	inline T swizzle
 	inline T swizzle
@@ -38,15 +38,97 @@ namespace glm_gtc_swizzle
 	}
 	}
 
 
 	template <typename T>
 	template <typename T>
-	inline detail::tref4<T> swizzle
+	inline detail::tvec4<T> swizzle
 	(
 	(
 		detail::tvec4<T> const & v,
 		detail::tvec4<T> const & v,
 		comp x, comp y, comp z, comp w
 		comp x, comp y, comp z, comp w
 	)
 	)
+	{
+		return detail::tvec4<T>(v[x], v[y],	v[z], v[w]);
+	}
+
+	template <typename T>
+	inline detail::tref4<T> swizzle
+	(
+		detail::tvec4<T> & v,
+		comp x, comp y, comp z, comp w
+	)
 	{
 	{
 		return detail::tref4<T>(v[x], v[y],	v[z], v[w]);
 		return detail::tref4<T>(v[x], v[y],	v[z], v[w]);
 	}
 	}
 
 
-}//namespace glm_gtc_swizzle
+	template <comp X>
+	inline int swizzle
+	(
+		detail::tvec4<int> const & v
+	)
+	{
+		return v[X];
+	}
+
+	template <comp X>
+	inline float swizzle
+	(
+		detail::tvec4<float> const & v
+	)
+	{
+		return v[X];
+	}
+
+	template <comp X, comp Y>
+	inline detail::tvec2<int> swizzle
+	(
+		detail::tvec4<int> const & v
+	)
+	{
+		return detail::tvec2<int>(v[X], v[Y]);
+	}
+
+	template <comp X, comp Y>
+	inline detail::tvec2<float> swizzle
+	(
+		detail::tvec4<float> const & v
+	)
+	{
+		return detail::tvec2<float>(v[X], v[Y]);
+	}
+
+	template <comp X, comp Y, comp Z>
+	inline detail::tvec3<int> swizzle
+	(
+		detail::tvec4<int> const & v
+	)
+	{
+		return detail::tvec3<int>(v[X], v[Y], v[Z]);
+	}
+
+	template <comp X, comp Y, comp Z>
+	inline detail::tvec3<float> swizzle
+	(
+		detail::tvec4<float> const & v
+	)
+	{
+		return detail::tvec3<float>(v[X], v[Y],	v[Z]);
+	}
+
+	template <comp X, comp Y, comp Z, comp W>
+	inline detail::tvec4<int> swizzle
+	(
+		detail::tvec4<int> const & v
+	)
+	{
+		return detail::tvec4<int>(v[X], v[Y], v[Z], v[W]);
+	}
+
+	template <comp X, comp Y, comp Z, comp W>
+	inline detail::tvec4<float> swizzle
+	(
+		detail::tvec4<float> const & v
+	)
+	{
+		return detail::tvec4<float>(v[X], v[Y],	v[Z], v[W]);
+	}
+
+}//namespace swizzle
 }//namespace gtc
 }//namespace gtc
 }//namespace glm
 }//namespace glm

+ 1 - 0
test/gtc/CMakeLists.txt

@@ -0,0 +1 @@
+glmCreateTestGTC(gtc-swizzle)

+ 46 - 0
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 <glm/glm.hpp>
+#include <glm/gtc/swizzle.hpp>
+
+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<glm::B, glm::G, glm::R, glm::A>(A);
+	glm::ivec3 C = glm::swizzle<glm::W, glm::Y, glm::Z>(A);
+	glm::ivec2 D = glm::swizzle<glm::W, glm::X>(A);
+	int E = glm::swizzle<glm::Q>(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;
+}