Java Code Examples for com.badlogic.gdx.utils.BufferUtils#newUnsafeByteBuffer()
The following examples show how to use
com.badlogic.gdx.utils.BufferUtils#newUnsafeByteBuffer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PCM.java From beatoraja with GNU General Public License v3.0 | 4 votes |
protected static ByteBuffer getDirectByteBuffer(int capacity) { ByteBuffer result = USE_UNSAFE ? BufferUtils.newUnsafeByteBuffer(capacity) : ByteBuffer.allocateDirect(capacity); return result.order(ByteOrder.LITTLE_ENDIAN); }
Example 2
Source File: FreeTypeFontGenerator.java From gdx-texture-packer-gui with Apache License 2.0 | 4 votes |
/** Creates a new generator from the given font file. Uses {@link FileHandle#length()} to determine the file size. If the file * length could not be determined (it was 0), an extra copy of the font bytes is performed. Throws a * {@link GdxRuntimeException} if loading did not succeed. */ public FreeTypeFontGenerator (FileHandle fontFile, int faceIndex) { name = fontFile.pathWithoutExtension(); int fileSize = (int)fontFile.length(); library = FreeType.initFreeType(); if (library == null) throw new GdxRuntimeException("Couldn't initialize FreeType"); ByteBuffer buffer = null; try { buffer = fontFile.map(); } catch (GdxRuntimeException e) { // Silently error, certain platforms do not support file mapping. } if (buffer == null) { InputStream input = fontFile.read(); try { if (fileSize == 0) { // Copy to a byte[] to get the file size, then copy to the buffer. byte[] data = StreamUtils.copyStreamToByteArray(input, 1024 * 16); buffer = BufferUtils.newUnsafeByteBuffer(data.length); BufferUtils.copy(data, 0, buffer, data.length); } else { // Trust the specified file size. buffer = BufferUtils.newUnsafeByteBuffer(fileSize); StreamUtils.copyStream(input, buffer); } } catch (IOException ex) { throw new GdxRuntimeException(ex); } finally { StreamUtils.closeQuietly(input); } } face = library.newMemoryFace(buffer, faceIndex); if (face == null) throw new GdxRuntimeException("Couldn't create face for font: " + fontFile); if (checkForBitmapFont()) return; setPixelSizes(0, 15); }
Example 3
Source File: FreeType.java From gdx-texture-packer-gui with Apache License 2.0 | 4 votes |
public Face newMemoryFace(byte[] data, int dataSize, int faceIndex) { ByteBuffer buffer = BufferUtils.newUnsafeByteBuffer(data.length); BufferUtils.copy(data, 0, buffer, data.length); return newMemoryFace(buffer, faceIndex); }
Example 4
Source File: GLBufferObject.java From libgdx-snippets with MIT License | 3 votes |
GLBufferObject(int target, boolean isStatic, int numElements, int elementSize) { handle = gl20.glGenBuffer(); this.target = target; usage = isStatic ? GL_STATIC_DRAW : GL_DYNAMIC_DRAW; this.elementSize = elementSize; byteBuffer = BufferUtils.newUnsafeByteBuffer(numElements * elementSize); createElementBuffer(byteBuffer); byteBuffer.flip(); }