public final class BufferUtils
extends java.lang.Object
BufferUtils
is a helper class for generating nio buffers from
jME data classes such as Vectors and ColorRGBA.Modifier and Type | Method and Description |
---|---|
static void |
addInBuffer(Vector2f toAdd,
java.nio.FloatBuffer buf,
int index)
Add to a Vector2f in-buffer.
|
static void |
addInBuffer(Vector3f toAdd,
java.nio.FloatBuffer buf,
int index)
Add to a Vector3f in-buffer.
|
static java.nio.Buffer |
clone(java.nio.Buffer buf)
Creates a clone of the given buffer.
|
static java.nio.ByteBuffer |
clone(java.nio.ByteBuffer buf)
Creates a new ByteBuffer with the same contents as the given ByteBuffer.
|
static java.nio.DoubleBuffer |
clone(java.nio.DoubleBuffer buf)
Creates a new DoubleBuffer with the same contents as the given
DoubleBuffer.
|
static java.nio.FloatBuffer |
clone(java.nio.FloatBuffer buf)
Creates a new FloatBuffer with the same contents as the given
FloatBuffer.
|
static java.nio.IntBuffer |
clone(java.nio.IntBuffer buf)
Creates a new IntBuffer with the same contents as the given IntBuffer.
|
static java.nio.ShortBuffer |
clone(java.nio.ShortBuffer buf)
Creates a new ShortBuffer with the same contents as the given
ShortBuffer.
|
static void |
copyInternal(java.nio.FloatBuffer buf,
int fromPos,
int toPos,
int length)
Copies floats from one position in the buffer to another.
|
static void |
copyInternalVector2(java.nio.FloatBuffer buf,
int fromPos,
int toPos)
Copies a Vector2f from one position in the buffer to another.
|
static void |
copyInternalVector3(java.nio.FloatBuffer buf,
int fromPos,
int toPos)
Copies a Vector3f from one position in the buffer to another.
|
static java.nio.ByteBuffer |
createByteBuffer(byte... data) |
static java.nio.ByteBuffer |
createByteBuffer(java.nio.ByteBuffer buf,
int size)
Create a new ByteBuffer of an appropriate size to hold the specified
number of ints only if the given buffer if not already the right size.
|
static java.nio.ByteBuffer |
createByteBuffer(int size)
Create a new ByteBuffer of the specified size.
|
static java.nio.ByteBuffer |
createByteBuffer(java.lang.String data) |
static java.nio.DoubleBuffer |
createDoubleBuffer(java.nio.DoubleBuffer buf,
int size)
Create a new DoubleBuffer of an appropriate size to hold the specified
number of doubles only if the given buffer if not already the right size.
|
static java.nio.DoubleBuffer |
createDoubleBuffer(int size)
Create a new DoubleBuffer of the specified size.
|
static java.nio.FloatBuffer |
createFloatBuffer(ColorRGBA... data)
Generate a new FloatBuffer using the given array of ColorRGBA objects.
|
static java.nio.FloatBuffer |
createFloatBuffer(float... data)
Generate a new FloatBuffer using the given array of float primitives.
|
static java.nio.FloatBuffer |
createFloatBuffer(int size)
Create a new FloatBuffer of the specified size.
|
static java.nio.FloatBuffer |
createFloatBuffer(Quaternion... data)
Generate a new FloatBuffer using the given array of Quaternion objects.
|
static java.nio.FloatBuffer |
createFloatBuffer(Vector2f... data)
Generate a new FloatBuffer using the given array of Vector2f objects.
|
static java.nio.FloatBuffer |
createFloatBuffer(Vector3f... data)
Generate a new FloatBuffer using the given array of Vector3f objects.
|
static java.nio.FloatBuffer |
createFloatBuffer(Vector4f... data)
Generate a new FloatBuffer using the given array of Vector4 objects.
|
static java.nio.IntBuffer |
createIntBuffer(int... data)
Generate a new IntBuffer using the given array of ints.
|
static java.nio.IntBuffer |
createIntBuffer(int size)
Create a new IntBuffer of the specified size.
|
static java.nio.IntBuffer |
createIntBuffer(java.nio.IntBuffer buf,
int size)
Create a new IntBuffer of an appropriate size to hold the specified
number of ints only if the given buffer if not already the right size.
|
static java.nio.ShortBuffer |
createShortBuffer(int size)
Create a new ShortBuffer of the specified size.
|
static java.nio.ShortBuffer |
createShortBuffer(short... data) |
static java.nio.ShortBuffer |
createShortBuffer(java.nio.ShortBuffer buf,
int size)
Create a new ShortBuffer of an appropriate size to hold the specified
number of shorts only if the given buffer if not already the right size.
|
static java.nio.FloatBuffer |
createVector2Buffer(java.nio.FloatBuffer buf,
int vertices)
Create a new FloatBuffer of an appropriate size to hold the specified
number of Vector2f object data only if the given buffer if not already
the right size.
|
static java.nio.FloatBuffer |
createVector2Buffer(int vertices)
Create a new FloatBuffer of an appropriate size to hold the specified
number of Vector2f object data.
|
static java.nio.FloatBuffer |
createVector3Buffer(java.nio.FloatBuffer buf,
int vertices)
Create a new FloatBuffer of an appropriate size to hold the specified
number of Vector3f object data only if the given buffer if not already
the right size.
|
static java.nio.FloatBuffer |
createVector3Buffer(int vertices)
Create a new FloatBuffer of an appropriate size to hold the specified
number of Vector3f object data.
|
static void |
destroyDirectBuffer(java.nio.Buffer toBeDestroyed)
Direct buffers are garbage collected by using a phantom reference and a
reference queue.
|
static java.nio.ByteBuffer |
ensureLargeEnough(java.nio.ByteBuffer buffer,
int required) |
static java.nio.FloatBuffer |
ensureLargeEnough(java.nio.FloatBuffer buffer,
int required)
Ensures there is at least the
required number of entries
left after the current position of the buffer. |
static java.nio.IntBuffer |
ensureLargeEnough(java.nio.IntBuffer buffer,
int required) |
static java.nio.ShortBuffer |
ensureLargeEnough(java.nio.ShortBuffer buffer,
int required) |
static boolean |
equals(Vector2f check,
java.nio.FloatBuffer buf,
int index)
Checks to see if the given Vector2f is equals to the data stored in the
buffer at the given data index.
|
static boolean |
equals(Vector3f check,
java.nio.FloatBuffer buf,
int index)
Checks to see if the given Vector3f is equals to the data stored in the
buffer at the given data index.
|
static float[] |
getFloatArray(java.nio.FloatBuffer buff)
Create a new float[] array and populate it with the given FloatBuffer's
contents.
|
static int[] |
getIntArray(java.nio.IntBuffer buff)
Create a new int[] array and populate it with the given IntBuffer's
contents.
|
static Vector2f[] |
getVector2Array(java.nio.FloatBuffer buff)
Generates a Vector2f array from the given FloatBuffer.
|
static Vector3f[] |
getVector3Array(java.nio.FloatBuffer buff)
Generates a Vector3f array from the given FloatBuffer.
|
static void |
multInBuffer(Vector2f toMult,
java.nio.FloatBuffer buf,
int index)
Multiply and store a Vector2f in-buffer.
|
static void |
multInBuffer(Vector3f toMult,
java.nio.FloatBuffer buf,
int index)
Multiply and store a Vector3f in-buffer.
|
static void |
normalizeVector2(java.nio.FloatBuffer buf,
int index)
Normalize a Vector2f in-buffer.
|
static void |
normalizeVector3(java.nio.FloatBuffer buf,
int index)
Normalize a Vector3f in-buffer.
|
static void |
populateFromBuffer(Vector2f vector,
java.nio.FloatBuffer buf,
int index)
Updates the values of the given vector from the specified buffer at the
index provided.
|
static void |
populateFromBuffer(Vector3f vector,
java.nio.FloatBuffer buf,
int index)
Updates the values of the given vector from the specified buffer at the
index provided.
|
static void |
populateFromBuffer(Vector4f vector,
java.nio.FloatBuffer buf,
int index)
Updates the values of the given vector from the specified buffer at the
index provided.
|
static void |
printCurrentDirectMemory(java.lang.StringBuilder store) |
static void |
setInBuffer(ColorRGBA color,
java.nio.FloatBuffer buf,
int index)
Sets the data contained in the given color into the FloatBuffer at the
specified index.
|
static void |
setInBuffer(Quaternion quat,
java.nio.FloatBuffer buf,
int index)
Sets the data contained in the given quaternion into the FloatBuffer at
the specified index.
|
static void |
setInBuffer(Vector2f vector,
java.nio.FloatBuffer buf,
int index)
Sets the data contained in the given Vector2F into the FloatBuffer at the
specified index.
|
static void |
setInBuffer(Vector3f vector,
java.nio.FloatBuffer buf,
int index)
Sets the data contained in the given Vector3F into the FloatBuffer at the
specified index.
|
static void |
setInBuffer(Vector4f vec,
java.nio.FloatBuffer buf,
int index)
Sets the data contained in the given vector4 into the FloatBuffer at the
specified index.
|
static void |
setTrackDirectMemoryEnabled(boolean enabled)
Set it to true if you want to enable direct memory tracking for debugging
purpose.
|
public static void setTrackDirectMemoryEnabled(boolean enabled)
enabled
- true to enable tracking, false to disable it
(default=false)public static java.nio.Buffer clone(java.nio.Buffer buf)
buf
- The buffer to clonepublic static java.nio.FloatBuffer createFloatBuffer(Vector3f... data)
data
- array of Vector3f objects to place into a new FloatBufferpublic static java.nio.FloatBuffer createFloatBuffer(Quaternion... data)
data
- array of Quaternion objects to place into a new FloatBufferpublic static java.nio.FloatBuffer createFloatBuffer(Vector4f... data)
data
- array of Vector4 objects to place into a new FloatBufferpublic static java.nio.FloatBuffer createFloatBuffer(ColorRGBA... data)
data
- array of ColorRGBA objects to place into a new FloatBufferpublic static java.nio.FloatBuffer createFloatBuffer(float... data)
data
- array of float primitives to place into a new FloatBufferpublic static java.nio.FloatBuffer createVector3Buffer(int vertices)
vertices
- number of vertices that need to be held by the newly created
bufferpublic static java.nio.FloatBuffer createVector3Buffer(java.nio.FloatBuffer buf, int vertices)
buf
- the buffer to first check and rewindvertices
- number of vertices that need to be held by the newly created
bufferpublic static void setInBuffer(ColorRGBA color, java.nio.FloatBuffer buf, int index)
color
- the data to insertbuf
- the buffer to insert intoindex
- the position to place the data; in terms of colors not floatspublic static void setInBuffer(Quaternion quat, java.nio.FloatBuffer buf, int index)
quat
- the Quaternion
to insertbuf
- the buffer to insert intoindex
- the position to place the data; in terms of quaternions not
floatspublic static void setInBuffer(Vector4f vec, java.nio.FloatBuffer buf, int index)
vec
- the Vector4f
to insertbuf
- the buffer to insert intoindex
- the position to place the data; in terms of vector4 not floatspublic static void setInBuffer(Vector3f vector, java.nio.FloatBuffer buf, int index)
vector
- the data to insertbuf
- the buffer to insert intoindex
- the position to place the data; in terms of vectors not floatspublic static void populateFromBuffer(Vector3f vector, java.nio.FloatBuffer buf, int index)
vector
- the vector to set data onbuf
- the buffer to read fromindex
- the position (in terms of vectors, not floats) to read from
the bufpublic static void populateFromBuffer(Vector4f vector, java.nio.FloatBuffer buf, int index)
vector
- the vector to set data onbuf
- the buffer to read fromindex
- the position (in terms of vectors, not floats) to read from
the bufpublic static Vector3f[] getVector3Array(java.nio.FloatBuffer buff)
buff
- the FloatBuffer to read frompublic static void copyInternalVector3(java.nio.FloatBuffer buf, int fromPos, int toPos)
buf
- the buffer to copy from/tofromPos
- the index of the vector to copytoPos
- the index to copy the vector topublic static void normalizeVector3(java.nio.FloatBuffer buf, int index)
buf
- the buffer to find the Vector3f withinindex
- the position (in terms of vectors, not floats) of the vector
to normalizepublic static void addInBuffer(Vector3f toAdd, java.nio.FloatBuffer buf, int index)
toAdd
- the vector to add frombuf
- the buffer to find the Vector3f withinindex
- the position (in terms of vectors, not floats) of the vector
to add topublic static void multInBuffer(Vector3f toMult, java.nio.FloatBuffer buf, int index)
toMult
- the vector to multiply againstbuf
- the buffer to find the Vector3f withinindex
- the position (in terms of vectors, not floats) of the vector
to multiplypublic static boolean equals(Vector3f check, java.nio.FloatBuffer buf, int index)
check
- the vector to check against - null will return false.buf
- the buffer to compare data withindex
- the position (in terms of vectors, not floats) of the vector
in the buffer to check againstpublic static java.nio.FloatBuffer createFloatBuffer(Vector2f... data)
data
- array of Vector2f objects to place into a new FloatBufferpublic static java.nio.FloatBuffer createVector2Buffer(int vertices)
vertices
- number of vertices that need to be held by the newly created
bufferpublic static java.nio.FloatBuffer createVector2Buffer(java.nio.FloatBuffer buf, int vertices)
buf
- the buffer to first check and rewindvertices
- number of vertices that need to be held by the newly created
bufferpublic static void setInBuffer(Vector2f vector, java.nio.FloatBuffer buf, int index)
vector
- the data to insertbuf
- the buffer to insert intoindex
- the position to place the data; in terms of vectors not floatspublic static void populateFromBuffer(Vector2f vector, java.nio.FloatBuffer buf, int index)
vector
- the vector to set data onbuf
- the buffer to read fromindex
- the position (in terms of vectors, not floats) to read from
the bufpublic static Vector2f[] getVector2Array(java.nio.FloatBuffer buff)
buff
- the FloatBuffer to read frompublic static void copyInternalVector2(java.nio.FloatBuffer buf, int fromPos, int toPos)
buf
- the buffer to copy from/tofromPos
- the index of the vector to copytoPos
- the index to copy the vector topublic static void normalizeVector2(java.nio.FloatBuffer buf, int index)
buf
- the buffer to find the Vector2f withinindex
- the position (in terms of vectors, not floats) of the vector
to normalizepublic static void addInBuffer(Vector2f toAdd, java.nio.FloatBuffer buf, int index)
toAdd
- the vector to add frombuf
- the buffer to find the Vector2f withinindex
- the position (in terms of vectors, not floats) of the vector
to add topublic static void multInBuffer(Vector2f toMult, java.nio.FloatBuffer buf, int index)
toMult
- the vector to multiply againstbuf
- the buffer to find the Vector2f withinindex
- the position (in terms of vectors, not floats) of the vector
to multiplypublic static boolean equals(Vector2f check, java.nio.FloatBuffer buf, int index)
check
- the vector to check against - null will return false.buf
- the buffer to compare data withindex
- the position (in terms of vectors, not floats) of the vector
in the buffer to check againstpublic static java.nio.IntBuffer createIntBuffer(int... data)
data
- array of ints to place into a new IntBufferpublic static int[] getIntArray(java.nio.IntBuffer buff)
buff
- the IntBuffer to read frompublic static float[] getFloatArray(java.nio.FloatBuffer buff)
buff
- the FloatBuffer to read frompublic static java.nio.DoubleBuffer createDoubleBuffer(int size)
size
- required number of double to store.public static java.nio.DoubleBuffer createDoubleBuffer(java.nio.DoubleBuffer buf, int size)
buf
- the buffer to first check and rewindsize
- number of doubles that need to be held by the newly created
bufferpublic static java.nio.DoubleBuffer clone(java.nio.DoubleBuffer buf)
buf
- the DoubleBuffer to copypublic static java.nio.FloatBuffer createFloatBuffer(int size)
size
- required number of floats to store.public static void copyInternal(java.nio.FloatBuffer buf, int fromPos, int toPos, int length)
buf
- the buffer to copy from/tofromPos
- the starting point to copy fromtoPos
- the starting point to copy tolength
- the number of floats to copypublic static java.nio.FloatBuffer clone(java.nio.FloatBuffer buf)
buf
- the FloatBuffer to copypublic static java.nio.IntBuffer createIntBuffer(int size)
size
- required number of ints to store.public static java.nio.IntBuffer createIntBuffer(java.nio.IntBuffer buf, int size)
buf
- the buffer to first check and rewindsize
- number of ints that need to be held by the newly created
bufferpublic static java.nio.IntBuffer clone(java.nio.IntBuffer buf)
buf
- the IntBuffer to copypublic static java.nio.ByteBuffer createByteBuffer(int size)
size
- required number of ints to store.public static java.nio.ByteBuffer createByteBuffer(java.nio.ByteBuffer buf, int size)
buf
- the buffer to first check and rewindsize
- number of bytes that need to be held by the newly created
bufferpublic static java.nio.ByteBuffer createByteBuffer(byte... data)
public static java.nio.ByteBuffer createByteBuffer(java.lang.String data)
public static java.nio.ByteBuffer clone(java.nio.ByteBuffer buf)
buf
- the ByteBuffer to copypublic static java.nio.ShortBuffer createShortBuffer(int size)
size
- required number of shorts to store.public static java.nio.ShortBuffer createShortBuffer(java.nio.ShortBuffer buf, int size)
buf
- the buffer to first check and rewindsize
- number of shorts that need to be held by the newly created
bufferpublic static java.nio.ShortBuffer createShortBuffer(short... data)
public static java.nio.ShortBuffer clone(java.nio.ShortBuffer buf)
buf
- the ShortBuffer to copypublic static java.nio.FloatBuffer ensureLargeEnough(java.nio.FloatBuffer buffer, int required)
required
number of entries
left after the current position of the buffer. If the buffer is too small
a larger one is created and the old one copied to the new buffer.buffer
- buffer that should be checked/copied (may be null)required
- minimum number of elements that should be remaining in the
returned bufferrequired
number of entries, same position as the
input buffer, not nullpublic static java.nio.IntBuffer ensureLargeEnough(java.nio.IntBuffer buffer, int required)
public static java.nio.ShortBuffer ensureLargeEnough(java.nio.ShortBuffer buffer, int required)
public static java.nio.ByteBuffer ensureLargeEnough(java.nio.ByteBuffer buffer, int required)
public static void printCurrentDirectMemory(java.lang.StringBuilder store)
public static void destroyDirectBuffer(java.nio.Buffer toBeDestroyed)
toBeDestroyed
- the buffer to de-allocate (not null)