Added log2 to GTC_integer

This commit is contained in:
Christophe Riccio
2014-11-19 23:09:02 +01:00
parent 88894045af
commit 4f4763600f
4 changed files with 20 additions and 25 deletions

View File

@@ -41,8 +41,8 @@
// Dependencies
#include "../detail/setup.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>
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
@@ -54,7 +54,10 @@ namespace glm
/// @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

View File

@@ -29,9 +29,19 @@
namespace glm{
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 glm