this.usage = usage; this.format = format; this.componentsLength = components * format.getComponentSize(); this.lastLimit = data.limit(); setUpdateNeeded();
@Override public String toString(){ String dataTxt = null; if (data != null){ dataTxt = ", elements="+data.limit(); } return getClass().getSimpleName() + "[fmt="+format.name() +", type="+bufType.name() +", usage="+usage.name() +dataTxt+"]"; }
int elSize = indexBuf.getFormat().getComponentSize(); int listStart = modeStart[0]; int stripStart = modeStart[1];
int elSize = indexBuf.getFormat().getComponentSize(); int listStart = modeStart[0]; int stripStart = modeStart[1];
private static void populateMatrix4fArray(Matrix4f[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents;
stride = ic.readInt("stride", 0); instanceSpan = ic.readInt("instanceSpan", 0); componentsLength = components * format.getComponentSize(); String dataName = "data" + format.name(); switch (format){ case Float:
this.usage = usage; this.format = format; this.componentsLength = components * format.getComponentSize(); this.lastLimit = data.limit(); setUpdateNeeded();
oc.write(instanceSpan, "instanceSpan", 0); String dataName = "data" + format.name(); Buffer roData = getDataReadOnly(); switch (format){
oc.write(stride, "stride", 0); String dataName = "data" + format.name(); switch (format){ case Float:
/** * Called to initialize the data in the <code>VertexBuffer</code>. Must only * be called once. * * @param usage The usage for the data, or how often will the data * be updated per frame. See the {@link Usage} enum. * @param components The number of components per element. * @param format The {@link Format format}, or data-type of a single * component. * @param data A native buffer, the format of which matches the {@link Format} * argument. */ public void setupData(Usage usage, int components, Format format, Buffer data){ if (id != -1) throw new UnsupportedOperationException("Data has already been sent. Cannot setupData again."); if (usage == null || format == null || data == null) throw new IllegalArgumentException("None of the arguments can be null"); if (components < 1 || components > 4) throw new IllegalArgumentException("components must be between 1 and 4"); this.data = data; this.components = components; this.usage = usage; this.format = format; this.componentsLength = components * format.getComponentSize(); this.lastLimit = data.limit(); setUpdateNeeded(); } public void setupData(Usage usage, int components, Format format, int offset, int stride){
offset = ic.readInt("offset", 0); stride = ic.readInt("stride", 0); componentsLength = components * format.getComponentSize(); String dataName = "data" + format.name(); switch (format){ case Float:
/** * Converts single floating-point data to {@link Format#Half half} floating-point data. */ public void convertToHalf(){ if (id != -1) throw new UnsupportedOperationException("Data has already been sent."); if (format != Format.Float) throw new IllegalStateException("Format must be float!"); int numElements = data.limit() / components; format = Format.Half; this.componentsLength = components * format.getComponentSize(); ByteBuffer halfData = BufferUtils.createByteBuffer(componentsLength * numElements); halfData.rewind(); FloatBuffer floatData = (FloatBuffer) data; floatData.rewind(); for (int i = 0; i < floatData.limit(); i++){ float f = floatData.get(i); short half = FastMath.convertFloatToHalf(f); halfData.putShort(half); } this.data = halfData; setUpdateNeeded(); dataSizeChanged = true; }
private static void populateShortArray(short[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); int arrayIndex = 0; while (index < end) { for (int i = 0; i < numComponents; i++) { if (componentSize == 2) { array[arrayIndex] = stream.readShort(); } else { array[arrayIndex] = stream.readByte(); } arrayIndex++; } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
/** * Converts single floating-point data to {@link Format#Half half} floating-point data. */ public void convertToHalf(){ if (id != -1) throw new UnsupportedOperationException("Data has already been sent."); if (format != Format.Float) throw new IllegalStateException("Format must be float!"); int numElements = data.capacity() / components; format = Format.Half; this.componentsLength = components * format.getComponentSize(); ByteBuffer halfData = BufferUtils.createByteBuffer(componentsLength * numElements); halfData.rewind(); FloatBuffer floatData = (FloatBuffer) data; floatData.rewind(); for (int i = 0; i < floatData.capacity(); i++){ float f = floatData.get(i); short half = FastMath.convertFloatToHalf(f); halfData.putShort(half); } this.data = halfData; setUpdateNeeded(); dataSizeChanged = true; }
private static void populateVector3fArray(Vector3f[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); int arrayIndex = 0; while (index < end) { array[arrayIndex] = new Vector3f( readAsFloat(stream, format), readAsFloat(stream, format), readAsFloat(stream, format) ); arrayIndex++; if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
private static void populateQuaternionArray(Quaternion[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); int arrayIndex = 0; while (index < end) { array[arrayIndex] = new Quaternion( readAsFloat(stream, format), readAsFloat(stream, format), readAsFloat(stream, format), readAsFloat(stream, format) ); arrayIndex++; if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
private static void populateByteArray(byte[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); int arrayIndex = 0; while (index < end) { for (int i = 0; i < numComponents; i++) { array[arrayIndex] = stream.readByte(); arrayIndex++; } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
private static void populateFloatArray(float[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); int arrayIndex = 0; while (index < end) { for (int i = 0; i < numComponents; i++) { array[arrayIndex] = readAsFloat(stream, format); arrayIndex++; } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
private static void populateShortBuffer(ShortBuffer buffer, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); while (index < end) { for (int i = 0; i < numComponents; i++) { buffer.put(stream.readShort()); } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } System.err.println(""); }
private static void populateFloatBuffer(FloatBuffer buffer, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); while (index < end) { for (int i = 0; i < numComponents; i++) { buffer.put(readAsFloat(stream, format)); } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }