Texture2D class Assets and loading
A 2D image texture ready to bind to a material's texture slot.
Create one from an asset (fromAsset), a decoded dart:ui image
(fromImage), or raw RGBA pixels (fromPixels). A mip chain is generated
at creation, downsampled correctly for the texture's TextureContent (sRGB
color averaged in linear light, normals renormalized), and the texture
carries its own TextureSampling (trilinear + anisotropic by default).
final albedo = await Texture2D.fromAsset('assets/brick_color.png');
final normal = await Texture2D.fromAsset('assets/brick_normal.png',
content: TextureContent.normal);
material.baseColorTexture = albedo;
material.normalTexture = normal;
- Implemented types
Properties
- gpuTexture → Texture
-
The underlying GPU texture, for advanced/interop use.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- 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
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
fromAsset(
String assetPath, {TextureContent content = TextureContent.color, TextureSampling sampling = const TextureSampling(), AssetBundle? bundle}) → Future< Texture2D> -
Loads, decodes, and uploads the image asset at
assetPath. -
fromImage(
Image image, {TextureContent content = TextureContent.color, TextureSampling sampling = const TextureSampling()}) → Future< Texture2D> -
Builds a texture from a decoded
image. -
fromPixels(
Uint8List pixels, int width, int height, {TextureContent content = TextureContent.color, TextureSampling sampling = const TextureSampling()}) → Texture2D -
Builds a texture from RGBA8888
pixels(straight alpha, row-major) ofwidthxheight.