private static void populateByteBuffer(ByteBuffer buffer, byte[] source, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; while (index < end) { for (int i = 0; i < numComponents; i++) { buffer.put(source[index + i]); } index += stride; } }
this.usage = usage; this.format = format; this.componentsLength = components * format.getComponentSize(); this.lastLimit = data.limit(); setUpdateNeeded();
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(""); }
@Override public SkinBuffers populate(Integer bufferViewIndex, int componentType, String type, int count, int byteOffset, boolean normalized) throws IOException { int numComponents = getNumberOfComponents(type); //can be bytes or shorts. VertexBuffer.Format format = VertexBuffer.Format.Byte; if (componentType == 5123) { format = VertexBuffer.Format.Short; } int dataSize = numComponents * count; short[] data = new short[dataSize]; if (bufferViewIndex == null) { //no referenced buffer, specs says to pad the data with zeros. padBuffer(data, dataSize); } else { readBuffer(bufferViewIndex, byteOffset, count, data, numComponents, format); } return new SkinBuffers(data, format.getComponentSize()); } }
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; } }
public void setupData(Usage usage, int components, Format format, int offset, int stride){ 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.offset = offset; this.stride = stride; setUpdateNeeded(); }
int calcInterleavedSize() { interleavedSize = 0; for(Mesh mesh : meshSet) { for(VertexBuffer vb : mesh.getBufferList()) { if (vb.getBufferType().equals(VertexBuffer.Type.Index) || vb.getBufferType().equals(VertexBuffer.Type.InterleavedData)){ continue; } int limit = vb.getData().capacity(); // interleavedSize += vb.getComponentsLength() * vb.get interleavedSize += limit * vb.getFormat().getComponentSize(); } } return interleavedSize; } }
private static void populateByteBuffer(ByteBuffer buffer, byte[] source, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; while (index < end) { for (int i = 0; i < numComponents; i++) { buffer.put(source[index + i]); } index += stride; } }
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();
/** * 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; } }
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 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; } }
@Override public SkinBuffers populate(Integer bufferViewIndex, int componentType, String type, int count, int byteOffset, boolean normalized) throws IOException { int numComponents = getNumberOfComponents(type); //can be bytes or shorts. VertexBuffer.Format format = VertexBuffer.Format.Byte; if (componentType == 5123) { format = VertexBuffer.Format.Short; } int dataSize = numComponents * count; short[] data = new short[dataSize]; if (bufferViewIndex == null) { //no referenced buffer, specs says to pad the data with zeros. padBuffer(data, dataSize); } else { readBuffer(bufferViewIndex, byteOffset, count, data, numComponents, format); } return new SkinBuffers(data, format.getComponentSize()); } }
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 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; } }
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 populateIntBuffer(IntBuffer 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.readInt()); } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }