Commit 8f3c3e28 by eguven Committed by Oliver Woodman

Add GlUtil createBuffer overload which doesn't copy values

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=217846755
parent 1ef3efaa
...@@ -95,14 +95,23 @@ public final class GlUtil { ...@@ -95,14 +95,23 @@ public final class GlUtil {
return program; 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) { public static FloatBuffer createBuffer(float[] data) {
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(data.length * C.BYTES_PER_FLOAT); return (FloatBuffer) createBuffer(data.length).put(data).flip();
byteBuffer.order(ByteOrder.nativeOrder()); }
FloatBuffer buffer = byteBuffer.asFloatBuffer();
buffer.put(data); /**
buffer.flip(); * Allocates a FloatBuffer.
return buffer; *
* @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();
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment