fromData static method

Texture2D fromData(
  1. TypedData data,
  2. int width,
  3. int height, {
  4. DataTextureFormat format = DataTextureFormat.rgba8,
  5. TextureSampling? sampling,
})

Builds a single-level texture from raw texels of format: data holds width x height texels, row by row, exactly.

Unlike fromPixels no mip chain is built and the texels are not treated as color, so this suits scalar fields, lookup tables and other data. sampling defaults to DataTextureFormat.defaultSampling.

Implementation

static Texture2D fromData(
  TypedData data,
  int width,
  int height, {
  DataTextureFormat format = DataTextureFormat.rgba8,
  TextureSampling? sampling,
}) {
  final bytes = dataTextureBytes(
    data,
    width * height * format.bytesPerTexel,
    'A ${width}x$height ${format.name} texture',
  );
  final texture = gpu.gpuContext.createTexture(
    gpu.StorageMode.hostVisible,
    width,
    height,
    format: dataTexturePixelFormat(format),
    enableRenderTargetUsage: false,
  );
  texture.overwrite(bytes);
  return Texture2D._(
    texture,
    (sampling ?? format.defaultSampling).toSamplerOptions(),
  );
}