toTexture method

Texture toTexture()

Uploads this texture's embedded image data to a Flutter GPU texture.

Throws if the texture has no embedded image (for example, a URI-only texture reference). Callers needing URI fallback should sample the asset bundle themselves before calling.

Implementation

gpu.Texture toTexture() {
  if (embeddedImage == null || embeddedImage!.bytes == null) {
    throw Exception('Texture has no embedded image');
  }
  gpu.Texture texture = gpu.gpuContext.createTexture(
    gpu.StorageMode.hostVisible,
    embeddedImage!.width,
    embeddedImage!.height,
  );
  Uint8List textureData = embeddedImage!.bytes! as Uint8List;
  texture.overwrite(ByteData.sublistView(textureData));

  return texture;
}