uploadVertexData method
- TypedData vertices,
- int vertexCount,
- TypedData? indices, {
- IndexType indexType = gpu.IndexType.int16,
Allocates GPU storage and uploads vertices (and optional indices)
into it in one step.
The vertices must match this geometry subclass's expected interleaved
layout (72 bytes per vertex for UnskinnedGeometry, 104 bytes for
SkinnedGeometry). The subclass may split the interleaved bytes into
several tightly packed streams (see _vertexStreamBytes); the streams
are bound via setVertexStreams and the indices via setIndices.
How many gpu.DeviceBuffers that takes, and where in them the indices
land, is the backend's to decide (see _uploadStreams), so read the
bound gpu.BufferViews rather than assuming a layout. Native packs the
streams and indices back to back into one buffer; web gives each role a
buffer of its own, since WebGL2 types a buffer on first bind.
Pass vertices and indices as the element type their store was
allocated as (the engine's packers build interleaved vertices in a
Float32List and indices in a Uint16List or Uint32List); a
ByteData over one of those costs a per-element read to upload on web.
See _uploadStreams.
Implementation
@override
void uploadVertexData(
TypedData vertices,
int vertexCount,
TypedData? indices, {
gpu.IndexType indexType = gpu.IndexType.int16,
}) {
if (!_uploadingBlend) {
if (vertexCount != _morphData.vertexCount) {
throw ArgumentError(
'Morphed geometry uploaded $vertexCount vertices, but its morph '
'targets cover ${_morphData.vertexCount}',
);
}
_baseVertexFloats = Float32List.fromList(
Float32List.sublistView(vertices),
);
_baseVertexCount = vertexCount;
_baseIndices = indices;
_baseIndexType = indexType;
_appliedWeights = null;
}
super.uploadVertexData(
vertices,
vertexCount,
indices,
indexType: indexType,
);
if (!_uploadingBlend) _updateMorphBounds();
}