Example usage for java.nio FloatBuffer rewind

List of usage examples for java.nio FloatBuffer rewind

Introduction

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

Prototype

public final Buffer rewind() 

Source Link

Document

Rewinds this buffer.

Usage

From source file:Main.java

public static void main(String[] args) {
    FloatBuffer floatBuffer = FloatBuffer.allocate(10);

    floatBuffer.put(0, 1.23F);/*from  w  w  w. ja  v a2  s  .  c  o  m*/

    floatBuffer.rewind();

    FloatBuffer floatBuffer1 = FloatBuffer.allocate(10);

    floatBuffer1.put(floatBuffer);

    System.out.println(floatBuffer.arrayOffset());

}

From source file:Main.java

public static void main(String[] args) {
    FloatBuffer floatBuffer = FloatBuffer.allocate(10);

    floatBuffer.put(0, 1.23F);/*from w w w .  j a  va2 s .c  om*/

    floatBuffer.rewind();

    float[] floatArray = new float[10];

    floatBuffer.get(floatArray);

    System.out.println(Arrays.toString(floatArray));

}

From source file:Main.java

public static void main(String[] args) {
    FloatBuffer floatBuffer = FloatBuffer.allocate(10);

    floatBuffer.put(0, 1.23F);/*from w  ww.j a  v  a2s. co  m*/

    floatBuffer.rewind();

    float[] floatArray = new float[10];

    floatBuffer.get(floatArray, 0, 3);

    System.out.println(Arrays.toString(floatArray));

}

From source file:Main.java

/**
 * Creates a float array from the provided {@link FloatBuffer}.
 * //w w w .j  a  v a2s  .c  o  m
 * @param buffer {@link FloatBuffer} the data source.
 * @return float array containing the data of the buffer.
 */
public static float[] getFloatArrayFromBuffer(FloatBuffer buffer) {
    float[] array = null;
    if (buffer.hasArray()) {
        array = buffer.array();
    } else {
        buffer.rewind();
        array = new float[buffer.capacity()];
        buffer.get(array);
    }
    return array;
}

From source file:Main.java

public static FloatBuffer createVector4Buffer(final FloatBuffer buf, final int vertices) {
    if (buf != null && buf.limit() == 4 * vertices) {
        buf.rewind();
        return buf;
    }/*from www .j a  v  a  2  s  .c  om*/
    return createFloatBuffer(4 * vertices);
}

From source file:Main.java

public static FloatBuffer createVector3Buffer(final FloatBuffer buf, final int vertices) {
    if (buf != null && buf.limit() == 3 * vertices) {
        buf.rewind();
        return buf;
    }//from w w  w . j  a va 2s  .c om

    return createFloatBuffer(3 * vertices);
}

From source file:Main.java

public static FloatBuffer createVector2Buffer(final FloatBuffer buf, final int vertices) {
    if (buf != null && buf.limit() == 2 * vertices) {
        buf.rewind();
        return buf;
    }//ww w.  j a  v a2  s .co m

    return createFloatBuffer(2 * vertices);
}

From source file:Main.java

public static FloatBuffer createVector4Buffer(final FloatBuffer buf, final int vertices) {
    if (buf != null && buf.limit() == SIZEOF_FLOAT * vertices) {
        buf.rewind();
        return buf;
    }/*from w  w  w .  j  a  v  a2s.  co m*/
    return createFloatBuffer(SIZEOF_FLOAT * vertices);
}

From source file:Main.java

public static FloatBuffer ensureLargeEnough(FloatBuffer buf, final int required) {
    if (buf == null || (buf.remaining() < required)) {
        final int position = (buf != null ? buf.position() : 0);
        final FloatBuffer newVerts = createFloatBuffer(position + required);
        if (buf != null) {
            buf.rewind();
            newVerts.put(buf);//w  w  w  .  ja v  a  2 s  .  c  om
            newVerts.position(position);
        }
        buf = newVerts;
    }
    return buf;
}

From source file:Main.java

public static FloatBuffer clone(final FloatBuffer buf) {
    if (buf == null) {
        return null;
    }// w  ww  .  j a  v a  2s  . c  om
    buf.rewind();

    final FloatBuffer copy;
    if (buf.isDirect()) {
        copy = createFloatBuffer(buf.limit());
    } else {
        copy = createFloatBufferOnHeap(buf.limit());
    }
    copy.put(buf);

    return copy;
}