本文整理汇总了Java中org.andengine.util.math.MathUtils.nextPowerOfTwo方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.nextPowerOfTwo方法的具体用法?Java MathUtils.nextPowerOfTwo怎么用?Java MathUtils.nextPowerOfTwo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.andengine.util.math.MathUtils
的用法示例。
在下文中一共展示了MathUtils.nextPowerOfTwo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LongMap
import org.andengine.util.math.MathUtils; //导入方法依赖的package包/类
/**
* Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity * loadFactor items
* before growing the backing table.
*/
public LongMap (int initialCapacity, float loadFactor) {
if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0: " + initialCapacity);
if (capacity > 1 << 30) throw new IllegalArgumentException("initialCapacity is too large: " + initialCapacity);
capacity = MathUtils.nextPowerOfTwo(initialCapacity);
if (loadFactor <= 0) throw new IllegalArgumentException("loadFactor must be > 0: " + loadFactor);
this.loadFactor = loadFactor;
threshold = (int)(capacity * loadFactor);
mask = capacity - 1;
hashShift = 31 - Integer.numberOfTrailingZeros(capacity);
stashCapacity = Math.max(3, (int)Math.ceil(Math.log(capacity)) + 1);
pushIterations = Math.max(Math.min(capacity, 32), (int)Math.sqrt(capacity) / 4);
keyTable = new long[capacity + stashCapacity];
valueTable = (V[])new Object[keyTable.length];
}
示例2: writeTextureToHardware
import org.andengine.util.math.MathUtils; //导入方法依赖的package包/类
@Override
protected void writeTextureToHardware(final GLState pGLState) throws IOException {
final IPVRTexturePixelBufferStrategyBufferManager pvrTextureLoadStrategyManager = this.mPVRTexturePixelBufferStrategy.newPVRTexturePixelBufferStrategyManager(this);
int width = this.getWidth();
int height = this.getHeight();
final int dataLength = this.mPVRTextureHeader.getDataLength();
final int bytesPerPixel = this.mPVRTextureHeader.getBitsPerPixel() / DataConstants.BITS_PER_BYTE;
/* Adjust unpack alignment. */
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
int currentLevel = 0;
int currentPixelDataOffset = 0;
while (currentPixelDataOffset < dataLength) {
if (currentLevel > 0 && (width != height || MathUtils.nextPowerOfTwo(width) != width)) {
Debug.w("Mipmap level '" + currentLevel + "' is not squared. Width: '" + width + "', height: '" + height + "'. Texture won't render correctly.");
}
final int currentPixelDataSize = height * width * bytesPerPixel;
/* Load the current level. */
this.mPVRTexturePixelBufferStrategy.loadPVRTextureData(pvrTextureLoadStrategyManager, width, height, bytesPerPixel, this.mPixelFormat, currentLevel, currentPixelDataOffset, currentPixelDataSize);
currentPixelDataOffset += currentPixelDataSize;
/* Prepare next mipmap level. */
width = Math.max(width / 2, 1);
height = Math.max(height / 2, 1);
currentLevel++;
}
/* Restore default unpack alignment. */
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, GLState.GL_UNPACK_ALIGNMENT_DEFAULT);
}