Texture2DArray class Assets and loading
A stack of same-size 2D layers in one GPU texture, sampled in a material as
a sampler2DArray with texture(name, vec3(uv, layer)).
Filtering is within a layer. A linear sampler blends neighbouring texels of the layer it reads, never neighbouring layers, so volume data that needs filtering across slices blends two layer reads in the shader.
final layers = Texture2DArray.fromLayers(
slices, // one Uint8List of width * height bytes per layer
width: 256,
height: 256,
format: DataTextureFormat.r8,
);
material.parameters.setTexture(
'layers',
layers.gpuTexture,
sampler: layers.sampledSampler,
);
- Implemented types
Constructors
- Texture2DArray.empty({required int width, required int height, required int layerCount, DataTextureFormat format = DataTextureFormat.rgba8, TextureSampling? sampling})
-
Allocates a 2D-array texture without uploading anything, for data that
arrives a layer at a time through writeLayer. Unwritten layers hold
undefined contents.
factory
-
Texture2DArray.fromLayers(List<
TypedData> layers, {required int width, required int height, DataTextureFormat format = DataTextureFormat.rgba8, TextureSampling? sampling}) -
Uploads
layers, eachwidthxheighttexels offormat, into a new 2D-array texture.factory
Properties
- byteSize → int
-
The GPU memory the texels occupy, excluding any driver padding.
no setter
- format → DataTextureFormat
-
The format of every layer.
final
- gpuTexture → Texture
-
The underlying GPU texture, for MaterialParameters.setTexture.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → int
-
The height of each layer in texels.
no setter
- layerByteSize → int
-
The bytes one layer holds.
no setter
- layerCount → int
-
The number of layers.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sampledSampler → SamplerOptions
-
The sampler this source is bound with.
no setteroverride
- sampledTexture → Texture?
-
The GPU texture to sample this frame, or null when none is available yet
(a live source before its first frame; callers substitute a placeholder).
no setteroverride
- width → int
-
The width of each layer in texels.
no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
writeLayer(
int layer, TypedData data) → void -
Replaces layer
layerwithdata, exactly one layer of texels.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- isSupported → bool
-
Whether the active backend can create 2D-array textures. True on the web
backends, and on Metal and Vulkan with Flutter 3.50 or newer.
no setter