List of usage examples for java.nio FloatBuffer put
public FloatBuffer put(FloatBuffer src)
From source file:Main.java
public static FloatBuffer toFloatBuffer(final float[] data) { final FloatBuffer buffer = ByteBuffer.allocateDirect(data.length * FLOAT_SIZE_BYTES) .order(ByteOrder.nativeOrder()).asFloatBuffer(); buffer.put(data).position(0); return buffer; }
From source file:Main.java
public static FloatBuffer createFloatBuffer(FloatBuffer buffer) { FloatBuffer dest = createFloatBuffer(buffer.capacity()); dest.clear();//from w w w. jav a2 s . c o m dest.put(buffer); dest.position(0); return dest; }
From source file:Main.java
public static FloatBuffer createFloatBuffer(FloatBuffer buf) { FloatBuffer dest = createFloatBuffer(buf.capacity()); dest.clear();// w w w .j a v a2 s.c o m dest.put(buf); dest.position(0); return dest; }
From source file:Main.java
public static void copy(final float[] data, final FloatBuffer buf, final int fromPos, final int toPos) { buf.position(fromPos);//w w w . java2 s. c o m buf.get(data); buf.position(toPos); buf.put(data); }
From source file:Main.java
private static final FloatBuffer createDebugColors(int drawMode, int size) { ByteBuffer bb = ByteBuffer.allocateDirect(size * 4 * 4); bb.order(ByteOrder.nativeOrder()); FloatBuffer colors = bb.asFloatBuffer(); if (drawMode == GL10.GL_TRIANGLES) { for (int i = 0; i < size * 4; i++) { colors.put(triangleColors[i % triangleColors.length]); }/*from w w w .j a v a2s. co m*/ } else { for (int i = 0; i < size; i++) { colors.put(1f); colors.put(0f); colors.put(1f); colors.put(1f); } } colors.rewind(); return colors; }
From source file:Main.java
public static FloatBuffer float2Buffer(float[] a) { FloatBuffer floatBuffer; ByteBuffer bb = ByteBuffer.allocateDirect(a.length * 4); bb.order(ByteOrder.nativeOrder()); floatBuffer = bb.asFloatBuffer();//from w ww.j a va 2 s. c o m floatBuffer.put(a); floatBuffer.position(0); return floatBuffer; }
From source file:Main.java
/** * Copies floats from one position in the buffer to another. * //from ww w .j a v a 2 s . c o m * @param buf * the buffer to copy from/to * @param fromPos * the starting point to copy from * @param toPos * the starting point to copy to * @param length * the number of floats to copy */ public static void copyInternal(FloatBuffer buf, int fromPos, int toPos, int length) { float[] data = new float[length]; buf.position(fromPos); buf.get(data); buf.position(toPos); buf.put(data); }
From source file:Main.java
public static FloatBuffer createFloatBuffer(float[] triangleCoords) { FloatBuffer vertexbuffer; ByteBuffer bb = ByteBuffer.allocateDirect(triangleCoords.length * 4);// 9*4 bb.order(ByteOrder.nativeOrder()); vertexbuffer = bb.asFloatBuffer();//from ww w.j a v a 2 s . com vertexbuffer.put(triangleCoords); vertexbuffer.position(0); return vertexbuffer; }
From source file:de.ailis.threedee.utils.BufferUtils.java
/** * Converts the specified float buffer to native endian and returns this new * buffer. If buffer is already in correct endian format then it is returned * right away./*from w w w . j av a 2 s .c o m*/ * * @param buffer * The float buffer to convert * @return The converted float buffer or the source buffer if no conversion * is needed */ public static FloatBuffer convertToNativeEndian(final FloatBuffer buffer) { if (buffer.order() == ByteOrder.nativeOrder()) return buffer; if (log.isTraceEnabled()) log.trace("Converting endianess of " + buffer.capacity() + " floats"); final ByteBuffer bytes = ByteBuffer.allocateDirect(buffer.capacity()); bytes.order(ByteOrder.nativeOrder()); final FloatBuffer floats = bytes.asFloatBuffer(); floats.put(buffer).rewind(); return floats; }
From source file:Main.java
public static FloatBuffer ensureLargeEnough(FloatBuffer buf, final int required) { if (buf == null || (buf.remaining() < required)) { final int position = (buf != null ? buf.position() : 0); final FloatBuffer newVerts = createFloatBuffer(position + required); if (buf != null) { buf.rewind();//from w ww . ja va 2 s .c o m newVerts.put(buf); newVerts.position(position); } buf = newVerts; } return buf; }