Example usage for java.nio FloatBuffer position

List of usage examples for java.nio FloatBuffer position

Introduction

In this page you can find the example usage for java.nio FloatBuffer position.

Prototype

public final Buffer position(int newPosition) 

Source Link

Document

Sets the position of this buffer.

Usage

From source file:Main.java

public static FloatBuffer create(float[] data) {
    FloatBuffer fb = create(data.length * 4).asFloatBuffer().put(data);
    fb.position(0);
    return fb;//from  w  w  w .ja  v  a  2s.c  o m
}

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);/*from w  w w.j  a v  a  2s.co  m*/
    buffer.position(0);
    return buffer;
}

From source file:Main.java

public static FloatBuffer createFloatBuffer(float[] coords) {
    FloatBuffer fb = createFloatBuffer(coords.length);
    fb.put(coords);// ww  w . jav a2 s  . c  o  m
    fb.position(0);
    return fb;
}

From source file:Main.java

/**
 * Allocates a direct float buffer, and populates it with the float array data.
 *//* ww  w. j ava  2 s  . c  om*/
public static FloatBuffer createFloatBuffer(float[] coords) {
    // Allocate a direct ByteBuffer, using 4 bytes per float, and copy coords into it.
    ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * SIZEOF_FLOAT);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.put(coords);
    fb.position(0);
    return fb;
}

From source file:Main.java

public static FloatBuffer toFloatBufferPositionZero(float[] values) {
    ByteBuffer vbb = ByteBuffer.allocateDirect(values.length * 4);
    vbb.order(ByteOrder.nativeOrder());
    FloatBuffer buffer = vbb.asFloatBuffer();
    buffer.put(values);/*w ww  .jav a  2 s .com*/
    buffer.position(0);
    return buffer;
}

From source file:Main.java

public static FloatBuffer makeFloatBuffer(int length) {
    final int floatSize = Float.SIZE / 8;
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(length * floatSize);
    byteBuffer.order(ByteOrder.nativeOrder());
    FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
    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  o m
 * @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

public static FloatBuffer floatArrayToBuffer(float[] floatArray) {
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(floatArray.length * 4);
    byteBuffer.order(ByteOrder.nativeOrder());
    FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
    floatBuffer.put(floatArray);/*from   w  w  w .  j a  v a  2 s. co  m*/
    floatBuffer.position(0);
    return floatBuffer;
}

From source file:Main.java

public static FloatBuffer toFloatBufferPositionZero(float[] values) {
    final ByteBuffer vbb = ByteBuffer.allocateDirect(values.length * 4);
    vbb.order(ByteOrder.nativeOrder());
    final FloatBuffer buffer = vbb.asFloatBuffer();
    buffer.put(values);//from   www. j  av  a2s.c  om
    buffer.position(0);
    return buffer;
}

From source file:Main.java

/**
 * create a Floatbuffer for a given Array
 * @param array/* w ww  . j a  va 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;
}