Class BufferUtils

java.lang.Object
com.blackrook.gloop.opengl.util.BufferUtils

public final class BufferUtils extends Object
Simple utility functions around buffers.
Author:
Matthew Tropiano
  • Field Details

    • SIZEOF_CHAR

      public static final int SIZEOF_CHAR
      The size of a character in bytes.
      See Also:
    • SIZEOF_INT

      public static final int SIZEOF_INT
      The size of an int in bytes.
      See Also:
    • SIZEOF_FLOAT

      public static final int SIZEOF_FLOAT
      The size of a float in bytes.
      See Also:
    • SIZEOF_BYTE

      public static final int SIZEOF_BYTE
      The size of a byte in bytes (This should always be 1, or Sun screwed up).
      See Also:
    • SIZEOF_SHORT

      public static final int SIZEOF_SHORT
      The size of a short in bytes.
      See Also:
    • SIZEOF_LONG

      public static final int SIZEOF_LONG
      The size of a long in bytes.
      See Also:
    • SIZEOF_DOUBLE

      public static final int SIZEOF_DOUBLE
      The size of a double in bytes.
      See Also:
  • Method Details

    • allocDirectByteBuffer

      public static ByteBuffer allocDirectByteBuffer(int len)
      Allocates space for a DIRECT ByteBuffer in native byte order (which really doesn't matter).
      Parameters:
      len - the length (IN BYTES) of the buffer.
      Returns:
      a direct buffer that can hold len items.
    • allocDirectIntBuffer

      public static IntBuffer allocDirectIntBuffer(int len)
      Allocates space for a DIRECT IntBuffer in native byte order.
      Parameters:
      len - the length (IN INTS) of the buffer.
      Returns:
      a direct buffer that can hold len items.
    • allocDirectFloatBuffer

      public static FloatBuffer allocDirectFloatBuffer(int len)
      Allocates space for a DIRECT FloatBuffer in native byte order.
      Parameters:
      len - the length (IN FLOATS) of the buffer.
      Returns:
      a direct buffer that can hold len items.
    • allocDirectLongBuffer

      public static LongBuffer allocDirectLongBuffer(int len)
      Allocates space for a DIRECT LongBuffer in native byte order
      Parameters:
      len - the length (IN LONGS) of the buffer.
      Returns:
      a direct buffer that can hold len items.
    • allocDirectShortBuffer

      public static ShortBuffer allocDirectShortBuffer(int len)
      Allocates space for a DIRECT ShortBuffer in native byte order
      Parameters:
      len - the length (IN SHORTS) of the buffer.
      Returns:
      a direct buffer that can hold len items.
    • allocDirectCharBuffer

      public static CharBuffer allocDirectCharBuffer(int len)
      Allocates space for a DIRECT CharBuffer in native byte order
      Parameters:
      len - the length (IN CHARS) of the buffer.
      Returns:
      a direct buffer that can hold len items.
    • allocDirectDoubleBuffer

      public static DoubleBuffer allocDirectDoubleBuffer(int len)
      Allocates space for a DIRECT DoubleBuffer in native byte order
      Parameters:
      len - the length (IN DOUBLES) of the buffer.
      Returns:
      a direct buffer that can hold len items.
    • wrapDirectBuffer

      public static ByteBuffer wrapDirectBuffer(byte[] b)
      Allocates a DIRECT ByteBuffer using byte array data. Useful for native wrappers that require direct ByteBuffers.
      Parameters:
      b - the byte array to wrap.
      Returns:
      a direct buffer that holds len items.
    • wrapDirectBuffer

      public static ShortBuffer wrapDirectBuffer(short[] s)
      Allocates a DIRECT ShortBuffer using short array data. Useful for native wrappers that require direct ShortBuffers.
      Parameters:
      s - the short array to wrap.
      Returns:
      a direct buffer that holds len items.
    • wrapDirectBuffer

      public static IntBuffer wrapDirectBuffer(int[] i)
      Allocates a DIRECT IntBuffer using int array data. Useful for native wrappers that require direct IntBuffers.
      Parameters:
      i - the int array to wrap.
      Returns:
      a direct buffer that holds len items.
    • wrapDirectBuffer

      public static FloatBuffer wrapDirectBuffer(float[] f)
      Allocates a DIRECT FloatBuffer using float array data. Useful for native wrappers that require direct FloatBuffers.
      Parameters:
      f - the float array to wrap.
      Returns:
      a direct buffer that holds len items.
    • wrapDirectBuffer

      public static LongBuffer wrapDirectBuffer(long[] l)
      Allocates a DIRECT LongBuffer using long array data. Useful for native wrappers that require direct LongBuffers.
      Parameters:
      l - the long array to wrap.
      Returns:
      a direct buffer that holds len items.
    • wrapDirectBuffer

      public static DoubleBuffer wrapDirectBuffer(double[] d)
      Allocates a DIRECT DoubleBuffer using double array data. Useful for native wrappers that require direct DoubleBuffers.
      Parameters:
      d - the double array to wrap.
      Returns:
      a direct buffer that holds len items.
    • printBuffer

      public static void printBuffer(ByteBuffer buffer, PrintStream out)
      Prints the contents of a buffer to an output print stream.
      Parameters:
      buffer - the buffer to print.
      out - the PrintStream to output the dump to.
    • printBuffer

      public static void printBuffer(CharBuffer buffer, PrintStream out)
      Prints the contents of a buffer to an output print stream.
      Parameters:
      buffer - the buffer to print.
      out - the PrintStream to output the dump to.
    • printBuffer

      public static void printBuffer(ShortBuffer buffer, PrintStream out)
      Prints the contents of a buffer to an output print stream.
      Parameters:
      buffer - the buffer to print.
      out - the PrintStream to output the dump to.
    • printBuffer

      public static void printBuffer(IntBuffer buffer, PrintStream out)
      Prints the contents of a buffer to an output print stream.
      Parameters:
      buffer - the buffer to print.
      out - the PrintStream to output the dump to.
    • printBuffer

      public static void printBuffer(FloatBuffer buffer, PrintStream out)
      Prints the contents of a buffer to an output print stream.
      Parameters:
      buffer - the buffer to print.
      out - the PrintStream to output the dump to.
    • printBuffer

      public static void printBuffer(LongBuffer buffer, PrintStream out)
      Prints the contents of a buffer to an output print stream.
      Parameters:
      buffer - the buffer to print.
      out - the PrintStream to output the dump to.
    • printBuffer

      public static void printBuffer(DoubleBuffer buffer, PrintStream out)
      Prints the contents of a buffer to an output print stream.
      Parameters:
      buffer - the buffer to print.
      out - the PrintStream to output the dump to.