Browse Source

Added GTC_integer, deprecated GTX_bit

Christophe Riccio 11 years ago
parent
commit
d3b368b65c
8 changed files with 192 additions and 209 deletions
  1. 94 0
      glm/gtc/integer.hpp
  2. 47 0
      glm/gtc/integer.inl
  3. 3 38
      glm/gtx/bit.hpp
  4. 0 155
      glm/gtx/bit.inl
  5. 1 0
      readme.txt
  6. 1 0
      test/gtc/CMakeLists.txt
  7. 46 15
      test/gtc/gtc_integer.cpp
  8. 0 1
      test/gtx/CMakeLists.txt

+ 94 - 0
glm/gtc/integer.hpp

@@ -0,0 +1,94 @@
+///////////////////////////////////////////////////////////////////////////////////
+/// OpenGL Mathematics (glm.g-truc.net)
+///
+/// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
+/// Permission is hereby granted, free of charge, to any person obtaining a copy
+/// of this software and associated documentation files (the "Software"), to deal
+/// in the Software without restriction, including without limitation the rights
+/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+/// copies of the Software, and to permit persons to whom the Software is
+/// furnished to do so, subject to the following conditions:
+/// 
+/// The above copyright notice and this permission notice shall be included in
+/// all copies or substantial portions of the Software.
+/// 
+/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+/// THE SOFTWARE.
+///
+/// @ref gtc_bit
+/// @file glm/gtc/integer.hpp
+/// @date 2014-10-25 / 2014-10-25
+/// @author Christophe Riccio
+///
+/// @see core (dependence)
+/// @see gtc_bitfield (dependence)
+///
+/// @defgroup gtc_integer GLM_GTC_integer
+/// @ingroup gtc
+/// 
+/// @brief Allow to perform bit operations on integer values
+/// 
+/// <glm/gtc/integer.hpp> need to be included to use these functionalities.
+///////////////////////////////////////////////////////////////////////////////////
+
+#pragma once
+
+// Dependencies
+#include "../detail/setup.hpp"
+#include "../detail/precision.hpp"
+#include <limits>
+
+#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
+#	pragma message("GLM: GLM_GTC_integer extension included")
+#endif
+
+namespace glm
+{
+	/// @addtogroup gtc_integer
+	/// @{
+
+	/// Return true if the value is a power of two number.
+	///
+	/// @see gtc_integer
+	template <typename genType>
+	GLM_FUNC_DECL bool isPowerOfTwo(genType Value);
+
+	/// Return true if the value is a power of two number.
+	///
+	/// @see gtc_integer
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_DECL vecType<bool, P> isPowerOfTwo(vecType<T, P> const & value);
+
+	/// Find the highest bit set to 1 in a integer variable and return its value. 
+	///
+	/// @see gtc_integer
+	template <typename genType> 
+	GLM_FUNC_DECL genType highestBitValue(genType const & value);
+
+	/// Return the power of two number which value is just higher the input value.
+	///
+	/// @see gtc_integer
+	template <typename genType> 
+	GLM_FUNC_DECL genType powerOfTwoAbove(genType const & value);
+
+	/// Return the power of two number which value is just lower the input value. 
+	///
+	/// @see gtc_integer
+	template <typename genType> 
+	GLM_FUNC_DECL genType powerOfTwoBelow(genType const & value);
+
+	/// Return the power of two number which value is the closet to the input value. 
+	///
+	/// @see gtc_integer
+	template <typename genType> 
+	GLM_FUNC_DECL genType powerOfTwoNearest(genType const & value);
+
+	/// @}
+} //namespace glm
+
+#include "integer.inl"

+ 47 - 0
glm/gtc/integer.inl

@@ -0,0 +1,47 @@
+///////////////////////////////////////////////////////////////////////////////////
+/// OpenGL Mathematics (glm.g-truc.net)
+///
+/// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
+/// Permission is hereby granted, free of charge, to any person obtaining a copy
+/// of this software and associated documentation files (the "Software"), to deal
+/// in the Software without restriction, including without limitation the rights
+/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+/// copies of the Software, and to permit persons to whom the Software is
+/// furnished to do so, subject to the following conditions:
+/// 
+/// The above copyright notice and this permission notice shall be included in
+/// all copies or substantial portions of the Software.
+/// 
+/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+/// THE SOFTWARE.
+///
+/// @ref gtc_integer
+/// @file glm/gtc/integer.inl
+/// @date 2014-10-25 / 2014-10-25
+/// @author Christophe Riccio
+///////////////////////////////////////////////////////////////////////////////////
+
+namespace glm
+{
+	////////////////
+	// isPowerOfTwo
+
+	template <typename genType>
+	GLM_FUNC_QUALIFIER bool isPowerOfTwo(genType Value)
+	{
+		genType Result = glm::abs(Value);
+		return !(Result & (Result - 1));
+	}
+
+	template <typename T, precision P, template <typename, precision> class vecType>
+	GLM_FUNC_QUALIFIER vecType<bool, P> isPowerOfTwo(vecType<T, P> const & value)
+	{
+		genType Result = glm::abs(Value);
+		return !(Result & (Result - 1));
+	}
+}//namespace glm

+ 3 - 38
glm/gtx/bit.hpp

@@ -39,44 +39,9 @@
 #pragma once
 
 // Dependencies
-#include "../detail/type_int.hpp"
-#include "../detail/setup.hpp"
-#include "../detail/precision.hpp"
 #include "../gtc/bitfield.hpp"
-#include <cstddef>
+#include "../gtc/integer.hpp"
 
-#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
-#	pragma message("GLM: GLM_GTX_bit extension included")
+#if(defined(GLM_MESSAGES))
+#	pragma message("GLM: GLM_GTX_bit extension is deprecated, include GLM_GTC_bitfield and GLM_GTC_integer instead")
 #endif
-
-namespace glm
-{
-	//! Find the highest bit set to 1 in a integer variable and return its value. 
-	/// @see gtx_bit
-	template <typename genType> 
-	GLM_FUNC_DECL genType highestBitValue(genType const & value);
-
-	//! Return true if the value is a power of two number. 
-	/// @see gtx_bit
-	template <typename genType> 
-	GLM_FUNC_DECL bool isPowerOfTwo(genType const & value);
-
-	//! Return the power of two number which value is just higher the input value.
-	/// @see gtx_bit
-	template <typename genType> 
-	GLM_FUNC_DECL genType powerOfTwoAbove(genType const & value);
-
-	//! Return the power of two number which value is just lower the input value. 
-	/// @see gtx_bit
-	template <typename genType> 
-	GLM_FUNC_DECL genType powerOfTwoBelow(genType const & value);
-
-	//! Return the power of two number which value is the closet to the input value. 
-	/// @see gtx_bit
-	template <typename genType> 
-	GLM_FUNC_DECL genType powerOfTwoNearest(genType const & value);
-
-	/// @}
-} //namespace glm
-
-#include "bit.inl"

+ 0 - 155
glm/gtx/bit.inl

@@ -1,155 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// Created : 2007-03-14
-// Updated : 2013-12-25
-// Licence : This source is under MIT License
-// File    : glm/gtx/bit.inl
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-#include "../detail/_vectorize.hpp"
-#include <limits>
-
-namespace glm
-{
-	// highestBitValue
-	template <typename genType>
-	GLM_FUNC_QUALIFIER genType highestBitValue
-	(
-		genType const & value
-	)
-	{
-		genType tmp = value;
-		genType result = genType(0);
-		while(tmp)
-		{
-			result = (tmp & (~tmp + 1)); // grab lowest bit
-			tmp &= ~result; // clear lowest bit
-		}
-		return result;
-	}
-
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec2<int, P> highestBitValue
-	(
-		tvec2<T, P> const & value
-	)
-	{
-		return tvec2<int, P>(
-			highestBitValue(value[0]),
-			highestBitValue(value[1]));
-	}
-
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec3<int, P> highestBitValue
-	(
-		tvec3<T, P> const & value
-	)
-	{
-		return tvec3<int, P>(
-			highestBitValue(value[0]),
-			highestBitValue(value[1]),
-			highestBitValue(value[2]));
-	}
-
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec4<int, P> highestBitValue
-	(
-		tvec4<T, P> const & value
-	)
-	{
-		return tvec4<int, P>(
-			highestBitValue(value[0]),
-			highestBitValue(value[1]),
-			highestBitValue(value[2]),
-			highestBitValue(value[3]));
-	}
-
-	// isPowerOfTwo
-	template <typename genType>
-	GLM_FUNC_QUALIFIER bool isPowerOfTwo(genType const & Value)
-	{
-		//detail::If<std::numeric_limits<genType>::is_signed>::apply(abs, Value);
-		//return !(Value & (Value - 1));
-
-		// For old complier?
-		genType Result = Value;
-		if(std::numeric_limits<genType>::is_signed)
-			Result = abs(Result);
-		return !(Result & (Result - 1));
-	}
-
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec2<bool, P> isPowerOfTwo
-	(
-		tvec2<T, P> const & value
-	)
-	{
-		return tvec2<bool, P>(
-			isPowerOfTwo(value[0]),
-			isPowerOfTwo(value[1]));
-	}
-
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec3<bool, P> isPowerOfTwo
-	(
-		tvec3<T, P> const & value
-	)
-	{
-		return tvec3<bool, P>(
-			isPowerOfTwo(value[0]),
-			isPowerOfTwo(value[1]),
-			isPowerOfTwo(value[2]));
-	}
-
-	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec4<bool, P> isPowerOfTwo
-	(
-		tvec4<T, P> const & value
-	)
-	{
-		return tvec4<bool, P>(
-			isPowerOfTwo(value[0]),
-			isPowerOfTwo(value[1]),
-			isPowerOfTwo(value[2]),
-			isPowerOfTwo(value[3]));
-	}
-
-	// powerOfTwoAbove
-	template <typename genType>
-	GLM_FUNC_QUALIFIER genType powerOfTwoAbove(genType const & value)
-	{
-		return isPowerOfTwo(value) ? value : highestBitValue(value) << 1;
-	}
-
-	VECTORIZE_VEC(powerOfTwoAbove)
-
-	// powerOfTwoBelow
-	template <typename genType>
-	GLM_FUNC_QUALIFIER genType powerOfTwoBelow
-	(
-		genType const & value
-	)
-	{
-		return isPowerOfTwo(value) ? value : highestBitValue(value);
-	}
-
-	VECTORIZE_VEC(powerOfTwoBelow)
-
-	// powerOfTwoNearest
-	template <typename genType>
-	GLM_FUNC_QUALIFIER genType powerOfTwoNearest
-	(
-		genType const & value
-	)
-	{
-		if(isPowerOfTwo(value))
-			return value;
-
-		genType prev = highestBitValue(value);
-		genType next = prev << 1;
-		return (next - value) < (value - prev) ? next : prev;
-	}
-
-	VECTORIZE_VEC(powerOfTwoNearest)
-}//namespace glm

+ 1 - 0
readme.txt

@@ -78,6 +78,7 @@ GLM 0.9.6.0: 2014-XX-XX
 - Added not function (from GLSL specification) on VC12
 - Optimized bitfield operations
 - Added GTC_bitfield extension, promoted GTX_bit
+- Added GTC_integer extension, promoted GTX_bit
 
 ================================================================================
 GLM 0.9.5.4: 2014-06-21

+ 1 - 0
test/gtc/CMakeLists.txt

@@ -1,6 +1,7 @@
 glmCreateTestGTC(gtc_bitfield)
 glmCreateTestGTC(gtc_constants)
 glmCreateTestGTC(gtc_epsilon)
+glmCreateTestGTC(gtc_integer)
 glmCreateTestGTC(gtc_matrix_access)
 glmCreateTestGTC(gtc_matrix_integer)
 glmCreateTestGTC(gtc_matrix_inverse)

+ 46 - 15
test/gtx/gtx_bit.cpp → test/gtc/gtc_integer.cpp

@@ -1,16 +1,15 @@
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// Created : 2010-09-16
+// Created : 2014-10-25
 // Updated : 2014-10-25
 // Licence : This source is under MIT licence
-// File    : test/gtx/bit.cpp
+// File    : test/gtc/integer.cpp
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-#include <glm/gtx/bit.hpp>
+#include <glm/gtc/integer.hpp>
 #include <glm/gtc/type_precision.hpp>
 
-
 namespace isPowerOfTwo
 {
 	template <typename genType>
@@ -20,29 +19,61 @@ namespace isPowerOfTwo
 		bool		Return;
 	};
 
-	type<int> const DataI32[] =
+	int test_int()
 	{
-		{0x00000001, true},
-		{0x00000002, true},
-		{0x00000004, true},
-		{0xffffffff, true},
-		{0x00000000, true},
-		{0x00000003, true}
-	};
+		type<int> const DataI32[] =
+		{
+			{0x00000001, true},
+			{0x00000002, true},
+			{0x00000004, true},
+			{0xffffffff, true},
+			{0x00000000, true},
+			{0x00000003, false}
+		};
 
-	int test()
-	{
 		int Error(0);
 
 		for(std::size_t i = 0, n = sizeof(DataI32) / sizeof(type<int>); i < n; ++i)
 		{
 			bool Result = glm::isPowerOfTwo(DataI32[i].Value);
 			Error += DataI32[i].Return == Result ? 0 : 1;
-			assert(!Error);
 		}
 
 		return Error;
 	}
+
+	int test_uint()
+	{
+		type<glm::uint> const DataU32[] =
+		{
+			{0x00000001, true},
+			{0x00000002, true},
+			{0x00000004, true},
+			{0x80000000, true},
+			{0x00000000, true},
+			{0x00000003, false}
+		};
+
+		int Error(0);
+
+		for(std::size_t i = 0, n = sizeof(DataU32) / sizeof(type<glm::uint>); i < n; ++i)
+		{
+			bool Result = glm::isPowerOfTwo(DataU32[i].Value);
+			Error += DataU32[i].Return == Result ? 0 : 1;
+		}
+
+		return Error;
+	}
+
+	int test()
+	{
+		int Error(0);
+
+		Error += test_int();
+		Error += test_uint();
+
+		return Error;
+	}
 }//isPowerOfTwo
 
 int main()

+ 0 - 1
test/gtx/CMakeLists.txt

@@ -1,5 +1,4 @@
 glmCreateTestGTC(gtx_associated_min_max)
-glmCreateTestGTC(gtx_bit)
 glmCreateTestGTC(gtx_closest_point)
 glmCreateTestGTC(gtx_color_space_YCoCg)
 glmCreateTestGTC(gtx_color_space)