libgdx API

com.badlogic.gdx.utils
Class BufferUtils

java.lang.Object
  extended by com.badlogic.gdx.utils.BufferUtils

public class BufferUtils
extends java.lang.Object

Class with static helper methods to increase the speed of array/direct buffer and direct buffer/direct buffer transfers

Author:
mzechner

Constructor Summary
BufferUtils()
           
 
Method Summary
static void clear(java.nio.ByteBuffer buffer, int numBytes)
          Writes the specified number of zeros to the buffer.
static void copy(java.nio.Buffer src, java.nio.Buffer dst, int numElements)
          Copies the contents of src to dst, starting from the current position of src, copying numElements elements (using the data type of src, no matter the datatype of dst).
static void copy(byte[] src, int srcOffset, java.nio.Buffer dst, int numElements)
          Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.
static void copy(char[] src, int srcOffset, java.nio.Buffer dst, int numElements)
          Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.
static void copy(double[] src, int srcOffset, java.nio.Buffer dst, int numElements)
          Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.
static void copy(float[] src, java.nio.Buffer dst, int numFloats, int offset)
          Copies numFloats floats from src starting at offset to dst.
static void copy(float[] src, int srcOffset, java.nio.Buffer dst, int numElements)
          Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.
static void copy(int[] src, int srcOffset, java.nio.Buffer dst, int numElements)
          Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.
static void copy(long[] src, int srcOffset, java.nio.Buffer dst, int numElements)
          Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.
static void copy(short[] src, int srcOffset, java.nio.Buffer dst, int numElements)
          Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.
static void disposeUnsafeByteBuffer(java.nio.ByteBuffer buffer)
           
static int getAllocatedBytesUnsafe()
           
static java.nio.ByteBuffer newByteBuffer(int numBytes)
           
static java.nio.CharBuffer newCharBuffer(int numChars)
           
static java.nio.DoubleBuffer newDoubleBuffer(int numDoubles)
           
static java.nio.FloatBuffer newFloatBuffer(int numFloats)
           
static java.nio.IntBuffer newIntBuffer(int numInts)
           
static java.nio.LongBuffer newLongBuffer(int numLongs)
           
static java.nio.ShortBuffer newShortBuffer(int numShorts)
           
static java.nio.ByteBuffer newUnsafeByteBuffer(int numBytes)
          Allocates a new direct ByteBuffer from native heap memory using the native byte order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferUtils

public BufferUtils()
Method Detail

copy

public static void copy(float[] src,
                        java.nio.Buffer dst,
                        int numFloats,
                        int offset)
Copies numFloats floats from src starting at offset to dst. Dst is assumed to be a direct Buffer. The method will crash if that is not the case. The position and limit of the buffer are ignored, the copy is placed at position 0 in the buffer. After the copying process the position of the buffer is set to 0 and its limit is set to numFloats * 4 if it is a ByteBuffer and numFloats if it is a FloatBuffer. In case the Buffer is neither a ByteBuffer nor a FloatBuffer the limit is not set. This is an expert method, use at your own risk.

Parameters:
src - the source array
dst - the destination buffer, has to be a direct Buffer
numFloats - the number of floats to copy
offset - the offset in src to start copying from

copy

public static void copy(byte[] src,
                        int srcOffset,
                        java.nio.Buffer dst,
                        int numElements)
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. The Buffer instance's Buffer.position() is used to define the offset into the Buffer itself. The position will stay the same, the limit will be set to position + numElements. The Buffer must be a direct Buffer with native byte order. No error checking is performed.

Parameters:
src - the source array.
srcOffset - the offset into the source array.
dst - the destination Buffer, its position is used as an offset.
numElements - the number of elements to copy.

copy

public static void copy(short[] src,
                        int srcOffset,
                        java.nio.Buffer dst,
                        int numElements)
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. The Buffer instance's Buffer.position() is used to define the offset into the Buffer itself. The position will stay the same, the limit will be set to position + numElements. The Buffer must be a direct Buffer with native byte order. No error checking is performed.

Parameters:
src - the source array.
srcOffset - the offset into the source array.
dst - the destination Buffer, its position is used as an offset.
numElements - the number of elements to copy.

copy

public static void copy(char[] src,
                        int srcOffset,
                        java.nio.Buffer dst,
                        int numElements)
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. The Buffer instance's Buffer.position() is used to define the offset into the Buffer itself. The position will stay the same, the limit will be set to position + numElements. The Buffer must be a direct Buffer with native byte order. No error checking is performed.

Parameters:
src - the source array.
srcOffset - the offset into the source array.
dst - the destination Buffer, its position is used as an offset.
numElements - the number of elements to copy.

copy

public static void copy(int[] src,
                        int srcOffset,
                        java.nio.Buffer dst,
                        int numElements)
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. The Buffer instance's Buffer.position() is used to define the offset into the Buffer itself. The position will stay the same, the limit will be set to position + numElements. The Buffer must be a direct Buffer with native byte order. No error checking is performed.

Parameters:
src - the source array.
srcOffset - the offset into the source array.
dst - the destination Buffer, its position is used as an offset.
numElements - the number of elements to copy.

copy

public static void copy(long[] src,
                        int srcOffset,
                        java.nio.Buffer dst,
                        int numElements)
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. The Buffer instance's Buffer.position() is used to define the offset into the Buffer itself. The position will stay the same, the limit will be set to position + numElements. The Buffer must be a direct Buffer with native byte order. No error checking is performed.

Parameters:
src - the source array.
srcOffset - the offset into the source array.
dst - the destination Buffer, its position is used as an offset.
numElements - the number of elements to copy.

copy

public static void copy(float[] src,
                        int srcOffset,
                        java.nio.Buffer dst,
                        int numElements)
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. The Buffer instance's Buffer.position() is used to define the offset into the Buffer itself. The position will stay the same, the limit will be set to position + numElements. The Buffer must be a direct Buffer with native byte order. No error checking is performed.

Parameters:
src - the source array.
srcOffset - the offset into the source array.
dst - the destination Buffer, its position is used as an offset.
numElements - the number of elements to copy.

copy

public static void copy(double[] src,
                        int srcOffset,
                        java.nio.Buffer dst,
                        int numElements)
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. The Buffer instance's Buffer.position() is used to define the offset into the Buffer itself. The position will stay the same, the limit will be set to position + numElements. The Buffer must be a direct Buffer with native byte order. No error checking is performed.

Parameters:
src - the source array.
srcOffset - the offset into the source array.
dst - the destination Buffer, its position is used as an offset.
numElements - the number of elements to copy.

copy

public static void copy(java.nio.Buffer src,
                        java.nio.Buffer dst,
                        int numElements)
Copies the contents of src to dst, starting from the current position of src, copying numElements elements (using the data type of src, no matter the datatype of dst). The dst Buffer.position() is used as the writing offset. The position of both Buffers will stay the same. The limit of the src Buffer will stay the same. The limit of the dst Buffer will be set to dst.position() + numElements, where numElements are translated to the number of elements appropriate for the dst Buffer data type. The Buffers must be direct Buffers with native byte order. No error checking is performed.

Parameters:
src - the source Buffer.
dst - the destination Buffer.
numElements - the number of elements to copy.

newFloatBuffer

public static java.nio.FloatBuffer newFloatBuffer(int numFloats)

newDoubleBuffer

public static java.nio.DoubleBuffer newDoubleBuffer(int numDoubles)

newByteBuffer

public static java.nio.ByteBuffer newByteBuffer(int numBytes)

newShortBuffer

public static java.nio.ShortBuffer newShortBuffer(int numShorts)

newCharBuffer

public static java.nio.CharBuffer newCharBuffer(int numChars)

newIntBuffer

public static java.nio.IntBuffer newIntBuffer(int numInts)

newLongBuffer

public static java.nio.LongBuffer newLongBuffer(int numLongs)

disposeUnsafeByteBuffer

public static void disposeUnsafeByteBuffer(java.nio.ByteBuffer buffer)

newUnsafeByteBuffer

public static java.nio.ByteBuffer newUnsafeByteBuffer(int numBytes)
Allocates a new direct ByteBuffer from native heap memory using the native byte order. Needs to be disposed with freeMemory(ByteBuffer).

Parameters:
numBytes -

getAllocatedBytesUnsafe

public static int getAllocatedBytesUnsafe()
Returns:
the number of bytes allocated with newUnsafeByteBuffer(int)

clear

public static void clear(java.nio.ByteBuffer buffer,
                         int numBytes)
Writes the specified number of zeros to the buffer. This is generally faster than reallocating a new buffer.


libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)