Renderer · class

GpuTimer

Explained in Hello world.

class GpuTimer implements FrameTimer
import { GpuTimer } from '@driftengine/core';

Constructor

new

constructor(gl: WebGL2RenderingContext, sampleEvery?: number)
ParameterTypeDescription
glWebGL2RenderingContext
sampleEvery?number

Properties

NameTypeDescription
availablereadonlybooleanFalse where the extension is missing or disabled, which is a normal state.
disjointDropsnumberSamples the driver said were untrustworthy. Reported, never silently dropped.

Accessors

NameTypeDescription
samplinggetbooleanWhether beginFrame said yes for the frame being drawn.

Methods

beginFrame

beginFrame(): boolean

Whether this frame is measured. Call once per frame, before any begin.

More

begin and end do nothing on an unmeasured frame, so the skipped frames really are free rather than merely cheap.

endFrame

endFrame(): void

Close the frame and queue it for reading.

More

Explicit rather than counting to three, because the shadow pass runs several times a frame — static, the depth peel, then dynamic — and the reflection pass may not run at all when water is off. A frame is over when the caller says so, and poll sums the brackets per slot, so three shadow passes are one shadow number rather than three partial ones.

begin

begin(slot: GpuSlot): void

Open a bracket. Never two at once — TIME_ELAPSED_EXT cannot nest, and the partition is what guarantees end runs before the next begin.

ParameterTypeDescription
slotGpuSlot

end

end(): void

poll

poll(): GpuSample | null

The oldest finished sample, or null. Never blocks and never waits for a result: a diagnostic that stalls the pipeline to measure it is measuring itself.

lastFrameMs

lastFrameMs(): number | null

The whole of the last resolved frame, in milliseconds, or null where nothing measured.

More

The three brackets are summed because they partition the frame rather than overlapping: shadows and reflection are the passes drawn before the scene, rest is everything after. A caller wanting the breakdown reads poll, which is what the frame meter does.

dispose

dispose(): void