API reference

Every public class, method, and event in @codexo/exojs. Generated from source.

C

classTexture

@codexo/exojs / rendering / stable

A static GPU texture sourced from an image, canvas, or video element. Holds the pixel source, its sampling state (ScaleModes, WrapModes) and its upload state (mip generation, alpha premultiplication). A `version` counter is incremented on every mutation that invalidates the GPU copy, so backends detect stale uploads without polling. Static helpers Texture.black, Texture.white, and Texture.empty provide ready-made placeholder textures. Default sampler options are configurable via Texture.defaultOptions.

23
props
12
methods
0
events
Import
import { Texture } from '@codexo/exojs'

A static GPU texture sourced from an image, canvas, or video element.

Holds the pixel source, its sampling state (ScaleModes, WrapModes) and its upload state (mip generation, alpha premultiplication). A `version` counter is incremented on every mutation that invalidates the GPU copy, so backends detect stale uploads without polling.

Static helpers Texture.black, Texture.white, and Texture.empty provide ready-made placeholder textures. Default sampler options are configurable via Texture.defaultOptions.

Constructors1
Methods12
addDestroyListener(listener: () => void): this
Register a callback to be invoked just before this texture is destroyed. Useful for backends to release their GPU-side texture objects.
destroy(): void
removeDestroyListener(listener: () => void): this
Install a compressed payload, replacing any pixel source, and resize to its base level. Pass null to drop it. Bumps version, so backends re-create their GPU texture - a format change cannot be patched into an existing one.
setGenerateMipMap(generateMipMap: boolean): this
setPremultiplyAlpha(premultiplyAlpha: boolean): this
setSize(width: number, height: number): this
updateSource(): this
Refresh the size from the current source and bump the version. Call after mutating the source's pixel data in place (e.g. drawing to a canvas) to notify backends that a re-upload is needed.
Create a solid-colour texture of the given square size (default 1×1). Accepts a Color instance or any CSS colour string; a Color with alpha below 1 is rendered with that alpha. Generalizes the fixed Texture.black/Texture.white helpers.
Properties23
empty: Texture
Hardware-compressed payload this texture uploads instead of a pixel source, or null for the ordinary case. Mutually exclusive with source: installing one clears the other, so a texture is never ambiguous about what it uploads. A handle that arrives empty from the loader can become either, which is what lets an asset variant swap a PNG for a KTX2 file without changing what a caller holds.
destroyed: boolean
true once destroy has run - a destroyed texture must not be bound.
error: Error | null
The error the last load failed with, or null outside 'failed'.
flipY: boolean
generateMipMap: boolean
height: number
loaded: Promise<this>
Promise that settles with this texture once its payload has loaded - resolved immediately for 'ready' textures, rejected with the load error for 'failed' ones. Re-materialized when a failed load is retried, so read it fresh from this getter rather than caching it across load cycles.
Load lifecycle of this texture. Directly constructed textures are 'ready'; deferred handles returned by loader.get('hero.png') / loader.get(Asset.type('texture', src)) start 'loading' and become 'ready' once the payload fills in, or 'failed' (showing the Texture.missing checker) when the load errors.
powerOfTwo: boolean
Whether both dimensions are powers of two. Non-power-of-two textures may have limited wrap-mode support on some hardware.
premultiplyAlpha: boolean
ready: boolean
true exactly when state is 'ready'.
version: number
Monotonically increasing version counter. Incremented by any mutation that requires a GPU re-upload: a source, size, or upload-parameter change. Filter and wrap changes do not bump it - backends resolve sampling state separately, so changing it costs no upload.
width: number
black: Texture
missing: Texture
Shared 8×8 magenta/black checkerboard shown in place of assets that failed to load - a visible error beats an invisible hole, in production too. Lazily created; every access returns the same instance.
white: Texture
Source