@Override public FloatBuffer sliceBuffer(FloatBuffer buffer) { return buffer.slice(); }
@Override public FloatBuffer sliceBuffer(FloatBuffer buffer) { return buffer.slice(); }
/** * Create a new direct byte buffer with native byte order that has the * same contents as the given float buffer. * * @param buffer The input buffer * @return The new byte buffer */ public static ByteBuffer createByteBufferFrom(FloatBuffer buffer) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(buffer.capacity() * Float.BYTES); FloatBuffer floatBuffer = byteBuffer.order(ByteOrder.nativeOrder()).asFloatBuffer(); floatBuffer.put(buffer.slice()); return byteBuffer; }
public static FloatBuffer sliced( FloatBuffer buffer, int first, int count ) { FloatBuffer buffer2 = buffer.duplicate( ); buffer2.limit( first + count ); buffer2.position( first ); return buffer2.slice( ); }
fb.position( floatStartPos ); fb.limit( floatStartPos + floatSize ); res = fb.slice(); // slice and duplicate may change byte order } else { throw new InternalError("Buffer not ByteBuffer, nor FloarBuffer, nor backing array given");
/** * @param position * in the normal buffer. * @param limit * the number of ordinates to copy * @return a copy of the direct normal floatbuffer, or <code>null</code> if the position /limit is out of range. */ public FloatBuffer getNormals( int position, int limit ) { if ( position < 0 || position > normalBuffer.capacity() ) { return null; } FloatBuffer fb = normalBuffer.asReadOnlyBuffer(); fb.position( position ); fb.limit( position + limit ); return fb.slice(); }
/** * @param position * in the texture buffer. * @param limit * the number of ordinates to copy * @return a copy of the direct texture floatbuffer, or <code>null</code> if the position/limit is out of range. */ public FloatBuffer getTextureCoordinates( int position, int limit ) { if ( position < 0 || position > textureBuffer.capacity() ) { return null; } FloatBuffer fb = textureBuffer.asReadOnlyBuffer(); fb.position( position ); fb.limit( position + limit ); return fb.slice(); }
/** * Calls slice on the specified buffer while maintaining the byteorder. * @see #slice(java.nio.Buffer, int, int) */ @SuppressWarnings("unchecked") public static <B extends Buffer> B slice(final B buffer) { if (buffer instanceof ByteBuffer) { final ByteBuffer bb = (ByteBuffer) buffer; return (B) bb.slice().order(bb.order()); // slice and duplicate may change byte order } else if (buffer instanceof IntBuffer) { return (B) ((IntBuffer) buffer).slice(); } else if (buffer instanceof ShortBuffer) { return (B) ((ShortBuffer) buffer).slice(); } else if (buffer instanceof FloatBuffer) { return (B) ((FloatBuffer) buffer).slice(); } else if (buffer instanceof DoubleBuffer) { return (B) ((DoubleBuffer) buffer).slice(); } else if (buffer instanceof LongBuffer) { return (B) ((LongBuffer) buffer).slice(); } else if (buffer instanceof CharBuffer) { return (B) ((CharBuffer) buffer).slice(); } throw new IllegalArgumentException("unexpected buffer type: " + buffer.getClass()); }
/** * @param position * in the coordinates buffer. * @param limit * the number of ordinates to copy * @return a copy of the direct coordinate floatbuffer, or <code>null</code> if the position /limit is out of range. */ public FloatBuffer getCoords( int position, int limit ) { if ( position < 0 || position > coordBuffer.capacity() ) { return null; } FloatBuffer fb = coordBuffer.asReadOnlyBuffer(); fb.position( position ); fb.limit( position + limit ); return fb.slice(); }
/** * Place holder for {@code Buffer.slice()}. * * @param b the buffer to slice. * @return the sliced buffer. */ public static Buffer slice(Buffer b) { if (b instanceof ByteBuffer) return ((ByteBuffer) b).slice(); if (b instanceof ShortBuffer) return ((ShortBuffer) b).slice(); if (b instanceof IntBuffer) return ((IntBuffer) b).slice(); if (b instanceof LongBuffer) return ((LongBuffer) b).slice(); if (b instanceof FloatBuffer) return ((FloatBuffer) b).slice(); if (b instanceof DoubleBuffer) return ((DoubleBuffer) b).slice(); throw new IllegalArgumentException(); } }
public static FloatBuffer getDirectBuffer(int size, FloatBuffer buffer) { if (buffer == null) { return buffer; } size = round4(size); if (buffer.isDirect()) { buffer.limit((size >> 2) + buffer.position()); return buffer; } FloatBuffer directBuffer = allocateDirectBuffer(size).asFloatBuffer(); directBuffer.put((FloatBuffer) ((FloatBuffer) buffer).slice().limit(size >> 2)); directBuffer.rewind(); return directBuffer; }
private static ByteBuffer getByteBuffer(int size, Buffer buffer, int bufferOffset) { if (buffer instanceof ByteBuffer) { buffer.limit(size); buffer.position(bufferOffset); return (ByteBuffer) buffer; } else if (buffer instanceof IntBuffer) { size = round4(size); ByteBuffer directBuffer = allocateDirectBuffer(size); directBuffer.asIntBuffer().put((IntBuffer) ((IntBuffer) buffer).slice().limit(size >> 2)); directBuffer.position(bufferOffset); return directBuffer; } else if (buffer instanceof ShortBuffer) { size = round2(size); ByteBuffer directBuffer = allocateDirectBuffer(size); directBuffer.asShortBuffer().put((ShortBuffer) ((ShortBuffer) buffer).slice().limit(size >> 1)); directBuffer.position(bufferOffset); return directBuffer; } else if (buffer instanceof FloatBuffer) { size = round4(size); ByteBuffer directBuffer = allocateDirectBuffer(size); directBuffer.asFloatBuffer().put((FloatBuffer) ((FloatBuffer) buffer).slice().limit(size >> 2)); directBuffer.position(bufferOffset); return directBuffer; } throw new IllegalArgumentException(); }
/** * Creates a new Pointer to the given buffer, taking into * account the position and array offset of the given buffer. * The buffer is assumed to be non-<code>null</code>, and * be either direct or have a backing array. * * @param buffer The buffer * @return The pointer */ private static Pointer computePointer(FloatBuffer buffer) { Pointer result = null; if (buffer.isDirect()) { int oldPosition = buffer.position(); buffer.position(0); result = Pointer.to(buffer.slice()).withByteOffset( oldPosition * Sizeof.FLOAT); buffer.position(oldPosition); } else if (buffer.hasArray()) { FloatBuffer t = FloatBuffer.wrap(buffer.array()); int elementOffset = buffer.position() + buffer.arrayOffset(); result = Pointer.to(t).withByteOffset( elementOffset * Sizeof.FLOAT); } return result; }
result = Pointer.to(buffer.slice()).withByteOffset( oldPosition * Sizeof.cl_float); buffer.position(oldPosition);
result = Pointer.to(buffer.slice()).withByteOffset( oldPosition * Sizeof.cl_float); buffer.position(oldPosition);
/** * Creates a new Pointer to the given buffer, taking into * account the position and array offset of the given buffer. * The buffer is assumed to be non-<code>null</code>, and * be either direct or have a backing array. * * @param buffer The buffer * @return The pointer */ private static Pointer computePointer(FloatBuffer buffer) { Pointer result = null; if (buffer.isDirect()) { int oldPosition = buffer.position(); buffer.position(0); result = Pointer.to(buffer.slice()).withByteOffset( oldPosition * Sizeof.FLOAT); buffer.position(oldPosition); } else if (buffer.hasArray()) { FloatBuffer t = FloatBuffer.wrap(buffer.array()); int elementOffset = buffer.position() + buffer.arrayOffset(); result = Pointer.to(t).withByteOffset( elementOffset * Sizeof.FLOAT); } return result; }
/** * Creates a new Pointer to the given buffer, taking into * account the position and array offset of the given buffer. * The buffer is assumed to be non-<code>null</code>, and * be either direct or have a backing array. * * @param buffer The buffer * @return The pointer */ private static Pointer computePointer(FloatBuffer buffer) { Pointer result = null; if (buffer.isDirect()) { int oldPosition = buffer.position(); buffer.position(0); result = Pointer.to(buffer.slice()).withByteOffset( oldPosition * Sizeof.FLOAT); buffer.position(oldPosition); } else if (buffer.hasArray()) { FloatBuffer t = FloatBuffer.wrap(buffer.array()); int elementOffset = buffer.position() + buffer.arrayOffset(); result = Pointer.to(t).withByteOffset( elementOffset * Sizeof.FLOAT); } return result; }
/** * Creates a new Pointer to the given buffer, taking into * account the position and array offset of the given buffer. * The buffer is assumed to be non-<code>null</code>, and * be either direct or have a backing array. * * @param buffer The buffer * @return The pointer */ private static Pointer computePointer(FloatBuffer buffer) { Pointer result = null; if (buffer.isDirect()) { int oldPosition = buffer.position(); buffer.position(0); result = Pointer.to(buffer.slice()).withByteOffset( oldPosition * Sizeof.FLOAT); buffer.position(oldPosition); } else if (buffer.hasArray()) { FloatBuffer t = FloatBuffer.wrap(buffer.array()); int elementOffset = buffer.position() + buffer.arrayOffset(); result = Pointer.to(t).withByteOffset( elementOffset * Sizeof.FLOAT); } return result; }