/** * Returns a copy of the specified buffer, with the specified new size. The new size must be greater than or equal * to the specified buffer's size. If the new size is greater than the specified buffer's size, this returns a new * buffer which is partially filled with the contents of the specified buffer. The returned buffer is a backed by a * direct ByteBuffer if and only if the specified buffer is direct. * * @param buffer the buffer to copy. * @param newSize the new buffer's size, in shorts. * * @return the new buffer, with the specified size. * * @throws ArgumentException if the buffer is null, if the new size is negative, or if the new size is less * than the buffer's remaing elements. */ public static ShortBuffer copyOf(ShortBuffer buffer, int newSize) { if (newSize < 0 || newSize < buffer.remaining()) { String message = Logging.getMessage("generic.SizeOutOfRange", newSize); Logging.logger().severe(message); throw new ArgumentException(message); } ShortBuffer newBuffer = newShortBuffer(newSize, buffer.isDirect()); int pos = buffer.position(); // Save the input buffer's current position. try { newBuffer.put(buffer); newBuffer.rewind(); } finally { buffer.position(pos); // Restore the input buffer's original position. } return(newBuffer); }
public MyRenderer(BasicCustomVideoRenderer parent) { this.mCustomVideoRenderer = parent; ByteBuffer bb = ByteBuffer.allocateDirect(mXYZCoords.Length * 4); bb.order(ByteOrder.nativeOrder()); mVertexBuffer = bb.asFloatBuffer(); mVertexBuffer.put(mXYZCoords); mVertexBuffer.position(0); ByteBuffer tb = ByteBuffer.allocateDirect(mUVCoords.Length * 4); tb.order(ByteOrder.nativeOrder()); mTextureBuffer = tb.asFloatBuffer(); mTextureBuffer.put(mUVCoords); mTextureBuffer.position(0); ByteBuffer dlb = ByteBuffer.allocateDirect(mVertexIndex.Length * 2); dlb.order(ByteOrder.nativeOrder()); mDrawListBuffer = dlb.asShortBuffer(); mDrawListBuffer.put(mVertexIndex); mDrawListBuffer.position(0); }
protected int replaceNaN(ShortBuffer shortBuffer, short value) { int length = shortBuffer.remaining(); int numValues = 0; if (this.tmpBuffer == null || this.tmpBuffer.length < shortBuffer.remaining()) { this.tmpBuffer = new short[length]; } shortBuffer.get(this.tmpBuffer, 0, length); shortBuffer.flip(); for (int i = 0; i < length; i++) { if (isNoValueShort(this.tmpBuffer[i])) { this.tmpBuffer[i] = value; } else { numValues++; } } shortBuffer.put(this.tmpBuffer, 0, length); shortBuffer.flip(); return(numValues); }
private void initTriangle() { // float has 4 bytes ByteBuffer vbb = ByteBuffer.allocateDirect(_nrOfVertices * 3 * 4); vbb.order(ByteOrder.nativeOrder()); _vertexBuffer = vbb.asFloatBuffer(); // short has 2 bytes ByteBuffer ibb = ByteBuffer.allocateDirect(_nrOfVertices * 2); ibb.order(ByteOrder.nativeOrder()); _indexBuffer = ibb.asShortBuffer(); float[] coords = { -0.5f, -0.5f, 0f, // (x1, y1, z1) 0.5f, -0.5f, 0f, // (x2, y2, z2) 0f, 0.5f, 0f // (x3, y3, z3) }; _vertexBuffer.put(coords); _indexBuffer.put(_indicesArray); _vertexBuffer.position(0); _indexBuffer.position(0); }
public static void copyBuffer(ShortBuffer dstBuffer, ShortBuffer srcBuffer) { if (dstBuffer != srcBuffer) { srcBuffer.rewind(); dstBuffer.put(srcBuffer); } }
private void initTriangle() { float[] coords = { -0.5f, -0.5f, 0.5f, // 0 0.5f, -0.5f, 0.5f, // 1 0f, -0.5f, -0.5f, // 2 0f, 0.5f, 0f, // 3 }; _nrOfVertices = coords.Length; float[] colors = { 1f, 0f, 0f, 1f, // point 0 red 0f, 1f, 0f, 1f, // point 1 green 0f, 0f, 1f, 1f, // point 2 blue 1f, 1f, 1f, 1f, // point 3 white }; short[] indices = new short[] { 0, 1, 3, // rwg 0, 2, 1, // rbg 0, 3, 2, // rbw 1, 2, 3, // bwg }; // float has 4 bytes, coordinate * 4 bytes ByteBuffer vbb = ByteBuffer.allocateDirect(coords.Length * 4); vbb.order(ByteOrder.nativeOrder()); _vertexBuffer = vbb.asFloatBuffer(); // short has 2 bytes, indices * 2 bytes ByteBuffer ibb = ByteBuffer.allocateDirect(indices.Length * 2); ibb.order(ByteOrder.nativeOrder()); _indexBuffer = ibb.asShortBuffer(); // float has 4 bytes, colors (RGBA) * 4 bytes ByteBuffer cbb = ByteBuffer.allocateDirect(colors.Length * 4); cbb.order(ByteOrder.nativeOrder()); _colorBuffer = cbb.asFloatBuffer(); _vertexBuffer.put(coords); _indexBuffer.put(indices); _colorBuffer.put(colors); _vertexBuffer.position(0); _indexBuffer.position(0); _colorBuffer.position(0); }
private void initTriangle() { // float has 4 bytes ByteBuffer vbb = ByteBuffer.allocateDirect(_nrOfVertices * 3 * 4); vbb.order(ByteOrder.nativeOrder()); _vertexBuffer = vbb.asFloatBuffer(); // short has 4 bytes ByteBuffer ibb = ByteBuffer.allocateDirect(_nrOfVertices * 2); ibb.order(ByteOrder.nativeOrder()); _indexBuffer = ibb.asShortBuffer(); // float has 4 bytes, 4 colors (RGBA) * number of vertices * 4 bytes ByteBuffer cbb = ByteBuffer.allocateDirect(4 * _nrOfVertices * 4); cbb.order(ByteOrder.nativeOrder()); _colorBuffer = cbb.asFloatBuffer(); float[] coords = { -0.5f, -0.5f, 0f, // (x1, y1, z1) 0.5f, -0.5f, 0f, // (x2, y2, z2) 0.5f, 0.5f, 0f // (x3, y3, z3) }; float[] colors = { 1f, 0f, 0f, 1f, // point 1 0f, 1f, 0f, 1f, // point 2 0f, 0f, 1f, 1f, // point 3 }; _vertexBuffer.put(coords); _indexBuffer.put(_indicesArray); _colorBuffer.put(colors); _vertexBuffer.position(0); _indexBuffer.position(0); _colorBuffer.position(0); }
public MyRenderer() { ByteBuffer bb = ByteBuffer.allocateDirect(mXYZCoords.Length * 4); bb.order(ByteOrder.nativeOrder()); mVertexBuffer = bb.asFloatBuffer(); mVertexBuffer.put(mXYZCoords); mVertexBuffer.position(0); ByteBuffer tb = ByteBuffer.allocateDirect(mUVCoords.Length * 4); tb.order(ByteOrder.nativeOrder()); mTextureBuffer = tb.asFloatBuffer(); mTextureBuffer.put(mUVCoords); mTextureBuffer.position(0); ByteBuffer dlb = ByteBuffer.allocateDirect(mVertexIndex.Length * 2); dlb.order(ByteOrder.nativeOrder()); mDrawListBuffer = dlb.asShortBuffer(); mDrawListBuffer.put(mVertexIndex); mDrawListBuffer.position(0); }
public static ShortBuffer getDirectBuffer(int size, ShortBuffer buffer) { if (buffer == null) { return(buffer); } size = Round2(size); if (buffer.Direct) { buffer.limit((size >> 1) + buffer.position()); return(buffer); } ShortBuffer directBuffer = allocateDirectBuffer(size).asShortBuffer(); directBuffer.put((ShortBuffer)((ShortBuffer)buffer).slice().limit(size >> 1)); directBuffer.rewind(); return(directBuffer); }
public override void write16(int address, short data) { address &= addressMask; shortBuffer.put(address >> 1, data); }