@babylonjs/lite-gl 0.1.0 → 0.2.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.
Files changed (61) hide show
  1. package/README.md +10 -34
  2. package/apply-states.d.ts +1 -0
  3. package/apply-states.js +30 -0
  4. package/apply-states.js.map +1 -0
  5. package/blend.d.ts +123 -0
  6. package/blend.js +194 -0
  7. package/blend.js.map +1 -0
  8. package/context.d.ts +130 -0
  9. package/context.js +354 -0
  10. package/context.js.map +1 -0
  11. package/depth-stencil.d.ts +155 -231
  12. package/depth-stencil.js +399 -262
  13. package/depth-stencil.js.map +1 -1
  14. package/dynamic-texture.d.ts +59 -149
  15. package/dynamic-texture.js +123 -69
  16. package/dynamic-texture.js.map +1 -1
  17. package/effect-renderer.d.ts +65 -0
  18. package/effect-renderer.js +132 -0
  19. package/effect-renderer.js.map +1 -0
  20. package/effect.d.ts +142 -0
  21. package/effect.js +465 -0
  22. package/effect.js.map +1 -0
  23. package/html-texture.d.ts +44 -143
  24. package/html-texture.js +87 -81
  25. package/html-texture.js.map +1 -1
  26. package/index.d.ts +23 -1482
  27. package/index.js +42 -263
  28. package/index.js.map +1 -1
  29. package/mesh.d.ts +210 -307
  30. package/mesh.js +436 -311
  31. package/mesh.js.map +1 -1
  32. package/package.json +5 -29
  33. package/render-loop.d.ts +8 -0
  34. package/render-loop.js +62 -0
  35. package/render-loop.js.map +1 -0
  36. package/render-target.d.ts +233 -290
  37. package/render-target.js +534 -335
  38. package/render-target.js.map +1 -1
  39. package/scissor.d.ts +30 -72
  40. package/scissor.js +47 -33
  41. package/scissor.js.map +1 -1
  42. package/shader.d.ts +22 -0
  43. package/shader.js +65 -0
  44. package/shader.js.map +1 -0
  45. package/sprites.d.ts +182 -263
  46. package/sprites.js +426 -10
  47. package/sprites.js.map +1 -1
  48. package/state.d.ts +126 -0
  49. package/state.js +153 -0
  50. package/state.js.map +1 -0
  51. package/texture.d.ts +142 -0
  52. package/texture.js +433 -0
  53. package/texture.js.map +1 -0
  54. package/effect-BxxwfB_O.js +0 -737
  55. package/effect-BxxwfB_O.js.map +0 -1
  56. package/sprites--1oyVtJ3.js +0 -437
  57. package/sprites--1oyVtJ3.js.map +0 -1
  58. package/state--j_ncWIi.js +0 -155
  59. package/state--j_ncWIi.js.map +0 -1
  60. package/texture-DaMd1gGm.js +0 -329
  61. package/texture-DaMd1gGm.js.map +0 -1
package/index.d.ts CHANGED
@@ -1,1482 +1,23 @@
1
- /** Make `wrapper.effect` current and ensure the shared fullscreen quad VAO
2
- * is bound. This MUST be called BEFORE any `setEffect*` call for the same
3
- * effect in the current frame (uniform setters write to the currently bound
4
- * program). */
5
- export declare function applyEffectWrapper(wrapper: GLEffectWrapper): void;
6
-
7
- /**
8
- * Configure vertex attributes from `vb`, reproducing Babylon's
9
- * `bindInstancesBuffer` exactly. For each descriptor: resolves the location
10
- * (explicit `index` or via the effect), enables the attribute array, issues
11
- * `vertexAttribPointer`, and sets the vertex divisor (`undefined → 1`). Every
12
- * touched location is tracked so {@link unbindInstanceAttributes} can reset its
13
- * divisor afterwards.
14
- *
15
- * `computeStride` controls the GL stride passed to `vertexAttribPointer`:
16
- * - `false` (default) → stride `0`: each attribute is independently tightly
17
- * packed. Combined with overlapping `offset`s this yields the "sliding window"
18
- * ShapeBuilder uses for distance-field tape buffers.
19
- * - `true` → stride = Σ(`size`·4 bytes): interleaved per-vertex/per-instance.
20
- *
21
- * Runs on the default (null) VAO — never corrupts the quad / sprite VAOs.
22
- * No-op on a lost/disposed context or before the effect is ready.
23
- *
24
- * @param engine - The engine.
25
- * @param vb - The buffer supplying the attribute data.
26
- * @param descriptors - The attribute layout.
27
- * @param effect - The effect whose attribute locations resolve unnamed indices.
28
- * @param computeStride - See above. Default `false`.
29
- */
30
- export declare function bindAttributes(engine: GLEngineContext, vb: GLVertexBuffer, descriptors: readonly GLAttributeDescriptor[], effect: GLEffect, computeStride?: boolean): void;
31
-
32
- /**
33
- * Bind an index buffer as the current element-array buffer (on the default
34
- * VAO). Cached. The lite-gl equivalent of Babylon's `_bindIndexBufferWithCache`.
35
- *
36
- * @param engine - The engine.
37
- * @param ib - The index buffer to bind.
38
- */
39
- export declare function bindIndexBuffer(engine: GLEngineContext, ib: GLIndexBuffer): void;
40
-
41
- /**
42
- * Bind a {@link GLMeshVao} (cached `gl.bindVertexArray`). Rarely called directly —
43
- * {@link drawMesh} binds it for you. Binding restores the VAO's recorded element
44
- * binding, so the element-buffer cache is updated in lock-step.
45
- *
46
- * @param engine - The engine.
47
- * @param vao - The mesh VAO to bind.
48
- */
49
- export declare function bindMeshVao(engine: GLEngineContext, vao: GLMeshVao): void;
50
-
51
- /**
52
- * Bind the render target's framebuffer as the draw target and set the viewport
53
- * to cover it. `rt = null` binds the default (canvas) framebuffer and resets the
54
- * viewport to the full canvas — the counterpart of Babylon's
55
- * `restoreDefaultFramebuffer`. Subsequent `drawEffect` / `drawIndexed` /
56
- * `clearEngine` calls write into the bound target.
57
- *
58
- * Cached. No-op on a lost/disposed context or a disposed `rt`. Mipmaps are NOT
59
- * regenerated here — refresh a target's mip chain explicitly via
60
- * {@link generateRenderTargetMipMaps} after rendering into it.
61
- *
62
- * @param engine - The engine.
63
- * @param rt - The render target to draw into, or `null` for the canvas.
64
- */
65
- export declare function bindRenderTarget(engine: GLEngineContext, rt: GLRenderTarget | null): void;
66
-
67
- /** Cached bind. Skips `gl.activeTexture` and/or `gl.bindTexture` when nothing
68
- * changes. No-op when `tex._disposed` or `engine._isLost`. */
69
- export declare function bindTexture(engine: GLEngineContext, unit: number, tex: GLTexture | null): void;
70
-
71
- /** Forget the source a dynamic texture retained for context-restore replay.
72
- * The current GPU pixels are kept (no re-upload), but the source reference is
73
- * dropped so it can be garbage-collected — and a subsequent
74
- * `webglcontextrestored` will re-blank the texture instead of replaying. Use
75
- * after the final {@link updateDynamicTexture} once the source (e.g. a large
76
- * atlas canvas) is no longer needed. No-op on a non-dynamic texture. */
77
- export declare function clearDynamicTextureSource(tex: GLTexture): void;
78
-
79
- /**
80
- * Clear the currently-bound framebuffer's color / depth / stencil buffers — the
81
- * lite-gl equivalent of Babylon's `clear(color, backBuffer, depth, stencil)`.
82
- * Depth/stencil clears respect the current write masks (set them first via
83
- * {@link setDepthState} / {@link setStencilState}). No-op when nothing is
84
- * requested or the context is lost/disposed.
85
- *
86
- * @param engine - The engine.
87
- * @param options - Which buffers to clear (and the color value).
88
- */
89
- export declare function clearEngine(engine: GLEngineContext, options: GLClearOptions): void;
90
-
91
- /** Create a texture backed by an empty (blank) `width × height` RGBA8
92
- * allocation, whose pixels are pushed on demand with
93
- * {@link updateDynamicTexture} — the WebGL counterpart of Babylon's
94
- * `ThinEngine.createDynamicTexture` + `ThinTexture` wrapper.
95
- *
96
- * The texture is immediately sampleable (reads as transparent black until the
97
- * first update). It is context-restore-safe: the most recent source pushed via
98
- * {@link updateDynamicTexture} is replayed into the fresh handle on
99
- * `webglcontextrestored` (and re-blanked if no update happened yet).
100
- *
101
- * `options.invertY` is ignored here (the blank allocation is flip-invariant);
102
- * per-update flip is controlled by {@link updateDynamicTexture}'s `invertY`.
103
- *
104
- * @param engine - The engine to create GL resources on.
105
- * @param width - Texture width in texels (clamped to ≥ 1).
106
- * @param height - Texture height in texels (clamped to ≥ 1).
107
- * @param options - Optional sampling/wrap config (see {@link GLTextureOptions})
108
- * plus this factory's own `generateMipMaps` flag (mipmaps are built after an
109
- * update when a source is present; defaults to `false`).
110
- * @returns The new {@link GLTexture}. */
111
- export declare function createDynamicTexture(engine: GLEngineContext, width: number, height: number, options?: GLTextureOptions & {
112
- generateMipMaps?: boolean;
113
- }): GLTexture;
114
-
115
- /** Compile + link a new effect. Does NOT block on link completion — `isReady`
116
- * starts false; consumers poll `isEffectReady` (typically from their render
117
- * callback) to drive finalization. */
118
- export declare function createEffect(engine: GLEngineContext, options: GLEffectOptions): GLEffect;
119
-
120
- /** Compile a fullscreen effect from shader source and wrap it; the wrapper OWNS
121
- * the resulting `GLEffect`. Mirrors lite's `createEffectWrapper(engine, options)`.
122
- * When `vertexSource` is omitted, a built-in fullscreen-quad vertex shader is
123
- * used, so callers can supply only `fragmentSource`. */
124
- export declare function createEffectWrapper(engine: GLEngineContext, options: GLEffectWrapperOptions): GLEffectWrapper;
125
-
126
- /**
127
- * Create an offscreen **float / half-float** render target — the HDR opt-in
128
- * counterpart of {@link createRenderTarget}. This is the only render-target
129
- * factory that references the `RGBA16F` / `RGBA32F` sized-format table, so RGBA8
130
- * consumers ship none of it.
131
- *
132
- * Defaults to `gl.HALF_FLOAT`; pass `options.type = gl.FLOAT` for full 32-bit.
133
- * The requested type is downgraded to the best renderable type the engine
134
- * supports (mirroring Babylon's `getTextureType`).
135
- *
136
- * @param engine - The engine to allocate GL resources on.
137
- * @param options - See {@link GLFloatRenderTargetOptions}.
138
- * @returns The new {@link GLRenderTarget}.
139
- * @throws As {@link createRenderTarget}.
140
- */
141
- export declare function createFloatRenderTarget(engine: GLEngineContext, options: GLFloatRenderTargetOptions): GLRenderTarget;
142
-
143
- /**
144
- * Create a float / half-float raw texture — the HDR counterpart of
145
- * {@link createRawTexture}. This is the ONLY texture factory that carries the
146
- * `RGBA16F` / `RGBA32F` sized-format knowledge (via {@link pickSizedInternalFormat}),
147
- * so byte-only consumers calling {@link createRawTexture} ship none of it.
148
- * Defaults to `gl.HALF_FLOAT`; pass `options.type = gl.FLOAT` for full 32-bit.
149
- * The caller is responsible for the matching engine cap (e.g.
150
- * `caps.textureFloatLinearFiltering`) when sampling these with `LINEAR`.
151
- *
152
- * @param engine - The engine.
153
- * @param data - Initial pixels (`Float32Array` for FLOAT, `Uint16Array` for
154
- * HALF_FLOAT), or `null` for an uninitialised allocation.
155
- * @param width - Texture width in texels (≥ 1).
156
- * @param height - Texture height in texels (≥ 1).
157
- * @param options - See {@link GLFloatTextureOptions}.
158
- * @returns The new {@link GLTexture}.
159
- */
160
- export declare function createFloatTexture(engine: GLEngineContext, data: ArrayBufferView | null, width: number, height: number, options?: GLFloatTextureOptions): GLTexture;
161
-
162
- /** Acquire a WebGL2 context on the canvas and build the pure-state handle.
163
- * Accepts an `HTMLCanvasElement` or an `OffscreenCanvas` (worker render paths —
164
- * e.g. the Lottie player — which size the drawing buffer via `setGLEngineSize`).
165
- * Throws if WebGL2 is unsupported. */
166
- export declare function createGLEngine(canvas: HTMLCanvasElement | OffscreenCanvas, options?: GLEngineOptions): GLEngineContext;
167
-
168
- /** Create a texture backed by an `<canvas>` / `<img>` / `<video>` element.
169
- * The initial upload is performed immediately; call `updateHtmlElementTexture`
170
- * to re-upload after the source has changed. */
171
- export declare function createHtmlElementTexture(engine: GLEngineContext, element: HTMLCanvasElement | HTMLImageElement | HTMLVideoElement, options?: GLHtmlElementTextureOptions): GLTexture;
172
-
173
- /**
174
- * Create a GPU index buffer. `Uint16Array` → 16-bit indices, `Uint32Array` →
175
- * 32-bit. Binds the default VAO first so it never corrupts the quad / sprite
176
- * VAO element bindings.
177
- *
178
- * @param engine - The engine.
179
- * @param data - The index data. Retained by reference for context-restore.
180
- * @returns The new {@link GLIndexBuffer}.
181
- */
182
- export declare function createIndexBuffer(engine: GLEngineContext, data: Uint16Array | Uint32Array): GLIndexBuffer;
183
-
184
- /**
185
- * Record a static mesh's attribute layout + index binding into a new VAO. The
186
- * effect MUST be ready (its attribute locations are resolved here, once). Returns
187
- * a {@link GLMeshVao} to draw with {@link drawMesh}.
188
- *
189
- * @param engine - The engine.
190
- * @param vertexBuffers - One or more buffers + their attribute layouts.
191
- * @param indexBuffer - The index buffer recorded into the VAO.
192
- * @param effect - The effect whose attribute locations resolve unnamed indices.
193
- * @returns The recorded {@link GLMeshVao}.
194
- */
195
- export declare function createMeshVao(engine: GLEngineContext, vertexBuffers: readonly GLMeshVertexBuffer[], indexBuffer: GLIndexBuffer, effect: GLEffect): GLMeshVao;
196
-
197
- /**
198
- * Create a {@link GLPingPong}: two same-sized {@link GLRenderTarget}s for
199
- * self-feedback effects. `read` starts as the first target and `write` the
200
- * second; {@link GLPingPong.swap} exchanges them allocation-free.
201
- *
202
- * @param engine - The engine to create GL resources on.
203
- * @param options - Applied identically to both targets.
204
- * @returns The new {@link GLPingPong}.
205
- * @throws As {@link createRenderTarget}. If the second target fails to build the
206
- * first is disposed before rethrowing (no leak).
207
- */
208
- export declare function createPingPong(engine: GLEngineContext, options: GLRenderTargetOptions): GLPingPong;
209
-
210
- /** Uint8 / float raw texture upload. The pixel data can be replaced later via
211
- * {@link updateRawTexture}; the sampling and wrap can be changed via
212
- * {@link updateTextureSamplingMode} / {@link updateTextureWrapMode}. */
213
- export declare function createRawTexture(engine: GLEngineContext, data: ArrayBufferView | null, width: number, height: number, format: GLenum, type: GLenum, options?: GLTextureOptions): GLTexture;
214
-
215
- /**
216
- * Create an offscreen **RGBA8** render target.
217
- *
218
- * The color attachment is an owned {@link GLTexture} (rebuilt by this target's
219
- * own restore hook), unless {@link GLRenderTargetOptions.colorTexture} supplies a
220
- * caller-managed (BYO) one. Mirrors Babylon's `createRenderTargetTexture`.
221
- *
222
- * @param engine - The engine to allocate GL resources on.
223
- * @param options - See {@link GLRenderTargetOptions} (`width`/`height` required).
224
- * @returns The new {@link GLRenderTarget}.
225
- * @throws If `width`/`height` are not positive integers, a GL handle could not
226
- * be allocated, or the resulting framebuffer is not complete. On failure every
227
- * partial GPU object (including an owned color texture) is released first.
228
- */
229
- export declare function createRenderTarget(engine: GLEngineContext, options: GLRenderTargetOptions): GLRenderTarget;
230
-
231
- /**
232
- * Create a sprite renderer with its own GPU buffers and compiled effect.
233
- *
234
- * Preallocates the CPU vertex scratch and the index buffer at `capacity`, so
235
- * {@link renderSprites} performs no allocations. The sprite GPU buffers are
236
- * rebuilt automatically on `webglcontextrestored` (the owned effect is rebuilt
237
- * by the engine's context-restore protocol).
238
- *
239
- * @param engine - The engine to create GL resources on.
240
- * @param options - See {@link GLSpriteRendererOptions}.
241
- * @returns The new {@link GLSpriteRenderer}.
242
- * @throws If `capacity` is not an integer in `[1, 16384]`, or if a provided
243
- * `cellWidth`/`cellHeight` is not positive.
244
- */
245
- export declare function createSpriteRenderer(engine: GLEngineContext, options: GLSpriteRendererOptions): GLSpriteRenderer;
246
-
247
- /**
248
- * Wrap an existing raw `WebGLTexture` (e.g. one created by a host renderer or a
249
- * previous engine) as a {@link GLTexture} — the lite-gl equivalent of
250
- * ShapeBuilder's `createTextureGraphicsResourceFromExternalWebGLTexture`.
251
- *
252
- * The wrapper does NOT own the underlying handle's upload — it is NOT registered
253
- * for context-restore replay (the external owner is responsible for that) and is
254
- * marked ready immediately. `disposeTexture` will still `gl.deleteTexture` it, so
255
- * only wrap a handle whose deletion you intend lite-gl to manage.
256
- *
257
- * @param engine - The engine.
258
- * @param handle - The external `WebGLTexture`.
259
- * @param width - Texture width in texels.
260
- * @param height - Texture height in texels.
261
- * @param options - Optional sampling/wrap to apply once (min/mag/wrapS/wrapT).
262
- * @returns A {@link GLTexture} wrapping the handle.
263
- */
264
- export declare function createTextureFromHandle(engine: GLEngineContext, handle: WebGLTexture, width: number, height: number, options?: GLTextureOptions): GLTexture;
265
-
266
- /**
267
- * Create a GPU vertex buffer from interleaved float data.
268
- *
269
- * @param engine - The engine.
270
- * @param data - The vertex data. Retained by reference for context-restore — do
271
- * not mutate it in place; use {@link updateVertexBuffer} to change contents.
272
- * @param dynamic - Hint that the buffer will be updated frequently
273
- * (`DYNAMIC_DRAW`). Default `false` (`STATIC_DRAW`).
274
- * @returns The new {@link GLVertexBuffer}.
275
- */
276
- export declare function createVertexBuffer(engine: GLEngineContext, data: Float32Array, dynamic?: boolean): GLVertexBuffer;
277
-
278
- /**
279
- * Disable blending — the equivalent of Babylon's `AlphaState.alphaBlend = false`.
280
- * Records the desired "blend off" state (flushed by `applyGLStates` before the
281
- * next draw); the actual `gl.disable(gl.BLEND)` is elided when blending is
282
- * already off at flush time. No-op when the context is lost or disposed.
283
- *
284
- * @param engine - The engine whose desired blend state is updated.
285
- */
286
- export declare function disableBlend(engine: GLEngineContext): void;
287
-
288
- /**
289
- * Disable the scissor test (`gl.disable(SCISSOR_TEST)`), cached. Repeated calls
290
- * after the first are elided.
291
- *
292
- * @param engine - The engine.
293
- */
294
- export declare function disableScissor(engine: GLEngineContext): void;
295
-
296
- /** Dispose a vertex or index buffer (delete the GL buffer + unregister). Clears
297
- * the array/element-buffer cache slot if it pointed at this buffer. Idempotent. */
298
- export declare function disposeBuffer(engine: GLEngineContext, buffer: GLVertexBuffer | GLIndexBuffer): void;
299
-
300
- /** Decrement the share count and, on the last release, delete the effect's
301
- * program + shaders, unregister it from the context + cache, and clear the
302
- * cached current-program if it pointed at this effect. A shared effect (still
303
- * referenced by another `createEffect` caller) is kept alive. Call exactly ONCE
304
- * per `createEffect` (each call decrements the ref count); safe (no-op) once the
305
- * effect is fully torn down. */
306
- export declare function disposeEffect(engine: GLEngineContext, effect: GLEffect): void;
307
-
308
- /** Dispose the wrapper and the effect it owns (idempotent). Mirrors lite's
309
- * `disposeEffectWrapper(wrapper)`. */
310
- export declare function disposeEffectWrapper(wrapper: GLEffectWrapper): void;
311
-
312
- /** Stops the render loop, removes DOM listeners, releases all known effects
313
- * and textures, then marks the context disposed. The browser-owned canvas
314
- * is left intact. */
315
- export declare function disposeGLEngine(engine: GLEngineContext): void;
316
-
317
- /** Dispose a {@link GLMeshVao}: delete the VAO and unregister its restore hook.
318
- * Does NOT dispose the vertex/index buffers (the caller owns those). Idempotent. */
319
- export declare function disposeMeshVao(engine: GLEngineContext, vao: GLMeshVao): void;
320
-
321
- /**
322
- * Release both targets of a {@link GLPingPong}. Idempotent, and a no-op for
323
- * `null`/`undefined` (matching {@link disposeRenderTarget}).
324
- *
325
- * @param engine - The engine that owns `pp`.
326
- * @param pp - The ping-pong pair to release, or `null`/`undefined` for a no-op.
327
- */
328
- export declare function disposePingPong(engine: GLEngineContext, pp: GLPingPong | null | undefined): void;
329
-
330
- /**
331
- * Release the render target's framebuffer, depth/stencil renderbuffer and (iff
332
- * owned) color texture, and unregister it from the engine. Idempotent, and a
333
- * no-op for `null`/`undefined` (so an optional target can be released
334
- * unconditionally). Clears the bound-framebuffer cache if it pointed at this
335
- * target, and any sampler slot that held the color texture handle.
336
- *
337
- * A BYO {@link GLRenderTargetOptions.colorTexture} is NOT disposed here — it is
338
- * engine-managed and the caller owns its lifetime.
339
- *
340
- * @param engine - The engine.
341
- * @param rt - The render target to dispose, or `null`/`undefined` for a no-op.
342
- */
343
- export declare function disposeRenderTarget(engine: GLEngineContext, rt: GLRenderTarget | null | undefined): void;
344
-
345
- /** Release the renderer's VAO/VBO/IBO and the effect it owns, and unregister
346
- * its context-restore handler. Idempotent. Does NOT dispose the texture — the
347
- * consumer that supplied it owns its lifetime. */
348
- export declare function disposeSpriteRenderer(renderer: GLSpriteRenderer): void;
349
-
350
- /** Disposes the texture. Walks `_state.boundTextures` and clears every slot
351
- * that still references the handle — otherwise a later `bindTexture(unit, B)`
352
- * to the same unit would be wrongly elided when slot still showed handle A. */
353
- export declare function disposeTexture(engine: GLEngineContext, tex: GLTexture): void;
354
-
355
- /** `gl.drawElements(TRIANGLES, 6, UNSIGNED_SHORT, 0)`. No-op when the
356
- * context is lost or there is no current program. */
357
- export declare function drawEffect(engine: GLEngineContext): void;
358
-
359
- /**
360
- * Draw indexed triangles from `ib` — the lite-gl equivalent of Babylon's
361
- * `drawElementsType` (triangle fill mode). When `instanceCount > 0` issues
362
- * `drawElementsInstanced`, otherwise `drawElements`. No-op on a lost/disposed
363
- * context or when no program is current.
364
- *
365
- * @param engine - The engine.
366
- * @param ib - The index buffer (also bound as a side-effect, cached).
367
- * @param indexCount - Number of indices to draw.
368
- * @param indexStart - First index offset (in indices, not bytes). Default 0.
369
- * @param instanceCount - Instance count for instanced draws. Default 0
370
- * (non-instanced).
371
- */
372
- export declare function drawIndexed(engine: GLEngineContext, ib: GLIndexBuffer, indexCount: number, indexStart?: number, instanceCount?: number): void;
373
-
374
- /**
375
- * Draw a static mesh recorded with {@link createMeshVao}: binds its VAO (cached),
376
- * flushes deferred GL state, and issues ONE `drawElements` (or
377
- * `drawElementsInstanced` when `instanceCount > 0`) over the VAO's full index
378
- * buffer. No per-draw attribute (re)binding. No-op on a lost/disposed context, a
379
- * disposed VAO, or when no program is current.
380
- *
381
- * @param engine - The engine.
382
- * @param vao - The mesh VAO to draw.
383
- * @param instanceCount - Instance count for instanced draws. Default 0 (non-instanced).
384
- */
385
- export declare function drawMesh(engine: GLEngineContext, vao: GLMeshVao, instanceCount?: number): void;
386
-
387
- /** Fires `cb` synchronously if the effect is already ready; otherwise queues
388
- * it for the next finalization. */
389
- export declare function executeWhenCompiled(engine: GLEngineContext, effect: GLEffect, cb: (e: GLEffect) => void): void;
390
-
391
- /** Regenerate a render target's color-attachment mip chain from its (freshly
392
- * rendered) level-0 — mipmaps for render targets are a pure manual opt-in
393
- * (call this after rendering into the target). No-op for a disposed target, a
394
- * handle-less color attachment, or a lost/disposed context. */
395
- export declare function generateRenderTargetMipMaps(engine: GLEngineContext, rt: GLRenderTarget): void;
396
-
397
- /**
398
- * Opt-in: give a `/render-target` {@link GLRenderTarget} a stencil attachment,
399
- * replacing the core's depth-only `DEPTH_COMPONENT16` renderbuffer with either a
400
- * packed **`DEPTH24_STENCIL8`** buffer (default — depth *and* stencil) or a
401
- * stencil-only **`STENCIL_INDEX8`** buffer.
402
- *
403
- * Stencil is intentionally NOT a {@link createRenderTarget} option: keeping this
404
- * helper in the `/depth-stencil` sub-entry means the stencil/packed renderbuffer
405
- * code tree-shakes out of every bundle that only needs a color (and optional
406
- * depth) target.
407
- *
408
- * The attachment is **restore-correct**: it is rebuilt automatically — at the new
409
- * size on {@link resizeRenderTarget}, and into the fresh framebuffer after a
410
- * `webglcontextrestored` event — so the stencil survives for the life of the
411
- * target, and {@link disposeRenderTarget} releases it along with the target.
412
- *
413
- * No-op on a lost/disposed context or a disposed target.
414
- *
415
- * @param engine - The engine that owns `rt`.
416
- * @param rt - The render target to attach the stencil buffer to.
417
- * @param options - `depth` (default `true`): when `true` the attachment is a
418
- * packed depth+stencil buffer (`DEPTH24_STENCIL8` on `DEPTH_STENCIL_ATTACHMENT`)
419
- * — the common case, and the correct choice when the target was created with
420
- * `generateDepthBuffer: true`. When `false` the attachment is stencil-only
421
- * (`STENCIL_INDEX8` on `STENCIL_ATTACHMENT`).
422
- * @throws If a renderbuffer handle could not be allocated or the framebuffer is
423
- * incomplete after attaching.
424
- */
425
- export declare function generateRenderTargetStencil(engine: GLEngineContext, rt: GLRenderTarget, options?: {
426
- depth?: boolean;
427
- }): void;
428
-
429
- /** Generate the mip chain for a texture from its level-0 contents — mipmaps as
430
- * an explicit opt-in function rather than baked into the create path. Binds for
431
- * upload (unit 0). No-op on a lost/disposed context or a handle-less texture. */
432
- export declare function generateTextureMipMaps(engine: GLEngineContext, tex: GLTexture): void;
433
-
434
- /** Current hardware-scaling factor — drawing-buffer = clientSize × dpr / level. */
435
- export declare function getHardwareScalingLevel(engine: GLEngineContext): number;
436
-
437
- /** Drawing-buffer height in physical pixels (`canvas.height`). */
438
- export declare function getRenderHeight(engine: GLEngineContext): number;
439
-
440
- /** The backing canvas element (an `HTMLCanvasElement`, or an `OffscreenCanvas`
441
- * for worker render paths). */
442
- export declare function getRenderingCanvas(engine: GLEngineContext): HTMLCanvasElement | OffscreenCanvas;
443
-
444
- /** Drawing-buffer width in physical pixels (`canvas.width`). */
445
- export declare function getRenderWidth(engine: GLEngineContext): number;
446
-
447
- /**
448
- * Describes one vertex attribute fed from a buffer — the lite-gl equivalent of
449
- * Babylon's `InstancingAttributeInfo`. Pass an array of these to
450
- * {@link bindAttributes}.
451
- */
452
- export declare interface GLAttributeDescriptor {
453
- /** Attribute name; resolved to a location via the effect when `index` is
454
- * omitted (`Effect.getAttributeLocationByName`). */
455
- name?: string;
456
- /** Explicit attribute location. When set, overrides the `name` lookup. */
457
- index?: number;
458
- /** Number of components, 1–4. */
459
- size: number;
460
- /** Byte offset of this attribute's first element within the buffer. Default 0. */
461
- offset?: number;
462
- /**
463
- * Per-instance vertex divisor. **Omitted/`undefined` → `1` (instanced)**,
464
- * matching Babylon's `bindInstancesBuffer`. Pass `0` explicitly for a
465
- * per-vertex attribute (e.g. the base mesh position).
466
- */
467
- divisor?: number;
468
- /** GL component type. Default `gl.FLOAT`. */
469
- type?: GLenum;
470
- /** Normalize fixed-point integer data to `[0,1]`/`[-1,1]`. Default `false`. */
471
- normalized?: boolean;
472
- }
473
-
474
- /**
475
- * Blend equation presets — the values WebGL2 accepts for
476
- * `gl.blendEquationSeparate`. Numeric values equal the GL enums so raw GL
477
- * integers (or Babylon's identical `Constants.GL_ALPHA_EQUATION_*`) pass
478
- * straight through.
479
- */
480
- export declare const GLBlendEquation: {
481
- /** `src + dst` (the GL default). */
482
- readonly ADD: 32774;
483
- /** `src - dst`. */
484
- readonly SUBTRACT: 32778;
485
- /** `dst - src`. */
486
- readonly REVERSE_SUBTRACT: 32779;
487
- /** `min(src, dst)`. */
488
- readonly MIN: 32775;
489
- /** `max(src, dst)`. */
490
- readonly MAX: 32776;
491
- };
492
-
493
- /** One of the {@link GLBlendEquation} preset values. */
494
- export declare type GLBlendEquation = (typeof GLBlendEquation)[keyof typeof GLBlendEquation];
495
-
496
- /**
497
- * Supported blend presets. Values mirror Babylon's `Constants.ALPHA_*` so the
498
- * raw Babylon integers can be passed straight through.
499
- */
500
- export declare const GLBlendMode: {
501
- /** No blending — `gl.disable(gl.BLEND)`. (`Constants.ALPHA_DISABLE`) */
502
- readonly DISABLE: 0;
503
- /** Additive — `blendFuncSeparate(SRC_ALPHA, ONE, ZERO, ONE)`. (`Constants.ALPHA_ADD`) */
504
- readonly ADD: 1;
505
- /** Standard (non-premultiplied) alpha — `blendFuncSeparate(SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ONE, ONE)`. (`Constants.ALPHA_COMBINE`) */
506
- readonly ALPHA: 2;
507
- /** Premultiplied alpha — `blendFuncSeparate(ONE, ONE_MINUS_SRC_ALPHA, ONE, ONE)`. (`Constants.ALPHA_PREMULTIPLIED`) */
508
- readonly PREMULTIPLIED: 7;
509
- };
510
-
511
- /** One of the {@link GLBlendMode} preset values (`0`, `1`, `2` or `7`). */
512
- export declare type GLBlendMode = (typeof GLBlendMode)[keyof typeof GLBlendMode];
513
-
514
- /**
515
- * Arbitrary separate-channel blend configuration — the lite-gl equivalent of
516
- * Babylon's `AlphaState.setAlphaBlendFunctionParameters` +
517
- * `setAlphaEquationParameters`. All factor / equation fields are raw WebGL2
518
- * enums (`gl.ONE`, `gl.SRC_ALPHA`, `gl.MIN`, …); use {@link GLBlendEquation} for
519
- * the equations if you prefer named presets.
520
- */
521
- export declare interface GLBlendState {
522
- /** RGB source factor (`gl.blendFuncSeparate` arg 1). */
523
- srcRGB: GLenum;
524
- /** RGB destination factor (`gl.blendFuncSeparate` arg 2). */
525
- dstRGB: GLenum;
526
- /** Alpha source factor (`gl.blendFuncSeparate` arg 3). */
527
- srcAlpha: GLenum;
528
- /** Alpha destination factor (`gl.blendFuncSeparate` arg 4). */
529
- dstAlpha: GLenum;
530
- /** RGB blend equation. Defaults to `FUNC_ADD`. */
531
- equationRGB?: GLenum;
532
- /** Alpha blend equation. Defaults to `FUNC_ADD`. */
533
- equationAlpha?: GLenum;
534
- }
535
-
536
- /** Options for {@link clearEngine}. */
537
- export declare interface GLClearOptions {
538
- /** When set, clears the color buffer to this RGBA color (alpha default 1). */
539
- color?: {
540
- r: number;
541
- g: number;
542
- b: number;
543
- a?: number;
544
- };
545
- /** Clear the depth buffer (respects the current depth write mask). */
546
- depth?: boolean;
547
- /** Clear the stencil buffer (respects the current stencil write mask). */
548
- stencil?: boolean;
549
- }
550
-
551
- /** Depth-buffer configuration for {@link setDepthState}. Omitted fields are
552
- * left unchanged. */
553
- export declare interface GLDepthState {
554
- /** Enable/disable the depth test (`gl.enable/disable(DEPTH_TEST)`). */
555
- test?: boolean;
556
- /** Enable/disable depth writes (`gl.depthMask`). */
557
- write?: boolean;
558
- /** Depth comparison function (`gl.depthFunc`), e.g. `gl.LESS`. */
559
- func?: GLenum;
560
- }
561
-
562
- /** A compiled + linked shader program with cached uniform, sampler and
563
- * attribute locations. Created by `createEffect`; most fields are managed
564
- * internally — drive it via `isEffectReady` / `useEffect` / the `setEffect*`
565
- * setters rather than mutating it directly. */
566
- export declare interface GLEffect {
567
- /** The `name` from the originating `GLEffectOptions`. */
568
- readonly name: string;
569
- /** The options this effect was created from (retained for context-restore). */
570
- readonly options: GLEffectOptions;
571
- /** The live `WebGLProgram`. Swapped for a fresh handle after context-restore. */
572
- program: WebGLProgram;
573
1
  /** Resolved during readiness finalization. Missing names map to `null` —
574
- * setters with a `null` location are silent no-ops (matches Babylon). */
575
- uniformLocations: {
576
- [name: string]: WebGLUniformLocation | null;
577
- };
578
- /** Fixed unit assignment for declared samplers, index into
579
- * `_state.boundTextures`. */
580
- samplerUnits: {
581
- [name: string]: number;
582
- };
583
2
  /** Resolved attribute locations, keyed by attribute name. */
584
- attributeLocations: {
585
- [name: string]: number;
586
- };
587
3
  /** True once the program has linked and finalization has run; the
588
- * `setEffect*` setters are no-ops until then. Poll `isEffectReady` to advance it. */
589
- isReady: boolean;
590
-
591
- /** Inputs to `createEffect`: shader sources plus the uniform, sampler and
592
- * attribute names whose locations are resolved during readiness finalization. */
593
- export declare interface GLEffectOptions {
594
- /** Human-readable label, surfaced in compile/link error messages. */
595
- name: string;
596
- /** GLSL ES 3.00 source, ready for `gl.shaderSource`. */
597
- vertexSource: string;
598
- /** GLSL ES 3.00 source, ready for `gl.shaderSource`. */
599
- fragmentSource: string;
600
- /** Declared uniform names. Locations are resolved during readiness
601
- * finalization. Names not declared here are legal but allocate cache
602
- * slots lazily on first setter use. */
603
- uniformNames: readonly string[];
604
- /** Declared sampler names, in unit-assignment order. Each gets a fixed
605
- * texture unit assigned during readiness finalization, and
606
- * `gl.uniform1i(loc, unit)` is called exactly once per program lifetime
607
- * (re-run after `webglcontextrestored`). */
608
- samplerNames: readonly string[];
609
- /** Default `["position"]`. The first attribute is bound to location 0 via
610
- * `gl.bindAttribLocation(program, 0, name)` BEFORE link, so the shared
611
- * fullscreen-quad VAO always feeds the same location. */
612
- attributeNames?: readonly string[];
613
- /** Optional `#define` block. Each unique `defines` string must be paired
614
- * with the same vertex/fragment source via a separate `createEffect` call —
615
- * the package does NOT cache compiled variants. */
616
- defines?: string;
617
- }
618
-
619
- /** A reusable fullscreen effect that compiles and OWNS its `GLEffect` — the
620
- * WebGL counterpart of lite's `EffectWrapper`. The wrapper retains the engine
621
- * it was created for, so `disposeEffectWrapper` / `applyEffectWrapper` take
622
- * only the wrapper. */
623
- export declare interface GLEffectWrapper {
624
- /** Name alias for the wrapper (and its effect). */
625
- readonly name: string;
626
- /** The compiled effect this wrapper owns. Exposed so the per-uniform
627
- * setters (`setEffectFloat`/`setEffectTexture`/…) can target it — the
628
- * WebGL divergence from lite's UBO-based `setEffectUniforms(wrapper, …)`. */
629
- readonly effect: GLEffect;
630
-
631
- /** Inputs to `createEffectWrapper`. Mirrors lite's `EffectWrapperOptions`: the
632
- * wrapper compiles and OWNS the effect built from this shader source. */
633
- export declare interface GLEffectWrapperOptions {
634
- /** Human-readable label for the wrapper and its effect. Defaults to
635
- * `"effect-wrapper"`. */
636
- name?: string;
637
- /** GLSL ES 3.00 vertex source. Defaults to a built-in fullscreen-quad
638
- * vertex shader (exposing a `vUv` varying), mirroring lite's default
639
- * `vertexWGSL`. */
640
- vertexSource?: string;
641
- /** GLSL ES 3.00 fragment source (≙ lite's `fragmentWGSL`). Required. */
642
- fragmentSource: string;
643
- /** Declared uniform names. Defaults to none. */
644
- uniformNames?: readonly string[];
645
- /** Declared sampler names, in unit-assignment order. Defaults to none. */
646
- samplerNames?: readonly string[];
647
- /** Attribute names; the first is bound to location 0. Defaults to
648
- * `["position"]`. */
649
- attributeNames?: readonly string[];
650
- /** Optional `#define` block prepended to both shader stages. */
651
- defines?: string;
652
- }
653
-
654
- /** Read-only WebGL2 capability limits, queried once at context creation. */
655
- export declare interface GLEngineCaps {
656
- /** `gl.MAX_TEXTURE_SIZE` — largest supported texture dimension, in texels. */
657
- readonly maxTextureSize: number;
658
- /** `gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS` — number of sampler binding slots. */
659
- readonly maxTextureUnits: number;
660
- /** The `KHR_parallel_shader_compile` extension used for async link polling,
661
- * or null when unsupported — linking is then treated as synchronous. */
662
- readonly parallelShaderCompile: {
663
- COMPLETION_STATUS_KHR: number;
664
- } | null;
665
- /** True when 32-bit float color attachments are renderable
666
- * (`EXT_color_buffer_float`). Mirrors Babylon's `caps.textureFloatRender`. */
667
- readonly textureFloatRender: boolean;
668
- /** True when 32-bit float textures support linear filtering
669
- * (`OES_texture_float_linear`). Mirrors `caps.textureFloatLinearFiltering`. */
670
- readonly textureFloatLinearFiltering: boolean;
671
- /** True when 16-bit half-float color attachments are renderable
672
- * (`EXT_color_buffer_float` or `EXT_color_buffer_half_float`). Mirrors
673
- * `caps.textureHalfFloatRender`. */
674
- readonly textureHalfFloatRender: boolean;
675
- /** Half-float linear filtering — always `true` in WebGL2 (it is core).
676
- * Kept as a field to mirror Babylon's `caps.textureHalfFloatLinearFiltering`. */
677
- readonly textureHalfFloatLinearFiltering: boolean;
678
- /** Whether non-power-of-two textures need POT dimensions for mips / wrap.
679
- * Always `false` in WebGL2 (NPOT is core). Mirrors `engine.needPOTTextures`. */
680
- readonly needPOTTextures: boolean;
681
- }
682
-
683
- /**
684
- * Pure-state handle for a WebGL2 canvas + its cached GL state.
685
- *
686
- * INVARIANT: consumers MUST NOT mutate GL state directly through `engine.gl`.
687
- * Doing so silently corrupts the cache in `_state`. The package owns every
688
- * GL call. (`engine.gl` is exposed only so downstream code that already has the
689
- * pattern of poking `engine._gl.getExtension(...)` can do that, but must NOT
690
- * call `bindTexture`/`useProgram`/`bindBuffer`/`viewport`/etc.)
691
- */
692
- export declare interface GLEngineContext {
693
- /** The canvas the WebGL2 context was acquired from. An `OffscreenCanvas` is
694
- * supported for worker render paths (e.g. the Lottie player); it has no CSS
695
- * box, so it must be sized explicitly via `setGLEngineSize` rather than the
696
- * CSS-derived `resizeGLEngine`. */
697
- readonly canvas: HTMLCanvasElement | OffscreenCanvas;
698
- /** The raw WebGL2 context. Do NOT mutate GL state through it — see the
699
- * type-level invariant above; the package owns every state-changing call. */
700
- readonly gl: WebGL2RenderingContext;
701
- /** Queried capability limits for this context. */
702
- readonly caps: GLEngineCaps;
703
-
704
- /** Constructor options forwarded to `canvas.getContext('webgl2', …)`. */
705
- export declare interface GLEngineOptions {
706
- /** Default: true. */
707
- alpha?: boolean;
708
- /** Default: true. */
709
- premultipliedAlpha?: boolean;
710
- /** Default: false. */
711
- antialias?: boolean;
712
- /** Default: false. */
713
- preserveDrawingBuffer?: boolean;
714
- /** Default: false — disabled for fullscreen-quad workloads. */
715
- depth?: boolean;
716
- /** Default: false. */
717
- stencil?: boolean;
718
- /** Default: "default". */
719
- powerPreference?: WebGLPowerPreference;
720
- /** Default: false. */
721
- failIfMajorPerformanceCaveat?: boolean;
722
- }
723
-
724
- /** Options for {@link createFloatRenderTarget} — {@link GLRenderTargetOptions}
725
- * plus the float color `type`. */
726
- export declare interface GLFloatRenderTargetOptions extends GLRenderTargetOptions {
727
- /** Float color attachment type. Default `gl.HALF_FLOAT`. Pass `gl.FLOAT` for
728
- * full 32-bit. Downgraded to the best renderable type the engine supports
729
- * (`caps.textureFloatRender` / `caps.textureHalfFloatRender`), mirroring
730
- * Babylon's `getTextureType`. */
731
- type?: GLenum;
732
- }
733
-
734
- /** Options for {@link createFloatTexture} — the shared {@link GLTextureOptions}
735
- * plus the float-specific `type` / `format`. */
736
- export declare interface GLFloatTextureOptions extends GLTextureOptions {
737
- /** Float texel type — `gl.HALF_FLOAT` (default) or `gl.FLOAT`. */
738
- type?: GLenum;
739
- /** Color format. Default `gl.RGBA`. */
740
- format?: GLenum;
741
- }
742
-
743
- /** Options for `createHtmlElementTexture` — the base texture options plus
744
- * HTML-source-specific settings. */
745
- export declare interface GLHtmlElementTextureOptions extends GLTextureOptions {
746
- /** High-level sampling preset. When set, derives `minFilter`/`magFilter`
747
- * (and `generateMipMaps` for `TRILINEAR`). Explicit `minFilter` /
748
- * `magFilter` / `generateMipMaps` options still take precedence. Omit for
749
- * the GL defaults (linear min + mag, no mipmaps). */
750
- samplingMode?: GLSamplingMode;
751
- /** Build a full mip chain after each upload. Independent of the core
752
- * texture options (this factory's mip behavior is sampling-mode-driven):
753
- * defaults to `true` only when `samplingMode` is `TRILINEAR`, otherwise
754
- * `false`. */
755
- generateMipMaps?: boolean;
756
- }
757
-
758
- /** A GPU index buffer. The lite-gl counterpart of Babylon's `DataBuffer` for
759
- * index data. */
760
- export declare interface GLIndexBuffer {
761
- /** The live `WebGLBuffer`. Swapped on `webglcontextrestored`. */
762
- handle: WebGLBuffer;
763
- /** Number of indices. */
764
- count: number;
765
- /** `true` for 32-bit (`Uint32Array`) indices, `false` for 16-bit. */
766
- is32Bits: boolean;
767
-
768
- /** A recorded Vertex Array Object capturing a static mesh's attribute layout +
769
- * index binding. Bind + draw it with {@link drawMesh} each frame — the GPU
770
- * replays the entire attribute setup from one `bindVertexArray`. Re-recorded
771
- * automatically on `webglcontextrestored`. */
772
- export declare interface GLMeshVao {
773
- /** The live `WebGLVertexArrayObject`. Swapped on `webglcontextrestored`. */
774
- handle: WebGLVertexArrayObject;
775
-
776
- /** One vertex buffer + its attribute layout, for {@link createMeshVao}. */
777
- export declare interface GLMeshVertexBuffer {
778
- /** The buffer supplying this group's attributes. */
779
- buffer: GLVertexBuffer;
780
- /** The attributes read from `buffer` (same shape as {@link bindAttributes}). */
781
- attributes: readonly GLAttributeDescriptor[];
782
- /** Stride mode (see {@link bindAttributes}): `false` (default) → stride `0`
783
- * per attribute; `true` → interleaved stride = Σ(`size`·4). */
784
- computeStride?: boolean;
785
- }
786
-
787
- /**
788
- * A pair of {@link GLRenderTarget}s for self-feedback effects: SAMPLE the
789
- * {@link GLPingPong.read | read} target (last frame's output) while RENDERING
790
- * into the {@link GLPingPong.write | write} target, then {@link GLPingPong.swap}.
791
- */
792
- export declare interface GLPingPong {
793
- /** The target to SAMPLE this frame (the previous frame's output). */
794
- readonly read: GLRenderTarget;
795
- /** The target to RENDER into this frame. */
796
- readonly write: GLRenderTarget;
797
- /** Exchange `read` and `write`. Call after rendering the `write` target each
798
- * frame. Allocation-free — flips an internal index, no objects created. */
799
- swap(): void;
800
-
801
- /**
802
- * An offscreen render target — a `WebGLFramebuffer` wrapping a color
803
- * {@link GLTexture} and an optional depth / stencil renderbuffer. The lite-gl
804
- * counterpart of Babylon's `RenderTargetWrapper`.
805
- */
806
- export declare interface GLRenderTarget {
807
- /** The color attachment, sampleable like any other {@link GLTexture}
808
- * (`setEffectTexture` / `bindTexture`). For an owned attachment its handle
809
- * is swapped on `webglcontextrestored` while consumers keep this same
810
- * reference. */
811
- texture: GLTexture;
812
- /** Color attachment width in texels. */
813
- width: number;
814
- /** Color attachment height in texels. */
815
- height: number;
816
- /** True once the color attachment + framebuffer are allocated. */
817
- isReady: boolean;
818
-
819
- /** Options for {@link createRenderTarget}. `width`/`height` are required; every
820
- * other field has a Babylon-matching default. The bare
821
- * `createRenderTarget(engine, { width, height })` makes an RGBA8 color-only
822
- * target with linear filtering and clamp wrapping. */
823
- export declare interface GLRenderTargetOptions {
824
- /** Color attachment width in texels. Must be a positive integer. */
825
- width: number;
826
- /** Color attachment height in texels. Must be a positive integer. */
827
- height: number;
828
- /** Allocate a depth renderbuffer (`DEPTH_COMPONENT16`). Default `false`.
829
- * Stencil is NOT a create option — opt in (packed depth+stencil, or
830
- * stencil-only) via `generateRenderTargetStencil`
831
- * (`@babylonjs/lite-gl/depth-stencil`), which keeps the stencil/packed
832
- * renderbuffer code out of the render-target core bundle. */
833
- generateDepthBuffer?: boolean;
834
- /** Color texture minification filter. Default `gl.LINEAR`. */
835
- minFilter?: GLenum;
836
- /** Color texture magnification filter. Default `gl.LINEAR`. */
837
- magFilter?: GLenum;
838
- /** Color texture S wrap. Default `gl.CLAMP_TO_EDGE`. */
839
- wrapS?: GLenum;
840
- /** Color texture T wrap. Default `gl.CLAMP_TO_EDGE`. */
841
- wrapT?: GLenum;
842
- /** Attach a caller-supplied (BYO) color {@link GLTexture} instead of creating
843
- * one. When supplied the render target does NOT own or restore it — the
844
- * texture is engine-managed (restored by the standard texture-restore path
845
- * first) and the RT re-attaches its swapped handle afterwards. The caller is
846
- * responsible for sizing it to `width`×`height` and for disposing it. */
847
- colorTexture?: GLTexture;
848
- }
849
-
850
- /** High-level sampling presets, mirroring Babylon's `Texture.*_SAMPLINGMODE`
851
- * numeric constants. Each resolves to GL min/mag filters (and mip generation
852
- * for `TRILINEAR`). */
853
- export declare const GLSamplingMode: {
854
- /** Nearest min + mag, no mipmaps. (`Texture.NEAREST_SAMPLINGMODE`) */
855
- readonly NEAREST: 1;
856
- /** Linear min + mag, no mipmaps. (`Texture.BILINEAR_SAMPLINGMODE`) */
857
- readonly BILINEAR: 2;
858
- /** Linear mag + linear-mipmap-linear min, mipmaps generated.
859
- * (`Texture.TRILINEAR_SAMPLINGMODE`) */
860
- readonly TRILINEAR: 3;
861
- };
862
-
863
- /** One of the {@link GLSamplingMode} preset values (`1`, `2` or `3`). */
864
- export declare type GLSamplingMode = (typeof GLSamplingMode)[keyof typeof GLSamplingMode];
865
-
866
- /** A single sprite — a plain data object mirroring the fields of Babylon's
867
- * `ThinSprite` that the renderer reads. No animation state: `cellIndex` is set
868
- * directly by the consumer (lite-gl does not port `ThinSprite.playAnimation`). */
869
- export declare interface GLSprite {
870
- /** World-space position of the sprite center. */
871
- position: {
872
- x: number;
873
- y: number;
874
- z: number;
875
- };
876
- /** Width in world units. */
877
- width: number;
878
- /** Height in world units. */
879
- height: number;
880
- /** Rotation angle, in radians. */
881
- angle: number;
882
- /** Sprite-sheet cell index (0-based, row-major). Out-of-range / negative
883
- * values are clamped to 0, matching Babylon's `if (!cellIndex) = 0`. Ignored
884
- * when a manual UV rect (`uSize`) is set. Optional — defaults to `0`. */
885
- cellIndex?: number;
886
- /** Optional tint; defaults to opaque white `{ r: 1, g: 1, b: 1, a: 1 }`. */
887
- color?: GLSpriteColor;
888
- /** Flip the cell horizontally. Defaults to `false`. */
889
- invertU?: boolean;
890
- /** Flip the cell vertically. Defaults to `false`. */
891
- invertV?: boolean;
892
- /** Manual UV rect — normalized left (U) origin in `[0, 1]`, mirroring
893
- * Babylon's `ThinSprite._xOffset`. Set together with {@link GLSprite.uSize}
894
- * to address an arbitrary sub-rectangle of the sheet instead of the fixed
895
- * `cellIndex` grid (used by the lottie atlas, whose cells vary in size). */
896
- uOffset?: number;
897
- /** Manual UV rect — normalized top (V) origin in `[0, 1]` (≙ Babylon
898
- * `ThinSprite._yOffset`). See {@link GLSprite.uSize}. */
899
- vOffset?: number;
900
- /** Manual UV rect — cell width in **texels** (≙ Babylon `ThinSprite._xSize`;
901
- * divided by the texture width when building vertices). Presence of `uSize`
902
- * switches the sprite into manual-UV mode (the `cellIndex` grid is ignored).
903
- * `0` samples a single column — the "solid color" trick. */
904
- uSize?: number;
905
- /** Manual UV rect — cell height in **texels** (≙ Babylon `ThinSprite._ySize`).
906
- * See {@link GLSprite.uSize}. Defaults to `0` when `uSize` is set but `vSize`
907
- * is omitted. */
908
- vSize?: number;
909
- /** When `false`, the sprite is skipped. Defaults to `true`. */
910
- isVisible?: boolean;
911
- }
912
-
913
- /** An RGBA color with each channel in `[0, 1]`, used for per-sprite tint. */
914
- export declare interface GLSpriteColor {
915
- /** Red, 0..1. */
916
- r: number;
917
- /** Green, 0..1. */
918
- g: number;
919
- /** Blue, 0..1. */
920
- b: number;
921
- /** Alpha, 0..1. */
922
- a: number;
923
- }
924
-
925
- /**
926
- * A sprite renderer owning its own VBO/IBO/VAO and `GLEffect`. Created by
927
- * {@link createSpriteRenderer}; drive it with {@link renderSprites} and release
928
- * it with {@link disposeSpriteRenderer}.
929
- */
930
- export declare interface GLSpriteRenderer {
931
- /** The sprite-sheet texture sampled by the shader. Swap via
932
- * {@link setSpriteRendererTexture}. */
933
- texture: GLTexture;
934
- /** Cell width in texels (selects the sub-rectangle for `cellIndex`). */
935
- cellWidth: number;
936
- /** Cell height in texels. */
937
- cellHeight: number;
938
- /** Per-corner UV/position inset (Babylon `SpriteRenderer` `epsilon`). */
939
- epsilon: number;
940
- /** Active blend mode applied by `renderSprites` before drawing. */
941
- blendMode: GLBlendMode;
942
- /** When `true`, `renderSprites` resets blend to {@link GLBlendMode.DISABLE}
943
- * after drawing (Babylon `autoResetAlpha`). */
944
- autoResetAlpha: boolean;
945
- /** Babylon-parity flag (no effect without a depth attachment). */
946
- disableDepthWrite: boolean;
947
- /** Maximum sprites per draw, fixed at creation. */
948
- readonly capacity: number;
949
-
950
- /** Options for {@link createSpriteRenderer}. */
951
- export declare interface GLSpriteRendererOptions {
952
- /** Maximum number of sprites drawable in one `renderSprites` call. Must be
953
- * an integer in `[1, 16384]` (the `Uint16` index-buffer limit). */
954
- capacity: number;
955
- /** Cell width in texels within the sprite sheet, for the fixed-grid
956
- * `cellIndex` path. Optional — defaults to `1`; irrelevant when every
957
- * sprite supplies a manual UV rect (`uSize`), as the lottie atlas does. */
958
- cellWidth?: number;
959
- /** Cell height in texels within the sprite sheet. Optional — defaults to
960
- * `1`. See {@link GLSpriteRendererOptions.cellWidth}. */
961
- cellHeight?: number;
962
- /** Per-corner UV/position inset applied to each quad vertex, in the `[0, 0.5)`
963
- * range — the `epsilon` constructor argument of Babylon's `SpriteRenderer`.
964
- * It both insets cell UV sampling (so a cell never bleeds its neighbours) and
965
- * shrinks the quad by `epsilon * size` per side. Defaults to `0.01` (Babylon's
966
- * `SpriteRenderer` default). Pass `0` to disable insetting — the lottie atlas
967
- * does this (it relies on edge-extruded cells + center sampling instead, so a
968
- * non-zero inset would shrink every sprite by ~`0.01·size` per edge). */
969
- epsilon?: number;
970
- /** The sprite-sheet texture. May be swapped later via
971
- * {@link setSpriteRendererTexture}. */
972
- texture: GLTexture;
973
- /** Blend mode for the draw. Defaults to {@link GLBlendMode.ALPHA} (2),
974
- * matching Babylon's `SpriteRenderer.blendMode` default. */
975
- blendMode?: GLBlendMode;
976
- /** When `true` (default), `renderSprites` resets the blend mode to
977
- * {@link GLBlendMode.DISABLE} after drawing — mirroring Babylon's
978
- * `SpriteRenderer.autoResetAlpha = true`. Set `false` to leave the
979
- * renderer's `blendMode` applied after the draw (the lottie player relies
980
- * on this so its premultiplied alpha mode persists across passes). */
981
- autoResetAlpha?: boolean;
982
- /** Accepted for Babylon API parity. lite-gl's default engine has no depth
983
- * attachment (`depth: false`), so there is no depth pre-pass and this flag
984
- * has no observable effect; it is stored verbatim for a future depth-aware
985
- * consumer. Defaults to `false`. */
986
- disableDepthWrite?: boolean;
987
- }
988
-
989
- /** Stencil configuration for {@link setStencilState}. Omitted fields are left
990
- * unchanged. The `func`/`ref`/`funcMask` triple and the
991
- * `opFail`/`opZFail`/`opZPass` triple are each applied as a unit (any member
992
- * present re-issues that GL call, merging the unspecified members from cache). */
993
- export declare interface GLStencilState {
994
- /** Enable/disable the stencil test (`gl.enable/disable(STENCIL_TEST)`). */
995
- test?: boolean;
996
- /** Stencil write mask (`gl.stencilMask`). */
997
- mask?: number;
998
- /** Comparison function (`gl.stencilFunc` arg 1), e.g. `gl.ALWAYS`. */
999
- func?: GLenum;
1000
- /** Reference value (`gl.stencilFunc` arg 2). */
1001
- ref?: number;
1002
- /** Comparison mask (`gl.stencilFunc` arg 3). */
1003
- funcMask?: number;
1004
- /** Op when the stencil test fails (`gl.stencilOp` arg 1). */
1005
- opFail?: GLenum;
1006
- /** Op when the stencil test passes but depth fails (`gl.stencilOp` arg 2). */
1007
- opZFail?: GLenum;
1008
- /** Op when both stencil and depth pass (`gl.stencilOp` arg 3). */
1009
- opZPass?: GLenum;
1010
- }
1011
-
1012
- /**
1013
- * Pure-state texture handle. The `handle` field is MUTABLE so the same logical
1014
- * texture survives a `webglcontextrestored` event — every consumer keeps the
1015
- * same `GLTexture` reference; only the internal `WebGLTexture` is swapped.
1016
- *
1017
- * `loadTexture2D` also uses the same handle for the 1×1 placeholder upload AND
1018
- * the final image upload — so a `bindTexture(engine, unit, tex)` made before the
1019
- * image has decoded remains valid once the image arrives.
1020
- */
1021
- export declare interface GLTexture {
1022
- /** The live `WebGLTexture`. MUTABLE — swapped for a fresh handle on
1023
- * `webglcontextrestored` while consumers keep the same `GLTexture` reference. */
1024
- handle: WebGLTexture;
1025
- /** GL texture target (always `gl.TEXTURE_2D` for this package). */
1026
- readonly target: GLenum;
1027
- /** Texture width in texels. Updated once an async upload resolves. */
1028
- width: number;
1029
- /** Texture height in texels. Updated once an async upload resolves. */
1030
- height: number;
1031
- /** True when the texture is safe to sample with final content (placeholders
1032
- * read as not-ready until their image/upload completes). */
1033
- isReady: boolean;
1034
-
1035
- /** Texture sampling / wrap options. All have GL-spec defaults. Mipmaps are NOT
1036
- * a create option — generate the chain explicitly via {@link generateTextureMipMaps}. */
1037
- export declare interface GLTextureOptions {
1038
- /** Default: false (matches Babylon's default raw-texture behaviour). */
1039
- invertY?: boolean;
1040
- /** Default: gl.LINEAR. */
1041
- minFilter?: GLenum;
1042
- /** Default: gl.LINEAR. */
1043
- magFilter?: GLenum;
1044
- /** Default: gl.CLAMP_TO_EDGE. May be `gl.REPEAT` / `gl.MIRRORED_REPEAT`
1045
- * (NPOT-safe in WebGL2). */
1046
- wrapS?: GLenum;
1047
- /** Default: gl.CLAMP_TO_EDGE. May be `gl.REPEAT` / `gl.MIRRORED_REPEAT`. */
1048
- wrapT?: GLenum;
1049
- /** `gl.pixelStorei(UNPACK_ALIGNMENT)` for the upload (1/2/4/8). Default 4.
1050
- * Use 1 for tightly-packed non-RGBA rows. */
1051
- unpackAlignment?: number;
1052
- /** Premultiply alpha at upload (`UNPACK_PREMULTIPLY_ALPHA_WEBGL`). Default
1053
- * false. */
1054
- premultiplyAlpha?: boolean;
1055
- /** Explicit sized internalFormat for `texImage2D`. When provided it is used
1056
- * verbatim and the inline LDR resolver is bypassed — this is how
1057
- * {@link createFloatTexture} injects its `RGBA16F` / `RGBA32F` choice
1058
- * without the byte path ever referencing the float-format table (keeping it
1059
- * tree-shakeable out of RGBA8-only bundles). Default: derived from
1060
- * `format`/`type` via the LDR resolver. */
1061
- internalFormat?: GLenum;
1062
- }
1063
-
1064
- /** A GPU vertex buffer holding interleaved float vertex data. The lite-gl
1065
- * counterpart of Babylon's `DataBuffer` for vertex data. */
1066
- export declare interface GLVertexBuffer {
1067
- /** The live `WebGLBuffer`. Swapped on `webglcontextrestored`. */
1068
- handle: WebGLBuffer;
1069
- /** Size of the GL buffer in bytes. */
1070
- byteLength: number;
1071
-
1072
- /** Pixel-space viewport rectangle passed to `setViewport`. */
1073
- export declare interface GLViewport {
1074
- /** Lower-left X origin in physical pixels. */
1075
- x: number;
1076
- /** Lower-left Y origin in physical pixels. */
1077
- y: number;
1078
- /** Width in physical pixels. */
1079
- w: number;
1080
- /** Height in physical pixels. */
1081
- h: number;
1082
- }
1083
-
1084
- /** Poll the link state and, on first success, run finalization (uniform-
1085
- * location resolution + one-shot sampler-unit `uniform1i` assignment +
1086
- * `_onCompiled` callbacks). Returns `true` once the effect is usable. */
1087
- export declare function isEffectReady(engine: GLEngineContext, effect: GLEffect): boolean;
1088
-
1089
- /** Asynchronous image upload.The returned texture is immediately usable (1×1
1090
- * transparent placeholder); `isReady` flips true once the image has been
1091
- * decoded and uploaded. The decoded `ImageBitmap` is retained on the texture
1092
- * for offline-safe `webglcontextrestored` replay. */
1093
- export declare function loadTexture2D(engine: GLEngineContext, url: string, options?: GLTextureOptions, onLoad?: (tex: GLTexture) => void, onError?: (err: Error) => void): GLTexture;
1094
-
1095
- /** Remove a previously-registered context-lost callback. */
1096
- export declare function offContextLost(engine: GLEngineContext, cb: () => void): void;
1097
-
1098
- /** Remove a previously-registered context-restored callback. */
1099
- export declare function offContextRestored(engine: GLEngineContext, cb: () => void): void;
1100
-
1101
- /** Register a `webglcontextlost` callback. Duplicate registrations are ignored. */
1102
- export declare function onContextLost(engine: GLEngineContext, cb: () => void): void;
1103
-
1104
- /** Register a `webglcontextrestored` callback. Duplicate registrations are ignored. */
1105
- export declare function onContextRestored(engine: GLEngineContext, cb: () => void): void;
1106
-
1107
- /**
1108
- * Synchronously read back a rectangle of the render target's color attachment
1109
- * via `gl.readPixels` — the lite-gl equivalent of Babylon's
1110
- * `_readTexturePixelsSync`. Binds the target's framebuffer (leaving it bound,
1111
- * matching Babylon).
1112
- *
1113
- * The returned array element type follows the color attachment type:
1114
- * `Uint8Array` for `UNSIGNED_BYTE`, `Float32Array` for `FLOAT`, `Uint16Array`
1115
- * for `HALF_FLOAT`. Origin is GL bottom-left.
1116
- *
1117
- * @param engine - The engine.
1118
- * @param rt - The render target to read from.
1119
- * @param x - Lower-left X of the read rectangle, in texels.
1120
- * @param y - Lower-left Y of the read rectangle, in texels.
1121
- * @param width - Read rectangle width in texels.
1122
- * @param height - Read rectangle height in texels.
1123
- * @param into - Optional preallocated buffer (`width*height*4` elements of the
1124
- * matching type). Reused to avoid per-call allocation.
1125
- * @returns The pixel buffer (the provided `into`, or a freshly allocated one).
1126
- * Empty buffer on a lost/disposed context.
1127
- */
1128
- export declare function readRenderTargetPixels(engine: GLEngineContext, rt: GLRenderTarget, x: number, y: number, width: number, height: number, into?: ArrayBufferView): ArrayBufferView;
1129
-
1130
- /**
1131
- * Build the per-sprite vertex data and draw all visible sprites in one
1132
- * `drawElements` call. Performs no allocations — the vertex scratch is reused
1133
- * and uploaded with `bufferSubData`.
1134
- *
1135
- * No-op when the context is lost/disposed, the renderer is disposed, the
1136
- * texture is not ready, the effect is not ready, or there are no visible
1137
- * sprites. Sets the renderer's blend mode before drawing and resets to
1138
- * {@link GLBlendMode.DISABLE} afterwards (matching Babylon's
1139
- * `autoResetAlpha = true`), so a subsequent `drawEffect` is unaffected.
1140
- *
1141
- * @param renderer - The renderer to draw with.
1142
- * @param sprites - The sprites to draw (only `isVisible !== false` are drawn;
1143
- * excess beyond `capacity` is ignored, matching Babylon).
1144
- * @param deltaTime - Accepted for Babylon API parity; unused (lite-gl `GLSprite`
1145
- * holds no animation state, so `cellIndex` is consumer-driven).
1146
- * @param viewMatrix - Column-major 4x4 view matrix.
1147
- * @param projectionMatrix - Column-major 4x4 projection matrix.
1148
- */
1149
- export declare function renderSprites(renderer: GLSpriteRenderer, sprites: readonly GLSprite[], deltaTime: number, viewMatrix: Float32Array | number[], projectionMatrix: Float32Array | number[]): void;
1150
-
1151
- /** Match drawing-buffer size to (clientSize × devicePixelRatio / _hsl). No-op
1152
- * if size already matches. Never touches viewport — `setViewport` owns that. */
1153
- export declare function resizeGLEngine(engine: GLEngineContext): void;
1154
-
1155
- /**
1156
- * Resize both targets of a {@link GLPingPong}. No-op when disposed.
1157
- *
1158
- * @param engine - The engine that owns `pp`.
1159
- * @param pp - The ping-pong pair to resize.
1160
- * @param width - New width in texels (positive integer).
1161
- * @param height - New height in texels (positive integer).
1162
- */
1163
- export declare function resizePingPong(engine: GLEngineContext, pp: GLPingPong, width: number, height: number): void;
1164
-
1165
- /**
1166
- * Resize the render target's color attachment (and depth/stencil renderbuffer).
1167
- * Reallocates storage at the new size; the contents are discarded. The
1168
- * `GLRenderTarget` / `GLTexture` identity is preserved, so consumers and
1169
- * effect-sampler bindings holding the reference stay valid. If this target was
1170
- * the live draw target, it is rebound (with the new-size viewport) afterwards.
1171
- *
1172
- * No-op when the size is unchanged or `rt` is disposed. While the context is
1173
- * lost the new size is recorded but the GL reallocation is deferred to the
1174
- * restore hook.
1175
- *
1176
- * @param engine - The engine.
1177
- * @param rt - The render target to resize.
1178
- * @param width - New width in texels (≥ 1).
1179
- * @param height - New height in texels (≥ 1).
1180
- */
1181
- export declare function resizeRenderTarget(engine: GLEngineContext, rt: GLRenderTarget, width: number, height: number): void;
1182
-
1183
- /** Register a per-frame callback. **No-op if `fn` is already registered**
1184
- * (matches Babylon `AbstractEngine.runRenderLoop`). Starts the rAF if this is
1185
- * the first registration. */
1186
- export declare function runRenderLoop(engine: GLEngineContext, fn: (dt: number) => void): void;
1187
-
1188
- /**
1189
- * Set the GL blend state to match Babylon's `setAlphaMode(mode)` exactly.
1190
- *
1191
- * | Mode | `gl.blendFuncSeparate(srcRGB, dstRGB, srcA, dstA)` |
1192
- * |--------------------|------------------------------------------------------------|
1193
- * | `DISABLE` (0) | — (`gl.disable(gl.BLEND)`) |
1194
- * | `ADD` (1) | `SRC_ALPHA, ONE, ZERO, ONE` |
1195
- * | `ALPHA` (2) | `SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ONE, ONE` |
1196
- * | `PREMULTIPLIED` (7)| `ONE, ONE_MINUS_SRC_ALPHA, ONE, ONE` |
1197
- *
1198
- * No-op when the context is lost or disposed.
1199
- *
1200
- * @param engine - The engine whose GL blend state is updated.
1201
- * @param mode - The {@link GLBlendMode} preset to apply.
1202
- */
1203
- export declare function setBlendMode(engine: GLEngineContext, mode: GLBlendMode): void;
1204
-
1205
- /**
1206
- * Enable blending with an arbitrary separate-channel function and equation —
1207
- * the lite-gl equivalent of Babylon's `AlphaState` with
1208
- * `setAlphaBlendFunctionParameters` + `setAlphaEquationParameters`.
1209
- *
1210
- * Supports every WebGL2 blend equation, including `MIN`, `MAX`,
1211
- * `FUNC_SUBTRACT` and `FUNC_REVERSE_SUBTRACT` (used by ShapeBuilder's darken /
1212
- * cutout blend modes). Records the desired config (flushed by `applyGLStates`
1213
- * before the next draw); at flush time the enable flag, the equation and the func
1214
- * are each cached independently, so a redundant state is fully elided and only
1215
- * the call whose params changed is re-issued — mirroring Babylon's `AlphaState`
1216
- * dirty flags. Because GL keeps the equation + func across `gl.disable(BLEND)`,
1217
- * re-enabling with unchanged params re-issues neither.
1218
- *
1219
- * No-op when the context is lost or disposed.
1220
- *
1221
- * @param engine - The engine whose desired blend state is updated.
1222
- * @param state - The separate-channel blend factors + equations to apply.
1223
- */
1224
- export declare function setBlendState(engine: GLEngineContext, state: GLBlendState): void;
1225
-
1226
- /**
1227
- * Buffer the color write mask into the DESIRED state — the lite-gl equivalent of
1228
- * Babylon's `setColorWrite` (which passes the same flag to all four channels).
1229
- * Flushed to GL (`gl.colorMask`) by `applyGLStates` before the next draw /
1230
- * clear.
1231
- *
1232
- * @param engine - The engine.
1233
- * @param r - Write red.
1234
- * @param g - Write green.
1235
- * @param b - Write blue.
1236
- * @param a - Write alpha.
1237
- */
1238
- export declare function setColorMask(engine: GLEngineContext, r: boolean, g: boolean, b: boolean, a: boolean): void;
1239
-
1240
- /**
1241
- * Enable/disable face culling and (optionally) set the cull face — the lite-gl
1242
- * equivalent of `engine.depthCullingState.cull` + `cullFace`.
1243
- *
1244
- * @param engine - The engine.
1245
- * @param enabled - Enable (`true`) or disable (`false`) `gl.CULL_FACE`.
1246
- * @param face - Optional cull face (`gl.BACK` / `gl.FRONT` / `gl.FRONT_AND_BACK`).
1247
- */
1248
- export declare function setCullState(engine: GLEngineContext, enabled: boolean, face?: GLenum): void;
1249
-
1250
- /**
1251
- * Buffer depth-buffer state (test enable, write mask, comparison function) into
1252
- * the DESIRED state — the lite-gl equivalent of mutating Babylon's
1253
- * `engine.depthCullingState.{depthTest,depthMask,depthFunc}`. Flushed to GL by
1254
- * `applyGLStates` before the next draw / clear; omitted fields are untouched.
1255
- *
1256
- * @param engine - The engine.
1257
- * @param state - The depth fields to change. Omitted fields are untouched.
1258
- */
1259
- export declare function setDepthState(engine: GLEngineContext, state: GLDepthState): void;
1260
-
1261
- /** Cached `gl.uniform3f` from an r/g/b color object. Delegates to `setEffectFloat3`. */
1262
- export declare function setEffectColor3(engine: GLEngineContext, effect: GLEffect, name: string, c: {
1263
- r: number;
1264
- g: number;
1265
- b: number;
1266
- }): void;
1267
-
1268
- /** Cached `gl.uniform4f` from an r/g/b/a color object. Delegates to `setEffectFloat4`. */
1269
- export declare function setEffectColor4(engine: GLEngineContext, effect: GLEffect, name: string, c: {
1270
- r: number;
1271
- g: number;
1272
- b: number;
1273
- a: number;
1274
- }): void;
1275
-
1276
- /** Cached `gl.uniform4f` from an r/g/b/a color WITHOUT premultiplication — the
1277
- * lite-gl equivalent of Babylon's `Effect.setDirectColor4`. Delegates to
1278
- * `setEffectFloat4` (lite-gl never premultiplies in the uniform setters, so
1279
- * this matches `setEffectColor4`; the distinct name eases the ShapeBuilder
1280
- * port). */
1281
- export declare function setEffectDirectColor4(engine: GLEngineContext, effect: GLEffect, name: string, c: {
1282
- r: number;
1283
- g: number;
1284
- b: number;
1285
- a: number;
1286
- }): void;
1287
-
1288
- /** Cached `gl.uniform1f`. No-op when context-lost, the effect isn't ready, the
1289
- * uniform is absent, or the value is unchanged since last upload. */
1290
- export declare function setEffectFloat(engine: GLEngineContext, effect: GLEffect, name: string, x: number): void;
1291
-
1292
- /** Cached `gl.uniform2f`. No-op when context-lost, the effect isn't ready, the
1293
- * uniform is absent, or the value is unchanged since last upload. */
1294
- export declare function setEffectFloat2(engine: GLEngineContext, effect: GLEffect, name: string, x: number, y: number): void;
1295
-
1296
- /** Cached `gl.uniform3f`. No-op when context-lost, the effect isn't ready, the
1297
- * uniform is absent, or the value is unchanged since last upload. */
1298
- export declare function setEffectFloat3(engine: GLEngineContext, effect: GLEffect, name: string, x: number, y: number, z: number): void;
1299
-
1300
- /** Cached `gl.uniform4f`. No-op when context-lost, the effect isn't ready, the
1301
- * uniform is absent, or the value is unchanged since last upload. */
1302
- export declare function setEffectFloat4(engine: GLEngineContext, effect: GLEffect, name: string, x: number, y: number, z: number, w: number): void;
1303
-
1304
- /** `gl.uniform1fv` — a flat float array (`Effect.setFloatArray` / `setArray`).
1305
- * Not value-cached. */
1306
- export declare function setEffectFloatArray(engine: GLEngineContext, effect: GLEffect, name: string, array: Float32Array | number[]): void;
1307
-
1308
- /** `gl.uniform4fv` — an array of `vec4`s (`Effect.setFloatArray4` / `setArray4`).
1309
- * Not value-cached. */
1310
- export declare function setEffectFloatArray4(engine: GLEngineContext, effect: GLEffect, name: string, array: Float32Array | number[]): void;
1311
-
1312
- /** Cached `gl.uniform1i`. No-op when context-lost, the effect isn't ready, the
1313
- * uniform is absent, or the value is unchanged since last upload. */
1314
- export declare function setEffectInt(engine: GLEngineContext, effect: GLEffect, name: string, x: number): void;
1315
-
1316
- /** `gl.uniform1iv` — a flat int array (`Effect.setIntArray`). Not value-cached. */
1317
- export declare function setEffectIntArray(engine: GLEngineContext, effect: GLEffect, name: string, array: Int32Array | number[]): void;
1318
-
1319
- /** `gl.uniformMatrix4fv` from a column-major 4×4 matrix — the lite-gl
1320
- * equivalent of Babylon's `Effect.setMatrix`. Not value-cached. */
1321
- export declare function setEffectMatrix(engine: GLEngineContext, effect: GLEffect, name: string, matrix: Float32Array | number[]): void;
1322
-
1323
- /** `gl.uniformMatrix3fv` from a column-major 3×3 matrix — the lite-gl
1324
- * equivalent of Babylon's `Effect.setMatrix3x3`. Not value-cached. */
1325
- export declare function setEffectMatrix3x3(engine: GLEngineContext, effect: GLEffect, name: string, matrix: Float32Array | number[]): void;
1326
-
1327
- /** Bind a texture to the sampler's pre-assigned unit (§4.4). NO `gl.uniform1i`
1328
- * is issued — that was done exactly once per program lifetime during
1329
- * finalization. This is the key win over Babylon's `Effect.setTexture` which
1330
- * re-issues the sampler binding on every call. */
1331
- export declare function setEffectTexture(engine: GLEngineContext, effect: GLEffect, samplerName: string, tex: GLTexture): void;
1332
-
1333
- /** Cached `gl.uniform2f` from an `{x,y}` vector object — the lite-gl equivalent
1334
- * of Babylon's `Effect.setVector2`. Delegates to `setEffectFloat2`. */
1335
- export declare function setEffectVector2(engine: GLEngineContext, effect: GLEffect, name: string, v: {
1336
- x: number;
1337
- y: number;
1338
- }): void;
1339
-
1340
- /**
1341
- * Set the drawing-buffer size to an EXPLICIT width/height in physical pixels
1342
- * (each divided by `_hsl`), independent of the canvas client/CSS size — the
1343
- * counterpart of Babylon's `ThinEngine.setSize`. Use when the render resolution
1344
- * is computed directly (e.g. animation dimensions × scale × dpr) rather than
1345
- * derived from CSS layout via {@link resizeGLEngine}. No-op on a disposed
1346
- * engine. Never touches the viewport — `setViewport` owns that.
1347
- *
1348
- * @param engine - The engine to resize.
1349
- * @param width - Target drawing-buffer width in physical pixels.
1350
- * @param height - Target drawing-buffer height in physical pixels.
1351
- */
1352
- export declare function setGLEngineSize(engine: GLEngineContext, width: number, height: number): void;
1353
-
1354
- /** Updates the hardware-scaling factor and triggers a resize. */
1355
- export declare function setHardwareScalingLevel(engine: GLEngineContext, level: number): void;
1356
-
1357
- /**
1358
- * Enable the scissor test and set the clip rectangle (lower-left origin),
1359
- * cached. Re-issues `gl.scissor` only when the rectangle changes, and
1360
- * `gl.enable(SCISSOR_TEST)` only on the disabled→enabled transition.
1361
- *
1362
- * @param engine - The engine.
1363
- * @param x - Lower-left X of the scissor rectangle, in pixels.
1364
- * @param y - Lower-left Y of the scissor rectangle, in pixels.
1365
- * @param width - Rectangle width in pixels.
1366
- * @param height - Rectangle height in pixels.
1367
- */
1368
- export declare function setScissor(engine: GLEngineContext, x: number, y: number, width: number, height: number): void;
1369
-
1370
- /** Swap the sprite-sheet texture (≙ Babylon assigning `SpriteRenderer.texture`
1371
- * after an async load). The cell size is unchanged — adjust `cellWidth` /
1372
- * `cellHeight` on the renderer directly if the new sheet differs. No-op when
1373
- * the renderer is disposed. */
1374
- export declare function setSpriteRendererTexture(renderer: GLSpriteRenderer, texture: GLTexture): void;
1375
-
1376
- /**
1377
- * Buffer stencil state (test enable, write mask, comparison func triple, op
1378
- * triple) into the DESIRED state — the lite-gl equivalent of mutating Babylon's
1379
- * `engine.stencilState.*`. Flushed by `applyGLStates` before the next draw /
1380
- * clear; omitted fields are untouched (merge-from-desired).
1381
- *
1382
- * @param engine - The engine.
1383
- * @param state - The stencil fields to change. Omitted fields are untouched.
1384
- */
1385
- export declare function setStencilState(engine: GLEngineContext, state: GLStencilState): void;
1386
-
1387
- /** Cached `gl.viewport`. Defaults to the full canvas in pixel coordinates. */
1388
- export declare function setViewport(engine: GLEngineContext, viewport?: GLViewport): void;
1389
-
1390
- /** Stop one (or all when omitted) registered callbacks. Cancels the rAF if
1391
- * no callbacks remain. */
1392
- export declare function stopRenderLoop(engine: GLEngineContext, fn?: (dt: number) => void): void;
1393
-
1394
- /**
1395
- * Reset the vertex divisor of every attribute touched by {@link bindAttributes}
1396
- * back to 0 — the lite-gl equivalent of Babylon's `unbindInstanceAttributes`.
1397
- * Call after an instanced draw so a following non-instanced draw is not skewed.
1398
- * No-op on a lost/disposed context.
1399
- *
1400
- * @param engine - The engine.
1401
- */
1402
- export declare function unbindInstanceAttributes(engine: GLEngineContext): void;
1403
-
1404
- /** Push 2D pixels into a {@link createDynamicTexture} texture from a canvas /
1405
- * `OffscreenCanvas` / image / video / `ImageBitmap` / `ImageData` source — the
1406
- * WebGL counterpart of Babylon's `ThinEngine.updateDynamicTexture`. The source
1407
- * is retained on the texture so it is replayed on `webglcontextrestored`.
1408
- * No-op when the context is lost/disposed or the texture is disposed.
1409
- *
1410
- * @param engine - The engine that owns the texture.
1411
- * @param tex - A texture created by {@link createDynamicTexture}.
1412
- * @param source - The 2D pixel source to upload.
1413
- * @param invertY - Flip vertically on upload (`UNPACK_FLIP_Y_WEBGL`). Default `false`.
1414
- * @param premultiplyAlpha - Premultiply on upload (`UNPACK_PREMULTIPLY_ALPHA_WEBGL`).
1415
- * Default `false`, matching Babylon's `updateDynamicTexture` default. */
1416
- export declare function updateDynamicTexture(engine: GLEngineContext, tex: GLTexture, source: TexImageSource, invertY?: boolean, premultiplyAlpha?: boolean): void;
1417
-
1418
- /** Re-upload the texture from its source element. No-op when the context is
1419
- * lost/disposed or the texture is disposed. */
1420
- export declare function updateHtmlElementTexture(engine: GLEngineContext, tex: GLTexture): void;
1421
-
1422
- /**
1423
- * Re-upload the pixel data (and optionally resize) of a texture created by
1424
- * {@link createRawTexture} — the lite-gl equivalent of Babylon's
1425
- * `updateRawTexture` / `_uploadDataToTextureDirectly`. Goes through the same
1426
- * upload closure used by context-restore, so the new contents survive a context
1427
- * loss. No-op on a lost/disposed/non-raw texture.
1428
- *
1429
- * @param engine - The engine.
1430
- * @param tex - The raw texture to update.
1431
- * @param data - New pixel data (must match the original `format`/`type`).
1432
- * @param options - Optional new `width`/`height` (default: unchanged) and
1433
- * `unpackAlignment` (default 4).
1434
- */
1435
- export declare function updateRawTexture(engine: GLEngineContext, tex: GLTexture, data: ArrayBufferView | null, options?: {
1436
- width?: number;
1437
- height?: number;
1438
- unpackAlignment?: number;
1439
- }): void;
1440
-
1441
- /** Update a texture's min/mag sampling filters — the lite-gl equivalent of
1442
- * Babylon's `updateTextureSamplingMode`. Binds for upload (unit 0) so the
1443
- * `texParameteri` lands on this texture. No-op on a lost/disposed context. */
1444
- export declare function updateTextureSamplingMode(engine: GLEngineContext, tex: GLTexture, minFilter: GLenum, magFilter: GLenum): void;
1445
-
1446
- /** Update a texture's S/T wrap modes (`gl.CLAMP_TO_EDGE` / `gl.REPEAT` /
1447
- * `gl.MIRRORED_REPEAT`) — the lite-gl equivalent of Babylon's
1448
- * `updateTextureWrappingMode`. No-op on a lost/disposed context. */
1449
- export declare function updateTextureWrapMode(engine: GLEngineContext, tex: GLTexture, wrapS: GLenum, wrapT: GLenum): void;
1450
-
1451
- /**
1452
- * Upload new contents into (part of) a vertex buffer via `bufferSubData`. A
1453
- * full-buffer update from offset 0 also refreshes the retained CPU data used
1454
- * for context-restore.
1455
- *
1456
- * @param engine - The engine.
1457
- * @param vb - The vertex buffer to update.
1458
- * @param data - The new float data.
1459
- * @param dstByteOffset - Destination byte offset within the buffer. Default 0.
1460
- */
1461
- export declare function updateVertexBuffer(engine: GLEngineContext, vb: GLVertexBuffer, data: Float32Array, dstByteOffset?: number): void;
1462
-
1463
- /** Cached `gl.useProgram`. No-op when the effect is not ready or already current. */
1464
- export declare function useEffect(engine: GLEngineContext, effect: GLEffect): void;
1465
-
1466
- /**
1467
- * Invalidate lite-gl's cached GL state so the next state-setting call in each
1468
- * category (program / buffer / texture / VAO / framebuffer bindings, blend,
1469
- * depth, stencil, scissor, color-mask, viewport, unpack) is re-issued instead
1470
- * of elided.
1471
- *
1472
- * Use this when a host application that SHARES this WebGL2 context mutates raw
1473
- * `gl.*` state outside lite-gl — e.g. a save/restore wrapper that resets the
1474
- * context to GL defaults around each render scope, or any interop layer that
1475
- * issues GL calls directly. Without it, lite-gl's redundant-call elision would
1476
- * skip the state changes needed to re-establish the scope, producing corrupted
1477
- * output. Owned GPU resources (the shared quad, render targets, meshes,
1478
- * effects, textures) are preserved — only the cached "current GL state" is
1479
- * reset. Mirrors Babylon's `Engine.wipeCaches()`.
1480
- *
1481
- * No-op while the context is lost or the engine is disposed.
1482
- */
1483
- export declare function wipeGLStateCache(engine: GLEngineContext): void;
1484
-
1485
- export { }
4
+ export { createGLEngine, disposeGLEngine, resizeGLEngine, setGLEngineSize, wipeGLStateCache, getRenderWidth, getRenderHeight, getHardwareScalingLevel, setHardwareScalingLevel, getRenderingCanvas, onContextLost, offContextLost, onContextRestored, offContextRestored, } from "./context.js";
5
+ export type { GLEngineOptions, GLEngineCaps, GLEngineContext } from "./context.js";
6
+ export { runRenderLoop, stopRenderLoop } from "./render-loop.js";
7
+ export { createEffect, useEffect, isEffectReady, executeWhenCompiled, disposeEffect, setEffectFloat, setEffectFloat2, setEffectFloat3, setEffectFloat4, setEffectColor3, setEffectColor4, setEffectVector2, setEffectDirectColor4, setEffectInt, setEffectTexture, setEffectMatrix, setEffectMatrix3x3, setEffectFloatArray, setEffectFloatArray4, setEffectIntArray, } from "./effect.js";
8
+ export type { GLEffectOptions, GLEffect } from "./effect.js";
9
+ export { createEffectWrapper, applyEffectWrapper, drawEffect, setViewport, disposeEffectWrapper } from "./effect-renderer.js";
10
+ export type { GLEffectWrapperOptions, GLEffectWrapper, GLViewport } from "./effect-renderer.js";
11
+ export { createRawTexture, createFloatTexture, generateTextureMipMaps, loadTexture2D, bindTexture, disposeTexture, updateRawTexture, updateTextureSamplingMode, updateTextureWrapMode, createTextureFromHandle, } from "./texture.js";
12
+ export type { GLTextureOptions, GLFloatTextureOptions, GLTexture } from "./texture.js";
13
+ export { createDynamicTexture, updateDynamicTexture, clearDynamicTextureSource } from "./dynamic-texture.js";
14
+ export { createRenderTarget, createFloatRenderTarget, bindRenderTarget, generateRenderTargetMipMaps, resizeRenderTarget, readRenderTargetPixels, disposeRenderTarget, createPingPong, resizePingPong, disposePingPong, } from "./render-target.js";
15
+ export type { GLRenderTarget, GLRenderTargetOptions, GLFloatRenderTargetOptions, GLPingPong } from "./render-target.js";
16
+ export { createVertexBuffer, updateVertexBuffer, createIndexBuffer, disposeBuffer, bindIndexBuffer, bindAttributes, unbindInstanceAttributes, drawIndexed, createMeshVao, bindMeshVao, drawMesh, disposeMeshVao, } from "./mesh.js";
17
+ export type { GLVertexBuffer, GLIndexBuffer, GLAttributeDescriptor, GLMeshVertexBuffer, GLMeshVao } from "./mesh.js";
18
+ export { GLBlendMode, GLBlendEquation, setBlendMode, setBlendState, disableBlend } from "./blend.js";
19
+ export type { GLBlendState } from "./blend.js";
20
+ export { setDepthState, setCullState, setStencilState, setColorMask, clearEngine, generateRenderTargetStencil } from "./depth-stencil.js";
21
+ export type { GLDepthState, GLStencilState, GLClearOptions } from "./depth-stencil.js";
22
+ export { setScissor, disableScissor } from "./scissor.js";
23
+ export { createSpriteRenderer, renderSprites, setSpriteRendererTexture, disposeSpriteRenderer } from "./sprites.js";
24
+ export type { GLSprite, GLSpriteColor, GLSpriteRendererOptions, GLSpriteRenderer } from "./sprites.js";
25
+ export { createHtmlElementTexture, updateHtmlElementTexture, GLSamplingMode } from "./html-texture.js";
26
+ export type { GLHtmlElementTextureOptions } from "./html-texture.js";