This is much faster than the current implementation (on my machine about ~10x)
private static int nearestPowerOfTwo(int n) {
--n;
n |= n >> 16;
n |= n >> 8;
n |= n >> 4;
n |= n >> 2;
n |= n >> 1;
++n;
return n;
}
This implementation is only correct for n <= 1073741824, after that an overflow occurs. However I think it will take some time until our textures are that big...