trackedViewport
The canvas size in pixels, kept current across resizes, in the two forms a stage wants.
trackedViewport(params: GpuFragmentParams): {
tracked(): {width: number; height: number}
safe(fp: GridFrameParams): {width: number; height: number}
}
Import sim from shaders/std and use sim.grids.trackedViewport.
tracked() is the size at the last resize, for a pass that works in the canvas's own pixels. safe(fp) prefers the size this frame reports and never returns less than 1, for an aspect ratio.
Parameters
| Name | Type | Notes |
|---|---|---|
params | GpuFragmentParams |
Example
const viewport = trackedViewport(params)
op.values('write', (f) => { const s = viewport.safe(f.frameParams); paramsU.write({aspect: s.width / s.height}) })
See also
gridSim— A field of cells advanced every frame by an ordered list of stages.