Class APIBuffer

java.lang.Object
com.jme3.lwjgl3.utils.APIBuffer

public class APIBuffer extends Object
Helper class for alternative API functions. Instead of the user passing their own buffer, thread-local instances of this class are used internally instead.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Returns the memory address of the internal ByteBuffer.
    long
    address(int offset)
    Returns the memory address of the specified offset.
    long
    addressSafe(Object value, int offset)
    Returns the memory address of the specified offset or NULL if the specified value is null.
    int
    Ensures space for an additional boolean value and returns the address offset.
    int
    booleanParam(boolean value)
    Ensures space for an additional boolean value, sets the specified value at the allocated offset and returns that offset.
    boolean
    booleanValue(int offset)
    Returns the boolean value at the specified offset.
    Returns the ByteBuffer that backs this APIBuffer.
    int
    bufferParam(int size)
    Ensures space for an additional buffer with the specified size (in bytes) and returns the address offset.
    int
    Ensures space for an additional byte value and returns the address offset.
    int
    byteParam(byte value)
    Ensures space for an additional byte value, sets the specified value at the allocated offset and returns that offset.
    byte
    byteValue(int offset)
    Returns the boolean value at the specified offset.
    int
    Ensures space for an additional double value and returns the address offset.
    int
    doubleParam(double value)
    Ensures space for an additional double value, sets the specified value at the allocated offset and returns that offset.
    double
    doubleValue(int offset)
    Returns the double value at the specified offset.
    int
    Ensures space for an additional float value and returns the address offset.
    int
    floatParam(float value)
    Ensures space for an additional float value, sets the specified value at the allocated offset and returns that offset.
    float
    floatValue(int offset)
    Returns the float value at the specified offset.
    int
    Returns the current parameter offset.
    int
    Ensures space for an additional int value and returns the address offset.
    int
    intParam(int value)
    Ensures space for an additional int value, sets the specified value at the allocated offset and returns that offset.
    void
    intParam(int offset, int index, int value)
    Sets an int value at the specified index of the int buffer that starts at the specified offset.
    int
    intValue(int offset)
    Returns the int value at the specified offset.
    int
    Ensures space for an additional long value and returns the address offset.
    int
    longParam(long value)
    Ensures space for an additional long value, sets the specified value at the allocated offset and returns that offset.
    long
    longValue(int offset)
    Returns the long value at the specified offset.
    void
    pointerArrayFree(int offset, int length)
    Frees length memory blocks stored in the APIBuffer, starting at the specified offset.
    int
    pointerArrayParam(long... pointers)
    Ensures space for an additional pointer buffer, sets the specified memory addresses and returns the address offset.
    int
    Ensures space for an additional pointer buffer, sets the memory addresses of the specified buffers and returns the address offset.
    int
    ASCII encodes the specified strings with a null-terminator and ensures space for a buffer filled with the memory addresses of the encoded strings.
    int
    ASCII encodes the specified strings and ensures space for two additional buffers filled with the lengths and memory addresses of the encoded strings, respectively.
    int
    ASCII encodes the specified strings and ensures space for two additional buffers filled with the lengths and memory addresses of the encoded strings, respectively.
    int
    Ensures space for two additional pointer buffers, sets the memory addresses and remaining bytes of the specified buffers and returns the address offset.
    int
    UTF16 encodes the specified strings with a null-terminator and ensures space for a buffer filled with the memory addresses of the encoded strings.
    int
    UTF16 encodes the specified strings and ensures space for two additional buffers filled with the lengths and memory addresses of the encoded strings, respectively.
    int
    UTF16 encodes the specified strings and ensures space for two additional buffers filled with the lengths and memory addresses of the encoded strings, respectively.
    int
    UTF8 encodes the specified strings with a null-terminator and ensures space for a buffer filled with the memory addresses of the encoded strings.
    int
    UTF8 encodes the specified strings and ensures space for two additional buffers filled with the lengths and memory addresses of the encoded strings, respectively.
    int
    UTF8 encodes the specified strings and ensures space for two additional buffers filled with the lengths and memory addresses of the encoded strings, respectively.
    int
    Ensures space for an additional pointer value and returns the address offset.
    void
    pointerParam(int offset, int index, long value)
    Sets a pointer value at the specified index of the pointer buffer that starts at the specified offset.
    int
    pointerParam(long value)
    Ensures space for an additional pointer value, sets the specified value at the allocated offset and returns that offset.
    long
    pointerValue(int offset)
    Returns the pointer value at the specified offset.
    pop()
    Restores the last pushed parameter offset.
    Pushes the current parameter offset to a stack.
    Resets the parameter offset to 0.
    void
    setOffset(int offset)
    Sets the current parameter offset.
    int
    Ensures space for an additional short value and returns the address offset.
    int
    shortParam(short value)
    Ensures space for an additional short value, sets the specified value at the allocated offset and returns that offset.
    short
    shortValue(int offset)
    Returns the short value at the specified offset.
    int
    stringParamASCII(CharSequence value, boolean nullTerminated)
    Ensures space for the specified string encoded in ASCII, encodes the string at the allocated offset and returns that offset.
    int
    stringParamUTF16(CharSequence value, boolean nullTerminated)
    Ensures space for the specified string encoded in UTF-16, encodes the string at the allocated offset and returns that offset.
    int
    stringParamUTF8(CharSequence value, boolean nullTerminated)
    Ensures space for the specified string encoded in UTF-8, encodes the string at the allocated offset and returns that offset.
    stringValueASCII(int offset, int limit)
    Returns the ASCII string value at the specified byte range.
    stringValueUTF16(int offset, int limit)
    Returns the UTF16 string value at the specified byte range.
    stringValueUTF8(int offset, int limit)
    Returns the UTF8 string value at the specified byte range.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • APIBuffer

      public APIBuffer()
  • Method Details

    • reset

      public APIBuffer reset()
      Resets the parameter offset to 0.
    • push

      public APIBuffer push()
      Pushes the current parameter offset to a stack.
    • pop

      public APIBuffer pop()
      Restores the last pushed parameter offset.
    • getOffset

      public int getOffset()
      Returns the current parameter offset.
    • setOffset

      public void setOffset(int offset)
      Sets the current parameter offset.
    • address

      public long address()
      Returns the memory address of the internal ByteBuffer. This address may change after a call to one of the <type>Param() methods.
    • address

      public long address(int offset)
      Returns the memory address of the specified offset. This address may change after a call to one of the <type>Param() methods.
    • addressSafe

      public long addressSafe(Object value, int offset)
      Returns the memory address of the specified offset or NULL if the specified value is null. This address may change after a call to one of the <type>Param() methods.
    • buffer

      public ByteBuffer buffer()
      Returns the ByteBuffer that backs this APIBuffer.
    • booleanParam

      public int booleanParam()
      Ensures space for an additional boolean value and returns the address offset.
    • byteParam

      public int byteParam()
      Ensures space for an additional byte value and returns the address offset.
    • shortParam

      public int shortParam()
      Ensures space for an additional short value and returns the address offset.
    • intParam

      public int intParam()
      Ensures space for an additional int value and returns the address offset.
    • longParam

      public int longParam()
      Ensures space for an additional long value and returns the address offset.
    • floatParam

      public int floatParam()
      Ensures space for an additional float value and returns the address offset.
    • doubleParam

      public int doubleParam()
      Ensures space for an additional double value and returns the address offset.
    • pointerParam

      public int pointerParam()
      Ensures space for an additional pointer value and returns the address offset.
    • bufferParam

      public int bufferParam(int size)
      Ensures space for an additional buffer with the specified size (in bytes) and returns the address offset.
    • booleanParam

      public int booleanParam(boolean value)
      Ensures space for an additional boolean value, sets the specified value at the allocated offset and returns that offset.
    • byteParam

      public int byteParam(byte value)
      Ensures space for an additional byte value, sets the specified value at the allocated offset and returns that offset.
    • shortParam

      public int shortParam(short value)
      Ensures space for an additional short value, sets the specified value at the allocated offset and returns that offset.
    • intParam

      public int intParam(int value)
      Ensures space for an additional int value, sets the specified value at the allocated offset and returns that offset.
    • longParam

      public int longParam(long value)
      Ensures space for an additional long value, sets the specified value at the allocated offset and returns that offset.
    • floatParam

      public int floatParam(float value)
      Ensures space for an additional float value, sets the specified value at the allocated offset and returns that offset.
    • doubleParam

      public int doubleParam(double value)
      Ensures space for an additional double value, sets the specified value at the allocated offset and returns that offset.
    • pointerParam

      public int pointerParam(long value)
      Ensures space for an additional pointer value, sets the specified value at the allocated offset and returns that offset.
    • pointerArrayParam

      public int pointerArrayParam(long... pointers)
      Ensures space for an additional pointer buffer, sets the specified memory addresses and returns the address offset.
    • pointerArrayParam

      public int pointerArrayParam(ByteBuffer... buffers)
      Ensures space for an additional pointer buffer, sets the memory addresses of the specified buffers and returns the address offset.
    • pointerArrayParamp

      public int pointerArrayParamp(ByteBuffer... buffers)
      Ensures space for two additional pointer buffers, sets the memory addresses and remaining bytes of the specified buffers and returns the address offset.
    • pointerArrayParamASCII

      public int pointerArrayParamASCII(CharSequence... strings)
      ASCII encodes the specified strings with a null-terminator and ensures space for a buffer filled with the memory addresses of the encoded strings.

      The encoded buffers must be later freed with pointerArrayFree(int, int).

      Returns:
      the offset to the memory address buffer
    • pointerArrayParamASCIIi

      public int pointerArrayParamASCIIi(CharSequence... strings)
      ASCII encodes the specified strings and ensures space for two additional buffers filled with the lengths and memory addresses of the encoded strings, respectively. The lengths are 4-bytes integers and the memory address buffer starts immediately after the lengths buffer.

      The encoded buffers must be later freed with pointerArrayFree(int, int).

      Returns:
      the offset to the lengths buffer
    • pointerArrayParamASCIIp

      public int pointerArrayParamASCIIp(CharSequence... strings)
      ASCII encodes the specified strings and ensures space for two additional buffers filled with the lengths and memory addresses of the encoded strings, respectively. The lengths are pointer-sized integers and the memory address buffer starts immediately after the lengths buffer.

      The encoded buffers must be later freed with pointerArrayFree(int, int).

      Returns:
      the offset to the lengths buffer
    • pointerArrayParamUTF8

      public int pointerArrayParamUTF8(CharSequence... strings)
      UTF8 encodes the specified strings with a null-terminator and ensures space for a buffer filled with the memory addresses of the encoded strings.

      The encoded buffers must be later freed with pointerArrayFree(int, int).

      Returns:
      the offset to the memory address buffer
    • pointerArrayParamUTF8i

      public int pointerArrayParamUTF8i(CharSequence... strings)
      UTF8 encodes the specified strings and ensures space for two additional buffers filled with the lengths and memory addresses of the encoded strings, respectively. The lengths are 4-bytes integers and the memory address buffer starts immediately after the lengths buffer.

      The encoded buffers must be later freed with pointerArrayFree(int, int).

      Returns:
      the offset to the lengths buffer
    • pointerArrayParamUTF8p

      public int pointerArrayParamUTF8p(CharSequence... strings)
      UTF8 encodes the specified strings and ensures space for two additional buffers filled with the lengths and memory addresses of the encoded strings, respectively. The lengths are pointer-sized integers and the memory address buffer starts immediately after the lengths buffer.

      The encoded buffers must be later freed with pointerArrayFree(int, int).

      Returns:
      the offset to the lengths buffer
    • pointerArrayParamUTF16

      public int pointerArrayParamUTF16(CharSequence... strings)
      UTF16 encodes the specified strings with a null-terminator and ensures space for a buffer filled with the memory addresses of the encoded strings.

      The encoded buffers must be later freed with pointerArrayFree(int, int).

      Returns:
      the offset to the memory address buffer
    • pointerArrayParamUTF16i

      public int pointerArrayParamUTF16i(CharSequence... strings)
      UTF16 encodes the specified strings and ensures space for two additional buffers filled with the lengths and memory addresses of the encoded strings, respectively. The lengths are 4-bytes integers and the memory address buffer starts immediately after the lengths buffer.

      The encoded buffers must be later freed with pointerArrayFree(int, int).

      Returns:
      the offset to the lengths buffer
    • pointerArrayParamUTF16p

      public int pointerArrayParamUTF16p(CharSequence... strings)
      UTF16 encodes the specified strings and ensures space for two additional buffers filled with the lengths and memory addresses of the encoded strings, respectively. The lengths are pointer-sized integers and the memory address buffer starts immediately after the lengths buffer.

      The encoded buffers must be later freed with pointerArrayFree(int, int).

      Returns:
      the offset to the lengths buffer
    • pointerArrayFree

      public void pointerArrayFree(int offset, int length)
      Frees length memory blocks stored in the APIBuffer, starting at the specified offset.
    • intParam

      public void intParam(int offset, int index, int value)
      Sets an int value at the specified index of the int buffer that starts at the specified offset.
    • pointerParam

      public void pointerParam(int offset, int index, long value)
      Sets a pointer value at the specified index of the pointer buffer that starts at the specified offset.
    • stringParamASCII

      public int stringParamASCII(CharSequence value, boolean nullTerminated)
      Ensures space for the specified string encoded in ASCII, encodes the string at the allocated offset and returns that offset.
    • stringParamUTF8

      public int stringParamUTF8(CharSequence value, boolean nullTerminated)
      Ensures space for the specified string encoded in UTF-8, encodes the string at the allocated offset and returns that offset.
    • stringParamUTF16

      public int stringParamUTF16(CharSequence value, boolean nullTerminated)
      Ensures space for the specified string encoded in UTF-16, encodes the string at the allocated offset and returns that offset.
    • booleanValue

      public boolean booleanValue(int offset)
      Returns the boolean value at the specified offset.
    • byteValue

      public byte byteValue(int offset)
      Returns the boolean value at the specified offset.
    • shortValue

      public short shortValue(int offset)
      Returns the short value at the specified offset.
    • intValue

      public int intValue(int offset)
      Returns the int value at the specified offset.
    • longValue

      public long longValue(int offset)
      Returns the long value at the specified offset.
    • floatValue

      public float floatValue(int offset)
      Returns the float value at the specified offset.
    • doubleValue

      public double doubleValue(int offset)
      Returns the double value at the specified offset.
    • pointerValue

      public long pointerValue(int offset)
      Returns the pointer value at the specified offset.
    • stringValueASCII

      public String stringValueASCII(int offset, int limit)
      Returns the ASCII string value at the specified byte range.
    • stringValueUTF8

      public String stringValueUTF8(int offset, int limit)
      Returns the UTF8 string value at the specified byte range.
    • stringValueUTF16

      public String stringValueUTF16(int offset, int limit)
      Returns the UTF16 string value at the specified byte range.