Example usage for java.nio ByteOrder nativeOrder

List of usage examples for java.nio ByteOrder nativeOrder

Introduction

In this page you can find the example usage for java.nio ByteOrder nativeOrder.

Prototype

public static ByteOrder nativeOrder() 

Source Link

Document

Returns the current platform byte order.

Usage

From source file:Main.java

public static ShortBuffer createShortBuffer(short[] shortData) {
    ShortBuffer drawListBuffer;/*www  .jav  a 2  s  . c o m*/
    ByteBuffer dlb = ByteBuffer.allocateDirect(
            // (# of coordinate values * 2 bytes per short)
            shortData.length * 2);
    dlb.order(ByteOrder.nativeOrder());
    drawListBuffer = dlb.asShortBuffer();
    drawListBuffer.put(shortData);
    drawListBuffer.position(0);
    return drawListBuffer;
}

From source file:Main.java

/**
 * Make a direct NIO FloatBuffer from an array of floats
 * @param arr The array/*w  w  w.  j  av a  2s  .  co  m*/
 * @return The newly created FloatBuffer
 */
public static FloatBuffer makeFloatBuffer(float[] arr) {
    ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.put(arr);
    fb.position(0);
    return fb;
}

From source file:Main.java

/**
 * create a Floatbuffer for a given Array
 * @param array// ww w  . j a v  a 2  s .co  m
 * @return
 */
public static FloatBuffer createFloatBuffer(float[] array) {
    final int floatSize = Float.SIZE / 8;
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length * floatSize);
    byteBuffer.order(ByteOrder.nativeOrder());
    FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
    floatBuffer.put(array);
    floatBuffer.position(0);
    return floatBuffer;
}

From source file:Main.java

/**
 * Creates a {@link FloatBuffer} based on the given data.
 *
 * @param data the data for the buffer/*from   ww  w. ja  va  2  s.  c om*/
 * @return the float buffer
 */
public static FloatBuffer createFloatBuffer(final float[] data) {
    ByteBuffer bbVertices = ByteBuffer.allocateDirect(data.length * 4);
    bbVertices.order(ByteOrder.nativeOrder());
    final FloatBuffer fBuffer = bbVertices.asFloatBuffer();
    fBuffer.put(data);
    fBuffer.position(0);
    return fBuffer;
}

From source file:Main.java

/**
 * Allocates a FloatBuffer with the given length.
 * //ww w.  j a  v  a  2  s .c om
 * @param length The length of the buffer to allocate (in elements, not bytes!).
 * @return The newly allocated buffer.
 */
public static FloatBuffer allocateFloatBuffer(int length) {
    return ByteBuffer.allocateDirect(length * 4) // float == 4 bytes
            .order(ByteOrder.nativeOrder()).asFloatBuffer();
}

From source file:Main.java

/**
 * Allocates a ShortBuffer with the given length.
 *
 * @param length The length of the buffer to allocate (in elements, not bytes!).
 * @return The newly allocated buffer.//w ww.ja va  2s.  c om
 */
public static ShortBuffer allocateShortBuffer(int length) {
    return ByteBuffer.allocateDirect(length * 2) // short == 2 bytes
            .order(ByteOrder.nativeOrder()).asShortBuffer();
}

From source file:Main.java

/**
 * Creates a {@link ShortBuffer} based on the given data.
 *
 * @param data the data for the buffer/*from www.  j  a v a 2 s  .c o m*/
 * @return the short buffer
 */
public static ShortBuffer createShortBuffer(final short[] data) {
    if (data == null) {
        return null;
    }
    ByteBuffer bbVertices = ByteBuffer.allocateDirect(data.length * 4);
    bbVertices.order(ByteOrder.nativeOrder());
    final ShortBuffer fBuffer = bbVertices.asShortBuffer();
    fBuffer.put(data);
    fBuffer.position(0);
    return fBuffer;
}

From source file:Main.java

public static FloatBuffer makeFloatBuffer(float[] i_arr) {
    ByteBuffer bb = ByteBuffer.allocateDirect(i_arr.length * 4);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.put(i_arr);//from   www  .  j  av  a  2  s.c  o m
    fb.position(0);
    return fb;
}

From source file:Main.java

public static FloatBuffer makeBuffer(float[] data) {
    ByteBuffer b = ByteBuffer.allocateDirect(data.length * 4);
    b.order(ByteOrder.nativeOrder());
    FloatBuffer buffer = b.asFloatBuffer();
    buffer.put(data);/* w ww  .  j a va2  s.  co  m*/
    buffer.position(0);
    return buffer;
}

From source file:Main.java

private static final FloatBuffer createDebugColors(int drawMode, int size) {
    ByteBuffer bb = ByteBuffer.allocateDirect(size * 4 * 4);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer colors = bb.asFloatBuffer();
    if (drawMode == GL10.GL_TRIANGLES) {
        for (int i = 0; i < size * 4; i++) {
            colors.put(triangleColors[i % triangleColors.length]);
        }/*  w w w  .  ja  va  2 s . c  o m*/
    } else {
        for (int i = 0; i < size; i++) {
            colors.put(1f);
            colors.put(0f);
            colors.put(1f);
            colors.put(1f);
        }
    }
    colors.rewind();
    return colors;
}