Browse Source

Replace function instanciations with macros by templates

Christophe Riccio 11 years ago
parent
commit
4fc68ffe49

+ 24 - 21
glm/detail/func_integer.hpp

@@ -38,6 +38,9 @@
 #pragma once
 
 #include "setup.hpp"
+#include "precision.hpp"
+#include "func_common.hpp"
+#include "func_vector_relational.hpp"
 
 namespace glm
 {
@@ -113,13 +116,13 @@ namespace glm
 	/// offset and bits is greater than the number of bits used
 	/// to store the operand.
 	///
-	/// @tparam genIUType Signed or unsigned integer scalar or vector types.
+	/// @tparam T Signed or unsigned integer scalar or vector types.
 	/// 
 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldExtract.xml">GLSL bitfieldExtract man page</a>
 	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
-	template <typename genIUType>
-	GLM_FUNC_DECL genIUType bitfieldExtract(
-		genIUType const & Value,
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_DECL vecType<T, P> bitfieldExtract(
+		vecType<T, P> const & Value,
 		int const & Offset,
 		int const & Bits);
 
@@ -133,14 +136,14 @@ namespace glm
 	/// offset and bits is greater than the number of bits used to
 	/// store the operand.
 	///
-	/// @tparam genIUType Signed or unsigned integer scalar or vector types.
+	/// @tparam T Signed or unsigned integer scalar or vector types.
 	///
 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldInsert.xml">GLSL bitfieldInsert man page</a>
 	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
-	template <typename genIUType>
-	GLM_FUNC_DECL genIUType bitfieldInsert(
-		genIUType const & Base,
-		genIUType const & Insert,
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_DECL vecType<T, P> bitfieldInsert(
+		vecType<T, P> const & Base,
+		vecType<T, P> const & Insert,
 		int const & Offset,
 		int const & Bits);
 
@@ -148,50 +151,50 @@ namespace glm
 	/// The bit numbered n of the result will be taken from bit (bits - 1) - n of value, 
 	/// where bits is the total number of bits used to represent value.
 	///
-	/// @tparam genIUType Signed or unsigned integer scalar or vector types.
+	/// @tparam T Signed or unsigned integer scalar or vector types.
 	///
 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldReverse.xml">GLSL bitfieldReverse man page</a>
 	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
-	template <typename genIUType>
-	GLM_FUNC_DECL genIUType bitfieldReverse(genIUType const & Value);
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_DECL vecType<T, P> bitfieldReverse(vecType<T, P> const & v);
 		
 	/// Returns the number of bits set to 1 in the binary representation of value.
 	///
-	/// @tparam genIUType Signed or unsigned integer scalar or vector types.
+	/// @tparam T Signed or unsigned integer scalar or vector types.
 	///
 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitCount.xml">GLSL bitCount man page</a>
 	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
 	///
 	/// @todo Clarify the declaration to specify that scalars are suported.
-	template <typename T, template <typename> class genIUType>
-	GLM_FUNC_DECL typename genIUType<T>::signed_type bitCount(genIUType<T> const & Value);
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_DECL vecType<int, P> bitCount(vecType<T, P> const & v);
 
 	/// Returns the bit number of the least significant bit set to
 	/// 1 in the binary representation of value. 
 	/// If value is zero, -1 will be returned.
 	///
-	/// @tparam genIUType Signed or unsigned integer scalar or vector types.
+	/// @tparam T Signed or unsigned integer scalar or vector types.
 	///
 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findLSB.xml">GLSL findLSB man page</a>
 	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
 	///
 	/// @todo Clarify the declaration to specify that scalars are suported.
-	template <typename T, template <typename> class genIUType>
-	GLM_FUNC_DECL typename genIUType<T>::signed_type findLSB(genIUType<T> const & Value);
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_DECL vecType<int, P> findLSB(vecType<T, P> const & v);
 
 	/// Returns the bit number of the most significant bit in the binary representation of value.
 	/// For positive integers, the result will be the bit number of the most significant bit set to 1. 
 	/// For negative integers, the result will be the bit number of the most significant
 	/// bit set to 0. For a value of zero or negative one, -1 will be returned.
 	///
-	/// @tparam genIUType Signed or unsigned integer scalar or vector types.
+	/// @tparam T Signed or unsigned integer scalar or vector types.
 	///
 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findMSB.xml">GLSL findMSB man page</a>
 	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
 	///
 	/// @todo Clarify the declaration to specify that scalars are suported.
-	template <typename T, template <typename> class genIUType>
-	GLM_FUNC_DECL typename genIUType<T>::signed_type findMSB(genIUType<T> const & Value);
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_DECL vecType<int, P> findMSB(vecType<T, P> const & v);
 
 	/// @}
 }//namespace glm

+ 43 - 129
glm/detail/func_integer.inl

@@ -410,78 +410,57 @@ namespace glm
 	}
 
 	// bitfieldReverse
-	template <typename genIUType>
-	GLM_FUNC_QUALIFIER genIUType bitfieldReverse(genIUType const & Value)
+	template <typename T>
+	GLM_FUNC_QUALIFIER T bitfieldReverse(T v)
 	{
-		GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'bitfieldReverse' only accept integer values");
-
-		genIUType Out = 0;
-		std::size_t BitSize = sizeof(genIUType) * 8;
-		for(std::size_t i = 0; i < BitSize; ++i)
-			if(Value & (genIUType(1) << i))
-				Out |= genIUType(1) << (BitSize - 1 - i);
-		return Out;
-	}	
+		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldReverse' only accept integer values");
 
-	VECTORIZE_VEC(bitfieldReverse)
+		return bitfieldReverse(tvec1<T>(v)).x;
+	}
 
-	// bitCount
-	template <typename genIUType>
-	GLM_FUNC_QUALIFIER int bitCount(genIUType const & Value)
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_QUALIFIER vecType<T, P> bitfieldReverse(vecType<T, P> const & v)
 	{
-		GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'bitCount' only accept integer values");
+		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldReverse' only accept integer values");
 
-		int Count = 0;
-		for(std::size_t i = 0; i < sizeof(genIUType) * std::size_t(8); ++i)
+		vecType<T, P> Result(0);
+		vecType<T, P> const Null(0);
+		T const BitSize = static_cast<T>(sizeof(T) * 8);
+		for(T i = 0; i < BitSize; ++i)
 		{
-			if(Value & (1 << i))
-				++Count;
+			vecType<T, P> const BitSet(v & (static_cast<T>(1) << i));
+			vecType<T, P> const BitFirst(BitSet >> i);
+			Result |= BitFirst << (BitSize - 1 - i);
 		}
-		return Count;
+		return Result;
 	}
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec2<int, P> bitCount
-	(
-		tvec2<T, P> const & value
-	)
+	// bitCount
+	template <typename genIUType>
+	GLM_FUNC_QUALIFIER int bitCount(genIUType x)
 	{
-		return tvec2<int, P>(
-			bitCount(value[0]),
-			bitCount(value[1]));
-	}
+		GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'bitCount' only accept integer values");
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec3<int, P> bitCount
-	(
-		tvec3<T, P> const & value
-	)
-	{
-		return tvec3<int, P>(
-			bitCount(value[0]),
-			bitCount(value[1]),
-			bitCount(value[2]));
+		return bitCount(tvec1(x)).x;
 	}
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec4<int, P> bitCount
-	(
-		tvec4<T, P> const & value
-	)
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_QUALIFIER vecType<int, P> bitCount(vecType<T, P> const & v)
 	{
-		return tvec4<int, P>(
-			bitCount(value[0]),
-			bitCount(value[1]),
-			bitCount(value[2]),
-			bitCount(value[3]));
+		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitCount' only accept integer values");
+
+		vecType<int, P> Count(0);
+		for(std::size_t i = 0; i < sizeof(T) * std::size_t(8); ++i)
+		{
+			if(v & (static_cast<T>(1) << i))
+				++Count;
+		}
+		return Count;
 	}
 
 	// findLSB
 	template <typename genIUType>
-	GLM_FUNC_QUALIFIER int findLSB
-	(
-		genIUType const & Value
-	)
+	GLM_FUNC_QUALIFIER int findLSB(genIUType Value)
 	{
 		GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findLSB' only accept integer values");
 		if(Value == 0)
@@ -492,50 +471,19 @@ namespace glm
 		return Bit;
 	}
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec2<int, P> findLSB
-	(
-		tvec2<T, P> const & value
-	)
-	{
-		return tvec2<int, P>(
-			findLSB(value[0]),
-			findLSB(value[1]));
-	}
-
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec3<int, P> findLSB
-	(
-		tvec3<T, P> const & value
-	)
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_QUALIFIER vecType<int, P> findLSB(vecType<T, P> const & x)
 	{
-		return tvec3<int, P>(
-			findLSB(value[0]),
-			findLSB(value[1]),
-			findLSB(value[2]));
-	}
+		GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findLSB' only accept integer values");
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec4<int, P> findLSB
-	(
-		tvec4<T, P> const & value
-	)
-	{
-		return tvec4<int, P>(
-			findLSB(value[0]),
-			findLSB(value[1]),
-			findLSB(value[2]),
-			findLSB(value[3]));
+		return detail::functor1<int, T, P, vecType>::call(findLSB, x);
 	}
 
 	// findMSB
-#if((GLM_ARCH != GLM_ARCH_PURE) && (GLM_COMPILER & GLM_COMPILER_VC))
+#if (GLM_ARCH != GLM_ARCH_PURE) && (GLM_COMPILER & GLM_COMPILER_VC)
 
 	template <typename genIUType>
-	GLM_FUNC_QUALIFIER int findMSB
-	(
-		genIUType const & Value
-	)
+	GLM_FUNC_QUALIFIER int findMSB(genIUType Value)
 	{
 		GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values");
 		if(Value == 0)
@@ -585,14 +533,10 @@ namespace glm
 			Mmi = _mm_and_si128(Mmi, One);
 		}
 		return Bit;
-
 */
 
 	template <typename genIUType>
-	GLM_FUNC_QUALIFIER int findMSB
-	(
-		genIUType const & Value
-	)
+	GLM_FUNC_QUALIFIER int findMSB(genIUType Value)
 	{
 		GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values");
 		
@@ -616,39 +560,9 @@ namespace glm
 	}
 #endif//(GLM_COMPILER)
 
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec2<int, P> findMSB
-	(
-		tvec2<T, P> const & value
-	)
-	{
-		return tvec2<int, P>(
-			findMSB(value[0]),
-			findMSB(value[1]));
-	}
-
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec3<int, P> findMSB
-	(
-		tvec3<T, P> const & value
-	)
-	{
-		return tvec3<int, P>(
-			findMSB(value[0]),
-			findMSB(value[1]),
-			findMSB(value[2]));
-	}
-
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec4<int, P> findMSB
-	(
-		tvec4<T, P> const & value
-	)
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_QUALIFIER vecType<int, P> findMSB(vecType<T, P> const & x)
 	{
-		return tvec4<int, P>(
-			findMSB(value[0]),
-			findMSB(value[1]),
-			findMSB(value[2]),
-			findMSB(value[3]));
+		return detail::functor1<int, T, P, vecType>::call(findMSB, x);
 	}
 }//namespace glm

+ 1 - 1
glm/detail/type_mat2x2.hpp

@@ -36,7 +36,7 @@
 
 namespace glm
 {
-	template <typename T, precision P>
+	template <typename T, precision P = defaultp>
 	struct tmat2x2
 	{
 		typedef T value_type;

+ 1 - 1
glm/detail/type_mat2x3.hpp

@@ -37,7 +37,7 @@
 
 namespace glm
 {
-	template <typename T, precision P>
+	template <typename T, precision P = defaultp>
 	struct tmat2x3
 	{
 		typedef T value_type;

+ 1 - 1
glm/detail/type_mat2x4.hpp

@@ -37,7 +37,7 @@
 
 namespace glm
 {
-	template <typename T, precision P>
+	template <typename T, precision P = defaultp>
 	struct tmat2x4
 	{
 		typedef T value_type;

+ 1 - 1
glm/detail/type_mat3x2.hpp

@@ -37,7 +37,7 @@
 
 namespace glm
 {
-	template <typename T, precision P>
+	template <typename T, precision P = defaultp>
 	struct tmat3x2
 	{
 		typedef T value_type;

+ 1 - 1
glm/detail/type_mat3x3.hpp

@@ -36,7 +36,7 @@
 
 namespace glm
 {
-	template <typename T, precision P>
+	template <typename T, precision P = defaultp>
 	struct tmat3x3
 	{
 		typedef T value_type;

+ 1 - 1
glm/detail/type_mat3x4.hpp

@@ -37,7 +37,7 @@
 
 namespace glm
 {
-	template <typename T, precision P>
+	template <typename T, precision P = defaultp>
 	struct tmat3x4
 	{
 		typedef T value_type;

+ 1 - 1
glm/detail/type_mat4x2.hpp

@@ -37,7 +37,7 @@
 
 namespace glm
 {
-	template <typename T, precision P>
+	template <typename T, precision P = defaultp>
 	struct tmat4x2
 	{
 		typedef T value_type;

+ 1 - 1
glm/detail/type_mat4x3.hpp

@@ -37,7 +37,7 @@
 
 namespace glm
 {
-	template <typename T, precision P>
+	template <typename T, precision P = defaultp>
 	struct tmat4x3
 	{
 		typedef T value_type;

+ 1 - 1
glm/detail/type_mat4x4.hpp

@@ -36,7 +36,7 @@
 
 namespace glm
 {
-	template <typename T, precision P>
+	template <typename T, precision P = defaultp>
 	struct tmat4x4
 	{
 		typedef T value_type;

+ 1 - 1
glm/detail/type_vec1.hpp

@@ -41,7 +41,7 @@
 
 namespace glm
 {
-	template <typename T, precision P>
+	template <typename T, precision P = defaultp>
 	struct tvec1
 	{
 		//////////////////////////////////////

+ 1 - 1
glm/detail/type_vec2.hpp

@@ -41,7 +41,7 @@
 
 namespace glm
 {
-	template <typename T, precision P>
+	template <typename T, precision P = defaultp>
 	struct tvec2
 	{
 		//////////////////////////////////////

+ 1 - 1
glm/detail/type_vec3.hpp

@@ -41,7 +41,7 @@
 
 namespace glm
 {
-	template <typename T, precision P>
+	template <typename T, precision P = defaultp>
 	struct tvec3
 	{	
 		//////////////////////////////////////

+ 1 - 1
glm/detail/type_vec4.hpp

@@ -66,7 +66,7 @@ namespace detail
 #	endif
 }//namespace detail
 
-	template <typename T, precision P>
+	template <typename T, precision P = defaultp>
 	struct tvec4
 	{
 		//////////////////////////////////////

+ 1 - 0
test/gtx/gtx_integer.cpp

@@ -70,3 +70,4 @@ int main()
 
 	return Error;
 }
+