Browse Source

Updated swizzle implementation

Christophe Riccio 15 years ago
parent
commit
866db89305
2 changed files with 25 additions and 20 deletions
  1. 11 12
      glm/gtx/simd_vec4.hpp
  2. 14 8
      glm/gtx/simd_vec4.inl

+ 11 - 12
glm/gtx/simd_vec4.hpp

@@ -59,11 +59,6 @@ namespace glm
 				float const & z, 
 				float const & z, 
 				float const & w);
 				float const & w);
 
 
-			////////////////////////////////////////
-			//// Swizzle constructors
-
-			//fvec4SIMD(ref4<float> const & r);
-
 			////////////////////////////////////////
 			////////////////////////////////////////
 			//// Convertion vector constructors
 			//// Convertion vector constructors
 
 
@@ -95,12 +90,16 @@ namespace glm
 			//////////////////////////////////////
 			//////////////////////////////////////
 			// Swizzle operators
 			// Swizzle operators
 
 
-			//float swizzle(comp X) const;
-			//vec2 const swizzle(comp X, comp Y) const;
-			//vec3 const swizzle(comp X, comp Y, comp Z) const;
-			//fvec4SIMD const swizzle(comp X, comp Y, comp Z, comp W) const;
-			//fvec4SIMD const swizzle(int X, int Y, int Z, int W) const;
-			//ref4<float> swizzle(comp X, comp Y, comp Z, comp W);
+			template <comp A, comp B, comp C, comp D>
+			fvec4SIMD& swizzle();
+			template <comp A, comp B, comp C, comp D>
+			fvec4SIMD swizzle() const;
+			template <comp A, comp B, comp C>
+			fvec4SIMD swizzle() const;
+			template <comp A, comp B>
+			fvec4SIMD swizzle() const;
+			template <comp A>
+			fvec4SIMD swizzle() const;
 		};
 		};
 
 
 	}//namespace detail
 	}//namespace detail
@@ -109,7 +108,7 @@ namespace glm
 	//! GLM_GTX_simd_vec4 extension: SIMD implementation of vec4 type.
 	//! GLM_GTX_simd_vec4 extension: SIMD implementation of vec4 type.
 	namespace simd_vec4
 	namespace simd_vec4
 	{
 	{
-		typedef detail::fvec4SIMD vec4SIMD;
+		typedef detail::fvec4SIMD simd_vec4;
 
 
 	}//namespace simd_vec4
 	}//namespace simd_vec4
 	}//namespace gtx
 	}//namespace gtx

+ 14 - 8
glm/gtx/simd_vec4.inl

@@ -11,8 +11,6 @@ namespace glm
 {
 {
 	namespace detail
 	namespace detail
 	{
 	{
-		//__m128 fvec4SIMD::one = _mm_set_ps1(1.f);
-
 		//////////////////////////////////////
 		//////////////////////////////////////
 		// Implicit basic constructors
 		// Implicit basic constructors
 
 
@@ -155,13 +153,21 @@ namespace glm
 		//////////////////////////////////////
 		//////////////////////////////////////
 		// Swizzle operators
 		// Swizzle operators
 
 
-		//inline fvec4SIMD const fvec4SIMD::swizzle(int d, int c, int b, int a) const
-		//{
-		//	int const Mask = ((d << 6) | (c << 4) | (b << 2) | (a << 0));
+		template <comp a, comp b, comp c, comp d>
+		inline fvec4SIMD fvec4SIMD::swizzle() const
+		{
+			int const Mask = ((int(d) << 6) | (int(c) << 4) | (int(b) << 2) | (int(a) << 0));
+
+			__m128 Data = _mm_shuffle_ps(this->Data, this->Data, Mask);
+			return fvec4SIMD(Data);
+		}
 
 
-		//	__m128 Data = _mm_shuffle_ps(this->Data, this->Data, Mask);
-		//	return fvec4SIMD(Data);
-		//}
+		template <comp a, comp b, comp c, comp d>
+		inline fvec4SIMD& fvec4SIMD::swizzle()
+		{
+			this->Data = _mm_shuffle_ps(this->Data, this->Data, (((int(d) << 6) | (int(c) << 4) | (int(b) << 2) | (int(a) << 0))));
+			return *this;
+		}
 
 
 		// operator+
 		// operator+
 		inline fvec4SIMD operator+ (fvec4SIMD const & v, float s)
 		inline fvec4SIMD operator+ (fvec4SIMD const & v, float s)