Android FloatBuffer Create createFloatBuffer(float[] floatData)

Here you can find the source of createFloatBuffer(float[] floatData)

Description

create Float Buffer

Declaration

public static final FloatBuffer createFloatBuffer(float[] floatData) 

Method Source Code

//package com.java2s;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

public class Main {
    public static final int FLOAT_SIZE_BYTES = 4;

    public static final FloatBuffer createFloatBuffer(float[] floatData) {
        FloatBuffer buffer = ByteBuffer
                .allocateDirect(floatData.length * FLOAT_SIZE_BYTES)
                .order(ByteOrder.nativeOrder()).asFloatBuffer()
                .put(floatData);/*w w  w  . j  a  v  a2 s.  c  o m*/
        buffer.position(0);

        return buffer;
    }

    /**
     * @param nElements Number of elements to create.
     * @param stride The stride between elements.
     * @return The constructed FloatBuffer
     */
    public static final FloatBuffer createFloatBuffer(int nElements,
            int stride) {
        FloatBuffer buffer = ByteBuffer
                .allocateDirect(nElements * stride * FLOAT_SIZE_BYTES)
                .order(ByteOrder.nativeOrder()).asFloatBuffer();
        buffer.position(0);

        return buffer;
    }
}

Related

  1. copy(float[] src, FloatBuffer dst, int numFloats, int offset)
  2. newFloatBuffer(int numFloats)
  3. newFloatBuffer(int numFloats)
  4. createFloatBuffer(float[] data)
  5. createFloatBuffer(float[] floatData)
  6. createFloatBuffer(int capacity)
  7. createFloatBuffer(int floatCount)
  8. createFloatBuffer(int nElements, int stride)