com.neovisionaries.android.opengl
Class BufferCreator

java.lang.Object
  extended by com.neovisionaries.android.opengl.BufferCreator

public final class BufferCreator
extends Object

Buffer creator.

Author:
Takahiko Kawasaki

Method Summary
static ByteBuffer createByteBuffer(byte[] data)
          This method is an alias of createByteBuffer(data, 0, data.length).
static ByteBuffer createByteBuffer(byte[] data, int offset, int length)
          Create a direct ByteBuffer with the native byte order.
static ByteBuffer createByteBuffer(int size)
          Create a direct ByteBuffer with the native byte order.
static FloatBuffer createFloatBuffer(float[] data)
          This method is an alias of createFloatBuffer(data, 0, data.length).
static FloatBuffer createFloatBuffer(float[] data, int offset, int length)
          Create a direct FloatBuffer with the native byte order.
static FloatBuffer createFloatBuffer(int size)
          Create a direct FloatBuffer with the native byte order.
static IntBuffer createIntBuffer(int size)
          Create a direct IntBuffer with the native byte order.
static IntBuffer createIntBuffer(int[] data)
          This method is an alias of createIntBuffer(data, 0, data.length).
static IntBuffer createIntBuffer(int[] data, int offset, int length)
          Create a direct IntBuffer with the native byte order.
static ShortBuffer createShortBuffer(int size)
          Create a direct ShortBuffer with the native byte order.
static ShortBuffer createShortBuffer(short[] data)
          This method is an alias of createShortBuffer(data, 0, data.length).
static ShortBuffer createShortBuffer(short[] data, int offset, int length)
          Create a direct ShortBuffer with the native byte order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createByteBuffer

public static ByteBuffer createByteBuffer(int size)
Create a direct ByteBuffer with the native byte order.

Internally, a ByteBuffer is created by ByteBuffer.allocateDirect(size) and its byte order is set to the native byte order, and this method returns the ByteBuffer.

Parameters:
size - The number of elements that the created ByteBuffer should be able to hold.
Returns:
A newly allocated ByteBuffer.
Throws:
IllegalArgumentException - 'size' is 0 or negative.

createByteBuffer

public static ByteBuffer createByteBuffer(byte[] data,
                                          int offset,
                                          int length)
Create a direct ByteBuffer with the native byte order.

Int values from the offset in the data array up to the specified length are set to a newly allocated ByteBuffer.

Parameters:
data - Data to set to a newly allocated ByteBuffer.
offset - The offset from the beginning of the data array.
length - The number of int values to use.
Returns:
A newly allocated ByteBuffer. Its position is 0 right after this method returns.
Throws:
IllegalArgumentException -
  • 'data' is null.
  • 'offset' is less than 0.
  • 'offset' is equal to or greater than the length of 'data'.
  • 'length' is 0 or less.
  • 'length' is greater than ('data.length' - 'offset').

createByteBuffer

public static ByteBuffer createByteBuffer(byte[] data)
This method is an alias of createByteBuffer(data, 0, data.length).

Parameters:
data - Data to set to a newly allocated ByteBuffer.
Returns:
A newly allocated ByteBuffer. Its position is 0 right after this method returns.
Throws:
IllegalArgumentException - 'data' is null or its length is 0.

createShortBuffer

public static ShortBuffer createShortBuffer(int size)
Create a direct ShortBuffer with the native byte order.

Internally, a ByteBuffer is created by ByteBuffer.allocateDirect(size * 2) and its byte order is set to the native byte order. What is returned by this method is the ByteBuffer's view as ShortBuffer.

Parameters:
size - The number of elements that the created ShortBuffer should be able to hold. Note that the unit is not 'bytes'.
Returns:
A newly allocated ShortBuffer.
Throws:
IllegalArgumentException - 'size' is 0 or negative.

createShortBuffer

public static ShortBuffer createShortBuffer(short[] data,
                                            int offset,
                                            int length)
Create a direct ShortBuffer with the native byte order.

Int values from the offset in the data array up to the specified length are set to a newly allocated ShortBuffer.

Parameters:
data - Data to set to a newly allocated ShortBuffer.
offset - The offset from the beginning of the data array.
length - The number of int values to use.
Returns:
A newly allocated ShortBuffer. Its position is 0 right after this method returns.
Throws:
IllegalArgumentException -
  • 'data' is null.
  • 'offset' is less than 0.
  • 'offset' is equal to or greater than the length of 'data'.
  • 'length' is 0 or less.
  • 'length' is greater than ('data.length' - 'offset').

createShortBuffer

public static ShortBuffer createShortBuffer(short[] data)
This method is an alias of createShortBuffer(data, 0, data.length).

Parameters:
data - Data to set to a newly allocated ShortBuffer.
Returns:
A newly allocated ShortBuffer. Its position is 0 right after this method returns.
Throws:
IllegalArgumentException - 'data' is null or its length is 0.

createIntBuffer

public static IntBuffer createIntBuffer(int size)
Create a direct IntBuffer with the native byte order.

Internally, a ByteBuffer is created by ByteBuffer.allocateDirect(size * 4) and its byte order is set to the native byte order. What is returned by this method is the ByteBuffer's view as IntBuffer.

Parameters:
size - The number of elements that the created IntBuffer should be able to hold. Note that the unit is not 'bytes'.
Returns:
A newly allocated IntBuffer.
Throws:
IllegalArgumentException - 'size' is 0 or negative.

createIntBuffer

public static IntBuffer createIntBuffer(int[] data,
                                        int offset,
                                        int length)
Create a direct IntBuffer with the native byte order.

Int values from the offset in the data array up to the specified length are set to a newly allocated IntBuffer.

Parameters:
data - Data to set to a newly allocated IntBuffer.
offset - The offset from the beginning of the data array.
length - The number of int values to use.
Returns:
A newly allocated IntBuffer. Its position is 0 right after this method returns.
Throws:
IllegalArgumentException -
  • 'data' is null.
  • 'offset' is less than 0.
  • 'offset' is equal to or greater than the length of 'data'.
  • 'length' is 0 or less.
  • 'length' is greater than ('data.length' - 'offset').

createIntBuffer

public static IntBuffer createIntBuffer(int[] data)
This method is an alias of createIntBuffer(data, 0, data.length).

Parameters:
data - Data to set to a newly allocated IntBuffer.
Returns:
A newly allocated IntBuffer. Its position is 0 right after this method returns.
Throws:
IllegalArgumentException - 'data' is null or its length is 0.

createFloatBuffer

public static FloatBuffer createFloatBuffer(int size)
Create a direct FloatBuffer with the native byte order.

Internally, a ByteBuffer is created by ByteBuffer.allocateDirect(size * 4) and its byte order is set to the native byte order. What is returned by this method is the ByteBuffer's view as FloatBuffer.

Parameters:
size - The number of elements that the created FloatBuffer should be able to hold. Note that the unit is not 'bytes'.
Returns:
A newly allocated FloatBuffer.
Throws:
IllegalArgumentException - 'size' is 0 or negative.

createFloatBuffer

public static FloatBuffer createFloatBuffer(float[] data,
                                            int offset,
                                            int length)
Create a direct FloatBuffer with the native byte order.

Float values from the offset in the data array up to the specified length are set to a newly allocated FloatBuffer.

Parameters:
data - Data to set to a newly allocated FloatBuffer.
offset - The offset from the beginning of the data array.
length - The number of float values to use.
Returns:
A newly allocated FloatBuffer. Its position is 0 right after this method returns.
Throws:
IllegalArgumentException -
  • 'data' is null.
  • 'offset' is less than 0.
  • 'offset' is equal to or greater than the length of 'data'.
  • 'length' is 0 or less.
  • 'length' is greater than ('data.length' - 'offset').

createFloatBuffer

public static FloatBuffer createFloatBuffer(float[] data)
This method is an alias of createFloatBuffer(data, 0, data.length).

Parameters:
data - Data to set to a newly allocated FloatBuffer.
Returns:
A newly allocated FloatBuffer. Its position is 0 right after this method returns.
Throws:
IllegalArgumentException - 'data' is null or its length is 0.