API reference

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

C

classDepthTexture

@codexo/exojs / rendering / stable

The depth attachment of a render target, bindable as a named texture of a custom MeshMaterial or SpriteMaterial. It is created by the target that opted into depth (`{ depth: true }`), owned by it, resized with it and destroyed with it; there is no way to construct one on its own and no source to upload. The value behind each texel is the window-space depth the last draw with a depth-writing material left there, which is the backend's mapping of the clip-space z that draw's vertex stage produced: nearer geometry is always the smaller value, but the absolute numbers differ between backends because WebGL2 maps NDC `[-1, 1]` onto `[0, 1]` where WebGPU's NDC z already is `[0, 1]`. Compare depths, do not hard-code them. That one slot is the whole of where it fits. It is NOT interchangeable with a colour texture: a drawable's own `texture`, a filter input, and every built-in renderer's texture binding expect a filterable colour format, which on WebGPU makes a depth view there a bind-group validation error rather than a wrong picture. Put it in the material's `textures` map and read it from the custom shader. Sampling constraints, both backends alike: - Fixed sampling state: `nearest` filtering, `clamp-to-edge` wrapping. A depth format is not filterable and the attachment's parameters are set once with the attachment, so setScaleMode and setWrapMode are no-ops here rather than changes that would silently fail to take. - One channel. GLSL reads it as `texture(sampler, uv).r`; WGSL declares the binding as `texture_depth_2d` and reads it as `textureSample(t, s, uv)`, which yields the bare `f32`. Comparison sampling (`sampler_comparison`, `sampler2DShadow`) is not used and not available. - Live. The texture is the attachment itself, not a copy, so sampling it in the same pass that writes it is undefined; sample it in a later pass. - Cleared with the colour attachment, to the far plane. A pass that preserves the target's colour preserves its depth too. Reading one before the owning target has ever been rendered into throws a `RenderError` - there is no attachment to sample yet.

24
props
12
methods
0
events
Import
import { DepthTexture } from '@codexo/exojs'

The depth attachment of a render target, bindable as a named texture of a custom MeshMaterial or SpriteMaterial.

It is created by the target that opted into depth (`{ depth: true }`), owned by it, resized with it and destroyed with it; there is no way to construct one on its own and no source to upload. The value behind each texel is the window-space depth the last draw with a depth-writing material left there, which is the backend's mapping of the clip-space z that draw's vertex stage produced: nearer geometry is always the smaller value, but the absolute numbers differ between backends because WebGL2 maps NDC `[-1, 1]` onto `[0, 1]` where WebGPU's NDC z already is `[0, 1]`. Compare depths, do not hard-code them.

That one slot is the whole of where it fits. It is NOT interchangeable with a colour texture: a drawable's own `texture`, a filter input, and every built-in renderer's texture binding expect a filterable colour format, which on WebGPU makes a depth view there a bind-group validation error rather than a wrong picture. Put it in the material's `textures` map and read it from the custom shader.

Sampling constraints, both backends alike:

- Fixed sampling state: `nearest` filtering, `clamp-to-edge` wrapping. A depth format is not filterable and the attachment's parameters are set once with the attachment, so setScaleMode and setWrapMode are no-ops here rather than changes that would silently fail to take. - One channel. GLSL reads it as `texture(sampler, uv).r`; WGSL declares the binding as `texture_depth_2d` and reads it as `textureSample(t, s, uv)`, which yields the bare `f32`. Comparison sampling (`sampler_comparison`, `sampler2DShadow`) is not used and not available. - Live. The texture is the attachment itself, not a copy, so sampling it in the same pass that writes it is undefined; sample it in a later pass. - Cleared with the colour attachment, to the far plane. A pass that preserves the target's colour preserves its depth too.

Reading one before the owning target has ever been rendered into throws a `RenderError` - there is no attachment to sample yet.

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
setScaleMode(): this
No-op: a depth attachment is sampled nearest on both backends.
setSize(width: number, height: number): this
setWrapMode(): this
No-op: a depth attachment is sampled clamp-to-edge on both backends.
updateSource(): this
No-op: a depth attachment has no CPU-side source to refresh from, and the inherited implementation would resize it to the null source's 0x0.
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.
Properties24
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
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.
Source