Skip to main content

Abstract Class: Texture

Defined in: modules/core/src/adapter/resources/texture.ts:203

Abstract Texture interface Texture Object https://gpuweb.github.io/gpuweb/#gputexture

Extends​

Constructors​

Constructor​

new Texture(device, props, backendProps?): Texture

Defined in: modules/core/src/adapter/resources/texture.ts:260

Do not use directly. Create with device.createTexture()

Parameters​

device​

Device

props​

TextureProps

backendProps?​
byteAlignment?​

number

Returns​

Texture

Overrides​

Resource.constructor

Properties​

baseDimension​

readonly baseDimension: "1d" | "2d" | "3d"

Defined in: modules/core/src/adapter/resources/texture.ts:223

base dimension of this texture


byteAlignment​

readonly byteAlignment: number

Defined in: modules/core/src/adapter/resources/texture.ts:237

Rows are multiples of this length, padded with extra bytes if needed


depth​

readonly depth: number

Defined in: modules/core/src/adapter/resources/texture.ts:231

depth of this texture


destroyed​

destroyed: boolean = false

Defined in: modules/core/src/adapter/resources/resource.ts:131

Whether this resource has been destroyed

Inherited from​

Resource.destroyed


device​

abstract readonly device: Device

Defined in: modules/core/src/adapter/resources/resource.ts:124

The device that this resource is associated with

Inherited from​

Resource.device


dimension​

readonly dimension: "1d" | "2d" | "2d-array" | "cube" | "cube-array" | "3d"

Defined in: modules/core/src/adapter/resources/texture.ts:221

dimension of this texture


format​

readonly format: TextureFormat

Defined in: modules/core/src/adapter/resources/texture.ts:225

format of this texture


handle​

abstract readonly handle: unknown

Defined in: modules/core/src/adapter/resources/resource.ts:126

The handle for the underlying resource, e.g. WebGL object or WebGPU handle

Inherited from​

Resource.handle


height​

readonly height: number

Defined in: modules/core/src/adapter/resources/texture.ts:229

height in pixels of this texture


id​

id: string

Defined in: modules/core/src/adapter/resources/resource.ts:118

props.id, for debugging.

Inherited from​

Resource.id


isReady​

readonly isReady: boolean = true

Defined in: modules/core/src/adapter/resources/texture.ts:246

isReady is always true. It is provided for type compatibility with DynamicTexture.


mipLevels​

readonly mipLevels: number

Defined in: modules/core/src/adapter/resources/texture.ts:233

mip levels in this texture


props​

readonly props: Required<Props>

Defined in: modules/core/src/adapter/resources/resource.ts:120

The props that this resource was created with

Inherited from​

Resource.props


ready​

readonly ready: Promise<Texture>

Defined in: modules/core/src/adapter/resources/texture.ts:244

The ready promise is always resolved. It is provided for type compatibility with DynamicTexture.


sampler​

abstract sampler: Sampler

Defined in: modules/core/src/adapter/resources/texture.ts:239

Default sampler for this texture


samples​

readonly samples: number

Defined in: modules/core/src/adapter/resources/texture.ts:235

sample count


updateTimestamp​

updateTimestamp: number

Defined in: modules/core/src/adapter/resources/texture.ts:249

"Time" of last update. Monotonically increasing timestamp. TODO move to DynamicTexture?


userData​

readonly userData: Record<string, unknown> = {}

Defined in: modules/core/src/adapter/resources/resource.ts:122

User data object, reserved for the application

Inherited from​

Resource.userData


view​

abstract view: TextureView

Defined in: modules/core/src/adapter/resources/texture.ts:241

Default view for this texture


width​

readonly width: number

Defined in: modules/core/src/adapter/resources/texture.ts:227

width in pixels of this texture


COPY_DST​

static COPY_DST: number = 0x02

Defined in: modules/core/src/adapter/resources/texture.ts:213

he texture can be used as the destination of a copy or write operation


COPY_SRC​

static COPY_SRC: number = 0x01

Defined in: modules/core/src/adapter/resources/texture.ts:211

The texture can be used as the source of a copy operation


defaultProps​

static defaultProps: Required<TextureProps>

Defined in: modules/core/src/adapter/resources/texture.ts:699

Default properties for resource

Overrides​

Resource.defaultProps


RENDER​

static RENDER: number = 0x10

Defined in: modules/core/src/adapter/resources/texture.ts:209

The texture can be used as a color or depth/stencil attachment in a render pass


RENDER_ATTACHMENT​

static RENDER_ATTACHMENT: number = 0x10

Defined in: modules/core/src/adapter/resources/texture.ts:218

Deprecated​

Use Texture.RENDER


SAMPLE​

static SAMPLE: number = 0x04

Defined in: modules/core/src/adapter/resources/texture.ts:205

The texture can be bound for use as a sampled texture in a shader


STORAGE​

static STORAGE: number = 0x08

Defined in: modules/core/src/adapter/resources/texture.ts:207

The texture can be bound for use as a storage texture in a shader


TEXTURE​

static TEXTURE: number = 0x04

Defined in: modules/core/src/adapter/resources/texture.ts:216

Deprecated​

Use Texture.SAMPLE

Accessors​

[toStringTag]​

Get Signature​

get [toStringTag](): string

Defined in: modules/core/src/adapter/resources/texture.ts:251

Returns​

string

Overrides​

Resource.[toStringTag]


isHandleBorrowed​

Get Signature​

get isHandleBorrowed(): boolean

Defined in: modules/core/src/adapter/resources/resource.ts:147

Whether luma.gl may only reference the opaque externally owned resource handle.

Returns​

boolean

Inherited from​

Resource.isHandleBorrowed


ownsHandle​

Get Signature​

get ownsHandle(): boolean

Defined in: modules/core/src/adapter/resources/resource.ts:140

Whether luma.gl created and owns the underlying resource handle.

Returns​

boolean

Inherited from​

Resource.ownsHandle

Methods​

_initializeData()​

_initializeData(data): void

Defined in: modules/core/src/adapter/resources/texture.ts:452

Initialize texture with supplied props

Parameters​

data​

ExternalImage | TypedArray | null | undefined

Returns​

void


_normalizeCopyElementImageOptions()​

_normalizeCopyElementImageOptions(options_): Required<CopyElementImageOptions>

Defined in: modules/core/src/adapter/resources/texture.ts:514

Parameters​

options_​

CopyElementImageOptions

Returns​

Required<CopyElementImageOptions>


_normalizeCopyExternalImageOptions()​

_normalizeCopyExternalImageOptions(options_): Required<CopyExternalImageOptions>

Defined in: modules/core/src/adapter/resources/texture.ts:494

Parameters​

options_​

CopyExternalImageOptions

Returns​

Required<CopyExternalImageOptions>


_normalizeCopyImageDataOptions()​

_normalizeCopyImageDataOptions(options_): Required<CopyImageDataOptions>

Defined in: modules/core/src/adapter/resources/texture.ts:485

Parameters​

options_​

CopyImageDataOptions

Returns​

Required<CopyImageDataOptions>


_normalizeTextureReadOptions()​

_normalizeTextureReadOptions(options_): Required<TextureReadOptions>

Defined in: modules/core/src/adapter/resources/texture.ts:531

Parameters​

options_​

TextureReadOptions

Returns​

Required<TextureReadOptions>


_normalizeTextureWriteOptions()​

_normalizeTextureWriteOptions(options_): Required<TextureWriteOptions>

Defined in: modules/core/src/adapter/resources/texture.ts:615

Parameters​

options_​

TextureWriteOptions

Returns​

Required<TextureWriteOptions>


attachResource()​

attachResource(resource): void

Defined in: modules/core/src/adapter/resources/resource.ts:200

Attaches a resource. Attached resources are auto destroyed when this resource is destroyed Called automatically when sub resources are auto created but can be called by application

Parameters​

resource​

Resource<ResourceProps>

Returns​

void

Inherited from​

Resource.attachResource


clone()​

clone(size?): Texture

Defined in: modules/core/src/adapter/resources/texture.ts:306

Create a new texture with the same parameters and optionally a different size

Parameters​

size?​
height​

number

width​

number

Returns​

Texture

Note​

Textures are immutable and cannot be resized after creation, but we can create a similar texture with the same parameters but a new size.

Note​

Does not copy contents of the texture


computeMemoryLayout()​

computeMemoryLayout(options_?): TextureMemoryLayout

Defined in: modules/core/src/adapter/resources/texture.ts:345

Calculates the memory layout of the texture, required when reading and writing data.

Parameters​

options_?​

TextureReadOptions = {}

Returns​

TextureMemoryLayout

the backend-aligned linear layout, in particular bytesPerRow which includes any required padding for buffer copy/read paths


copyElementImage()​

abstract copyElementImage(options): object

Defined in: modules/core/src/adapter/resources/texture.ts:322

Copy live DOM element pixels into the texture when supported by the current browser backend.

Parameters​

options​

CopyElementImageOptions

Returns​

object

height​

height: number

width​

width: number


copyExternalImage()​

abstract copyExternalImage(options): object

Defined in: modules/core/src/adapter/resources/texture.ts:319

Copy an image (e.g an ImageBitmap) into the texture

Parameters​

options​

CopyExternalImageOptions

Returns​

object

height​

height: number

width​

width: number


copyImageData()​

copyImageData(options): void

Defined in: modules/core/src/adapter/resources/texture.ts:333

Copy raw image data (bytes) into the texture.

Parameters​

options​

CopyImageDataOptions

Returns​

void

Note​

Deprecated compatibility wrapper over writeData.

Note​

Uses the same layout defaults and alignment rules as writeData.

Note​

Tightly packed CPU uploads can omit bytesPerRow and rowsPerImage.

Note​

If the CPU source rows are padded, pass explicit bytesPerRow and rowsPerImage.

Deprecated​

Use writeData()


createView()​

abstract createView(props): TextureView

Defined in: modules/core/src/adapter/resources/texture.ts:316

Create a texture view for this texture

Parameters​

props​

TextureViewProps

Returns​

TextureView


delete()​

delete(): this

Defined in: modules/core/src/adapter/resources/resource.ts:181

Returns​

this

Deprecated​

Use destroy()

Inherited from​

Resource.delete


destroy()​

destroy(): void

Defined in: modules/core/src/adapter/resources/resource.ts:173

destroy can be called on any resource to release it before it is garbage collected.

Returns​

void

Inherited from​

Resource.destroy


destroyAttachedResource()​

destroyAttachedResource(resource): void

Defined in: modules/core/src/adapter/resources/resource.ts:214

Destroys a resource (only if owned), and removes from the owned (auto-destroy) list for this resource.

Parameters​

resource​

Resource<ResourceProps>

Returns​

void

Inherited from​

Resource.destroyAttachedResource


destroyAttachedResources()​

destroyAttachedResources(): void

Defined in: modules/core/src/adapter/resources/resource.ts:221

Destroy all owned resources. Make sure the resources are no longer needed before calling.

Returns​

void

Inherited from​

Resource.destroyAttachedResources


detachResource()​

detachResource(resource): void

Defined in: modules/core/src/adapter/resources/resource.ts:207

Detach an attached resource. The resource will no longer be auto-destroyed when this resource is destroyed.

Parameters​

resource​

Resource<ResourceProps>

Returns​

void

Inherited from​

Resource.detachResource


generateMipmapsWebGL()​

generateMipmapsWebGL(): void

Defined in: modules/core/src/adapter/resources/texture.ts:429

Generate mipmaps (WebGL only)

Returns​

void


getProps()​

getProps(): object

Defined in: modules/core/src/adapter/resources/resource.ts:190

Combines a map of user props and default props, only including props from defaultProps

Returns​

object

returns a map of overridden default props

Inherited from​

Resource.getProps


readBuffer()​

readBuffer(options?, buffer?): Buffer

Defined in: modules/core/src/adapter/resources/texture.ts:372

Read the contents of a texture into a GPU Buffer.

Parameters​

options?​

TextureReadOptions

buffer?​

Buffer

Returns​

Buffer

A Buffer containing the texture data.

Note​

The memory layout of the texture data is determined by the texture format and dimensions.

Note​

The application can call Texture.computeMemoryLayout() to compute the backend-aligned layout.

Note​

The application can call Buffer.readAsync() to read the returned buffer on the CPU.

Note​

The destination buffer must be supplied by the caller and must be large enough for the requested region.

Note​

On WebGPU this corresponds to a texture-to-buffer copy and uses buffer-copy alignment rules.

Note​

On WebGL, luma.gl emulates the same logical readback behavior.


readDataAsync()​

readDataAsync(options?): Promise<ArrayBuffer>

Defined in: modules/core/src/adapter/resources/texture.ts:384

Reads data from a texture into an ArrayBuffer.

Parameters​

options?​

TextureReadOptions

Returns​

Promise<ArrayBuffer>

An ArrayBuffer containing the texture data.

Note​

The memory layout of the texture data is determined by the texture format and dimensions.

Note​

The application can call Texture.computeMemoryLayout() to compute the layout.

Deprecated​

Use Texture.readBuffer() with an explicit destination buffer, or DynamicTexture.readAsync() for convenience readback.


readDataSyncWebGL()​

readDataSyncWebGL(options?): ArrayBuffer | ArrayBufferView<ArrayBufferLike>

Defined in: modules/core/src/adapter/resources/texture.ts:424

WebGL can read data synchronously.

Parameters​

options?​

TextureReadOptions

Returns​

ArrayBuffer | ArrayBufferView<ArrayBufferLike>

Note​

While it is convenient, the performance penalty is very significant


setSampler()​

setSampler(sampler): void

Defined in: modules/core/src/adapter/resources/texture.ts:311

Set sampler props associated with this texture

Parameters​

sampler​

SamplerProps | Sampler

Returns​

void


toJSON()​

toJSON(): string

Defined in: modules/core/src/adapter/resources/resource.ts:113

Compact serialization for assertion diffs and structured debug logs.

Returns​

string

Inherited from​

Resource.toJSON


toString()​

toString(): string

Defined in: modules/core/src/adapter/resources/texture.ts:255

Returns​

string

Overrides​

Resource.toString


writeBuffer()​

writeBuffer(buffer, options?): void

Defined in: modules/core/src/adapter/resources/texture.ts:398

Writes a GPU Buffer into a texture.

Parameters​

buffer​

Buffer

Source GPU buffer.

options?​

TextureWriteOptions

Destination subresource, extent, and source layout options.

Returns​

void

Note​

The memory layout of the texture data is determined by the texture format and dimensions.

Note​

The application can call Texture.computeMemoryLayout() to compute the backend-aligned layout.

Note​

On WebGPU this corresponds to a buffer-to-texture copy and uses buffer-copy alignment rules.

Note​

On WebGL, luma.gl emulates the same destination and layout semantics.


writeData()​

writeData(data, options?): void

Defined in: modules/core/src/adapter/resources/texture.ts:411

Writes an array buffer into a texture.

Parameters​

data​

ArrayBuffer | SharedArrayBuffer | ArrayBufferView<ArrayBufferLike>

Source texel data.

options?​

TextureWriteOptions

Destination subresource, extent, and source layout options.

Returns​

void

Note​

If bytesPerRow and rowsPerImage are omitted, luma.gl computes a tightly packed CPU-memory layout for the requested region.

Note​

On WebGPU this corresponds to GPUQueue.writeTexture() and does not implicitly pad rows to 256 bytes.

Note​

On WebGL, padded CPU data is supported via the same bytesPerRow and rowsPerImage options.