Refine search
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); } }
@Override public ByteOrder deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { if (ByteOrder.BIG_ENDIAN.toString().equals(jp.getText())) { return ByteOrder.BIG_ENDIAN; } return ByteOrder.LITTLE_ENDIAN; } }
private void initData(){ ByteBuffer a=ByteBuffer.allocateDirect(cubePositions.length*4); a.order(ByteOrder.nativeOrder()); vertexBuf=a.asFloatBuffer(); vertexBuf.put(cubePositions); vertexBuf.position(0); ByteBuffer b=ByteBuffer.allocateDirect(color.length*4); b.order(ByteOrder.nativeOrder()); colorBuf=b.asFloatBuffer(); colorBuf.put(color); colorBuf.position(0); ByteBuffer c=ByteBuffer.allocateDirect(index.length*2); c.order(ByteOrder.nativeOrder()); indexBuf=c.asShortBuffer(); indexBuf.put(index); indexBuf.position(0); }
/** Allocates a FloatBuffer with the given data. */ public static FloatBuffer createBuffer(float[] data) { ByteBuffer bb = ByteBuffer.allocateDirect(data.length * C.BYTES_PER_FLOAT); bb.order(ByteOrder.nativeOrder()); FloatBuffer buffer = bb.asFloatBuffer(); buffer.put(data); buffer.position(0); return buffer; }
public String glGetProgramInfoLog (int program) { ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 10); buffer.order(ByteOrder.nativeOrder()); ByteBuffer tmp = ByteBuffer.allocateDirect(4); tmp.order(ByteOrder.nativeOrder()); IntBuffer intBuffer = tmp.asIntBuffer(); GL20.glGetProgramInfoLog(program, intBuffer, buffer); int numBytes = intBuffer.get(0); byte[] bytes = new byte[numBytes]; buffer.get(bytes); return new String(bytes); }
private void updateVertexData() { final GLBubbleGeometry.GeometryArrays arrays = roundedGeometry.generateVertexData(roundRadius, viewPortGLBounds, viewPortSize,arrowSize,arrowOffsetFromCenter,arrowDirection); triangleVerticesData = arrays.triangleVertices; triangleIndicesData = arrays.triangleIndices; if (triangleVertices != null) { triangleVertices.clear(); } else { triangleVertices = ByteBuffer.allocateDirect(triangleVerticesData.length * FLOAT_SIZE_BYTES) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); } if (triangleIndices != null) { triangleIndices.clear(); } else { triangleIndices = ByteBuffer.allocateDirect(triangleIndicesData.length * SHORT_SIZE_BYTES) .order(ByteOrder.nativeOrder()) .asShortBuffer(); } triangleVertices.put(triangleVerticesData).position(0); triangleIndices.put(triangleIndicesData).position(0); }
vbb.order(ByteOrder.nativeOrder()); vertexBuffer = vbb.asFloatBuffer(); vertexBuffer.put(vertices); vertexBuffer.position(0); ibb.order(ByteOrder.nativeOrder()); indexBuffer = ibb.asShortBuffer(); indexBuffer.put(indices); indexBuffer.position(0);
public void drainDecoderBufferAndQueue(final int bufferIndex, final long presentationTimeUs) { if (mActualDecodedFormat == null) { throw new RuntimeException("Buffer received before format!"); } final ByteBuffer data = bufferIndex == BUFFER_INDEX_END_OF_STREAM ? null : mDecoderBuffers.getOutputBuffer(bufferIndex); AudioBuffer buffer = mEmptyBuffers.poll(); if (buffer == null) { buffer = new AudioBuffer(); } buffer.bufferIndex = bufferIndex; buffer.presentationTimeUs = presentationTimeUs; buffer.data = data == null ? null : data.asShortBuffer(); if (mOverflowBuffer.data == null) { mOverflowBuffer.data = ByteBuffer .allocateDirect(data.capacity()) .order(ByteOrder.nativeOrder()) .asShortBuffer(); mOverflowBuffer.data.clear().flip(); } mFilledBuffers.add(buffer); }
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);
if(screenshot){ int screenshotSize = width * height; ByteBuffer bb = ByteBuffer.allocateDirect(screenshotSize * 4); bb.order(ByteOrder.nativeOrder()); gl.glReadPixels(0, 0, width, height, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb); int pixelsBuffer[] = new int[screenshotSize]; bb.asIntBuffer().get(pixelsBuffer); bb = null; Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); bitmap.setPixels(pixelsBuffer, screenshotSize-width, -width, 0, 0, width, height); pixelsBuffer = null; short sBuffer[] = new short[screenshotSize]; ShortBuffer sb = ShortBuffer.wrap(sBuffer); bitmap.copyPixelsToBuffer(sb); //Making created bitmap (from OpenGL points) compatible with Android bitmap for (int i = 0; i < screenshotSize; ++i) { short v = sBuffer[i]; sBuffer[i] = (short) (((v&0x1f) << 11) | (v&0x7e0) | ((v&0xf800) >> 11)); } sb.rewind(); bitmap.copyPixelsFromBuffer(sb); lastScreenshot = bitmap; screenshot = false; }
@Override public void onDraw(final int textureId, final FloatBuffer cubeBuffer, final FloatBuffer textureBuffer) { FloatBuffer vertBuffer = cubeBuffer; if (!ignoreAspectRatio) { float[] adjustedVertices = new float[8]; cubeBuffer.position(0); cubeBuffer.get(adjustedVertices); float normalizedHeight = (float) getOutputHeight() / (float) getOutputWidth(); adjustedVertices[1] *= normalizedHeight; adjustedVertices[3] *= normalizedHeight; adjustedVertices[5] *= normalizedHeight; adjustedVertices[7] *= normalizedHeight; vertBuffer = ByteBuffer.allocateDirect(adjustedVertices.length * 4) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); vertBuffer.put(adjustedVertices).position(0); } super.onDraw(textureId, vertBuffer, textureBuffer); }
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); } }
static private void testViewsPutIndex() { System.out.println("JTranscNioTest.test2:"); for (ByteOrder byteOrder : new ByteOrder[]{ByteOrder.LITTLE_ENDIAN, ByteOrder.BIG_ENDIAN, ByteOrder.nativeOrder()}) { for (int n = 0; n < 2; n++) { final int len = 64; ByteBuffer buffer = ByteBuffer.allocate(len).order(byteOrder); ShortBuffer shortBuffer = buffer.asShortBuffer(); CharBuffer charBuffer = buffer.asCharBuffer(); IntBuffer intBuffer = buffer.asIntBuffer(); LongBuffer longBuffer = buffer.asLongBuffer(); FloatBuffer floatBuffer = buffer.asFloatBuffer(); DoubleBuffer doubleBuffer = buffer.asDoubleBuffer(); buffer.put(1, (byte)0x77); shortBuffer.put(1, (short)0x12345); charBuffer.put(2, (char)0x12345); intBuffer.put(3, 0x12345789); floatBuffer.put(4, (float)1.0); longBuffer.put(5, 0x12345789ABCDEF1L); doubleBuffer.put(6, 1.0); byte[] out = new byte[len]; buffer.position(0); buffer.get(out, 0, len); System.out.println(byteOrder + ":" + JTranscHex.encode(out)); } } }
private static FloatBuffer nativeFloatBuffer(float... array) { FloatBuffer buffer = ByteBuffer.allocateDirect(array.length * 4).order( ByteOrder.nativeOrder()).asFloatBuffer(); buffer.put(array); buffer.flip(); return buffer; }
public static ByteBuffer newByteBuffer (int numBytes) { ByteBuffer buffer = ByteBuffer.allocateDirect(numBytes); buffer.order(ByteOrder.nativeOrder()); return buffer; }
static private void test2() { System.out.println("JTranscNioTest.test2:"); for (ByteOrder byteOrder : new ByteOrder[]{ByteOrder.LITTLE_ENDIAN, ByteOrder.BIG_ENDIAN, ByteOrder.nativeOrder()}) { ByteBuffer buffer = ByteBuffer.allocate(16).order(byteOrder); for (int n = 0; n < 2; n++) { buffer.putInt(n * 4, Float.floatToRawIntBits(1f)); FloatBuffer floatBuffer = buffer.asFloatBuffer(); IntBuffer intBuffer = buffer.asIntBuffer(); LongBuffer longBuffer = buffer.asLongBuffer(); ShortBuffer shortBuffer = buffer.asShortBuffer(); System.out.println("Endian:" + byteOrder); System.out.println("FLOAT:" + floatBuffer.get(n)); System.out.println("INT:" + intBuffer.get(n)); System.out.println("LONG:" + longBuffer.get(n)); System.out.println("SHORT[0]:" + shortBuffer.get(n * 2 + 0)); System.out.println("SHORT[1]:" + shortBuffer.get(n * 2 + 1)); } } }
/** * Convert an array to a byte buffer * @param arr the array * @return a direct byte buffer with the array contents */ public static IntBuffer toBuffer(int... arr) { ByteBuffer directBuffer = ByteBuffer.allocateDirect(arr.length * 4).order(ByteOrder.nativeOrder()); IntBuffer buffer = directBuffer.asIntBuffer(); for (int i = 0; i < arr.length; i++) buffer.put(i, arr[i]); return buffer; }
FloatBuffer yourFloatBuffer; float[] yourFloatArray; FloatBuffer byteBuf = ByteBuffer.allocateDirect(yourFloatArray.length * 4); byteBuf.order(ByteOrder.nativeOrder()); yourFloatBuffer = byteBuf.asFloatBuffer(); yourFloatBuffer.put(yourFloatArray); yourFloatBuffer.position(0);
final int flags = extractFlags(srcMem); final boolean bigEndian = (flags & BIG_ENDIAN_FLAG_MASK) > 0; final String nativeOrder = ByteOrder.nativeOrder().toString(); final boolean readOnly = (flags & READ_ONLY_FLAG_MASK) > 0; final boolean empty = (flags & EMPTY_FLAG_MASK) > 0;