Engine API Reference - v2.23.0-beta.17
    Preparing search index...

    Class TextureRenderer

    Displays textures for a single frame, for debugging. Call draw or sceneDepth during update or prerender on every frame the preview should be visible. Positions specify the top-left corner in normalized camera-viewport coordinates: (0, 0) is top-left and (1, 1) is bottom-right. Width and height are fractions of the viewport; a rectangle of (0, 0, 1, 1) fills it. Signed sizes can flip a preview, and rectangles can extend outside the viewport.

    Supports 2D color textures in normalized, floating-point and device-supported compressed formats. Linear and sRGB color, and RGBM, RGBE and RGBP encoded HDR color, are detected automatically with the default channels selection, and single-channel formats such as PIXELFORMAT_R8 display their channel as grayscale. Other selections display stored channel values, including alpha, as opaque previews.

    Depth textures using PIXELFORMAT_DEPTH, PIXELFORMAT_DEPTH16 or PIXELFORMAT_DEPTHSTENCIL are displayed as raw grayscale values. Use sceneDepth to display the rendering camera's scene depth, linearized and normalized by its far clip distance. The camera must have scene depth capture enabled.

    Cube, volume, array, integer and multisampled textures are not supported. On WebGL2, raw depth textures must have comparison sampling disabled, and both raw depth and non-filterable float textures require nearest minification and magnification filters. WebGPU supports these textures regardless of their filtering and comparison sampler settings.

    Resources are released automatically when the application is destroyed, or earlier by calling destroy. Supplied textures are never destroyed by this helper.

    Previews produce fully opaque pixels but are drawn as alpha-blended instances, so they render in layers that only draw their transparent sub-layer, such as the default UI layer, which is also where they escape a camera frame's post-processing. They do not write or test depth and do not cast shadows. Ordering against other transparent geometry follows the destination layer's transparent sort mode.

    Every camera rendering the destination layer draws the previews, including cameras rendering into a texture. Set camera to limit them to a single camera, typically the one rendering to the screen. A render pass whose target has the previewed texture among its attachments never draws that preview: sampling a texture while rendering into it is undefined on WebGL and an error on WebGPU. Both rules are applied as each layer is rendered, against the target the pass really renders into, so they hold for camera frames and custom render passes and do not depend on frustum culling.

    const textures = new TextureRenderer(app);
    app.on('update', () => {
    textures.draw(texture, 0.7, 0.7, 0.25, 0.25);
    });
    // camera is an entity with a camera component.
    camera.camera.requestSceneDepthMap(true);
    const textures = new TextureRenderer(app);
    app.on('update', () => {
    textures.sceneDepth(0.7, 0.7, 0.25, 0.25);
    });
    Index
    camera: CameraComponent | null = null

    The only camera that draws the previews, or null to let every camera rendering the destination layer draw them. Defaults to null.

    layer: Layer | null = null

    The layer used by subsequent draw calls, or null to use the application's default debug drawing layer (normally Immediate). Defaults to null.

    • set channels(value: string): void

      Channels displayed by subsequent draw calls. Must be exactly three characters from 'r', 'g', 'b' and 'a'. Defaults to 'rgb', which displays automatically decoded color, or the stored channel as grayscale for single-channel formats. Other selections display stored channel values without color decoding: for example, 'rrr' displays red as grayscale, 'aaa' displays alpha, and 'bgr' swaps red and blue. Values from 0 to 1 map directly from black to white. Output is always opaque. Ignored for depth textures and sceneDepth. Invalid values leave the previous selection unchanged.

      Parameters

      • value: string

      Returns void

      textures.channels = 'aaa';
      textures.draw(texture, 0, 0, 0.25, 0.25);
    • Removes all previews and releases the renderer's resources. Does not destroy supplied textures. Safe to call repeatedly; subsequent draw calls are ignored.

      Returns void

    • Displays a 2D color or depth texture for this frame. Color encoding and supported filtering are detected automatically when channels is 'rgb'. Other selections display stored channel values. Raw depth is shown as grayscale without projection-dependent linearization; use sceneDepth for camera depth. Texture row 0 is displayed at the top. For rendered textures, use RENDERTARGET_ORIGIN_TOP on their render target for consistent orientation across backends.

      Cube, volume, array, integer and multisampled textures are not supported. On WebGL2, depth textures must have comparison sampling disabled. Raw depth and non-filterable float textures must use nearest minification and magnification filters on WebGL2. WebGPU samples these textures independently of their filtering and comparison sampler settings.

      Parameters

      • texture: Texture

        The caller-owned texture to display.

      • x: number

        Left edge as a fraction of the camera viewport width.

      • y: number

        Top edge as a fraction of the camera viewport height.

      • width: number

        Width as a fraction of the camera viewport width.

      • height: number

        Height as a fraction of the camera viewport height.

      Returns void

    • Displays the rendering camera's scene depth for this frame, linearized and normalized by its far clip distance. The camera must already supply a scene depth map, for example using CameraComponent#requestSceneDepthMap, and this layer must render after depth capture.

      Parameters

      • x: number

        Left edge as a fraction of the camera viewport width.

      • y: number

        Top edge as a fraction of the camera viewport height.

      • width: number

        Width as a fraction of the camera viewport width.

      • height: number

        Height as a fraction of the camera viewport height.

      Returns void