Files
gods-eye-view/src/render/contract/quality.d.ts
T
Sameh Khamis 8db995acfc Define the renderer contract, with a stub renderer and a conformance suite
The renderer contract is what the application asks of a 3D renderer. It is nine ports
(frame, globe, draw, camera, query, input, effects, credits, quality) plus
the renderer itself, one strict .d.ts per port in src/render/contract/.
PORTS lists every member at run time, and a TypeScript-compiler test fails
when the list and the types disagree on one member. An optional member
exists only with its capability; a required one answers null or empty
without it. Nothing in the application uses the contract yet.

The stub renderer (src/render/stub/) implements every port in memory and
draws nothing. Its camera is a port of the default camera's maths: views,
lookAt, flights with their height arc and easing, rectangle framing on the
geodesic midpoint, the view rectangle with its horizon and pole cases,
changed thresholds, follows, and flights that finish inside the call.

The conformance suite (src/render/conformance/) runs 59 checks against
a renderer through the contract alone, in Node or in a browser page. The
camera checks compare traces recorded from Cesium's own Camera, headless on
a virtual clock (scripts/record-camera-goldens.mjs), to 1 mm, 1e-9 and
1e-3 px. The other checks cover listener rules on every subscription, the
frame loop, draw sets, picks, motion clocks, heights, leases, imagery,
styles, credits and quality knobs. The stub passes all of them but the
model check, which needs a glTF asset.

Reference scenes draw one scene per primitive family, a city and a
calibration path from orbit to the street, from contract calls only and
with no network. /dev/conformance/ draws them on the Cesium scene renderer
(src/render/cesium/sceneRenderer.js), records references through a
dev-server-only, loopback-only endpoint, and compares captures with
pixelmatch's antialias detection plus a solid-pixel count. Measured on
Cesium: every MSAA setting passes, and a dropped 4 px point, a dropped 2 px
line and a 1 px shift of the view fail. visual.js states the limits.

The package exports ./render/contract, ./render/stub and
./render/conformance. Documented in docs/RENDERER-CONTRACT.md,
docs/CODE-BOUNDARIES.md and docs/CURRENT-STATE.md.
2026-11-04 14:21:48 -08:00

117 lines
3.4 KiB
TypeScript

/**
* Adaptive quality. A governor above the contract decides a level; each
* renderer reports its frame signals, lists the settings it supports and
* applies them. Nothing here is engine-specific.
*/
import type { Off } from './common';
export interface QualitySettings {
/** Absolute device pixel ratio for the scene; 0 = browser recommended. */
pixelRatio: number;
/** Pixel ratio of screen-space overlays. */
overlayPixelRatio: number;
msaa: 0 | 2 | 4 | 8;
/** 0..1: 3D tile detail (screen-space error, both directions). */
tiles3dDetail: number;
terrainDetail: number;
imageryDetail: number;
tilesCacheBytes: number;
clouds: 'off' | 'low' | 'medium' | 'high' | 'ultra';
shadows: boolean;
water: 'off' | 'low' | 'high';
atmosphere: 'off' | 'low' | 'high';
milkyWay: 'low' | 'high';
/** 0..1 density of particle fields (wind, weather). */
particles: number;
models: { maxInstances: number; maxDistance: number };
postFx: { bloom: boolean; sharpen: boolean; style: 'low' | 'high' };
/** Frame rate of animated styles. */
animatedStyleFps: number;
/** Updates per second of a screen modulation sweep. */
sonarCadenceHz: number;
targetFps: number;
}
export type QualityKey = keyof QualitySettings;
export interface KnobDescriptor {
key: QualityKey;
kind: 'number' | 'boolean' | 'enum' | 'object';
min?: number;
max?: number;
options?: readonly string[] | readonly number[];
default: unknown;
/** Relative cost, 0 (free) to 1 (the heaviest knob). */
cost: number;
/** Changing it recreates the drawing context. */
recreates?: boolean;
/** What else changing it affects (lower tile detail lowers height accuracy). */
couples?: string[];
}
export interface FrameSignals {
cpuMs: number;
/** `gpuTiming`. */
gpuMs?: number;
passes?: Record<string, number>;
drawCalls?: number;
commands?: number;
tilesInFlight?: number;
memory?: { gpuBytes?: number; tilesBytes?: number };
pixelRatio: number;
width: number;
height: number;
mode: 'demand' | 'continuous';
/** This frame was asked for (not continuous). */
requested: boolean;
holds: string[];
/** Spread of present intervals over the last second, ms. */
presentJitterMs?: number;
}
export interface DeviceFacts {
backend: 'webgl1' | 'webgl2' | 'webgpu';
gpuVendor?: string;
gpuRenderer?: string;
maxTextureSize: number;
msaaSamples: number[];
gpuTimer: boolean;
}
export interface ProbeResult {
device: DeviceFacts;
browser: {
devicePixelRatio: number;
screen: { width: number; height: number };
hardwareConcurrency?: number;
deviceMemory?: number;
touchOnly: boolean;
};
knobs: KnobDescriptor[];
}
export interface BenchResult {
frames: number;
cpuMs: { median: number; p95: number };
gpuMs?: { median: number; p95: number };
}
export interface QualityPort {
/** The settings this renderer supports, with ranges, defaults and costs. */
knobs(): KnobDescriptor[];
get(): Partial<QualitySettings>;
/** Applied at the next frame; returns the keys it ignored as unsupported. */
set(settings: Partial<QualitySettings>): QualityKey[];
device(): DeviceFacts;
probe(): ProbeResult;
readonly signals: {
readonly gpuTiming: 'none' | 'frame' | 'perPass';
on(event: 'frame', cb: (signals: FrameSignals) => void): Off;
};
/** `benchmark`: the renderer's own; the governor has a default. */
benchmark?(options: {
durationMs: number;
scene?: 'standard';
}): Promise<BenchResult>;
}