private void ensureBufferCapacity (int numBytes) { if (buffer == null || buffer.capacity() < numBytes) { buffer = com.badlogic.gdx.utils.BufferUtils.newByteBuffer(numBytes); floatBuffer = buffer.asFloatBuffer(); intBuffer = buffer.asIntBuffer(); } }
@Override public void updateIndices (int targetOffset, short[] indices, int offset, int count) { final int pos = byteBuffer.position(); byteBuffer.position(targetOffset * 2); BufferUtils.copy(indices, offset, byteBuffer, count); byteBuffer.position(pos); }
@Override public void dispose () { doneFreeType(address); for(ByteBuffer buffer: fontData.values()) { if (BufferUtils.isUnsafeByteBuffer(buffer)) BufferUtils.disposeUnsafeByteBuffer(buffer); } }
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); }
public boolean loadFile(final com.badlogic.gdx.files.FileHandle fileHandle) { final int len = (int)fileHandle.length(); if (len <= 0) throw new com.badlogic.gdx.utils.GdxRuntimeException("Incorrect file specified"); java.nio.ByteBuffer buff = com.badlogic.gdx.utils.BufferUtils.newUnsafeByteBuffer(len); buff.put(fileHandle.readBytes()); buff.position(0); boolean result = loadFileFromMemory(buff, len); com.badlogic.gdx.utils.BufferUtils.disposeUnsafeByteBuffer(buff); return result; }
ByteBuffer bb = BufferUtils.newByteBuffer(8); CharBuffer cb = BufferUtils.newCharBuffer(8); ShortBuffer sb = BufferUtils.newShortBuffer(8); IntBuffer ib = BufferUtils.newIntBuffer(8); LongBuffer lb = BufferUtils.newLongBuffer(8); FloatBuffer fb = BufferUtils.newFloatBuffer(8); DoubleBuffer db = BufferUtils.newDoubleBuffer(8); BufferUtils.copy(new byte[] {1, 2, 3, 4}, 0, bb, 4); checkInt(bb.get(), 1); checkInt(bb.get(), 2); BufferUtils.copy(new char[] {1, 2, 3, 4}, 0, cb, 4); checkInt(cb.get(), 1); checkInt(cb.get(), 2); checkInt(cb.get(), 4); cb.position(0); BufferUtils.copy(new char[] {5, 6, 7, 8}, 1, cb, 3); checkInt(cb.get(), 6); checkInt(cb.get(), 7); BufferUtils.copy(new short[] {1, 2, 3, 4}, 0, sb, 4); checkInt(sb.get(), 1); checkInt(sb.get(), 2); checkInt(sb.get(), 4); sb.position(0); BufferUtils.copy(new short[] {5, 6, 7, 8}, 1, sb, 3);
private void benchByte () { ByteBuffer bb = BufferUtils.newByteBuffer(1024 * 1024); byte[] bytes = new byte[1024 * 1024]; int len = bytes.length; for (int j = 0; j < NUM_MB; j++) { bb.clear(); BufferUtils.copy(bytes, 0, bb, len);
private static int getMaxTextureUnits () { IntBuffer buffer = BufferUtils.newIntBuffer(16); Gdx.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_IMAGE_UNITS, buffer); return buffer.get(0); }
/** Constructs a new interleaved VertexArray * * @param numVertices the maximum number of vertices * @param attributes the {@link VertexAttributes} */ public VertexArray (int numVertices, VertexAttributes attributes) { this.attributes = attributes; byteBuffer = BufferUtils.newUnsafeByteBuffer(this.attributes.vertexSize * numVertices); buffer = byteBuffer.asFloatBuffer(); buffer.flip(); byteBuffer.flip(); }
/** Constructs a new ShaderProgram and immediately compiles it. * * @param vertexShader the vertex shader * @param fragmentShader the fragment shader */ public ShaderProgram (String vertexShader, String fragmentShader) { if (vertexShader == null) throw new IllegalArgumentException("vertex shader must not be null"); if (fragmentShader == null) throw new IllegalArgumentException("fragment shader must not be null"); if (prependVertexCode != null && prependVertexCode.length() > 0) vertexShader = prependVertexCode + vertexShader; if (prependFragmentCode != null && prependFragmentCode.length() > 0) fragmentShader = prependFragmentCode + fragmentShader; this.vertexShaderSource = vertexShader; this.fragmentShaderSource = fragmentShader; this.matrix = BufferUtils.newFloatBuffer(16); compileShaders(vertexShader, fragmentShader); if (isCompiled()) { fetchAttributes(); fetchUniforms(); addManagedShader(Gdx.app, this); } }
private void benchInt () { IntBuffer ib = BufferUtils.newIntBuffer(1024 * 1024 / 4); int[] ints = new int[1024 * 1024 / 4]; int len = ints.length; for (int j = 0; j < NUM_MB; j++) { ib.clear(); BufferUtils.copy(ints, 0, ib, len);
private void benchFloat () { FloatBuffer fb = BufferUtils.newFloatBuffer(1024 * 1024 / 4); float[] floats = new float[1024 * 1024 / 4]; int len = floats.length; for (int j = 0; j < NUM_MB; j++) { fb.clear(); BufferUtils.copy(floats, 0, fb, len);
/** Disposes this IndexArray and all its associated OpenGL resources. */ public void dispose () { BufferUtils.disposeUnsafeByteBuffer(byteBuffer); } }
FloatBuffer workBuffer = BufferUtils.newFloatBuffer(mesh.getVerticesBuffer().capacity()); BufferUtils.copy(mesh.getVerticesBuffer(), workBuffer, mesh.getNumVertices() * mesh.getVertexSize() / 4); BufferUtils.transform(workBuffer, 3, mesh.getVertexSize(), mesh.getNumVertices(), transform);
private static int getMaxTextureUnits () { IntBuffer buffer = BufferUtils.newIntBuffer(16); Gdx.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_IMAGE_UNITS, buffer); return buffer.get(0); }
/** Constructs a new interleaved VertexArray * * @param numVertices the maximum number of vertices * @param attributes the {@link VertexAttributes} */ public VertexArray (int numVertices, VertexAttributes attributes) { this.attributes = attributes; byteBuffer = BufferUtils.newUnsafeByteBuffer(this.attributes.vertexSize * numVertices); buffer = byteBuffer.asFloatBuffer(); buffer.flip(); byteBuffer.flip(); }
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); }
/** Constructs a new ShaderProgram and immediately compiles it. * * @param vertexShader the vertex shader * @param fragmentShader the fragment shader */ public ShaderProgram (String vertexShader, String fragmentShader) { if (vertexShader == null) throw new IllegalArgumentException("vertex shader must not be null"); if (fragmentShader == null) throw new IllegalArgumentException("fragment shader must not be null"); if (prependVertexCode != null && prependVertexCode.length() > 0) vertexShader = prependVertexCode + vertexShader; if (prependFragmentCode != null && prependFragmentCode.length() > 0) fragmentShader = prependFragmentCode + fragmentShader; this.vertexShaderSource = vertexShader; this.fragmentShaderSource = fragmentShader; this.matrix = BufferUtils.newFloatBuffer(16); compileShaders(vertexShader, fragmentShader); if (isCompiled()) { fetchAttributes(); fetchUniforms(); addManagedShader(Gdx.app, this); } }
/** Disposes this IndexArray and all its associated OpenGL resources. */ public void dispose () { BufferUtils.disposeUnsafeByteBuffer(byteBuffer); } }
public boolean loadFile(final com.badlogic.gdx.files.FileHandle fileHandle) { final int len = (int)fileHandle.length(); if (len <= 0) throw new com.badlogic.gdx.utils.GdxRuntimeException("Incorrect file specified"); java.nio.ByteBuffer buff = com.badlogic.gdx.utils.BufferUtils.newUnsafeByteBuffer(len); buff.put(fileHandle.readBytes()); buff.position(0); boolean result = loadFileFromMemory(buff, len); com.badlogic.gdx.utils.BufferUtils.disposeUnsafeByteBuffer(buff); return result; }