public Float32Array copy (FloatBuffer buffer) { if (GWT.isProdMode()) { return ((Float32Array)((HasArrayBufferView)buffer).getTypedArray()).subarray(buffer.position(), buffer.remaining()); } else { ensureCapacity(buffer); for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) { floatBuffer.set(j, buffer.get(i)); } return floatBuffer.subarray(0, buffer.remaining()); } }
public void setColors(float[] colors, boolean override) { final BufferInfo colorInfo = mBuffers.get(COLOR_BUFFER_KEY); if (colorInfo.buffer == null || override == true) { colorInfo.buffer = ByteBuffer .allocateDirect(colors.length * FLOAT_SIZE_BYTES) .order(ByteOrder.nativeOrder()).asFloatBuffer(); ((FloatBuffer) colorInfo.buffer).put(colors); colorInfo.buffer.position(0); } else { ((FloatBuffer) colorInfo.buffer).put(colors); colorInfo.buffer.position(0); } }
fromView.order(ByteOrder.nativeOrder()); toView.order(ByteOrder.nativeOrder()); switch (bufferType) { case INT: IntBuffer toInt = toView.asIntBuffer(); for (int i = 0; i < n; i++) { int put = fromInt.get(fromOffset + i * fromStride); toInt.put(toOffset + i * toStride, put); FloatBuffer toFloat = toView.asFloatBuffer(); for (int i = 0; i < n; i++) { float put = fromFloat.get(fromOffset + i * fromStride); toFloat.put(toOffset + i * toStride, put); DoubleBuffer toDouble = toView.asDoubleBuffer(); for (int i = 0; i < n; i++) { toDouble.put(toOffset + i * toStride, fromDouble.get(fromOffset + i * fromStride));
FloatBuffer normals = geometry.getMesh().getFloatBuffer(Type.Normal); if (normals != null) { for (int i = 0; i < normals.limit(); i += 3) { if (scale.x < 0) { normals.put(i, -normals.get(i)); normals.put(i + 1, -normals.get(i + 1)); normals.put(i + 2, -normals.get(i + 2)); LOGGER.finer("Flipping index order in triangle mesh."); Buffer indexBuffer = geometry.getMesh().getBuffer(Type.Index).getData(); for (int i = 0; i < indexBuffer.limit(); i += 3) { if (indexBuffer instanceof ShortBuffer) { short index = ((ShortBuffer) indexBuffer).get(i + 1); ((ShortBuffer) indexBuffer).put(i + 1, ((ShortBuffer) indexBuffer).get(i + 2)); ((ShortBuffer) indexBuffer).put(i + 2, index); } else { int index = ((IntBuffer) indexBuffer).get(i + 1); ((IntBuffer) indexBuffer).put(i + 1, ((IntBuffer) indexBuffer).get(i + 2)); ((IntBuffer) indexBuffer).put(i + 2, index);
case Short: case UnsignedShort: short s = ((ShortBuffer) buf2).get(index); ((ShortBuffer) buf1).put(s); break; int i = ((IntBuffer) buf2).get(index); ((IntBuffer) buf1).put(i); break; case Float: float f = ((FloatBuffer) buf2).get(index); ((FloatBuffer) buf1).put(f); break; case Double: double d = ((DoubleBuffer) buf2).get(index); ((DoubleBuffer) buf1).put(d); break; default:
Number get(DataType dataType, int index) { if (dataType == DataType.BYTE) return bb.get(index); if (dataType == DataType.SHORT) return bb.asShortBuffer().get(index); if (dataType == DataType.INT) return bb.asIntBuffer().get(index); if (dataType == DataType.LONG) return bb.asLongBuffer().get(index); if (dataType == DataType.FLOAT) return bb.asFloatBuffer().get(index); if (dataType == DataType.DOUBLE) return bb.asDoubleBuffer().get(index); return Double.NaN; }
private static void copyBuffer(Buffer buffer, long handle, long flags, int d1) { if (d1 != buffer.capacity()) { Class<?> cls = null; if (buffer instanceof ByteBuffer) { cls.getName() + " of capacity " + d1 + ". Got " + cls.getName() + " of capacity " + buffer.capacity()); int offset = 0; int shift = VM.getInt(VM.getObjectAddress(buffer) + _ELEMENT_SIZE_SHIFT_OFFSET); if (buffer.isDirect()) { src = VM.getLong(VM.getObjectAddress(buffer) + EFFECTIVE_DIRECT_ADDRESS_OFFSET); } else { } else if (buffer instanceof IntBuffer) { array = new int[d1]; ((IntBuffer) buffer).get((int[]) array); } else if (buffer instanceof LongBuffer) { array = new long[d1]; ((LongBuffer) buffer).get((long[]) array); } else if (buffer instanceof FloatBuffer) { array = new float[d1]; ((FloatBuffer) buffer).get((float[]) array); } else if (buffer instanceof DoubleBuffer) { array = new double[d1]; ((DoubleBuffer) buffer).get((double[]) array); buffer.position(pos);
outVb.data.clear(); ByteBuffer bin = (ByteBuffer) srcData; ByteBuffer bout = (ByteBuffer) outVb.data; bin.position(inPos).limit(inPos + elementSz * len); bout.position(outPos).limit(outPos + elementSz * len); bout.put(bin); break; IntBuffer iin = (IntBuffer) srcData; IntBuffer iout = (IntBuffer) outVb.data; iin.position(inPos).limit(inPos + elementSz * len); iout.position(outPos).limit(outPos + elementSz * len); iout.put(iin); break; case Float: FloatBuffer fin = (FloatBuffer) srcData; FloatBuffer fout = (FloatBuffer) outVb.data; fin.position(inPos).limit(inPos + elementSz * len); fout.position(outPos).limit(outPos + elementSz * len); fout.put(fin); break; default:
checkInt(cb.get(), 8); sb.position(4); BufferUtils.copy(new short[] {1, 2, 3, 4}, 0, sb, 4); checkInt(sb.get(), 1); checkInt(sb.get(), 2); ib.position(4); BufferUtils.copy(new int[] {1, 2, 3, 4}, 0, ib, 4); checkInt(ib.get(), 1); checkInt(ib.get(), 2); lb.position(4); BufferUtils.copy(new long[] {1, 2, 3, 4}, 0, lb, 4); checkInt(lb.get(), 1); checkInt(lb.get(), 2); fb.position(4); BufferUtils.copy(new float[] {1, 2, 3, 4}, 0, fb, 4); checkFloat(fb.get(), 1); checkFloat(fb.get(), 2); checkFloat(fb.get(), 3); checkFloat(fb.get(), 4); fb.position(0); BufferUtils.copy(new float[] {5, 6, 7, 8}, 1, fb, 3); checkFloat(fb.get(), 6); checkFloat(fb.get(), 7); checkFloat(fb.get(), 8);
val fb = bb.order(ByteOrder.nativeOrder()).asIntBuffer(); val fa = new float[fb.capacity()]; for (int e = 0; e < fb.capacity(); e++) fa[e] = (float) fb.get(e); val fb = bb.order(ByteOrder.nativeOrder()).asFloatBuffer(); val fa = new float[fb.capacity()]; for (int e = 0; e < fb.capacity(); e++) fa[e] = fb.get(e); val fb = bb.order(ByteOrder.nativeOrder()).asDoubleBuffer(); val da = new double[fb.capacity()]; for (int e = 0; e < fb.capacity(); e++) da[e] = fb.get(e); val lb = bb.order(ByteOrder.nativeOrder()).asLongBuffer(); val fa = new float[lb.capacity()]; for (int e = 0; e < lb.capacity(); e++) fa[e] = (float) lb.get(e); if (fa.length == 0) throw new ND4JIllegalStateException("Can't find Tensor values! Probably you've forgot to freeze graph before saving?");
public void setColor(float r, float g, float b, float a, boolean createNewBuffer) { BufferInfo colorInfo = mBuffers.get(COLOR_BUFFER_KEY); if (colorInfo.buffer == null || colorInfo.buffer.limit() == 0) { colorInfo = new BufferInfo(); colorInfo.buffer = ByteBuffer.allocateDirect(mNumVertices * 4 * FLOAT_SIZE_BYTES) .order(ByteOrder.nativeOrder()).asFloatBuffer(); createNewBuffer = true; mBuffers.add(COLOR_BUFFER_KEY, colorInfo); } colorInfo.buffer.position(0); while (colorInfo.buffer.remaining() > 3) { ((FloatBuffer) colorInfo.buffer).put(r); ((FloatBuffer) colorInfo.buffer).put(g); ((FloatBuffer) colorInfo.buffer).put(b); ((FloatBuffer) colorInfo.buffer).put(a); } colorInfo.buffer.position(0); if (createNewBuffer) { createBuffer(colorInfo, BufferType.FLOAT_BUFFER, GLES20.GL_ARRAY_BUFFER); } else { GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, colorInfo.bufferHandle); GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, colorInfo.buffer.limit() * FLOAT_SIZE_BYTES, colorInfo.buffer, GLES20.GL_STATIC_DRAW); } GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); }
vbb.order(ByteOrder.nativeOrder()); mVertexBuffer = vbb.asIntBuffer(); mVertexBuffer.put(vertices); mVertexBuffer.position(0); ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length*4); cbb.order(ByteOrder.nativeOrder()); mColorBuffer = cbb.asFloatBuffer(); mColorBuffer.put(colors); mColorBuffer.position(0); mIndexBuffer = ByteBuffer.allocateDirect(indices.length); mIndexBuffer.put(indices); mIndexBuffer.position(0); } public void draw(GL10 gl) { gl.glFrontFace(gl.GL_CW);
data.clear(); case UnsignedShort: ShortBuffer sin = (ShortBuffer) data; sin.put(inPos + elementPos, (Short)val); break; case Int: case UnsignedInt: IntBuffer iin = (IntBuffer) data; iin.put(inPos + elementPos, (Integer)val); break; case Float: FloatBuffer fin = (FloatBuffer) data; fin.put(inPos + elementPos, (Float)val); break; default:
data.clear(); switch (format){ case Byte: case UnsignedInt: IntBuffer ibuf = (IntBuffer) data; ibuf.limit(total); IntBuffer inewBuf = BufferUtils.createIntBuffer(total); inewBuf.put(ibuf); data = inewBuf; break; case Float: FloatBuffer fbuf = (FloatBuffer) data; fbuf.limit(total); FloatBuffer fnewBuf = BufferUtils.createFloatBuffer(total); fnewBuf.put(fbuf); data = fnewBuf; break; throw new UnsupportedOperationException("Unrecognized buffer format: "+format); data.clear(); setUpdateNeeded(); dataSizeChanged = true;
if (vertexBuffer.getData() instanceof FloatBuffer) { FloatBuffer b = (FloatBuffer) vertexBuffer.getData(); float[] arr = new float[b.capacity()]; b.rewind(); b.get(arr); b.rewind(); for (float v : arr) { System.err.print(v + ","); short[] arr = new short[b.capacity()]; b.rewind(); b.get(arr); b.rewind(); for (short v : arr) { int[] arr = new int[b.capacity()]; b.rewind(); b.get(arr); b.rewind(); for (int v : arr) {
public void setVertices(float[] vertices, boolean override) { final BufferInfo vertexInfo = mBuffers.get(VERTEX_BUFFER_KEY); if (vertexInfo.buffer == null || override == true) { if (vertexInfo.buffer != null) { vertexInfo.buffer.clear(); } vertexInfo.buffer = ByteBuffer .allocateDirect(vertices.length * FLOAT_SIZE_BYTES) .order(ByteOrder.nativeOrder()).asFloatBuffer(); ((FloatBuffer) vertexInfo.buffer).put(vertices); vertexInfo.buffer.position(0); mNumVertices = vertices.length / 3; } else { ((FloatBuffer) vertexInfo.buffer).put(vertices); } }