Added integer log2 implementation with compute_log2 class
This commit is contained in:
parent
c004d95bdf
commit
742013f6d3
@ -60,7 +60,8 @@ namespace glm
|
|||||||
|
|
||||||
//! Returns the log2 of x. Can be reliably using to compute mipmap count from the texture size.
|
//! Returns the log2 of x. Can be reliably using to compute mipmap count from the texture size.
|
||||||
//! From GLM_GTX_integer extension.
|
//! From GLM_GTX_integer extension.
|
||||||
unsigned int log2(unsigned int x);
|
template <typename genType>
|
||||||
|
genType log2(genType const & x);
|
||||||
|
|
||||||
//! Returns the floor log2 of x.
|
//! Returns the floor log2 of x.
|
||||||
//! From GLM_GTX_integer extension.
|
//! From GLM_GTX_integer extension.
|
||||||
|
@ -53,23 +53,21 @@ namespace detail
|
|||||||
x += (x >> 16);
|
x += (x >> 16);
|
||||||
return(x & 0x0000003f);
|
return(x & 0x0000003f);
|
||||||
}
|
}
|
||||||
}//namespace detail
|
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct compute_log2<float_or_int_value::INT>
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
T operator() (T const & Value) const
|
||||||
|
{
|
||||||
#if(GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_GCC))
|
#if(GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_GCC))
|
||||||
|
return Value <= T(1) ? T(0) : T(32) - nlz(Value - T(1));
|
||||||
GLM_FUNC_QUALIFIER unsigned int log2(unsigned int x)
|
|
||||||
{
|
|
||||||
return x <= 1 ? 0 : unsigned(32) - nlz(x - 1u);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
return T(32) - nlz(Value - T(1));
|
||||||
GLM_FUNC_QUALIFIER unsigned int log2(unsigned int x)
|
|
||||||
{
|
|
||||||
return unsigned(32) - nlz(x - 1u);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}//namespace detail
|
||||||
|
|
||||||
// Henry Gordon Dietz: http://aggregate.org/MAGIC/
|
// Henry Gordon Dietz: http://aggregate.org/MAGIC/
|
||||||
unsigned int floor_log2(unsigned int x)
|
unsigned int floor_log2(unsigned int x)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user