export type TextureSlot = { /** * - The persistent screen-space quad. */ meshInstance: MeshInstance; /** * - Material owned by this slot. */ material: ShaderMaterial; /** * - The last sampling mode. */ mode: string; /** * - The last source encoding. */ encoding: string; /** * - Channels selected for this preview. */ channelIndices: Int32Array; /** * - The texture shown this frame, or null. */ texture: Texture | null; }; export type TexturePool = { /** * - Slots in submission order. */ slots: TextureSlot[]; /** * - Registered instances, used for cleanup. */ meshInstances: MeshInstance[]; /** * - Number of submissions this frame. */ used: number; }; /** * Displays textures for a single frame, for debugging. Call {@link draw} or {@link 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 {@link channels} selection, and single-channel formats such as * {@link PIXELFORMAT_R8} display their channel as grayscale. Other selections display stored * channel values, including alpha, as opaque previews. * * Depth textures using {@link PIXELFORMAT_DEPTH}, {@link PIXELFORMAT_DEPTH16} or * {@link PIXELFORMAT_DEPTHSTENCIL} are displayed as raw grayscale values. Use {@link 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 * {@link 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 {@link 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. * * @example * const textures = new TextureRenderer(app); * app.on('update', () => { * textures.draw(texture, 0.7, 0.7, 0.25, 0.25); * }); * @example * // 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); * }); * @category Graphics */ export class TextureRenderer { /** * Creates a debug texture renderer. * * @param {AppBase} app - The application to render into and bind resource lifetime to. */ constructor(app: AppBase); /** * The layer used by subsequent draw calls, or null to use the application's default debug * drawing layer (normally Immediate). Defaults to null. * * @type {Layer|null} */ layer: Layer | null; /** * The only camera that draws the previews, or null to let every camera rendering the * destination layer draw them. Defaults to null. * * @type {CameraComponent|null} */ camera: CameraComponent | null; /** @private */ private _channels; /** @private */ private _channelIndices; /** * Channels displayed by subsequent {@link 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 * {@link sceneDepth}. Invalid values leave the previous selection unchanged. * * @type {string} * @example * textures.channels = 'aaa'; * textures.draw(texture, 0, 0, 0.25, 0.25); */ set channels(value: string); get channels(): string; /** * @type {Map} * @private */ private _pools; /** * @type {Map} * @private */ private _shaderDescs; /** * @type {Mesh|null} * @private */ private _mesh; /** @private */ private _app; /** * Displays a 2D color or depth texture for this frame. Color encoding and supported filtering * are detected automatically when {@link channels} is 'rgb'. Other selections display stored * channel values. Raw depth is shown as grayscale without * projection-dependent linearization; use {@link sceneDepth} for camera depth. Texture row 0 * is displayed at the top. For rendered textures, use {@link 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. * * @param {Texture} texture - The caller-owned texture to display. * @param {number} x - Left edge as a fraction of the camera viewport width. * @param {number} y - Top edge as a fraction of the camera viewport height. * @param {number} width - Width as a fraction of the camera viewport width. * @param {number} height - Height as a fraction of the camera viewport height. */ draw(texture: Texture, x: number, y: number, width: number, height: number): 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 * {@link CameraComponent#requestSceneDepthMap}, and this layer must render after depth capture. * * @param {number} x - Left edge as a fraction of the camera viewport width. * @param {number} y - Top edge as a fraction of the camera viewport height. * @param {number} width - Width as a fraction of the camera viewport width. * @param {number} height - Height as a fraction of the camera viewport height. */ sceneDepth(x: number, y: number, width: number, height: number): void; /** * @param {Texture|null} texture - Source texture, or null for scene depth. * @param {string} mode - Sampling mode. * @param {string} encoding - Source encoding. * @param {number} x - Normalized left edge. * @param {number} y - Normalized top edge. * @param {number} width - Normalized width. * @param {number} height - Normalized height. * @param {Int32Array} channelIndices - The channels shown by a raw encoding. * @private */ private _draw; /** * Whether a pass draws a preview: only the selected camera if one is set, and never a pass * rendering into the texture the preview samples. * * @param {TextureSlot} slot - The preview. * @param {Camera} camera - The camera rendering the layer. * @param {RenderTarget|null} renderTarget - The target the pass renders into. * @returns {boolean} True to draw the preview in this pass. * @private */ private _isDrawnBy; /** * Applies camera and attachment restrictions after culling, using the actual pass target. * The pass mask skips shader preparation and resource binding as well as the draw itself. * * @param {CameraComponent} cameraComponent - The camera rendering the layer. * @param {Layer} layer - The layer about to be rendered. * @private */ private _onPreRenderLayer; /** * Keeps previews out of other passes until their destination layer explicitly enables them. * * @param {CameraComponent} cameraComponent - The camera that rendered the layer. * @param {Layer} layer - The layer that was rendered. * @private */ private _onPostRenderLayer; /** @private */ private _endFrame; /** * Removes all previews and releases the renderer's resources. Does not destroy supplied * textures. Safe to call repeatedly; subsequent draw calls are ignored. */ destroy(): void; } import { MeshInstance } from '../../scene/mesh-instance.js'; import { ShaderMaterial } from '../../scene/materials/shader-material.js'; import type { Texture } from '../../platform/graphics/texture.js'; import type { Layer } from '../../scene/layer.js'; import type { CameraComponent } from '../../framework/components/camera/component.js'; import type { AppBase } from '../../framework/app-base.js';