Added log2 to GTC_integer
This commit is contained in:
parent
88894045af
commit
4f4763600f
@ -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/func_integer.hpp"
|
||||||
#include "../detail/_vectorize.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
|
||||||
|
@ -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
|
||||||
|
@ -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);
|
||||||
|
@ -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/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user