wrapTexture function
TextureHandle
wrapTexture({
- required Object backend,
- required int width,
- required int height,
- required TextureFormat format,
- int sampleCount = 1,
- StorageMode storageMode = StorageMode.devicePrivate,
- TextureType? type,
- TextureDimension? dimension,
- int? depthOrArrayLayers,
- int mipLevelCount = 1,
- TextureUsage usage = TextureUsage.standard,
- TextureAllocator? owner,
A TextureHandle over a backend's own backend texture — for a backend's
implementation of GraphicsDevice, from package:flutter3d_hardware/ backend.dart. Application code never makes a handle; a device hands one
out. owner is the device whose releaseTexture the handle's dispose
calls.
Say the shape with dimension. type is the pre-1.0 way to say it
and is still read when dimension is absent: TextureType.textureCube
means a cube. When both are given they must agree (a cube type with a
cube or cube-array dimension, any other type with any other dimension),
or this throws an ArgumentError rather than make a handle whose two
fields tell the engine two different shapes.
Implementation
TextureHandle wrapTexture({
required Object backend,
required int width,
required int height,
required TextureFormat format,
int sampleCount = 1,
StorageMode storageMode = StorageMode.devicePrivate,
TextureType? type,
TextureDimension? dimension,
int? depthOrArrayLayers,
int mipLevelCount = 1,
TextureUsage usage = TextureUsage.standard,
TextureAllocator? owner,
}) {
if (type != null &&
dimension != null &&
(type == TextureType.textureCube) != _isCube(dimension)) {
throw ArgumentError(
'wrapTexture was told type ${type.name} and dimension '
'${dimension.name}, which are two different shapes. Say the shape '
'with dimension alone.',
'type',
);
}
final shape =
dimension ??
(type == TextureType.textureCube
? TextureDimension.cube
: TextureDimension.d2);
return TextureHandle._(
owner?.releaseTexture,
backend: backend,
width: width,
height: height,
format: format,
sampleCount: sampleCount,
storageMode: storageMode,
type: _isCube(shape)
? TextureType.textureCube
: (type == TextureType.textureExternalOES
? TextureType.textureExternalOES
: TextureType.texture2D),
dimension: shape,
depthOrArrayLayers: depthOrArrayLayers ?? (_isCube(shape) ? 6 : 1),
mipLevelCount: mipLevelCount,
usage: usage,
);
}