uploadVertexData method

void uploadVertexData(
  1. ByteData vertices,
  2. int vertexCount,
  3. ByteData? indices, {
  4. IndexType indexType = gpu.IndexType.int16,
})

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);

  if (deviceBuffer == null) {
    throw Exception('Failed to allocate geometry buffer');
  }

  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);
  }
}