Android FloatBuffer Create createFloatBuffer(int nElements, int stride)

Here you can find the source of createFloatBuffer(int nElements, int stride)

Description

create Float Buffer

Parameter

Parameter Description
nElements Number of elements to create.
stride The stride between elements.

Return

The constructed FloatBuffer

Declaration

public static final FloatBuffer createFloatBuffer(int nElements,
        int stride) 

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);/*from w ww . java  2 s  . com*/
        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. createFloatBuffer(float[] data)
  2. createFloatBuffer(float[] floatData)
  3. createFloatBuffer(float[] floatData)
  4. createFloatBuffer(int capacity)
  5. createFloatBuffer(int floatCount)
  6. createFloatBuffer(int nElements, int stride)
  7. createFloatBuffer(int size)
  8. createFloatBuffer(int size)
  9. createFloatBuffer(int size)