Browse Source

Added log2 to GTC_integer

Christophe Riccio 11 years ago
parent
commit
4f4763600f
4 changed files with 20 additions and 25 deletions
  1. 6 3
      glm/gtc/integer.hpp
  2. 13 3
      glm/gtc/integer.inl
  3. 1 5
      glm/gtx/integer.hpp
  4. 0 14
      glm/gtx/integer.inl

+ 6 - 3
glm/gtc/integer.hpp

@@ -41,8 +41,8 @@
 // Dependencies
 // Dependencies
 #include "../detail/setup.hpp"
 #include "../detail/setup.hpp"
 #include "../detail/precision.hpp"
 #include "../detail/precision.hpp"
-#include "../detail/type_int.hpp"
-#include "../detail/_vectorize.hpp"
+#include "../detail/func_integer.hpp"
+#include "../detail/func_exponential.hpp"
 #include <limits>
 #include <limits>
 
 
 #if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
 #if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
@@ -54,7 +54,10 @@ namespace glm
 	/// @addtogroup gtc_integer
 	/// @addtogroup gtc_integer
 	/// @{
 	/// @{
 
 
-
+	/// Returns the log2 of x. Can be reliably using to compute mipmap count from the texture size.
+	/// From GLM_GTC_integer extension.
+	template <typename genIUType>
+	GLM_FUNC_DECL genIUType log2(genIUType x);
 
 
 	/// @}
 	/// @}
 } //namespace glm
 } //namespace glm

+ 13 - 3
glm/gtc/integer.inl

@@ -29,9 +29,19 @@
 namespace glm{
 namespace glm{
 namespace detail
 namespace detail
 {
 {
+	GLM_FUNC_QUALIFIER unsigned int nlz(unsigned int x) 
+	{
+		return 31u - findMSB(x);
+	}
 
 
+	template <>
+	struct compute_log2<false>
+	{
+		template <typename T>
+		GLM_FUNC_QUALIFIER T operator() (T const & Value) const
+		{
+			return Value <= static_cast<T>(1) ? T(0) : T(32) - nlz(Value - T(1));
+		}
+	};
 }//namespace detail
 }//namespace detail
-
-
-
 }//namespace glm
 }//namespace glm

+ 1 - 5
glm/gtx/integer.hpp

@@ -39,6 +39,7 @@
 
 
 // Dependency:
 // Dependency:
 #include "../glm.hpp"
 #include "../glm.hpp"
+#include "../gtc/integer.hpp"
 
 
 #if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
 #if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
 #	pragma message("GLM: GLM_GTX_integer extension included")
 #	pragma message("GLM: GLM_GTX_integer extension included")
@@ -57,11 +58,6 @@ namespace glm
 	//! From GLM_GTX_integer extension.
 	//! From GLM_GTX_integer extension.
 	GLM_FUNC_DECL int sqrt(int x);
 	GLM_FUNC_DECL int sqrt(int x);
 
 
-	//! Returns the log2 of x. Can be reliably using to compute mipmap count from the texture size.
-	//! From GLM_GTX_integer extension.
-	template <typename genIUType>
-	GLM_FUNC_DECL genIUType log2(genIUType x);
-
 	//! Returns the floor log2 of x.
 	//! Returns the floor log2 of x.
 	//! From GLM_GTX_integer extension.
 	//! From GLM_GTX_integer extension.
 	GLM_FUNC_DECL unsigned int floor_log2(unsigned int x);
 	GLM_FUNC_DECL unsigned int floor_log2(unsigned int x);

+ 0 - 14
glm/gtx/integer.inl

@@ -53,20 +53,6 @@ namespace detail
 		x += (x >> 16);
 		x += (x >> 16);
 		return(x & 0x0000003f);
 		return(x & 0x0000003f);
 	}
 	}
-
-	template <>
-	struct compute_log2<false>
-	{
-		template <typename T>
-		GLM_FUNC_QUALIFIER T operator() (T const & Value) const
-		{
-#if(GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_GCC))
-			return Value <= static_cast<T>(1) ? T(0) : T(32) - nlz(Value - T(1));
-#else
-			return T(32) - nlz(Value - T(1));
-#endif
-		}
-	};
 }//namespace detail
 }//namespace detail
 
 
 	// Henry Gordon Dietz: http://aggregate.org/MAGIC/
 	// Henry Gordon Dietz: http://aggregate.org/MAGIC/