Android FloatBuffer Create setupFloatBuffer(FloatBuffer preBuffer, float[] array)

Here you can find the source of setupFloatBuffer(FloatBuffer preBuffer, float[] array)

Description

setup Float Buffer

License

Open Source License

Declaration

public static FloatBuffer setupFloatBuffer(FloatBuffer preBuffer,
            float[] array) 

Method Source Code

//package com.java2s;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

public class Main {
    public static FloatBuffer setupFloatBuffer(FloatBuffer preBuffer,
            float[] array) {

        if (preBuffer == null || preBuffer.capacity() < array.length) {
            preBuffer = createFloatBuffer(array.length * 2);
        } else {//w ww .  j av  a  2 s .  com
            preBuffer.clear();
        }
        preBuffer.put(array);
        preBuffer.position(0);
        return preBuffer;
    }

    public static FloatBuffer createFloatBuffer(int floatCount) {
        ByteBuffer data = ByteBuffer.allocateDirect(floatCount * 4);
        data.order(ByteOrder.nativeOrder());
        FloatBuffer p1 = data.asFloatBuffer();
        return p1;
    }
}

Related

  1. toFloatBuffer(float[] array)
  2. arr2FloatBuffer(float [] arr)
  3. arr2FloatBuffer(float[] coords)
  4. floatToBuffer(float[] a)
  5. floatToBuffer(float[] a)
  6. list2FloatBuffer(List arr)
  7. list2FloatBuffer(List list)
  8. getFloatBuffer(float[] list)
  9. buildFloatBuffer(float[] buffer)