Add GlUtil createBuffer overload which doesn't copy values

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=217846755
This commit is contained in:
eguven 2018-10-19 03:14:26 -07:00 committed by Oliver Woodman
parent 1ef3efaa90
commit 8f3c3e2841

View File

@ -95,14 +95,23 @@ public final class GlUtil {
return program;
}
/** Allocates a FloatBuffer with the given data. */
/**
* Allocates a FloatBuffer with the given data.
*
* @param data Used to initialize the new buffer.
*/
public static FloatBuffer createBuffer(float[] data) {
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(data.length * C.BYTES_PER_FLOAT);
byteBuffer.order(ByteOrder.nativeOrder());
FloatBuffer buffer = byteBuffer.asFloatBuffer();
buffer.put(data);
buffer.flip();
return buffer;
return (FloatBuffer) createBuffer(data.length).put(data).flip();
}
/**
* Allocates a FloatBuffer.
*
* @param capacity The new buffer's capacity, in floats.
*/
public static FloatBuffer createBuffer(int capacity) {
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(capacity * C.BYTES_PER_FLOAT);
return byteBuffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
}
/**