createTexture method

Texture createTexture(
  1. StorageMode storageMode,
  2. int width,
  3. int height, {
  4. PixelFormat format = PixelFormat.r8g8b8a8UNormInt,
  5. dynamic sampleCount = 1,
  6. TextureCoordinateSystem coordinateSystem = TextureCoordinateSystem.renderToTexture,
  7. TextureType? textureType,
  8. bool enableRenderTargetUsage = true,
  9. bool enableShaderReadUsage = true,
  10. bool enableShaderWriteUsage = false,
})

Allocates a new texture in GPU-resident memory.

Throws an exception if the Texture creation failed.

Implementation

Texture createTexture(
  StorageMode storageMode,
  int width,
  int height, {
  PixelFormat format = PixelFormat.r8g8b8a8UNormInt,
  sampleCount = 1,
  TextureCoordinateSystem coordinateSystem =
      TextureCoordinateSystem.renderToTexture,

  /// The type of texture to create.
  ///
  /// If not specified, this will be inferred from the `sampleCount`.
  TextureType? textureType,
  bool enableRenderTargetUsage = true,
  bool enableShaderReadUsage = true,
  bool enableShaderWriteUsage = false,
}) {
  final resolvedTextureType =
      textureType ??
      ((sampleCount == 1)
          ? TextureType.texture2D
          : TextureType.texture2DMultisample);
  Texture result = Texture._initialize(
    this,
    storageMode,
    format,
    width,
    height,
    sampleCount,
    coordinateSystem,
    resolvedTextureType,
    enableRenderTargetUsage,
    enableShaderReadUsage,
    enableShaderWriteUsage,
  );
  if (!result.isValid) {
    throw Exception('Texture creation failed');
  }
  return result;
}