Added 'upperPowerOfTwo' function.

This commit is contained in:
David Williams 2013-01-03 00:05:28 +01:00
parent bf5a9f7ab8
commit 575f4824cc
2 changed files with 14 additions and 0 deletions

View File

@ -37,6 +37,7 @@ namespace PolyVox
int32_t roundToInteger(float r);
template <typename Type>
Type clamp(const Type& value, const Type& low, const Type& high);
uint32_t upperPowerOfTwo(uint32_t v);
inline int32_t roundTowardsNegInf(float r)
{

View File

@ -60,4 +60,17 @@ namespace PolyVox
else
return ((uInput & (uInput-1)) == 0);
}
// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
uint32_t upperPowerOfTwo(uint32_t v)
{
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
return v;
}
}