uploadVertexData method
void
uploadVertexData(})
Allocates a gpu.DeviceBuffer and uploads vertices (and optional
indices) into it in one step.
The vertices must match this geometry subclass's expected layout
(48 bytes per vertex for UnskinnedGeometry, 80 bytes for
SkinnedGeometry). When indices is supplied, the buffer is sized
to hold both ranges back-to-back and bound via setIndices.
Implementation
void uploadVertexData(
ByteData vertices,
int vertexCount,
ByteData? indices, {
gpu.IndexType indexType = gpu.IndexType.int16,
}) {
gpu.DeviceBuffer deviceBuffer = gpu.gpuContext.createDeviceBuffer(
gpu.StorageMode.hostVisible,
indices == null
? vertices.lengthInBytes
: vertices.lengthInBytes + indices.lengthInBytes,
);
deviceBuffer.overwrite(vertices, destinationOffsetInBytes: 0);
setVertices(
gpu.BufferView(
deviceBuffer,
offsetInBytes: 0,
lengthInBytes: vertices.lengthInBytes,
),
vertexCount,
);
if (indices != null) {
deviceBuffer.overwrite(
indices,
destinationOffsetInBytes: vertices.lengthInBytes,
);
setIndices(
gpu.BufferView(
deviceBuffer,
offsetInBytes: vertices.lengthInBytes,
lengthInBytes: indices.lengthInBytes,
),
indexType,
);
}
if (_localBounds == null && vertexCount > 0 && _autoScanBoundsOnUpload) {
_scanLocalBoundsFromVertices(vertices, vertexCount);
}
}