Skip to main content

Class: DynamicTexture

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:37

Dynamic Textures

  • Mipmaps - DynamicTexture can generate mipmaps for textures (WebGPU does not provide built-in mipmap generation).

  • Texture initialization and updates - complex textures (2d array textures, cube textures, 3d textures) need multiple images DynamicTexture provides an API that makes it easy to provide the required data.

  • Texture resizing - Textures are immutable in WebGPU, meaning that they cannot be resized after creation. DynamicTexture provides a resize() method that internally creates a new texture with the same parameters but a different size.

  • Async image data initialization - It is often very convenient to be able to initialize textures with promises returned by image or data loading functions, as it allows a callback-free linear style of programming.

Note​

GPU Textures are quite complex objects, with many subresources and modes of usage. The DynamicTexture class allows luma.gl to provide some support for working with textures without accumulating excessive complexity in the core Texture class which is designed as an immutable nature of GPU resource.

Implements​

Constructors​

Constructor​

new DynamicTexture(device, props): DynamicTexture

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:67

Parameters​

device​

Device

props​

DynamicTextureProps

Returns​

DynamicTexture

Properties​

destroyed​

destroyed: boolean

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:49


device​

readonly device: Device

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:38


generation​

generation: number

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:51

Monotonic version that increments whenever texture, view, or sampler identity changes.

Implementation of​

TextureBindingSource.generation


id​

readonly id: string

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:39

Stable resource identifier used in loading and debug messages.

Implementation of​

TextureBindingSource.id


isReady​

isReady: boolean

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:48

Whether the source can resolve a concrete binding for the current draw.

Implementation of​

TextureBindingSource.isReady


props​

props: Readonly<Required<DynamicTextureProps>>

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:41

Props with defaults resolved (except data which is processed separately)


ready​

readonly ready: Promise<Texture>

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:47

Ready when GPU texture has been created and data (if any) uploaded


updateTimestamp​

updateTimestamp: number

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:53

Last update timestamp for texture content, readiness, or identity changes.

Implementation of​

TextureBindingSource.updateTimestamp


defaultProps​

static defaultProps: Required<DynamicTextureProps>

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:113

Accessors​

[toStringTag]​

Get Signature​

get [toStringTag](): string

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:59

Returns​

string


sampler​

Get Signature​

get sampler(): Sampler

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:57

Returns​

Sampler


texture​

Get Signature​

get texture(): Texture

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:56

Returns​

Texture


view​

Get Signature​

get view(): TextureView

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:58

Returns​

TextureView

Methods​

destroy()​

destroy(): void

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:70

Returns​

void


generateMipmaps()​

generateMipmaps(): void

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:71

Returns​

void


getCubeArrayFaceIndex()​

getCubeArrayFaceIndex(cubeIndex, face): number

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:92

Convert cube face label to texture slice index. Index can be used with setTexture2DData().

Parameters​

cubeIndex​

number

face​

TextureCubeFace

Returns​

number


getCubeFaceIndex()​

getCubeFaceIndex(face): number

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:90

Convert cube face label to texture slice index. Index can be used with setTexture2DData().

Parameters​

face​

TextureCubeFace

Returns​

number


initAsync()​

initAsync(originalPropsWithAsyncData): Promise<void>

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:69

Parameters​

originalPropsWithAsyncData​

DynamicTextureProps

Returns​

Promise<void>

Note​

Fire and forget; caller can await ready


readAsync()​

readAsync(options?): Promise<ArrayBuffer>

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:80

Reads texture contents back to CPU memory.

Parameters​

options?​

TextureReadOptions

Returns​

Promise<ArrayBuffer>


readBuffer()​

readBuffer(options?): Promise<Buffer>

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:78

Copies texture contents into a GPU buffer and waits until the copy is complete. The caller owns the returned buffer and must destroy it when finished.

Parameters​

options?​

TextureReadOptions

Returns​

Promise<Buffer>


resize()​

resize(size): boolean

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:85

Resize by cloning the underlying immutable texture. Does not copy contents; caller may need to re-upload and/or regenerate mips.

Parameters​

size​
height​

number

width​

number

Returns​

boolean


resolveTextureBinding()​

resolveTextureBinding(_bindingLayout): Texture | null

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:66

Resolves this ready dynamic texture as an ordinary copied texture binding.

Parameters​

_bindingLayout​

TextureBindingLayout

Reflected texture-like shader slot; DynamicTexture always resolves a copied texture.

Returns​

Texture | null

The copied texture, or null while the source is not ready.

Implementation of​

TextureBindingSource.resolveTextureBinding


setSampler()​

setSampler(sampler?): void

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:73

Set sampler or create one from props

Parameters​

sampler?​

Sampler | SamplerProps

Returns​

void


setTexture1DData()​

setTexture1DData(data): void

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:94

Parameters​

data​

TextureSliceData

Returns​

void

Note​

experimental: Set multiple mip levels (1D)


setTexture2DData()​

setTexture2DData(lodData, z?): void

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:96

Parameters​

lodData​

TextureSliceData

z?​

number

Returns​

void

Note​

experimental: Set multiple mip levels (2D), optionally at z, slice (depth/array level) index


setTexture3DData()​

setTexture3DData(data): void

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:98

3D: multiple depth slices, each may carry multiple mip levels

Parameters​

data​

Texture3DData

Returns​

void


setTextureArrayData()​

setTextureArrayData(data): void

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:100

2D array: multiple layers, each may carry multiple mip levels

Parameters​

data​

TextureArrayData

Returns​

void


setTextureCubeArrayData()​

setTextureCubeArrayData(data): void

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:104

Cube array: multiple cubes (faces×layers), each face may carry multiple mips

Parameters​

data​

TextureCubeArrayData

Returns​

void


setTextureCubeData()​

setTextureCubeData(data): void

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:102

Cube: 6 faces, each may carry multiple mip levels

Parameters​

data​

TextureCubeData

Returns​

void


toString()​

toString(): string

Defined in: modules/core/dist/dynamic/dynamic-texture/dynamic-texture.d.ts:60

Returns a string representation of an object.

Returns​

string