@actis/core 26.3.0 → 26.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -2
- package/dist/index.cjs +1691 -208
- package/dist/index.d.cts +516 -56
- package/dist/index.d.mts +516 -56
- package/dist/index.mjs +1681 -209
- package/dist/worker-entry.mjs +12701 -0
- package/package.json +5 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,84 +1,279 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
1
|
+
import { AttachmentOptions, BufferInfo, FramebufferInfo, ProgramInfo } from "twgl.js";
|
|
2
|
+
|
|
3
|
+
//#region src/types/gl.d.ts
|
|
4
|
+
type GL = WebGLRenderingContext | WebGL2RenderingContext;
|
|
5
|
+
type GLContextCapabilities = Readonly<{
|
|
6
|
+
isWebGL2: boolean;
|
|
7
|
+
supportsFloatColorBuffer: boolean;
|
|
8
|
+
supportsFloatTexture: boolean;
|
|
9
|
+
supportsFloatTextureLinear: boolean;
|
|
10
|
+
}>;
|
|
12
11
|
//#endregion
|
|
13
|
-
//#region src/types/
|
|
14
|
-
type
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
type UniformType = '1f' | '1i' | '2fv' | '3fv' | '4fv';
|
|
12
|
+
//#region src/types/context.d.ts
|
|
13
|
+
type GLContextVersion = 1 | 2;
|
|
14
|
+
type RendererContext = Readonly<{
|
|
15
|
+
capabilities: GLContextCapabilities;
|
|
16
|
+
webglVersion: GLContextVersion;
|
|
17
|
+
}>;
|
|
22
18
|
//#endregion
|
|
23
19
|
//#region src/shader/Shader.d.ts
|
|
24
20
|
/**
|
|
25
|
-
* Compiles and manages a WebGL shader program.
|
|
21
|
+
* Compiles and manages a WebGL shader program using twgl.js.
|
|
26
22
|
* Responsible for compiling, linking, and providing access to uniforms and attributes.
|
|
27
23
|
*/
|
|
28
24
|
declare class Shader {
|
|
29
25
|
private gl;
|
|
30
|
-
private
|
|
31
|
-
|
|
26
|
+
private readonly capabilities;
|
|
27
|
+
programInfo: ProgramInfo;
|
|
32
28
|
private onError;
|
|
33
|
-
|
|
34
|
-
constructor(gl:
|
|
35
|
-
private compileShader;
|
|
29
|
+
readonly passName: string;
|
|
30
|
+
constructor(gl: GL, capabilities: GLContextCapabilities, vertexSource: string | undefined, fragmentSource: string, onError: (details: ShaderError) => void, passName: string);
|
|
36
31
|
private extractErrorCoords;
|
|
37
|
-
private linkProgram;
|
|
38
32
|
use(): void;
|
|
39
|
-
|
|
33
|
+
setUniforms(uniforms: ShaderUniformMap): void;
|
|
40
34
|
getAttribLocation(name: string): number;
|
|
41
35
|
private defaultVertexShader;
|
|
42
36
|
}
|
|
43
37
|
//#endregion
|
|
38
|
+
//#region src/types/texture.d.ts
|
|
39
|
+
type TextureWrapMode = number | 'clamp-to-edge' | 'repeat' | 'mirrored-repeat';
|
|
40
|
+
type TextureFilterMode = number | 'nearest' | 'linear' | 'nearest-mipmap-nearest' | 'linear-mipmap-nearest' | 'nearest-mipmap-linear' | 'linear-mipmap-linear';
|
|
41
|
+
type TextureOptions = Omit<AttachmentOptions, 'auto' | 'mag' | 'min' | 'minMag' | 'wrap' | 'wrapS' | 'wrapT'> & {
|
|
42
|
+
auto?: boolean;
|
|
43
|
+
generateMipmaps?: boolean;
|
|
44
|
+
mag?: TextureFilterMode;
|
|
45
|
+
magFilter?: TextureFilterMode;
|
|
46
|
+
min?: TextureFilterMode;
|
|
47
|
+
minFilter?: TextureFilterMode;
|
|
48
|
+
minMag?: TextureFilterMode;
|
|
49
|
+
wrap?: TextureWrapMode;
|
|
50
|
+
wrapS?: TextureWrapMode;
|
|
51
|
+
wrapT?: TextureWrapMode;
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/texture/TextureParameters.d.ts
|
|
55
|
+
type TextureFramebufferAttachmentOptions = AttachmentOptions;
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/texture/Texture.d.ts
|
|
58
|
+
/**
|
|
59
|
+
* Minimal named wrapper around a WebGL texture handle.
|
|
60
|
+
* Used internally for pass outputs and texture bindings.
|
|
61
|
+
*/
|
|
62
|
+
declare class Texture {
|
|
63
|
+
readonly name: string;
|
|
64
|
+
private capabilities?;
|
|
65
|
+
private readonly options;
|
|
66
|
+
private handleValue;
|
|
67
|
+
constructor(name: string, options?: TextureOptions, handle?: WebGLTexture, capabilities?: GLContextCapabilities);
|
|
68
|
+
get handle(): WebGLTexture | undefined;
|
|
69
|
+
applyParameters(gl: GL): void;
|
|
70
|
+
generateMipmap(gl: GL, width: number, height: number): boolean;
|
|
71
|
+
getFramebufferAttachmentOptions(gl: GL): TextureFramebufferAttachmentOptions;
|
|
72
|
+
setHandle(handle?: WebGLTexture): this;
|
|
73
|
+
private getCapabilities;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/fbo/FBO.d.ts
|
|
77
|
+
/**
|
|
78
|
+
* Wrapper around a WebGL framebuffer and its color attachment texture.
|
|
79
|
+
*/
|
|
80
|
+
declare class FBO {
|
|
81
|
+
private gl;
|
|
82
|
+
private readonly capabilities;
|
|
83
|
+
private framebufferInfo;
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
readonly texture: Texture;
|
|
87
|
+
constructor(gl: GL, capabilities: GLContextCapabilities, width: number, height: number, texture: Texture);
|
|
88
|
+
private create;
|
|
89
|
+
get info(): FramebufferInfo;
|
|
90
|
+
bind(): void;
|
|
91
|
+
resize(width: number, height: number): void;
|
|
92
|
+
clear(framebufferInfo?: FramebufferInfo): void;
|
|
93
|
+
private getAttachmentOptions;
|
|
94
|
+
private ensureAttachmentSupport;
|
|
95
|
+
private assertFramebufferComplete;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
44
98
|
//#region src/pass/Pass.d.ts
|
|
45
99
|
/**
|
|
46
100
|
* Represents a render pass in the WebGL pipeline.
|
|
47
|
-
* Responsible for managing framebuffer, texture, and draw calls for a single pass.
|
|
48
101
|
*/
|
|
49
102
|
declare class Pass {
|
|
50
|
-
gl:
|
|
103
|
+
gl: GL;
|
|
51
104
|
shader: Shader;
|
|
52
105
|
width: number;
|
|
53
106
|
height: number;
|
|
54
|
-
texture: WebGLTexture;
|
|
55
|
-
framebuffer: WebGLFramebuffer;
|
|
56
|
-
next: Pass | null;
|
|
57
107
|
offscreen: boolean;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
108
|
+
pingPong: boolean;
|
|
109
|
+
textures: Array<Texture | undefined>;
|
|
110
|
+
bufferInfo: BufferInfo;
|
|
111
|
+
private fbos;
|
|
112
|
+
private readBufferIndex;
|
|
113
|
+
constructor(gl: GL, capabilities: GLContextCapabilities, shader: Shader, geometry: BufferInfo, width: number, height: number, offscreen?: boolean, textures?: Array<Texture | undefined>, pingPong?: boolean, textureOptions?: TextureOptions);
|
|
114
|
+
get fbo(): FBO | null;
|
|
115
|
+
get texture(): Texture | undefined;
|
|
62
116
|
use(): void;
|
|
63
117
|
resize(width: number, height: number): void;
|
|
64
118
|
draw(): void;
|
|
65
|
-
|
|
66
|
-
private
|
|
67
|
-
private
|
|
119
|
+
clear(): void;
|
|
120
|
+
private get readFBO();
|
|
121
|
+
private get writeFBO();
|
|
122
|
+
private swap;
|
|
68
123
|
}
|
|
69
124
|
//#endregion
|
|
70
|
-
//#region src/
|
|
125
|
+
//#region src/types/renderer.d.ts
|
|
126
|
+
declare const TEXTURE_CHANNEL_COUNT = 4;
|
|
127
|
+
type PassConfig = {
|
|
128
|
+
name: string;
|
|
129
|
+
fragmentShader: string;
|
|
130
|
+
texture?: TextureOptions;
|
|
131
|
+
vertexShader?: string;
|
|
132
|
+
pingPong?: boolean;
|
|
133
|
+
textures: string[];
|
|
134
|
+
};
|
|
135
|
+
type RendererConfig = {
|
|
136
|
+
passes: PassConfig[];
|
|
137
|
+
};
|
|
138
|
+
type RendererMetrics = {
|
|
139
|
+
paused: boolean;
|
|
140
|
+
time: number;
|
|
141
|
+
frameRate: number;
|
|
142
|
+
width: number;
|
|
143
|
+
height: number;
|
|
144
|
+
};
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/types/pipeline.d.ts
|
|
147
|
+
type PipelineEntry = {
|
|
148
|
+
dependencies: string[];
|
|
149
|
+
name: string;
|
|
150
|
+
pass: Pass;
|
|
151
|
+
};
|
|
152
|
+
type PipelineRegistry = {
|
|
153
|
+
add: (entry: PipelineEntry) => void;
|
|
154
|
+
clear: () => void;
|
|
155
|
+
get: (name: string) => PipelineEntry | undefined;
|
|
156
|
+
getAll: () => PipelineEntry[];
|
|
157
|
+
has: (name: string) => boolean;
|
|
158
|
+
};
|
|
159
|
+
type PipelineSorter = {
|
|
160
|
+
sort: (registry: PipelineRegistry) => Pass[];
|
|
161
|
+
};
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/types/shader.d.ts
|
|
164
|
+
type ShaderError = {
|
|
165
|
+
passName: string;
|
|
166
|
+
coords: {
|
|
167
|
+
line: number;
|
|
168
|
+
message: string;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/types/uniform.d.ts
|
|
173
|
+
type ShaderUniformMap = Record<string, unknown>;
|
|
174
|
+
type UniformContextTarget = 'pass' | 'present';
|
|
175
|
+
type UniformContext = Readonly<{
|
|
176
|
+
date: readonly [number, number, number, number];
|
|
177
|
+
frame: number;
|
|
178
|
+
frameRate: number;
|
|
179
|
+
mouse: readonly [number, number];
|
|
180
|
+
passName: string;
|
|
181
|
+
resolution: readonly [number, number];
|
|
182
|
+
target: UniformContextTarget;
|
|
183
|
+
textures: readonly (Texture | undefined)[];
|
|
184
|
+
time: number;
|
|
185
|
+
timeDelta: number;
|
|
186
|
+
}>;
|
|
187
|
+
type UniformProvider = Readonly<{
|
|
188
|
+
id: string;
|
|
189
|
+
resolve: (context: UniformContext) => ShaderUniformMap | undefined;
|
|
190
|
+
}>;
|
|
71
191
|
/**
|
|
72
|
-
*
|
|
192
|
+
* Serializable uniform provider: static values resolved every frame without
|
|
193
|
+
* a function call. The only provider form that can cross into a worker.
|
|
194
|
+
* Values must be structured-cloneable (numbers, arrays, plain objects).
|
|
73
195
|
*/
|
|
74
|
-
|
|
196
|
+
type StaticUniformProvider = Readonly<{
|
|
197
|
+
id: string;
|
|
198
|
+
values: ShaderUniformMap;
|
|
199
|
+
}>;
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/engine/FrameDriver.d.ts
|
|
202
|
+
/**
|
|
203
|
+
* One-shot frame scheduler abstraction.
|
|
204
|
+
*
|
|
205
|
+
* The main thread drives frames with `requestAnimationFrame`, which does not
|
|
206
|
+
* exist inside workers. Decoupling the render loop from rAF lets the same
|
|
207
|
+
* renderer core run on either host with an appropriate driver.
|
|
208
|
+
*/
|
|
209
|
+
type FrameCallback = (time: number) => void;
|
|
210
|
+
type FrameDriver = {
|
|
211
|
+
request: (callback: FrameCallback) => void;
|
|
212
|
+
cancel: () => void;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Main-thread driver backed by `requestAnimationFrame`. Safe to construct
|
|
216
|
+
* during SSR or in workers: scheduling becomes a no-op when rAF is missing.
|
|
217
|
+
*/
|
|
218
|
+
declare function rafFrameDriver(): FrameDriver;
|
|
219
|
+
/**
|
|
220
|
+
* Host-agnostic driver backed by a timer. Used inside workers, where
|
|
221
|
+
* `requestAnimationFrame` is unavailable.
|
|
222
|
+
*/
|
|
223
|
+
declare function timerFrameDriver(intervalMs?: number): FrameDriver;
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/engine/RendererCore.d.ts
|
|
226
|
+
/** Canvas surface the core can render into on any host (main thread or worker). */
|
|
227
|
+
type RenderSurface = HTMLCanvasElement | OffscreenCanvas;
|
|
228
|
+
/** Downscaled raw pixels captured from a pass output (bottom-up row order). */
|
|
229
|
+
type PassPixelData = {
|
|
230
|
+
data: Uint8Array;
|
|
231
|
+
width: number;
|
|
232
|
+
height: number;
|
|
233
|
+
};
|
|
234
|
+
type RendererCoreOptions = {
|
|
235
|
+
canvas: RenderSurface;
|
|
236
|
+
onError?: (details: {
|
|
237
|
+
passName: string;
|
|
238
|
+
coords: {
|
|
239
|
+
line: number;
|
|
240
|
+
message: string;
|
|
241
|
+
};
|
|
242
|
+
}) => void; /** Device pixels per CSS pixel. Defaults to 1; the DOM shell syncs it from `devicePixelRatio`. */
|
|
243
|
+
pixelRatio?: number; /** Frame scheduler. Defaults to a timer driver, which works on every host. */
|
|
244
|
+
frameDriver?: FrameDriver;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Host-agnostic WebGL renderer core: GL context, passes, uniforms, loop.
|
|
248
|
+
*
|
|
249
|
+
* Deliberately free of DOM APIs (`window`, `document`, listeners, rAF) so it
|
|
250
|
+
* can run inside a worker against an `OffscreenCanvas`. Hosts own the
|
|
251
|
+
* surrounding concerns and feed the core explicitly:
|
|
252
|
+
* - viewport size via {@link setDisplaySize}
|
|
253
|
+
* - pointer position via {@link setPointer} (device pixels, Y-up)
|
|
254
|
+
* - frame scheduling via the injected {@link FrameDriver}
|
|
255
|
+
*/
|
|
256
|
+
declare class RendererCore {
|
|
257
|
+
private static readonly presentFragmentShader;
|
|
75
258
|
private gl;
|
|
76
|
-
private
|
|
259
|
+
private readonly capabilities;
|
|
260
|
+
private pipeline;
|
|
77
261
|
private canvas;
|
|
78
|
-
private
|
|
262
|
+
private readonly frameDriver;
|
|
263
|
+
private frameScheduled;
|
|
264
|
+
private passConfigs;
|
|
79
265
|
private textureMap;
|
|
80
266
|
private now;
|
|
81
267
|
private onError;
|
|
268
|
+
private readonly compiler;
|
|
269
|
+
private readonly presentShader;
|
|
270
|
+
private readonly screenTriangle;
|
|
271
|
+
private readonly uniformManager;
|
|
272
|
+
private thumbnailScratchFramebuffer;
|
|
273
|
+
private thumbnailScratchTexture;
|
|
274
|
+
private thumbnailScratchWidth;
|
|
275
|
+
private thumbnailScratchHeight;
|
|
276
|
+
private readonly boundRender;
|
|
82
277
|
mouseX: number;
|
|
83
278
|
mouseY: number;
|
|
84
279
|
time: number;
|
|
@@ -91,27 +286,292 @@ declare class WebGLRenderer {
|
|
|
91
286
|
currentFrame: number;
|
|
92
287
|
currentTime: number;
|
|
93
288
|
startTime: number;
|
|
94
|
-
|
|
289
|
+
private pausedAt;
|
|
290
|
+
constructor(options: RendererCoreOptions);
|
|
291
|
+
private initializeWebGLContext;
|
|
292
|
+
/**
|
|
293
|
+
* Pointer position in device pixels, Y-up relative to the drawing buffer.
|
|
294
|
+
* Hosts compute this from DOM events; the core performs no layout reads.
|
|
295
|
+
*/
|
|
296
|
+
setPointer(x: number, y: number): void;
|
|
297
|
+
setPixelRatio(ratio: number): void;
|
|
298
|
+
/**
|
|
299
|
+
* Explicit drawing-buffer size. Replaces the implicit
|
|
300
|
+
* `clientWidth`-based resize, which `OffscreenCanvas` cannot provide.
|
|
301
|
+
*/
|
|
302
|
+
setDisplaySize(width: number, height: number): void;
|
|
303
|
+
addPass(pass: Pass): void;
|
|
304
|
+
getPass(name: string): Pass | undefined;
|
|
305
|
+
getPasses(): Pass[];
|
|
306
|
+
forEachPass(callback: (pass: Pass) => void): void;
|
|
307
|
+
getPassNames(): string[];
|
|
308
|
+
/**
|
|
309
|
+
* Capture downscaled raw pixels of a pass output. Hosts encode these for
|
|
310
|
+
* display (2D canvas on the main thread, `ImageBitmap` in a worker).
|
|
311
|
+
* Returns null when unavailable. Never throws.
|
|
312
|
+
*/
|
|
313
|
+
capturePassPixels(name: string, maxSize?: number): PassPixelData | null;
|
|
314
|
+
private capturePassViaBlit;
|
|
315
|
+
private capturePassViaFullRead;
|
|
316
|
+
private ensureThumbnailScratch;
|
|
317
|
+
private disposeThumbnailScratch;
|
|
318
|
+
getMetrics(): RendererMetrics;
|
|
319
|
+
getContextState(): RendererContext;
|
|
320
|
+
clear(): void;
|
|
321
|
+
registerUniformProvider(provider: UniformProvider | StaticUniformProvider): void;
|
|
322
|
+
unregisterUniformProvider(providerId: string): boolean;
|
|
323
|
+
private updateTime;
|
|
324
|
+
render(currentTime: number): void;
|
|
325
|
+
setup(config: RendererConfig): void;
|
|
326
|
+
play(): void;
|
|
327
|
+
resume(): void;
|
|
328
|
+
pause(): void;
|
|
329
|
+
reset(): void;
|
|
330
|
+
/**
|
|
331
|
+
* Release loop scheduling and GL scratch resources. Passes keep their GL
|
|
332
|
+
* objects; hosts owning the context decide its lifetime.
|
|
333
|
+
*/
|
|
334
|
+
dispose(): void;
|
|
335
|
+
private renderFrame;
|
|
336
|
+
private syncPassTextures;
|
|
337
|
+
private syncPassTexturesForPass;
|
|
338
|
+
private updateTextureMapForPass;
|
|
339
|
+
private presentTexture;
|
|
340
|
+
private getTextureBindings;
|
|
341
|
+
private cancelScheduledFrame;
|
|
342
|
+
private clearCanvas;
|
|
343
|
+
private resetPlaybackState;
|
|
344
|
+
}
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region src/engine/WebGLRenderer.d.ts
|
|
347
|
+
/**
|
|
348
|
+
* Main-thread `WebGLRenderer`: {@link RendererCore} plus the DOM shell —
|
|
349
|
+
* pointer/resize listeners, `requestAnimationFrame` loop, and 2D-canvas
|
|
350
|
+
* thumbnail encoding.
|
|
351
|
+
*
|
|
352
|
+
* @deprecated Prefer `createRenderer(canvas)` — worker-first with automatic
|
|
353
|
+
* main-thread fallback and the same public surface. Direct construction
|
|
354
|
+
* always renders on the main thread; use `createRenderer(canvas,
|
|
355
|
+
* { mode: 'main' })` to pin that explicitly.
|
|
356
|
+
*/
|
|
357
|
+
declare class WebGLRenderer extends RendererCore {
|
|
358
|
+
private readonly displayCanvas;
|
|
359
|
+
private thumbnailCanvas;
|
|
360
|
+
private resizeObserver;
|
|
361
|
+
private readonly handleResize;
|
|
362
|
+
private readonly handleMouseMove;
|
|
363
|
+
private readonly handleTouchStart;
|
|
364
|
+
private readonly handleTouchMove;
|
|
365
|
+
constructor(canvas: HTMLCanvasElement, onError?: (details: {
|
|
95
366
|
passName: string;
|
|
96
367
|
coords: {
|
|
97
368
|
line: number;
|
|
98
369
|
message: string;
|
|
99
370
|
};
|
|
100
371
|
}) => void);
|
|
101
|
-
private initializeWebGLContext;
|
|
102
|
-
private initMouseEvents;
|
|
103
372
|
private setMousePosition;
|
|
104
|
-
private
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
373
|
+
private syncSizeToDisplay;
|
|
374
|
+
/**
|
|
375
|
+
* Capture a downscaled data-URL thumbnail of a pass output.
|
|
376
|
+
* Cheap by design: blits to a small scratch FBO (WebGL2) so only
|
|
377
|
+
* thumbnail-sized pixels are read back. Returns null when unavailable.
|
|
378
|
+
*/
|
|
379
|
+
capturePassDataURL(name: string, maxSize?: number): string | null;
|
|
380
|
+
private thumbnailCanvasRef;
|
|
381
|
+
/** Encode bottom-up GL pixels to a data URL. Shared with worker hosts. */
|
|
382
|
+
static pixelsToDataURL(canvas: RenderSurface, pixels: Uint8Array, width: number, height: number): string | null;
|
|
383
|
+
dispose(): void;
|
|
384
|
+
}
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/pipeline/Pipeline.d.ts
|
|
387
|
+
/**
|
|
388
|
+
* Orchestrates pass storage and dependency resolution for the render graph
|
|
389
|
+
*/
|
|
390
|
+
declare class Pipeline {
|
|
391
|
+
private readonly registry;
|
|
392
|
+
private readonly sorter;
|
|
393
|
+
private orderedPasses;
|
|
394
|
+
private dirty;
|
|
395
|
+
constructor(registry?: PipelineRegistry, sorter?: PipelineSorter);
|
|
396
|
+
add(name: string, pass: Pass, dependencies?: string[]): void;
|
|
397
|
+
clear(): void;
|
|
398
|
+
resize(width: number, height: number): void;
|
|
399
|
+
forEach(callback: (pass: Pass) => void): void;
|
|
400
|
+
get(name: string): Pass | undefined;
|
|
401
|
+
toArray(): Pass[];
|
|
402
|
+
private getOrderedPasses;
|
|
403
|
+
}
|
|
404
|
+
//#endregion
|
|
405
|
+
//#region src/worker/protocol.d.ts
|
|
406
|
+
type ErrorDetails = {
|
|
407
|
+
passName: string;
|
|
408
|
+
coords: {
|
|
409
|
+
line: number;
|
|
410
|
+
message: string;
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
/** Worker -> main thread. */
|
|
414
|
+
type WorkerEvent = {
|
|
415
|
+
type: 'ready';
|
|
416
|
+
version: number;
|
|
417
|
+
} | {
|
|
418
|
+
type: 'fatal';
|
|
419
|
+
reason: string;
|
|
420
|
+
} | {
|
|
421
|
+
type: 'error';
|
|
422
|
+
details: ErrorDetails;
|
|
423
|
+
} | {
|
|
424
|
+
type: 'context';
|
|
425
|
+
capabilities: GLContextCapabilities;
|
|
426
|
+
webglVersion: GLContextVersion;
|
|
427
|
+
} | {
|
|
428
|
+
type: 'metrics';
|
|
429
|
+
metrics: RendererMetrics;
|
|
430
|
+
} | {
|
|
431
|
+
type: 'passes';
|
|
432
|
+
names: string[];
|
|
433
|
+
} | {
|
|
434
|
+
type: 'capture-result';
|
|
435
|
+
id: number;
|
|
436
|
+
name: string;
|
|
437
|
+
maxSize: number;
|
|
438
|
+
data: ArrayBuffer | null;
|
|
439
|
+
width: number;
|
|
440
|
+
height: number;
|
|
441
|
+
};
|
|
442
|
+
//#endregion
|
|
443
|
+
//#region src/worker/OffscreenWebGLRenderer.d.ts
|
|
444
|
+
/**
|
|
445
|
+
* Main-thread proxy for a worker-hosted {@link RendererCore}. Same public
|
|
446
|
+
* surface as {@link WebGLRenderer}: fire-and-forget commands cross the
|
|
447
|
+
* boundary, while synchronous reads (`getMetrics`, `getPassNames`,
|
|
448
|
+
* `capturePassDataURL`) are served from caches the worker pushes.
|
|
449
|
+
* Construct via {@link createRenderer}, never directly.
|
|
450
|
+
*/
|
|
451
|
+
declare class OffscreenWebGLRenderer {
|
|
452
|
+
readonly isOffscreenRenderer: true;
|
|
453
|
+
mouseX: number;
|
|
454
|
+
mouseY: number;
|
|
455
|
+
time: number;
|
|
456
|
+
timeDelta: number;
|
|
457
|
+
realToCSSPixels: number;
|
|
458
|
+
paused: boolean;
|
|
459
|
+
playbackTime: number;
|
|
460
|
+
lastTime: number;
|
|
461
|
+
frameRate: number;
|
|
462
|
+
currentFrame: number;
|
|
463
|
+
currentTime: number;
|
|
464
|
+
startTime: number;
|
|
465
|
+
private readonly worker;
|
|
466
|
+
private readonly displayCanvas;
|
|
467
|
+
private readonly onError;
|
|
468
|
+
private detachHost;
|
|
469
|
+
private readonly encodeCanvas;
|
|
470
|
+
private passNames;
|
|
471
|
+
private metrics;
|
|
472
|
+
private contextState;
|
|
473
|
+
private thumbnails;
|
|
474
|
+
private captureId;
|
|
475
|
+
private disposed;
|
|
476
|
+
constructor(canvas: HTMLCanvasElement, worker: Worker, options?: {
|
|
477
|
+
onError?: (details: ErrorDetails) => void;
|
|
478
|
+
detachHost?: (() => void) | null;
|
|
479
|
+
});
|
|
480
|
+
/**
|
|
481
|
+
* Take over the worker message stream. Called by the factory once the
|
|
482
|
+
* init handshake succeeds; replays the buffered first event.
|
|
483
|
+
*/
|
|
484
|
+
connect(firstEvent?: WorkerEvent): void;
|
|
485
|
+
/** Late-bind host teardown (the host needs the proxy to exist first). */
|
|
486
|
+
setDetachHost(detach: (() => void) | null): void;
|
|
487
|
+
/** The visible canvas (transferred control; the browser composites it). */
|
|
488
|
+
get canvas(): HTMLCanvasElement;
|
|
489
|
+
private post;
|
|
490
|
+
private handleEvent;
|
|
491
|
+
private applyMetrics;
|
|
492
|
+
private applyCapture;
|
|
111
493
|
setup(config: RendererConfig): void;
|
|
112
494
|
play(): void;
|
|
495
|
+
resume(): void;
|
|
113
496
|
pause(): void;
|
|
114
497
|
reset(): void;
|
|
498
|
+
clear(): void;
|
|
499
|
+
setPointer(x: number, y: number): void;
|
|
500
|
+
setPixelRatio(ratio: number): void;
|
|
501
|
+
setDisplaySize(width: number, height: number): void;
|
|
502
|
+
registerUniformProvider(provider: UniformProvider | StaticUniformProvider): void;
|
|
503
|
+
unregisterUniformProvider(providerId: string): boolean;
|
|
504
|
+
getPassNames(): string[];
|
|
505
|
+
getMetrics(): RendererMetrics;
|
|
506
|
+
getContextState(): RendererContext;
|
|
507
|
+
/**
|
|
508
|
+
* Last encoded thumbnail for a pass, or null until the worker round-trip
|
|
509
|
+
* completes. Call {@link requestPassCapture} first (e.g. on a poll
|
|
510
|
+
* interval); the following read observes the fresh frame.
|
|
511
|
+
*/
|
|
512
|
+
capturePassDataURL(name: string, maxSize?: number): string | null;
|
|
513
|
+
/** Ask the worker to capture and push a fresh thumbnail for `name`. */
|
|
514
|
+
requestPassCapture(name: string, maxSize?: number): void;
|
|
515
|
+
addPass(_pass: Pass): void;
|
|
516
|
+
getPass(_name: string): Pass | undefined;
|
|
517
|
+
getPasses(): Pass[];
|
|
518
|
+
forEachPass(_callback: (pass: Pass) => void): void;
|
|
519
|
+
dispose(): void;
|
|
520
|
+
}
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/worker/createRenderer.d.ts
|
|
523
|
+
/** Either renderer implementation. Both share the same public surface. */
|
|
524
|
+
type Renderer = WebGLRenderer | OffscreenWebGLRenderer;
|
|
525
|
+
/** Worker-first (`auto`), worker-only, or main-thread-only. */
|
|
526
|
+
type RendererMode = 'auto' | 'worker' | 'main';
|
|
527
|
+
type RendererFallbackReason = 'ssr-no-dom' | 'no-worker' | 'no-offscreen-canvas' | 'no-webgl' | 'worker-spawn-failed' | 'worker-handshake-timeout' | 'worker-version-mismatch' | 'worker-gl-unavailable' | 'worker-transferred-fatal' | 'canvas-already-bound';
|
|
528
|
+
type CreateRendererOptions = {
|
|
529
|
+
/** Default `'auto'`: worker when supported, silent main-thread fallback. */mode?: RendererMode;
|
|
530
|
+
/**
|
|
531
|
+
* Pre-constructed worker running the engine worker entry. Preferred when
|
|
532
|
+
* the host bundler owns worker bundling (e.g. Vite `?worker` imports),
|
|
533
|
+
* which guarantees a correct URL in both dev and prod builds.
|
|
534
|
+
* Takes precedence over `workerUrl`.
|
|
535
|
+
*/
|
|
536
|
+
worker?: Worker;
|
|
537
|
+
/**
|
|
538
|
+
* Worker script URL. Defaults to the sibling worker entry next to this
|
|
539
|
+
* module (`worker-entry.mjs` in dist, `worker-entry.ts` from source).
|
|
540
|
+
*/
|
|
541
|
+
workerUrl?: string; /** Notified (auto mode) whenever the worker path is abandoned. */
|
|
542
|
+
onFallback?: (reason: RendererFallbackReason) => void;
|
|
543
|
+
onError?: (details: ErrorDetails) => void; /** Handshake deadline before falling back. Default 2000ms. */
|
|
544
|
+
handshakeTimeoutMs?: number; /** Skip host wiring (resize/pointer) when the caller owns it. Default true. */
|
|
545
|
+
attachHost?: boolean;
|
|
546
|
+
};
|
|
547
|
+
declare class WorkerUnsupportedError extends Error {
|
|
548
|
+
readonly reason: RendererFallbackReason;
|
|
549
|
+
constructor(reason: RendererFallbackReason, options?: {
|
|
550
|
+
cause?: unknown;
|
|
551
|
+
});
|
|
115
552
|
}
|
|
553
|
+
/**
|
|
554
|
+
* Whether this canvas was already transferred by {@link createRenderer}.
|
|
555
|
+
* A stamped canvas can never render on the main thread again — mount a
|
|
556
|
+
* fresh element and dispose the previous renderer first.
|
|
557
|
+
*/
|
|
558
|
+
declare function isCanvasAlreadyTransferred(canvas: HTMLCanvasElement): boolean;
|
|
559
|
+
/**
|
|
560
|
+
* Create a renderer, worker-first by default.
|
|
561
|
+
*
|
|
562
|
+
* `auto` probes `Worker` -> `transferControlToOffscreen` -> WebGL ->
|
|
563
|
+
* handshake, falling back to the main-thread `WebGLRenderer` at the first
|
|
564
|
+
* failure (`onFallback` reports why). `worker` throws
|
|
565
|
+
* {@link WorkerUnsupportedError} instead of falling back; `main` always
|
|
566
|
+
* constructs {@link WebGLRenderer} directly.
|
|
567
|
+
*
|
|
568
|
+
* Note: transferring a canvas is irreversible. A GPU that works on the main
|
|
569
|
+
* thread is assumed to work in the worker; the pre-flight probe plus versioned
|
|
570
|
+
* handshake make a post-transfer failure unlikely. If the worker still dies
|
|
571
|
+
* after transfer, the canvas cannot be recovered on the main thread, so
|
|
572
|
+
* creation throws {@link WorkerUnsupportedError} (`worker-transferred-fatal`)
|
|
573
|
+
* even in `auto` mode.
|
|
574
|
+
*/
|
|
575
|
+
declare function createRenderer(canvas: HTMLCanvasElement, options?: CreateRendererOptions): Promise<Renderer>;
|
|
116
576
|
//#endregion
|
|
117
|
-
export { Pass, type PassConfig, type RendererConfig, Shader, WebGLRenderer };
|
|
577
|
+
export { type CreateRendererOptions, FBO, type FrameCallback, type FrameDriver, type GL, type GLContextVersion, OffscreenWebGLRenderer, Pass, type PassConfig, type PassPixelData, Pipeline, type RenderSurface, type Renderer, type RendererConfig, type RendererContext, RendererCore, type RendererCoreOptions, type RendererFallbackReason, type RendererMetrics, type RendererMode, Shader, type ShaderUniformMap, type StaticUniformProvider, TEXTURE_CHANNEL_COUNT, Texture, type TextureFilterMode, type TextureOptions, type TextureWrapMode, type UniformContext, type UniformContextTarget, type UniformProvider, WebGLRenderer, WorkerUnsupportedError, createRenderer, isCanvasAlreadyTransferred, rafFrameDriver, timerFrameDriver };
|