playcanvas-opti-pixel - v1.3.1
    Preparing search index...

    Interface ICoverageBuffer

    Packed CPU view-space Z (metres) taken from one mip of a hierarchical Z-buffer. Shared by WebGL (transform feedback / PBO) and WebGPU (compute / mapAsync).

    Build the pyramid first (update / updateSceneDepth), then capture. Each axis picks the stored mip nearest to the buffer's max resolution; the coarser of the two is packed. If that mip's screen footprint, clamped to the max, would still cover three or more source texels per packed pixel, the next coarser mip is used. The CPU map is that footprint rounded to whole texels. Pixel i covers screen UV [i / cpuWidth, (i + 1) / cpuWidth] (the same on Y) and reads the HZB texels under that slice. Each packed texel is that device Z, linearized to metres.

    interface ICoverageBuffer {
        cpuCameraParams: Float32Array;
        cpuDepth: Float32Array;
        cpuHeight: number;
        cpuReadback: boolean;
        cpuReady: boolean;
        cpuVersion: number;
        cpuViewProjection: Float32Array;
        cpuWidth: number;
        device: GraphicsDevice;
        enabled: boolean;
        height: number;
        sourceMip: number;
        width: number;
        capture(hzb: IHierarchicalZBuffer, camera: Camera): void;
        destroy(): void;
        frameUpdate(dt: number): void;
        resize(maxWidth?: number, maxHeight?: number): void;
    }

    Implemented by

    Index
    cpuCameraParams: Float32Array

    Camera.fillShaderParams of that same camera. x is 1 / far, y is far, z is near, w is 1 for an orthographic camera and 0 for perspective. Same lifetime as cpuViewProjection.

    cpuDepth: Float32Array

    View-space Z of the published capture, in metres. Length is width × height. A publish writes a tightly packed map of cpuWidth × cpuHeight into the front of the array and leaves texels past that prefix untouched. Row 0 is the bottom of the screen. Construct and a packed-size rebuild allocate a new array filled with 1e10.

    cpuHeight: number

    Height of the published map. See cpuWidth.

    cpuReadback: boolean

    When false, capture does not pack or start a readback. frameUpdate still publishes a readback already in flight. Defaults to true.

    cpuReady: boolean

    True after frameUpdate has published a capture. False before the first publish, after resize changes the packed pixel count (maxWidth * maxHeight), and on WebGL after context loss. A resize that keeps that count leaves a published map ready.

    cpuVersion: number

    Bumped when frameUpdate publishes a capture, and when resize changes the packed pixel count. Changing readbackSlots does not bump it. The tester recopies cpuDepth when this differs from the copy it last applied and cpuReady is set.

    cpuViewProjection: Float32Array

    View-projection of the camera packed into the published map (projection × view, 16 column-major floats). A packed-size rebuild replaces cpuDepth and leaves this matrix unchanged until the next publish. Read it with the map while cpuReady is set.

    cpuWidth: number

    Width of the published map, in texels. Screen footprint of the mip that was packed, clamped to width. Reports width until the first publish and after resize changes the packed pixel count.

    device: GraphicsDevice

    Device that owns the pack and the readback ring.

    enabled: boolean

    When false, capture does nothing. Defaults to true.

    height: number

    Cap on the packed map height, in texels. The published footprint is cpuHeight.

    sourceMip: number

    Stored HZB level selected by the last capture that took a readback slot. Stays 0 until then. Level 0 is also a real mip.

    width: number

    Cap on the packed map width, in texels. The published footprint is cpuWidth.

    • Select a mip of an already-built pyramid, pack it into the CPU map, and start an async readback. The selected level is written to sourceMip. Device Z is linearized in the pack. No-op when this buffer or the pyramid is disabled, when cpuReadback is off, or without a pyramid texture. Also no-op when no readback slot is free, when a readback was already submitted this frame, or on a WebGL tick that readbackPeriod skips. Call after hzb.update / hzb.updateSceneDepth, once opaque depth is in the pyramid.

      Parameters

      Returns void

    • Set the packed-map cap. Omitted sizes keep the current cap.

      The readback ring holds maxWidth * maxHeight pixels and is rebuilt only when that count changes. A same-count change keeps in-flight captures and the published map. A rebuild drops them: cpuReady becomes false, cpuVersion increments, and cpuDepth is filled with 1e10.

      Screen size belongs to the HZB. A window resize does not call this, so in-flight captures and the published map stay.

      Parameters

      • OptionalmaxWidth: number
      • OptionalmaxHeight: number

      Returns void