decodeToTexture static method

Future<Texture> decodeToTexture(
  1. Uint8List data, {
  2. TextureFormat textureFormat = TextureFormat.RGB32F,
  3. PixelDataFormat pixelDataFormat = PixelDataFormat.RGB,
  4. PixelDataType pixelDataType = PixelDataType.FLOAT,
  5. int levels = 1,
  6. bool requireAlpha = false,
})

Decodes the image contained in data and returns a texture of the corresponding size with the image set as mip-level 0.

Implementation

static Future<Texture> decodeToTexture(Uint8List data,
    {TextureFormat textureFormat = TextureFormat.RGB32F,
    PixelDataFormat pixelDataFormat = PixelDataFormat.RGB,
    PixelDataType pixelDataType = PixelDataType.FLOAT,
    int levels = 1,
    bool requireAlpha = false}) async {
  final decodedImage = await FilamentApp.instance!
      .decodeImage(data, requireAlpha: requireAlpha);

  final texture = await FilamentApp.instance!.createTexture(
      await decodedImage.getWidth(), await decodedImage.getHeight(),
      textureFormat: textureFormat, levels: levels);

  await texture.setLinearImage(decodedImage, pixelDataFormat, pixelDataType);

  return texture;
}