createTexture method
A brand-new texture matching descriptor, with the single
TextureHandle that will ever stand for it, contents undefined until
written.
One creator since 1.0. A RenderTargetDescriptor — the 2D target
the pool lends out, sampled, drawn into and copied either way — is what
every allocator makes. Any other TextureDescriptor is the general form
a GraphicsDevice makes beside it (it was createTextureWithDescriptor):
a 2D array, a 3D texture, a cube or a cube array, with
TextureDescriptor.mipLevelCount levels and the usages it names, gated
by the feature the shape needs — textureArrays, texture3D,
cubeTextures, cubeArrayTextures, and textureWrites for the general
form itself; a TextureUsage.storage texture needs storageTextures
and a format whose support says storage. A device without one throws
UnsupportedCapabilityException, and a size past its limits an ArgumentError.
Implementation
@override
TextureHandle createTexture(TextureDescriptor descriptor) {
if (descriptor is RenderTargetDescriptor) return _createTarget(descriptor);
features.require(DeviceFeature.textureWrites, backend: _name);
final shape = switch (descriptor.dimension) {
TextureDimension.d2Array => DeviceFeature.textureArrays,
TextureDimension.d3 => DeviceFeature.texture3D,
TextureDimension.cube => DeviceFeature.cubeTextures,
TextureDimension.cubeArray => DeviceFeature.cubeArrayTextures,
TextureDimension.d1 => DeviceFeature.texture1D,
TextureDimension.d2 => null,
_ => throw UnsupportedError(
'the fake backend cannot allocate a ${descriptor.dimension} texture',
),
};
if (shape != null) features.require(shape, backend: _name);
if (descriptor.usage.contains(TextureUsage.storage)) {
features.require(DeviceFeature.storageTextures, backend: _name);
}
calls.add(RecordedCall('createTexture', arguments: descriptor));
return _born(
wrapTexture(
owner: this,
backend: 'fake ${_serial++}',
width: descriptor.width,
height: descriptor.height,
format: descriptor.format,
sampleCount: descriptor.sampleCount,
storageMode: descriptor.storageMode,
dimension: descriptor.dimension,
depthOrArrayLayers: descriptor.depthOrArrayLayers,
mipLevelCount: descriptor.mipLevelCount,
usage: descriptor.usage,
),
);
}