@babylonjs/lite-gl 1.24.0 → 1.25.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/CHANGELOG.md +26 -0
- package/README.md +5 -4
- package/blend.d.ts +1 -1
- package/blend.js +1 -1
- package/blend.js.map +1 -1
- package/context.d.ts +47 -4
- package/context.js +100 -11
- package/context.js.map +1 -1
- package/depth-stencil.d.ts +3 -2
- package/depth-stencil.js +10 -11
- package/depth-stencil.js.map +1 -1
- package/dynamic-texture.d.ts +6 -3
- package/dynamic-texture.js +16 -4
- package/dynamic-texture.js.map +1 -1
- package/effect.d.ts +12 -3
- package/effect.js +35 -24
- package/effect.js.map +1 -1
- package/family.d.ts +5 -1
- package/family.js.map +1 -1
- package/framebuffer-validation.d.ts +20 -0
- package/framebuffer-validation.js +37 -0
- package/framebuffer-validation.js.map +1 -0
- package/html-texture.d.ts +2 -2
- package/html-texture.js.map +1 -1
- package/index.d.ts +3 -2
- package/index.js +3 -2
- package/index.js.map +1 -1
- package/mesh.d.ts +68 -14
- package/mesh.js +211 -61
- package/mesh.js.map +1 -1
- package/package.json +3 -3
- package/render-target.d.ts +11 -9
- package/render-target.js +50 -35
- package/render-target.js.map +1 -1
- package/scissor.d.ts +1 -1
- package/scissor.js.map +1 -1
- package/sprites.d.ts +5 -3
- package/sprites.js +24 -23
- package/sprites.js.map +1 -1
- package/state.d.ts +25 -13
- package/state.js +13 -10
- package/state.js.map +1 -1
- package/text/_gpu/text-instances.js +1 -1
- package/text/_gpu/text-instances.js.map +1 -1
- package/texture-3d.d.ts +2 -1
- package/texture-3d.js +7 -2
- package/texture-3d.js.map +1 -1
- package/texture-source.d.ts +4 -2
- package/texture-source.js +3 -2
- package/texture-source.js.map +1 -1
- package/texture.d.ts +18 -8
- package/texture.js +61 -35
- package/texture.js.map +1 -1
- package/web-family.d.ts +2 -1
- package/web-family.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## @babylonjs/lite-gl v1.25.0
|
|
4
|
+
|
|
5
|
+
_No notable changes since npm-lite-gl-v1.24.1._
|
|
6
|
+
|
|
7
|
+
## @babylonjs/lite-gl v1.24.1
|
|
8
|
+
|
|
9
|
+
### ⚠️ BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
- **particle:** NPE value, math and sprite-cell blocks ([#939](https://github.com/BabylonJS/Babylon-Lite/pull/939))
|
|
12
|
+
|
|
13
|
+
### ✨ Features
|
|
14
|
+
|
|
15
|
+
- **lite-gl:** context-loss opt-out, attribute-pointer cache and correctness fixes ([#936](https://github.com/BabylonJS/Babylon-Lite/pull/936))
|
|
16
|
+
- **compat:** advance upstream sync watermarks ([#940](https://github.com/BabylonJS/Babylon-Lite/pull/940))
|
|
17
|
+
|
|
18
|
+
### 🐛 Bug Fixes
|
|
19
|
+
|
|
20
|
+
- break lazy-import cycles that made Vite 8 emit unused chunks ([#941](https://github.com/BabylonJS/Babylon-Lite/pull/941))
|
|
21
|
+
- **shadow:** compose CSM and ESM/PCF receivers in mixed scenes ([#937](https://github.com/BabylonJS/Babylon-Lite/pull/937))
|
|
22
|
+
|
|
23
|
+
### 🧪 Tests
|
|
24
|
+
|
|
25
|
+
- **gl:** guard against import cycles in the shipped dist ([#942](https://github.com/BabylonJS/Babylon-Lite/pull/942))
|
|
26
|
+
|
|
27
|
+
**Full Changelog**: https://github.com/BabylonJS/Babylon-Lite/compare/npm-lite-gl-v1.24.0...npm-lite-gl-v1.24.1
|
|
28
|
+
|
|
3
29
|
## @babylonjs/lite-gl v1.24.0
|
|
4
30
|
|
|
5
31
|
### ✨ Features
|
package/README.md
CHANGED
|
@@ -9,8 +9,7 @@ bundler keeps only what you import.
|
|
|
9
9
|
It is a focused subset of Babylon.js' rendering primitives, validated to render
|
|
10
10
|
**near-identically** (within ±1–2 LSB ANGLE / SwiftShader codegen noise) to
|
|
11
11
|
Babylon's `ThinEngine` / `EffectRenderer` / `SpriteRenderer` / `HtmlElementTexture`
|
|
12
|
-
path — every feature has a side-by-side parity scene in `tests/gl/parity
|
|
13
|
-
downstream, the NeonBrush effect suite). Swapping `@babylonjs/core` for lite-gl
|
|
12
|
+
path — every feature has a side-by-side parity scene in `tests/gl/parity/`. Swapping `@babylonjs/core` for lite-gl
|
|
14
13
|
typically shrinks an effect's shipped bundle **~10–16×** (≈4–6 KB gzip vs
|
|
15
14
|
≈40–80 KB).
|
|
16
15
|
|
|
@@ -138,7 +137,8 @@ so code can be written once for either backend
|
|
|
138
137
|
- **Engine / lifecycle** — `createGLEngine`, `disposeGLEngine`, `resizeGLEngine`,
|
|
139
138
|
`getRenderWidth`, `getRenderHeight`, `get/setHardwareScalingLevel`,
|
|
140
139
|
`getRenderingCanvas`, and `on/offContextLost` + `on/offContextRestored`
|
|
141
|
-
(context-loss is handled: effects and textures are rebuilt on restore
|
|
140
|
+
(context-loss is handled: effects and textures are rebuilt on restore;
|
|
141
|
+
`createHostOwnedGLEngine` opts out for hosts that recreate everything themselves).
|
|
142
142
|
- **Render loop** — `runRenderLoop`, `stopRenderLoop`, plus `beginFrame` /
|
|
143
143
|
`endFrame` for hosts that drive their own frame.
|
|
144
144
|
- **GPU frame timing (optional)** — `captureGPUFrameTime`,
|
|
@@ -184,7 +184,8 @@ so code can be written once for either backend
|
|
|
184
184
|
`readRenderTargetPixelsToBuffer` (same, into a `PIXEL_PACK_BUFFER` at a byte
|
|
185
185
|
`offset`), `disposeRenderTarget`.
|
|
186
186
|
- **Meshes / buffers** — `createVertexBuffer`, `updateVertexBuffer`,
|
|
187
|
-
`createIndexBuffer`, `bindAttributes
|
|
187
|
+
`createIndexBuffer`, `bindAttributes` (or `bindAttributesCached` to elide unchanged
|
|
188
|
+
pointers and divisors when rebinding every draw), `drawIndexed` (instanced), `disposeBuffer`.
|
|
188
189
|
- **Depth / stencil / scissor** — `setDepthState`, `setStencilState`,
|
|
189
190
|
`setStencilOpSeparate` (independent front/back operations), `setCullState`,
|
|
190
191
|
`setColorMask`, `clearEngine`; `setScissor`, `disableScissor`.
|
package/blend.d.ts
CHANGED
|
@@ -98,7 +98,7 @@ export declare function setBlendMode(engine: GLEngineContext, mode: GLBlendMode)
|
|
|
98
98
|
* `setAlphaBlendFunctionParameters` + `setAlphaEquationParameters`.
|
|
99
99
|
*
|
|
100
100
|
* Supports every WebGL2 blend equation, including `MIN`, `MAX`,
|
|
101
|
-
* `FUNC_SUBTRACT` and `FUNC_REVERSE_SUBTRACT` (
|
|
101
|
+
* `FUNC_SUBTRACT` and `FUNC_REVERSE_SUBTRACT` (e.g. for darken /
|
|
102
102
|
* cutout blend modes). Records the desired config (flushed by `applyGLStates`
|
|
103
103
|
* before the next draw); at flush time the enable flag, the equation and the func
|
|
104
104
|
* are each cached independently, so a redundant state is fully elided and only
|
package/blend.js
CHANGED
|
@@ -77,7 +77,7 @@ export function setBlendMode(engine, mode) {
|
|
|
77
77
|
* `setAlphaBlendFunctionParameters` + `setAlphaEquationParameters`.
|
|
78
78
|
*
|
|
79
79
|
* Supports every WebGL2 blend equation, including `MIN`, `MAX`,
|
|
80
|
-
* `FUNC_SUBTRACT` and `FUNC_REVERSE_SUBTRACT` (
|
|
80
|
+
* `FUNC_SUBTRACT` and `FUNC_REVERSE_SUBTRACT` (e.g. for darken /
|
|
81
81
|
* cutout blend modes). Records the desired config (flushed by `applyGLStates`
|
|
82
82
|
* before the next draw); at flush time the enable flag, the equation and the func
|
|
83
83
|
* are each cached independently, so a redundant state is fully elided and only
|
package/blend.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blend.js","sourceRoot":"","sources":["../src/blend.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE9J;;;GAGG;AACH,MAAM,CAA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AAC;AACL,CAAC","sourcesContent":["/**\n * Blend-mode state — the WebGL counterpart of Babylon's `Engine.setAlphaMode`\n * (presets) and `AlphaState.setAlphaBlendFunctionParameters` /\n * `setAlphaEquationParameters` (the arbitrary separate func + equation path).\n *\n * The numeric {@link GLBlendMode} values intentionally match Babylon's\n * `Constants.ALPHA_*` (`ALPHA_DISABLE = 0`, `ALPHA_ADD = 1`, `ALPHA_COMBINE = 2`,\n * `ALPHA_PREMULTIPLIED = 7`) so a consumer can forward raw Babylon constants\n * without a translation table.\n *\n * DEFERRED MODEL (matches Babylon's `AlphaState`): these setters do NOT touch\n * `gl.*`. They record only the DESIRED blend config into the `d*` mirror fields\n * of `GLState` and raise `statesDirty`; `applyGLStates` (apply-states.ts) flushes\n * the diff to GL right before each draw / clear. Setting blend A then B then A\n * with no draw in between therefore applies exactly one blend state (A), and a\n * blend left unchanged across frames re-issues nothing.\n *\n * Both {@link setBlendMode} and {@link setBlendState} feed the same desired\n * fields, so the preset and arbitrary paths can never desync.\n */\nimport { type GLEngineContext } from \"./context.js\";\nimport { RS_BLEND_DST_A, RS_BLEND_DST_RGB, RS_BLEND_ENABLED, RS_BLEND_EQ_A, RS_BLEND_EQ_RGB, RS_BLEND_SRC_A, RS_BLEND_SRC_RGB, RS_DESIRED } from \"./state.js\";\n\n/**\n * Supported blend presets. Values mirror Babylon's `Constants.ALPHA_*` so the\n * raw Babylon integers can be passed straight through.\n */\nexport const GLBlendMode = {\n /** No blending — `gl.disable(gl.BLEND)`. (`Constants.ALPHA_DISABLE`) */\n DISABLE: 0,\n /** Additive — `blendFuncSeparate(SRC_ALPHA, ONE, ZERO, ONE)`. (`Constants.ALPHA_ADD`) */\n ADD: 1,\n /** Standard (non-premultiplied) alpha — `blendFuncSeparate(SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ONE, ONE)`. (`Constants.ALPHA_COMBINE`) */\n ALPHA: 2,\n /** Premultiplied alpha — `blendFuncSeparate(ONE, ONE_MINUS_SRC_ALPHA, ONE, ONE)`. (`Constants.ALPHA_PREMULTIPLIED`) */\n PREMULTIPLIED: 7,\n} as const;\n\n/** One of the {@link GLBlendMode} preset values (`0`, `1`, `2` or `7`). */\nexport type GLBlendMode = (typeof GLBlendMode)[keyof typeof GLBlendMode];\n\n/**\n * Blend equation presets — the values WebGL2 accepts for\n * `gl.blendEquationSeparate`. Numeric values equal the GL enums so raw GL\n * integers (or Babylon's identical `Constants.GL_ALPHA_EQUATION_*`) pass\n * straight through.\n */\nexport const GLBlendEquation = {\n /** `src + dst` (the GL default). */\n ADD: 0x8006,\n /** `src - dst`. */\n SUBTRACT: 0x800a,\n /** `dst - src`. */\n REVERSE_SUBTRACT: 0x800b,\n /** `min(src, dst)`. */\n MIN: 0x8007,\n /** `max(src, dst)`. */\n MAX: 0x8008,\n} as const;\n\n/** One of the {@link GLBlendEquation} preset values. */\nexport type GLBlendEquation = (typeof GLBlendEquation)[keyof typeof GLBlendEquation];\n\n/**\n * Arbitrary separate-channel blend configuration — the lite-gl equivalent of\n * Babylon's `AlphaState.setAlphaBlendFunctionParameters` +\n * `setAlphaEquationParameters`. All factor / equation fields are raw WebGL2\n * enums (`gl.ONE`, `gl.SRC_ALPHA`, `gl.MIN`, …); use {@link GLBlendEquation} for\n * the equations if you prefer named presets.\n */\nexport interface GLBlendState {\n /** RGB source factor (`gl.blendFuncSeparate` arg 1). */\n srcRGB: GLenum;\n /** RGB destination factor (`gl.blendFuncSeparate` arg 2). */\n dstRGB: GLenum;\n /** Alpha source factor (`gl.blendFuncSeparate` arg 3). */\n srcAlpha: GLenum;\n /** Alpha destination factor (`gl.blendFuncSeparate` arg 4). */\n dstAlpha: GLenum;\n /** RGB blend equation. Defaults to `FUNC_ADD`. */\n equationRGB?: GLenum;\n /** Alpha blend equation. Defaults to `FUNC_ADD`. */\n equationAlpha?: GLenum;\n}\n\n/** GL `FUNC_ADD` — the implicit equation used by the {@link GLBlendMode}\n * presets (matching Babylon's `setAlphaMode`, which leaves it at the default). */\nconst FUNC_ADD = 0x8006;\n/** GL `gl.BLEND`. */\nconst BLEND = 0x0be2;\n\n/**\n * Set the GL blend state to match Babylon's `setAlphaMode(mode)` exactly.\n *\n * | Mode | `gl.blendFuncSeparate(srcRGB, dstRGB, srcA, dstA)` |\n * |--------------------|------------------------------------------------------------|\n * | `DISABLE` (0) | — (`gl.disable(gl.BLEND)`) |\n * | `ADD` (1) | `SRC_ALPHA, ONE, ZERO, ONE` |\n * | `ALPHA` (2) | `SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ONE, ONE` |\n * | `PREMULTIPLIED` (7)| `ONE, ONE_MINUS_SRC_ALPHA, ONE, ONE` |\n *\n * No-op when the context is lost or disposed.\n *\n * @param engine - The engine whose GL blend state is updated.\n * @param mode - The {@link GLBlendMode} preset to apply.\n */\nexport function setBlendMode(engine: GLEngineContext, mode: GLBlendMode): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n switch (mode) {\n case GLBlendMode.DISABLE:\n disableBlend(engine);\n return;\n case GLBlendMode.ADD:\n applyBlend(engine, gl.SRC_ALPHA, gl.ONE, gl.ZERO, gl.ONE, FUNC_ADD, FUNC_ADD);\n return;\n case GLBlendMode.ALPHA:\n applyBlend(engine, gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE, FUNC_ADD, FUNC_ADD);\n return;\n case GLBlendMode.PREMULTIPLIED:\n applyBlend(engine, gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE, FUNC_ADD, FUNC_ADD);\n return;\n }\n}\n\n/**\n * Enable blending with an arbitrary separate-channel function and equation —\n * the lite-gl equivalent of Babylon's `AlphaState` with\n * `setAlphaBlendFunctionParameters` + `setAlphaEquationParameters`.\n *\n * Supports every WebGL2 blend equation, including `MIN`, `MAX`,\n * `FUNC_SUBTRACT` and `FUNC_REVERSE_SUBTRACT` (used by ShapeBuilder's darken /\n * cutout blend modes). Records the desired config (flushed by `applyGLStates`\n * before the next draw); at flush time the enable flag, the equation and the func\n * are each cached independently, so a redundant state is fully elided and only\n * the call whose params changed is re-issued — mirroring Babylon's `AlphaState`\n * dirty flags. Because GL keeps the equation + func across `gl.disable(BLEND)`,\n * re-enabling with unchanged params re-issues neither.\n *\n * No-op when the context is lost or disposed.\n *\n * @param engine - The engine whose desired blend state is updated.\n * @param state - The separate-channel blend factors + equations to apply.\n */\nexport function setBlendState(engine: GLEngineContext, state: GLBlendState): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n applyBlend(engine, state.srcRGB, state.dstRGB, state.srcAlpha, state.dstAlpha, state.equationRGB ?? FUNC_ADD, state.equationAlpha ?? FUNC_ADD);\n}\n\n/**\n * Disable blending — the equivalent of Babylon's `AlphaState.alphaBlend = false`.\n * Records the desired \"blend off\" state (flushed by `applyGLStates` before the\n * next draw); the actual `gl.disable(gl.BLEND)` is elided when blending is\n * already off at flush time. No-op when the context is lost or disposed.\n *\n * @param engine - The engine whose desired blend state is updated.\n */\nexport function disableBlend(engine: GLEngineContext): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n s.rs[RS_BLEND_ENABLED + RS_DESIRED] = 0;\n s._flushBlend = flushBlend;\n s.statesDirty = true;\n}\n\n/* ──────────────────────────── internal apply ──────────────────────────── */\n\n/** Record a granular blend config into the DESIRED (`rs[RS_* + RS_DESIRED]`)\n * slots and mark it dirty. No `gl.*` here — `applyGLStates` reconciles\n * desired→actual at the next flush, caching the enable flag, equation and func\n * independently so each is re-issued only when its params change (and never on a\n * bare re-enable). */\nfunction applyBlend(engine: GLEngineContext, srcRGB: number, dstRGB: number, srcAlpha: number, dstAlpha: number, eqRGB: number, eqAlpha: number): void {\n const rs = engine._state.rs;\n rs[RS_BLEND_ENABLED + RS_DESIRED] = 1;\n rs[RS_BLEND_SRC_RGB + RS_DESIRED] = srcRGB;\n rs[RS_BLEND_DST_RGB + RS_DESIRED] = dstRGB;\n rs[RS_BLEND_SRC_A + RS_DESIRED] = srcAlpha;\n rs[RS_BLEND_DST_A + RS_DESIRED] = dstAlpha;\n rs[RS_BLEND_EQ_RGB + RS_DESIRED] = eqRGB;\n rs[RS_BLEND_EQ_A + RS_DESIRED] = eqAlpha;\n engine._state._flushBlend = flushBlend;\n engine._state.statesDirty = true;\n}\n\n/**\n * Reconcile the deferred blend state DESIRED → ACTUAL — the per-category half of\n * Babylon's `_alphaState.apply`. Installed onto `_state._flushBlend` by the blend\n * setters and dispatched by {@link applyGLStates}; co-located here so a scene that\n * never sets a blend mode tree-shakes both this reconciler and its GL code out of\n * the bundle.\n *\n * The enable flag, the equation and the func are reconciled as THREE independent\n * cached sub-states (mirroring Babylon's `_AlphaState` `_isAlphaBlendDirty` /\n * `_isBlendEquationParametersDirty` / `_isBlendFunctionParametersDirty`). GL\n * retains the blend equation + func across `gl.disable(BLEND)`, so their cached\n * actual values stay valid while blending is off — re-enabling with unchanged\n * params therefore issues ONLY `gl.enable(BLEND)` and re-issues neither\n * `blendEquationSeparate` nor `blendFuncSeparate`. A desired `-1` (never\n * requested) leaves GL untouched. @internal\n */\nfunction flushBlend(engine: GLEngineContext): void {\n const gl = engine.gl;\n const rs = engine._state.rs;\n const dBlend = rs[RS_BLEND_ENABLED + RS_DESIRED]!;\n if (dBlend === -1) {\n return;\n }\n // 1. enable / disable — independent of the func + equation cache below.\n if (dBlend !== rs[RS_BLEND_ENABLED]) {\n rs[RS_BLEND_ENABLED] = dBlend;\n if (dBlend === 1) {\n gl.enable(BLEND);\n } else {\n gl.disable(BLEND);\n }\n }\n // While blending is off the equation/func are not observable and GL keeps the\n // last values, so leave their cache untouched (Babylon does the same) — the\n // next enable with identical params then re-issues nothing.\n if (dBlend !== 1) {\n return;\n }\n // 2. equation — re-issued only when the params actually changed.\n const eqRGB = rs[RS_BLEND_EQ_RGB + RS_DESIRED]!;\n const eqA = rs[RS_BLEND_EQ_A + RS_DESIRED]!;\n if (rs[RS_BLEND_EQ_RGB] !== eqRGB || rs[RS_BLEND_EQ_A] !== eqA) {\n gl.blendEquationSeparate(eqRGB, eqA);\n rs[RS_BLEND_EQ_RGB] = eqRGB;\n rs[RS_BLEND_EQ_A] = eqA;\n }\n // 3. func — re-issued only when the params actually changed.\n const srcRGB = rs[RS_BLEND_SRC_RGB + RS_DESIRED]!;\n const dstRGB = rs[RS_BLEND_DST_RGB + RS_DESIRED]!;\n const srcA = rs[RS_BLEND_SRC_A + RS_DESIRED]!;\n const dstA = rs[RS_BLEND_DST_A + RS_DESIRED]!;\n if (rs[RS_BLEND_SRC_RGB] !== srcRGB || rs[RS_BLEND_DST_RGB] !== dstRGB || rs[RS_BLEND_SRC_A] !== srcA || rs[RS_BLEND_DST_A] !== dstA) {\n gl.blendFuncSeparate(srcRGB, dstRGB, srcA, dstA);\n rs[RS_BLEND_SRC_RGB] = srcRGB;\n rs[RS_BLEND_DST_RGB] = dstRGB;\n rs[RS_BLEND_SRC_A] = srcA;\n rs[RS_BLEND_DST_A] = dstA;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"blend.js","sourceRoot":"","sources":["../src/blend.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE9J;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,wEAAwE;IACxE,OAAO,EAAE,CAAC;IACV,yFAAyF;IACzF,GAAG,EAAE,CAAC;IACN,sIAAsI;IACtI,KAAK,EAAE,CAAC;IACR,uHAAuH;IACvH,aAAa,EAAE,CAAC;CACV,CAAC;AAKX;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC3B,oCAAoC;IACpC,GAAG,EAAE,MAAM;IACX,mBAAmB;IACnB,QAAQ,EAAE,MAAM;IAChB,mBAAmB;IACnB,gBAAgB,EAAE,MAAM;IACxB,uBAAuB;IACvB,GAAG,EA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G,KAAK,CAAC;QAC5B,EAAE,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC;IAC5B,CAAC;IACD,6DAA6D;IAC7D,MAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,GAAG,UAAU,CAAE,CAAC;IAClD,MAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,GAAG,UAAU,CAAE,CAAC;IAClD,MAAM,IAAI,GAAG,EAAE,CAAC,cAAc,GAAG,UAAU,CAAE,CAAC;IAC9C,MAAM,IAAI,GAAG,EAAE,CAAC,cAAc,GAAG,UAAU,CAAE,CAAC;IAC9C,IAAI,EAAE,CAAC,gBAAgB,CAAC,KAAK,MAAM,IAAI,EAAE,CAAC,gBAAgB,CAAC,KAAK,MAAM,IAAI,EAAE,CAAC,cAAc,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC,cAAc,CAAC,KAAK,IAAI,EAAE,CAAC;QACnI,EAAE,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACjD,EAAE,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAAC;QAC9B,EAAE,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAAC;QAC9B,EAAE,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;QAC1B,EAAE,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IAC9B,CAAC;AACL,CAAC","sourcesContent":["/**\n * Blend-mode state — the WebGL counterpart of Babylon's `Engine.setAlphaMode`\n * (presets) and `AlphaState.setAlphaBlendFunctionParameters` /\n * `setAlphaEquationParameters` (the arbitrary separate func + equation path).\n *\n * The numeric {@link GLBlendMode} values intentionally match Babylon's\n * `Constants.ALPHA_*` (`ALPHA_DISABLE = 0`, `ALPHA_ADD = 1`, `ALPHA_COMBINE = 2`,\n * `ALPHA_PREMULTIPLIED = 7`) so a consumer can forward raw Babylon constants\n * without a translation table.\n *\n * DEFERRED MODEL (matches Babylon's `AlphaState`): these setters do NOT touch\n * `gl.*`. They record only the DESIRED blend config into the `d*` mirror fields\n * of `GLState` and raise `statesDirty`; `applyGLStates` (apply-states.ts) flushes\n * the diff to GL right before each draw / clear. Setting blend A then B then A\n * with no draw in between therefore applies exactly one blend state (A), and a\n * blend left unchanged across frames re-issues nothing.\n *\n * Both {@link setBlendMode} and {@link setBlendState} feed the same desired\n * fields, so the preset and arbitrary paths can never desync.\n */\nimport { type GLEngineContext } from \"./context.js\";\nimport { RS_BLEND_DST_A, RS_BLEND_DST_RGB, RS_BLEND_ENABLED, RS_BLEND_EQ_A, RS_BLEND_EQ_RGB, RS_BLEND_SRC_A, RS_BLEND_SRC_RGB, RS_DESIRED } from \"./state.js\";\n\n/**\n * Supported blend presets. Values mirror Babylon's `Constants.ALPHA_*` so the\n * raw Babylon integers can be passed straight through.\n */\nexport const GLBlendMode = {\n /** No blending — `gl.disable(gl.BLEND)`. (`Constants.ALPHA_DISABLE`) */\n DISABLE: 0,\n /** Additive — `blendFuncSeparate(SRC_ALPHA, ONE, ZERO, ONE)`. (`Constants.ALPHA_ADD`) */\n ADD: 1,\n /** Standard (non-premultiplied) alpha — `blendFuncSeparate(SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ONE, ONE)`. (`Constants.ALPHA_COMBINE`) */\n ALPHA: 2,\n /** Premultiplied alpha — `blendFuncSeparate(ONE, ONE_MINUS_SRC_ALPHA, ONE, ONE)`. (`Constants.ALPHA_PREMULTIPLIED`) */\n PREMULTIPLIED: 7,\n} as const;\n\n/** One of the {@link GLBlendMode} preset values (`0`, `1`, `2` or `7`). */\nexport type GLBlendMode = (typeof GLBlendMode)[keyof typeof GLBlendMode];\n\n/**\n * Blend equation presets — the values WebGL2 accepts for\n * `gl.blendEquationSeparate`. Numeric values equal the GL enums so raw GL\n * integers (or Babylon's identical `Constants.GL_ALPHA_EQUATION_*`) pass\n * straight through.\n */\nexport const GLBlendEquation = {\n /** `src + dst` (the GL default). */\n ADD: 0x8006,\n /** `src - dst`. */\n SUBTRACT: 0x800a,\n /** `dst - src`. */\n REVERSE_SUBTRACT: 0x800b,\n /** `min(src, dst)`. */\n MIN: 0x8007,\n /** `max(src, dst)`. */\n MAX: 0x8008,\n} as const;\n\n/** One of the {@link GLBlendEquation} preset values. */\nexport type GLBlendEquation = (typeof GLBlendEquation)[keyof typeof GLBlendEquation];\n\n/**\n * Arbitrary separate-channel blend configuration — the lite-gl equivalent of\n * Babylon's `AlphaState.setAlphaBlendFunctionParameters` +\n * `setAlphaEquationParameters`. All factor / equation fields are raw WebGL2\n * enums (`gl.ONE`, `gl.SRC_ALPHA`, `gl.MIN`, …); use {@link GLBlendEquation} for\n * the equations if you prefer named presets.\n */\nexport interface GLBlendState {\n /** RGB source factor (`gl.blendFuncSeparate` arg 1). */\n srcRGB: GLenum;\n /** RGB destination factor (`gl.blendFuncSeparate` arg 2). */\n dstRGB: GLenum;\n /** Alpha source factor (`gl.blendFuncSeparate` arg 3). */\n srcAlpha: GLenum;\n /** Alpha destination factor (`gl.blendFuncSeparate` arg 4). */\n dstAlpha: GLenum;\n /** RGB blend equation. Defaults to `FUNC_ADD`. */\n equationRGB?: GLenum;\n /** Alpha blend equation. Defaults to `FUNC_ADD`. */\n equationAlpha?: GLenum;\n}\n\n/** GL `FUNC_ADD` — the implicit equation used by the {@link GLBlendMode}\n * presets (matching Babylon's `setAlphaMode`, which leaves it at the default). */\nconst FUNC_ADD = 0x8006;\n/** GL `gl.BLEND`. */\nconst BLEND = 0x0be2;\n\n/**\n * Set the GL blend state to match Babylon's `setAlphaMode(mode)` exactly.\n *\n * | Mode | `gl.blendFuncSeparate(srcRGB, dstRGB, srcA, dstA)` |\n * |--------------------|------------------------------------------------------------|\n * | `DISABLE` (0) | — (`gl.disable(gl.BLEND)`) |\n * | `ADD` (1) | `SRC_ALPHA, ONE, ZERO, ONE` |\n * | `ALPHA` (2) | `SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ONE, ONE` |\n * | `PREMULTIPLIED` (7)| `ONE, ONE_MINUS_SRC_ALPHA, ONE, ONE` |\n *\n * No-op when the context is lost or disposed.\n *\n * @param engine - The engine whose GL blend state is updated.\n * @param mode - The {@link GLBlendMode} preset to apply.\n */\nexport function setBlendMode(engine: GLEngineContext, mode: GLBlendMode): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n switch (mode) {\n case GLBlendMode.DISABLE:\n disableBlend(engine);\n return;\n case GLBlendMode.ADD:\n applyBlend(engine, gl.SRC_ALPHA, gl.ONE, gl.ZERO, gl.ONE, FUNC_ADD, FUNC_ADD);\n return;\n case GLBlendMode.ALPHA:\n applyBlend(engine, gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE, FUNC_ADD, FUNC_ADD);\n return;\n case GLBlendMode.PREMULTIPLIED:\n applyBlend(engine, gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE, FUNC_ADD, FUNC_ADD);\n return;\n }\n}\n\n/**\n * Enable blending with an arbitrary separate-channel function and equation —\n * the lite-gl equivalent of Babylon's `AlphaState` with\n * `setAlphaBlendFunctionParameters` + `setAlphaEquationParameters`.\n *\n * Supports every WebGL2 blend equation, including `MIN`, `MAX`,\n * `FUNC_SUBTRACT` and `FUNC_REVERSE_SUBTRACT` (e.g. for darken /\n * cutout blend modes). Records the desired config (flushed by `applyGLStates`\n * before the next draw); at flush time the enable flag, the equation and the func\n * are each cached independently, so a redundant state is fully elided and only\n * the call whose params changed is re-issued — mirroring Babylon's `AlphaState`\n * dirty flags. Because GL keeps the equation + func across `gl.disable(BLEND)`,\n * re-enabling with unchanged params re-issues neither.\n *\n * No-op when the context is lost or disposed.\n *\n * @param engine - The engine whose desired blend state is updated.\n * @param state - The separate-channel blend factors + equations to apply.\n */\nexport function setBlendState(engine: GLEngineContext, state: GLBlendState): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n applyBlend(engine, state.srcRGB, state.dstRGB, state.srcAlpha, state.dstAlpha, state.equationRGB ?? FUNC_ADD, state.equationAlpha ?? FUNC_ADD);\n}\n\n/**\n * Disable blending — the equivalent of Babylon's `AlphaState.alphaBlend = false`.\n * Records the desired \"blend off\" state (flushed by `applyGLStates` before the\n * next draw); the actual `gl.disable(gl.BLEND)` is elided when blending is\n * already off at flush time. No-op when the context is lost or disposed.\n *\n * @param engine - The engine whose desired blend state is updated.\n */\nexport function disableBlend(engine: GLEngineContext): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n s.rs[RS_BLEND_ENABLED + RS_DESIRED] = 0;\n s._flushBlend = flushBlend;\n s.statesDirty = true;\n}\n\n/* ──────────────────────────── internal apply ──────────────────────────── */\n\n/** Record a granular blend config into the DESIRED (`rs[RS_* + RS_DESIRED]`)\n * slots and mark it dirty. No `gl.*` here — `applyGLStates` reconciles\n * desired→actual at the next flush, caching the enable flag, equation and func\n * independently so each is re-issued only when its params change (and never on a\n * bare re-enable). */\nfunction applyBlend(engine: GLEngineContext, srcRGB: number, dstRGB: number, srcAlpha: number, dstAlpha: number, eqRGB: number, eqAlpha: number): void {\n const rs = engine._state.rs;\n rs[RS_BLEND_ENABLED + RS_DESIRED] = 1;\n rs[RS_BLEND_SRC_RGB + RS_DESIRED] = srcRGB;\n rs[RS_BLEND_DST_RGB + RS_DESIRED] = dstRGB;\n rs[RS_BLEND_SRC_A + RS_DESIRED] = srcAlpha;\n rs[RS_BLEND_DST_A + RS_DESIRED] = dstAlpha;\n rs[RS_BLEND_EQ_RGB + RS_DESIRED] = eqRGB;\n rs[RS_BLEND_EQ_A + RS_DESIRED] = eqAlpha;\n engine._state._flushBlend = flushBlend;\n engine._state.statesDirty = true;\n}\n\n/**\n * Reconcile the deferred blend state DESIRED → ACTUAL — the per-category half of\n * Babylon's `_alphaState.apply`. Installed onto `_state._flushBlend` by the blend\n * setters and dispatched by {@link applyGLStates}; co-located here so a scene that\n * never sets a blend mode tree-shakes both this reconciler and its GL code out of\n * the bundle.\n *\n * The enable flag, the equation and the func are reconciled as THREE independent\n * cached sub-states (mirroring Babylon's `_AlphaState` `_isAlphaBlendDirty` /\n * `_isBlendEquationParametersDirty` / `_isBlendFunctionParametersDirty`). GL\n * retains the blend equation + func across `gl.disable(BLEND)`, so their cached\n * actual values stay valid while blending is off — re-enabling with unchanged\n * params therefore issues ONLY `gl.enable(BLEND)` and re-issues neither\n * `blendEquationSeparate` nor `blendFuncSeparate`. A desired `-1` (never\n * requested) leaves GL untouched. @internal\n */\nfunction flushBlend(engine: GLEngineContext): void {\n const gl = engine.gl;\n const rs = engine._state.rs;\n const dBlend = rs[RS_BLEND_ENABLED + RS_DESIRED]!;\n if (dBlend === -1) {\n return;\n }\n // 1. enable / disable — independent of the func + equation cache below.\n if (dBlend !== rs[RS_BLEND_ENABLED]) {\n rs[RS_BLEND_ENABLED] = dBlend;\n if (dBlend === 1) {\n gl.enable(BLEND);\n } else {\n gl.disable(BLEND);\n }\n }\n // While blending is off the equation/func are not observable and GL keeps the\n // last values, so leave their cache untouched (Babylon does the same) — the\n // next enable with identical params then re-issues nothing.\n if (dBlend !== 1) {\n return;\n }\n // 2. equation — re-issued only when the params actually changed.\n const eqRGB = rs[RS_BLEND_EQ_RGB + RS_DESIRED]!;\n const eqA = rs[RS_BLEND_EQ_A + RS_DESIRED]!;\n if (rs[RS_BLEND_EQ_RGB] !== eqRGB || rs[RS_BLEND_EQ_A] !== eqA) {\n gl.blendEquationSeparate(eqRGB, eqA);\n rs[RS_BLEND_EQ_RGB] = eqRGB;\n rs[RS_BLEND_EQ_A] = eqA;\n }\n // 3. func — re-issued only when the params actually changed.\n const srcRGB = rs[RS_BLEND_SRC_RGB + RS_DESIRED]!;\n const dstRGB = rs[RS_BLEND_DST_RGB + RS_DESIRED]!;\n const srcA = rs[RS_BLEND_SRC_A + RS_DESIRED]!;\n const dstA = rs[RS_BLEND_DST_A + RS_DESIRED]!;\n if (rs[RS_BLEND_SRC_RGB] !== srcRGB || rs[RS_BLEND_DST_RGB] !== dstRGB || rs[RS_BLEND_SRC_A] !== srcA || rs[RS_BLEND_DST_A] !== dstA) {\n gl.blendFuncSeparate(srcRGB, dstRGB, srcA, dstA);\n rs[RS_BLEND_SRC_RGB] = srcRGB;\n rs[RS_BLEND_DST_RGB] = dstRGB;\n rs[RS_BLEND_SRC_A] = srcA;\n rs[RS_BLEND_DST_A] = dstA;\n }\n}\n"]}
|
package/context.d.ts
CHANGED
|
@@ -71,8 +71,30 @@ export interface GLEngineContext {
|
|
|
71
71
|
/** Acquire a WebGL2 context on the canvas and build the pure-state handle.
|
|
72
72
|
* Accepts an `HTMLCanvasElement` or an `OffscreenCanvas` (worker render paths —
|
|
73
73
|
* e.g. the Lottie player — which size the drawing buffer via `setGLEngineSize`).
|
|
74
|
-
* Throws if WebGL2 is unsupported.
|
|
74
|
+
* Throws if WebGL2 is unsupported. Resources recover automatically after
|
|
75
|
+
* context loss; use `createHostOwnedGLEngine` when the host recreates instead. */
|
|
75
76
|
export declare function createGLEngine(canvas: HTMLCanvasElement | OffscreenCanvas, options?: GLEngineOptions): GLEngineContext;
|
|
77
|
+
/**
|
|
78
|
+
* Create an engine whose context-loss recovery is owned by the host, matching
|
|
79
|
+
* ThinEngine's `doNotHandleContextLost: true`. Same canvas/options contract as
|
|
80
|
+
* {@link createGLEngine}, except:
|
|
81
|
+
* - `webglcontextlost` still stops rendering, marks the engine lost and fires
|
|
82
|
+
* `onContextLost` callbacks, but never calls `preventDefault()`, so the
|
|
83
|
+
* browser does not restore the context; `onContextRestored` never fires;
|
|
84
|
+
* - resources created on this engine retain no CPU replay sources (buffer
|
|
85
|
+
* data, texture pixels, sprite indices) and install no restore hooks,
|
|
86
|
+
* saving memory. Effects still keep their public `options` (including the
|
|
87
|
+
* shader sources) and source-derived cache key, which serve readiness
|
|
88
|
+
* diagnostics and effect deduplication rather than replay.
|
|
89
|
+
*
|
|
90
|
+
* After a loss the engine stays lost: dispose it and recreate the engine and
|
|
91
|
+
* every resource (on a fresh canvas or once the host has a new context).
|
|
92
|
+
*
|
|
93
|
+
* @param canvas - An `HTMLCanvasElement` or `OffscreenCanvas`.
|
|
94
|
+
* @param options - WebGL2 context attributes, as for {@link createGLEngine}.
|
|
95
|
+
* @returns The engine. Throws if WebGL2 is unsupported.
|
|
96
|
+
*/
|
|
97
|
+
export declare function createHostOwnedGLEngine(canvas: HTMLCanvasElement | OffscreenCanvas, options?: GLEngineOptions): GLEngineContext;
|
|
76
98
|
/** Stops the render loop, removes DOM listeners, releases all known effects
|
|
77
99
|
* and textures, then marks the context disposed. The browser-owned canvas
|
|
78
100
|
* is left intact. */
|
|
@@ -106,11 +128,31 @@ export declare function setGLEngineSize(engine: GLEngineContext, width: number,
|
|
|
106
128
|
* skip the state changes needed to re-establish the scope, producing corrupted
|
|
107
129
|
* output. Owned GPU resources (the shared quad, render targets, meshes,
|
|
108
130
|
* effects, textures) are preserved — only the cached "current GL state" is
|
|
109
|
-
* reset. Mirrors Babylon's `Engine.wipeCaches()`.
|
|
131
|
+
* reset. Mirrors Babylon's `Engine.wipeCaches(bruteForce)`.
|
|
132
|
+
*
|
|
133
|
+
* After a wipe the VAO / framebuffer bindings are UNKNOWN (not assumed to be
|
|
134
|
+
* the defaults), so the next mesh / render-target call rebinds them even if the
|
|
135
|
+
* host left its own objects bound. The current program is forgotten: call
|
|
136
|
+
* `useEffect` again before drawing.
|
|
137
|
+
*
|
|
138
|
+
* `bruteForce` additionally normalizes, with raw GL calls, state lite-gl relies
|
|
139
|
+
* on but never caches, back to WebGL2 defaults: the default VAO with every
|
|
140
|
+
* vertex attribute array disabled, sampler objects unbound from every texture
|
|
141
|
+
* unit, no `PIXEL_PACK` / `PIXEL_UNPACK` buffer, zero pack / unpack row and
|
|
142
|
+
* skip layout, browser-default unpack colorspace conversion, `frontFace(CCW)`,
|
|
143
|
+
* `depthRange(0, 1)`, `clearDepth(1)`, `clearStencil(0)`, `blendColor(0, 0, 0, 0)`
|
|
144
|
+
* and `POLYGON_OFFSET_FILL` / `RASTERIZER_DISCARD` / `SAMPLE_COVERAGE` /
|
|
145
|
+
* `SAMPLE_ALPHA_TO_COVERAGE` disabled. Use it when the host may leave arbitrary
|
|
146
|
+
* state behind (it costs roughly `MAX_VERTEX_ATTRIBS + maxTextureUnits + 20`
|
|
147
|
+
* GL calls); per-draw hand-offs with a known host should prefer the plain wipe
|
|
148
|
+
* plus targeted resets.
|
|
110
149
|
*
|
|
111
150
|
* No-op while the context is lost or the engine is disposed.
|
|
151
|
+
*
|
|
152
|
+
* @param engine - The engine.
|
|
153
|
+
* @param bruteForce - Also normalize untracked GL state (see above). Default `false`.
|
|
112
154
|
*/
|
|
113
|
-
export declare function wipeGLStateCache(engine: GLEngineContext): void;
|
|
155
|
+
export declare function wipeGLStateCache(engine: GLEngineContext, bruteForce?: boolean): void;
|
|
114
156
|
/** Drawing-buffer width in physical pixels (`canvas.width`). */
|
|
115
157
|
export declare function getRenderWidth(engine: GLEngineContext): number;
|
|
116
158
|
/** Drawing-buffer height in physical pixels (`canvas.height`). */
|
|
@@ -130,7 +172,8 @@ export declare function getRenderingCanvas(engine: GLEngineContext): HTMLCanvasE
|
|
|
130
172
|
export declare function onContextLost(engine: GLEngineContext, cb: () => void): void;
|
|
131
173
|
/** Remove a previously-registered context-lost callback. */
|
|
132
174
|
export declare function offContextLost(engine: GLEngineContext, cb: () => void): void;
|
|
133
|
-
/** Register
|
|
175
|
+
/** Register an automatic `webglcontextrestored` callback. Never fires on an
|
|
176
|
+
* engine from `createHostOwnedGLEngine`. Duplicate registrations are ignored. */
|
|
134
177
|
export declare function onContextRestored(engine: GLEngineContext, cb: () => void): void;
|
|
135
178
|
/** Remove a previously-registered context-restored callback. */
|
|
136
179
|
export declare function offContextRestored(engine: GLEngineContext, cb: () => void): void;
|
package/context.js
CHANGED
|
@@ -2,7 +2,8 @@ import { createGLState, resetGLState, resetGLStateCache } from "./state.js";
|
|
|
2
2
|
/** Acquire a WebGL2 context on the canvas and build the pure-state handle.
|
|
3
3
|
* Accepts an `HTMLCanvasElement` or an `OffscreenCanvas` (worker render paths —
|
|
4
4
|
* e.g. the Lottie player — which size the drawing buffer via `setGLEngineSize`).
|
|
5
|
-
* Throws if WebGL2 is unsupported.
|
|
5
|
+
* Throws if WebGL2 is unsupported. Resources recover automatically after
|
|
6
|
+
* context loss; use `createHostOwnedGLEngine` when the host recreates instead. */
|
|
6
7
|
export function createGLEngine(canvas, options) {
|
|
7
8
|
const o = options ?? {};
|
|
8
9
|
const attrs = {
|
|
@@ -39,17 +40,44 @@ export function createGLEngine(canvas, options) {
|
|
|
39
40
|
_onRestored: [],
|
|
40
41
|
_isLost: false,
|
|
41
42
|
_disposed: false,
|
|
42
|
-
_lostHandler: () =>
|
|
43
|
-
_restoredHandler: () =>
|
|
43
|
+
_lostHandler: (e) => handleContextLost(engine, e),
|
|
44
|
+
_restoredHandler: () => handleContextRestored(engine),
|
|
44
45
|
_wasLoopActive: false,
|
|
45
46
|
_scheduleFrame: null,
|
|
46
47
|
};
|
|
47
|
-
engine._lostHandler = (e) => handleContextLost(engine, e);
|
|
48
|
-
engine._restoredHandler = () => handleContextRestored(engine);
|
|
49
48
|
canvas.addEventListener("webglcontextlost", engine._lostHandler, false);
|
|
50
49
|
canvas.addEventListener("webglcontextrestored", engine._restoredHandler, false);
|
|
51
50
|
return engine;
|
|
52
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Create an engine whose context-loss recovery is owned by the host, matching
|
|
54
|
+
* ThinEngine's `doNotHandleContextLost: true`. Same canvas/options contract as
|
|
55
|
+
* {@link createGLEngine}, except:
|
|
56
|
+
* - `webglcontextlost` still stops rendering, marks the engine lost and fires
|
|
57
|
+
* `onContextLost` callbacks, but never calls `preventDefault()`, so the
|
|
58
|
+
* browser does not restore the context; `onContextRestored` never fires;
|
|
59
|
+
* - resources created on this engine retain no CPU replay sources (buffer
|
|
60
|
+
* data, texture pixels, sprite indices) and install no restore hooks,
|
|
61
|
+
* saving memory. Effects still keep their public `options` (including the
|
|
62
|
+
* shader sources) and source-derived cache key, which serve readiness
|
|
63
|
+
* diagnostics and effect deduplication rather than replay.
|
|
64
|
+
*
|
|
65
|
+
* After a loss the engine stays lost: dispose it and recreate the engine and
|
|
66
|
+
* every resource (on a fresh canvas or once the host has a new context).
|
|
67
|
+
*
|
|
68
|
+
* @param canvas - An `HTMLCanvasElement` or `OffscreenCanvas`.
|
|
69
|
+
* @param options - WebGL2 context attributes, as for {@link createGLEngine}.
|
|
70
|
+
* @returns The engine. Throws if WebGL2 is unsupported.
|
|
71
|
+
*/
|
|
72
|
+
export function createHostOwnedGLEngine(canvas, options) {
|
|
73
|
+
const engine = createGLEngine(canvas, options);
|
|
74
|
+
engine._noRestore = true;
|
|
75
|
+
canvas.removeEventListener("webglcontextlost", engine._lostHandler, false);
|
|
76
|
+
canvas.removeEventListener("webglcontextrestored", engine._restoredHandler, false);
|
|
77
|
+
engine._lostHandler = () => handleContextLost(engine);
|
|
78
|
+
canvas.addEventListener("webglcontextlost", engine._lostHandler, false);
|
|
79
|
+
return engine;
|
|
80
|
+
}
|
|
53
81
|
/** Stops the render loop, removes DOM listeners, releases all known effects
|
|
54
82
|
* and textures, then marks the context disposed. The browser-owned canvas
|
|
55
83
|
* is left intact. */
|
|
@@ -105,6 +133,7 @@ export function disposeGLEngine(engine) {
|
|
|
105
133
|
if (!buf._disposed) {
|
|
106
134
|
buf._disposed = true;
|
|
107
135
|
buf._deleteGpu(gl);
|
|
136
|
+
buf._data = buf._restore = undefined;
|
|
108
137
|
}
|
|
109
138
|
}
|
|
110
139
|
engine._buffers.length = 0;
|
|
@@ -175,21 +204,80 @@ export function setGLEngineSize(engine, width, height) {
|
|
|
175
204
|
* skip the state changes needed to re-establish the scope, producing corrupted
|
|
176
205
|
* output. Owned GPU resources (the shared quad, render targets, meshes,
|
|
177
206
|
* effects, textures) are preserved — only the cached "current GL state" is
|
|
178
|
-
* reset. Mirrors Babylon's `Engine.wipeCaches()`.
|
|
207
|
+
* reset. Mirrors Babylon's `Engine.wipeCaches(bruteForce)`.
|
|
208
|
+
*
|
|
209
|
+
* After a wipe the VAO / framebuffer bindings are UNKNOWN (not assumed to be
|
|
210
|
+
* the defaults), so the next mesh / render-target call rebinds them even if the
|
|
211
|
+
* host left its own objects bound. The current program is forgotten: call
|
|
212
|
+
* `useEffect` again before drawing.
|
|
213
|
+
*
|
|
214
|
+
* `bruteForce` additionally normalizes, with raw GL calls, state lite-gl relies
|
|
215
|
+
* on but never caches, back to WebGL2 defaults: the default VAO with every
|
|
216
|
+
* vertex attribute array disabled, sampler objects unbound from every texture
|
|
217
|
+
* unit, no `PIXEL_PACK` / `PIXEL_UNPACK` buffer, zero pack / unpack row and
|
|
218
|
+
* skip layout, browser-default unpack colorspace conversion, `frontFace(CCW)`,
|
|
219
|
+
* `depthRange(0, 1)`, `clearDepth(1)`, `clearStencil(0)`, `blendColor(0, 0, 0, 0)`
|
|
220
|
+
* and `POLYGON_OFFSET_FILL` / `RASTERIZER_DISCARD` / `SAMPLE_COVERAGE` /
|
|
221
|
+
* `SAMPLE_ALPHA_TO_COVERAGE` disabled. Use it when the host may leave arbitrary
|
|
222
|
+
* state behind (it costs roughly `MAX_VERTEX_ATTRIBS + maxTextureUnits + 20`
|
|
223
|
+
* GL calls); per-draw hand-offs with a known host should prefer the plain wipe
|
|
224
|
+
* plus targeted resets.
|
|
179
225
|
*
|
|
180
226
|
* No-op while the context is lost or the engine is disposed.
|
|
227
|
+
*
|
|
228
|
+
* @param engine - The engine.
|
|
229
|
+
* @param bruteForce - Also normalize untracked GL state (see above). Default `false`.
|
|
181
230
|
*/
|
|
182
|
-
export function wipeGLStateCache(engine) {
|
|
231
|
+
export function wipeGLStateCache(engine, bruteForce = false) {
|
|
183
232
|
if (engine._disposed || engine._isLost) {
|
|
184
233
|
return;
|
|
185
234
|
}
|
|
186
|
-
|
|
235
|
+
const s = engine._state;
|
|
236
|
+
resetGLStateCache(s);
|
|
237
|
+
// Brute force disables every attribute array below; a plain wipe leaves
|
|
238
|
+
// host-enabled arrays unknown (ThinEngine's `_mustWipeVertexAttributes`).
|
|
239
|
+
s._unknownAttribs = !bruteForce;
|
|
187
240
|
const invalidators = engine._stateCacheInvalidators;
|
|
188
241
|
if (invalidators) {
|
|
189
242
|
for (const invalidate of invalidators) {
|
|
190
243
|
invalidate();
|
|
191
244
|
}
|
|
192
245
|
}
|
|
246
|
+
if (bruteForce) {
|
|
247
|
+
const gl = engine.gl;
|
|
248
|
+
gl.bindVertexArray(null);
|
|
249
|
+
s.boundVao = null;
|
|
250
|
+
const attribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
251
|
+
for (let i = 0; i < attribs; i++) {
|
|
252
|
+
gl.disableVertexAttribArray(i);
|
|
253
|
+
}
|
|
254
|
+
for (let u = 0; u < s.boundTextures.length; u++) {
|
|
255
|
+
gl.bindSampler(u, null);
|
|
256
|
+
}
|
|
257
|
+
gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, null);
|
|
258
|
+
gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
|
|
259
|
+
for (const p of [
|
|
260
|
+
gl.UNPACK_ROW_LENGTH,
|
|
261
|
+
gl.UNPACK_IMAGE_HEIGHT,
|
|
262
|
+
gl.UNPACK_SKIP_PIXELS,
|
|
263
|
+
gl.UNPACK_SKIP_ROWS,
|
|
264
|
+
gl.UNPACK_SKIP_IMAGES,
|
|
265
|
+
gl.PACK_ROW_LENGTH,
|
|
266
|
+
gl.PACK_SKIP_PIXELS,
|
|
267
|
+
gl.PACK_SKIP_ROWS,
|
|
268
|
+
]) {
|
|
269
|
+
gl.pixelStorei(p, 0);
|
|
270
|
+
}
|
|
271
|
+
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.BROWSER_DEFAULT_WEBGL);
|
|
272
|
+
gl.frontFace(gl.CCW);
|
|
273
|
+
gl.depthRange(0, 1);
|
|
274
|
+
gl.clearDepth(1);
|
|
275
|
+
gl.clearStencil(0);
|
|
276
|
+
gl.blendColor(0, 0, 0, 0);
|
|
277
|
+
for (const cap of [gl.POLYGON_OFFSET_FILL, gl.RASTERIZER_DISCARD, gl.SAMPLE_COVERAGE, gl.SAMPLE_ALPHA_TO_COVERAGE]) {
|
|
278
|
+
gl.disable(cap);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
193
281
|
}
|
|
194
282
|
/** Drawing-buffer width in physical pixels (`canvas.width`). */
|
|
195
283
|
export function getRenderWidth(engine) {
|
|
@@ -237,7 +325,8 @@ export function offContextLost(engine, cb) {
|
|
|
237
325
|
engine._onLost.splice(i, 1);
|
|
238
326
|
}
|
|
239
327
|
}
|
|
240
|
-
/** Register
|
|
328
|
+
/** Register an automatic `webglcontextrestored` callback. Never fires on an
|
|
329
|
+
* engine from `createHostOwnedGLEngine`. Duplicate registrations are ignored. */
|
|
241
330
|
export function onContextRestored(engine, cb) {
|
|
242
331
|
if (engine._onRestored.indexOf(cb) === -1) {
|
|
243
332
|
engine._onRestored.push(cb);
|
|
@@ -253,8 +342,8 @@ export function offContextRestored(engine, cb) {
|
|
|
253
342
|
/* ───────────────────────── internal: loss / restore ───────────────────── */
|
|
254
343
|
function handleContextLost(engine, e) {
|
|
255
344
|
// Opt-in to restore. Without preventDefault() the browser will NOT fire
|
|
256
|
-
// webglcontextrestored later.
|
|
257
|
-
e
|
|
345
|
+
// webglcontextrestored later. Host-owned engines pass no event.
|
|
346
|
+
e?.preventDefault();
|
|
258
347
|
if (engine._isLost || engine._disposed) {
|
|
259
348
|
return;
|
|
260
349
|
}
|
package/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAgB,MAAM,YAAY,CAAC;AAkO1F;;;uCAGuC;AACvC,MAAM,UAAU,cAAc,CAAC,MAA2C,EAAE,OAAyB;IACjG,MAAM,CAAC,GAAG,OAAO,IAAI,EAAE,CAAC;IACxB,MAAM,K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AE,IAAI;QACrC,eAAe,EAAE,KAAK;KACzB,CAAC;AACN,CAAC;AAED,SAAS,WAAW,CAAC,CAA2B;IAC5C,KAAK,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;AACL,CAAC","sourcesContent":["import type { GLEffect } from \"./effect.js\";\nimport type { GLTexture } from \"./texture.js\";\nimport type { GLTexture3D } from \"./texture-3d.js\";\nimport type { GLRenderTarget } from \"./render-target.js\";\nimport type { GLPerfCounter } from \"./gpu-frame-time.js\";\nimport { createGLState, resetGLState, resetGLStateCache, type GLState } from \"./state.js\";\n\n/**\n * Minimal shape of a context-restorable GL buffer (vertex / index), kept local\n * to this module so the public `GLEngineContext` type carries no dependency on\n * the tree-shakeable `mesh` entry. `mesh.ts`'s `GLVertexBuffer` /\n * `GLIndexBuffer` satisfy it structurally.\n * @internal\n */\nexport interface GLManagedBuffer {\n handle: WebGLBuffer;\n /** @internal */\n _disposed: boolean;\n /** @internal */\n _deleteGpu: (gl: WebGL2RenderingContext) => void;\n /** @internal */\n _restore: (engine: GLEngineContext) => void;\n}\n\n/**\n * Per-frame begin / end hooks installed by opt-in modules (currently only\n * `captureGPUFrameTime`). Invoked by the render loop around its callbacks, or\n * by manual `beginFrame` / `endFrame` calls. Kept local so the context type\n * carries no runtime dependency on the tree-shakeable timing module.\n * @internal\n */\nexport interface GLFrameHooks {\n /** @internal */\n _begin: () => void;\n /** @internal */\n _end: () => void;\n /** Releases any GL resources owned by the hooks. @internal */\n _dispose: () => void;\n}\n\n/** Constructor options forwarded to `canvas.getContext('webgl2', …)`. */\nexport interface GLEngineOptions {\n /** Default: true. */\n alpha?: boolean;\n /** Default: true. */\n premultipliedAlpha?: boolean;\n /** Default: false. */\n antialias?: boolean;\n /** Default: false. */\n preserveDrawingBuffer?: boolean;\n /** Default: false — disabled for fullscreen-quad workloads. */\n depth?: boolean;\n /** Default: false. */\n stencil?: boolean;\n /** Default: \"default\". */\n powerPreference?: WebGLPowerPreference;\n /** Default: false. */\n failIfMajorPerformanceCaveat?: boolean;\n}\n\n/** Read-only WebGL2 capability limits, queried at creation and refreshed after\n * context restoration because extension objects do not survive context loss. */\nexport interface GLEngineCaps {\n /** `gl.MAX_TEXTURE_SIZE` — largest supported texture dimension, in texels. */\n readonly maxTextureSize: number;\n /** `gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS` — number of sampler binding slots. */\n readonly maxTextureUnits: number;\n /** The `KHR_parallel_shader_compile` extension used for async link polling,\n * or null when unsupported — linking is then treated as synchronous. */\n readonly parallelShaderCompile: { COMPLETION_STATUS_KHR: number } | null;\n /** True when 32-bit float color attachments are renderable\n * (`EXT_color_buffer_float`). Mirrors Babylon's `caps.textureFloatRender`. */\n readonly textureFloatRender: boolean;\n /** True when 32-bit float textures support linear filtering\n * (`OES_texture_float_linear`). Mirrors `caps.textureFloatLinearFiltering`. */\n readonly textureFloatLinearFiltering: boolean;\n /** True when 16-bit half-float color attachments are renderable\n * (`EXT_color_buffer_float` or `EXT_color_buffer_half_float`). Mirrors\n * `caps.textureHalfFloatRender`. */\n readonly textureHalfFloatRender: boolean;\n /** Half-float linear filtering — always `true` in WebGL2 (it is core).\n * Kept as a field to mirror Babylon's `caps.textureHalfFloatLinearFiltering`. */\n readonly textureHalfFloatLinearFiltering: boolean;\n /** Whether non-power-of-two textures need POT dimensions for mips / wrap.\n * Always `false` in WebGL2 (NPOT is core). Mirrors `engine.needPOTTextures`. */\n readonly needPOTTextures: boolean;\n}\n\n/**\n * Pure-state handle for a WebGL2 canvas + its cached GL state.\n *\n * INVARIANT: consumers MUST NOT mutate GL state directly through `engine.gl`.\n * Doing so silently corrupts the cache in `_state`. The package owns every\n * GL call. (`engine.gl` is exposed only so downstream code that already has the\n * pattern of poking `engine._gl.getExtension(...)` can do that, but must NOT\n * call `bindTexture`/`useProgram`/`bindBuffer`/`viewport`/etc.)\n */\nexport interface GLEngineContext {\n /** The canvas the WebGL2 context was acquired from. An `OffscreenCanvas` is\n * supported for worker render paths (e.g. the Lottie player); it has no CSS\n * box, so it must be sized explicitly via `setGLEngineSize` rather than the\n * CSS-derived `resizeGLEngine`. */\n readonly canvas: HTMLCanvasElement | OffscreenCanvas;\n /** The raw WebGL2 context. Do NOT mutate GL state through it — see the\n * type-level invariant above; the package owns every state-changing call. */\n readonly gl: WebGL2RenderingContext;\n /** Queried capability limits for this context. */\n readonly caps: GLEngineCaps;\n /**\n * Hardware-scaling-level — drawingBufferWidth = clientWidth * dpr / _hsl.\n * @internal\n */\n _hsl: number;\n /**\n * rAF id when a render loop is active, 0 otherwise.\n * @internal\n */\n _rafId: number;\n /**\n * Per-frame callbacks. `runRenderLoop` is a no-op if `fn` is already\n * registered (matches Babylon `AbstractEngine.runRenderLoop`).\n * @internal\n */\n _loops: ((dt: number) => void)[];\n /**\n * Timestamp of last frame for delta computation.\n * @internal\n */\n _prevNow: number;\n /**\n * Cached GL state. See §4 of 00-lite-gl.md.\n * @internal\n */\n _state: GLState;\n /**\n * Live effect registry — populated by `createEffect`, removed by\n * `disposeEffect`. Used by the context-restored protocol to rebuild\n * programs.\n * @internal\n */\n _effects: GLEffect[];\n /**\n * Per-engine effect cache keyed by source descriptor (vertex+fragment\n * source, defines, attribute/uniform/sampler names). `createEffect` returns\n * (and ref-counts) the cached `GLEffect` when an identical descriptor is\n * requested, so identical shaders share ONE WebGLProgram — letting\n * `useEffect`'s current-program cache elide redundant `gl.useProgram`.\n * @internal\n */\n _effectCache: Map<string, GLEffect>;\n /**\n * Live managed 2D/3D texture registry. Set deletion avoids linear searches\n * and array shifts during eviction; iteration preserves creation order\n * among survivors for context-restore replay.\n * @internal\n */\n _textures: Set<GLTexture | GLTexture3D>;\n /**\n * Live render-target registry — populated by `createRenderTarget`. Used by\n * the context-restored protocol to rebuild framebuffers + attachments after\n * their color textures have been replayed. Empty (and tree-shaken) when the\n * render-target module is unused.\n * @internal\n */\n _renderTargets: GLRenderTarget[];\n /**\n * The render target currently bound for drawing (`bindRenderTarget`), or\n * `null` for the default canvas framebuffer. Tracked so that leaving a\n * mipmapped target (`restoreDefaultFramebuffer(engine)` or switching to\n * another target) can regenerate its mip chain — mirroring Babylon's\n * auto-mipmap on `unBindFramebuffer`. Reset to `null` on context-lost.\n * @internal\n */\n _currentRenderTarget: GLRenderTarget | null;\n /**\n * Live vertex / index buffer registry — populated by `createVertexBuffer` /\n * `createIndexBuffer`. Used by the context-restored protocol to re-upload\n * the retained CPU data into fresh GL buffers. Empty (and tree-shaken) when\n * the mesh module is unused.\n * @internal\n */\n _buffers: GLManagedBuffer[];\n /** @internal */\n _onLost: (() => void)[];\n /** @internal */\n _onRestored: (() => void)[];\n /**\n * True between `webglcontextlost` and `webglcontextrestored`. While\n * true, every `setEffect*` / `bindTexture` / `drawEffect` is a no-op.\n * @internal\n */\n _isLost: boolean;\n /**\n * True once the context has been disposed; subsequent calls become no-ops.\n * @internal\n */\n _disposed: boolean;\n /**\n * DOM handlers — retained so dispose can `removeEventListener` them.\n * @internal\n */\n _lostHandler: (e: Event) => void;\n /** @internal */\n _restoredHandler: () => void;\n /**\n * True when a render loop was active at the moment of `webglcontextlost`,\n * so we can resume it from the restored handler.\n * @internal\n */\n _wasLoopActive: boolean;\n /**\n * Installed by `runRenderLoop` on first call. Lets the context-restored\n * handler resume a loop without a circular runtime import from render-loop.\n * Null if the render-loop module is tree-shaken out.\n * @internal\n */\n _scheduleFrame: ((engine: GLEngineContext) => void) | null;\n /** Optional feature-owned state-cache invalidators. Allocated lazily by the first feature that needs one.\n * @internal */\n _stateCacheInvalidators?: (() => void)[];\n /** Frame hooks installed while `captureGPUFrameTime(engine, true)` is active.\n * @internal */\n _frameHooks?: GLFrameHooks;\n /** GPU frame-time counter, created lazily by `getGPUFrameTimeCounter`.\n * @internal */\n _gpuFrameTime?: GLPerfCounter;\n /** Sample count of the canvas drawing buffer, queried lazily by `presentRenderTarget`.\n * @internal */\n _canvasSamples?: number;\n}\n\n/** Acquire a WebGL2 context on the canvas and build the pure-state handle.\n * Accepts an `HTMLCanvasElement` or an `OffscreenCanvas` (worker render paths —\n * e.g. the Lottie player — which size the drawing buffer via `setGLEngineSize`).\n * Throws if WebGL2 is unsupported. */\nexport function createGLEngine(canvas: HTMLCanvasElement | OffscreenCanvas, options?: GLEngineOptions): GLEngineContext {\n const o = options ?? {};\n const attrs: WebGLContextAttributes = {\n alpha: o.alpha ?? true,\n premultipliedAlpha: o.premultipliedAlpha ?? true,\n antialias: o.antialias ?? false,\n preserveDrawingBuffer: o.preserveDrawingBuffer ?? false,\n depth: o.depth ?? false,\n stencil: o.stencil ?? false,\n powerPreference: o.powerPreference ?? \"default\",\n failIfMajorPerformanceCaveat: o.failIfMajorPerformanceCaveat ?? false,\n };\n const gl = canvas.getContext(\"webgl2\", attrs) as WebGL2RenderingContext | null;\n if (gl === null) {\n throw new Error(\"lite-gl: WebGL2 is not supported on this canvas\");\n }\n\n const caps = queryCaps(gl);\n\n const engine: GLEngineContext = {\n canvas,\n gl,\n caps,\n _hsl: 1,\n _rafId: 0,\n _loops: [],\n _prevNow: 0,\n _state: createGLState(caps.maxTextureUnits),\n _effects: [],\n _effectCache: new Map(),\n _textures: new Set(),\n _renderTargets: [],\n _currentRenderTarget: null,\n _buffers: [],\n _onLost: [],\n _onRestored: [],\n _isLost: false,\n _disposed: false,\n _lostHandler: () => {},\n _restoredHandler: () => {},\n _wasLoopActive: false,\n _scheduleFrame: null,\n };\n\n engine._lostHandler = (e: Event) => handleContextLost(engine, e);\n engine._restoredHandler = () => handleContextRestored(engine);\n canvas.addEventListener(\"webglcontextlost\", engine._lostHandler as EventListener, false);\n canvas.addEventListener(\"webglcontextrestored\", engine._restoredHandler, false);\n\n return engine;\n}\n\n/** Stops the render loop, removes DOM listeners, releases all known effects\n * and textures, then marks the context disposed. The browser-owned canvas\n * is left intact. */\nexport function disposeGLEngine(engine: GLEngineContext): void {\n if (engine._disposed) {\n return;\n }\n engine._disposed = true;\n if (engine._rafId !== 0) {\n cancelAnimationFrame(engine._rafId);\n engine._rafId = 0;\n }\n engine._loops.length = 0;\n engine._frameHooks?._dispose();\n engine._frameHooks = undefined;\n engine.canvas.removeEventListener(\"webglcontextlost\", engine._lostHandler as EventListener, false);\n engine.canvas.removeEventListener(\"webglcontextrestored\", engine._restoredHandler, false);\n\n const gl = engine.gl;\n const textures = Array.from(engine._textures);\n engine._textures.clear();\n // Iterate snapshots — dispose paths can mutate the live registries.\n const effects = engine._effects.slice();\n for (const eff of effects) {\n if (!eff._disposed) {\n eff._disposed = true;\n eff.isReady = false;\n gl.deleteProgram(eff.program);\n gl.deleteShader(eff._vs);\n gl.deleteShader(eff._fs);\n }\n }\n engine._effects.length = 0;\n engine._effectCache.clear();\n for (const tex of textures) {\n // The snapshot contains live textures only. Force-delete every handle,\n // even if reentrant disposal marks a later texture disposed first.\n tex._disposed = true;\n gl.deleteTexture(tex.handle);\n }\n // Render targets own their FBO + renderbuffer + color texture; free them via\n // the per-RT closure so context.ts needs no runtime import of render-target.\n const rts = engine._renderTargets.slice();\n for (const rt of rts) {\n if (!rt._disposed) {\n rt._disposed = true;\n rt._deleteGpu(gl);\n }\n }\n engine._renderTargets.length = 0;\n\n // Mesh vertex/index buffers own a single GL buffer each; free via closure.\n const buffers = engine._buffers.slice();\n for (const buf of buffers) {\n if (!buf._disposed) {\n buf._disposed = true;\n buf._deleteGpu(gl);\n }\n }\n engine._buffers.length = 0;\n\n resetGLState(engine._state);\n engine._currentRenderTarget = null;\n engine._onLost.length = 0;\n engine._onRestored.length = 0;\n engine._stateCacheInvalidators?.splice(0);\n}\n\n/** Match drawing-buffer size to (clientSize × devicePixelRatio / _hsl). No-op\n * if size already matches. Never touches viewport — `setViewport` owns that. */\nexport function resizeGLEngine(engine: GLEngineContext): void {\n if (engine._disposed || engine._isLost) {\n return;\n }\n const canvas = engine.canvas;\n // An OffscreenCanvas has no CSS box (no clientWidth/clientHeight); it is sized\n // explicitly via setGLEngineSize, so CSS-derived auto-resize is a no-op for it.\n if (!(\"clientWidth\" in canvas)) {\n return;\n }\n const dpr = typeof devicePixelRatio === \"number\" ? devicePixelRatio : 1;\n const w = Math.max(1, Math.floor((canvas.clientWidth * dpr) / engine._hsl));\n const h = Math.max(1, Math.floor((canvas.clientHeight * dpr) / engine._hsl));\n if (canvas.width !== w) {\n canvas.width = w;\n }\n if (canvas.height !== h) {\n canvas.height = h;\n }\n}\n\n/**\n * Set the drawing-buffer size to an EXPLICIT width/height in physical pixels\n * (each divided by `_hsl`), independent of the canvas client/CSS size — the\n * counterpart of Babylon's `ThinEngine.setSize`. Use when the render resolution\n * is computed directly (e.g. animation dimensions × scale × dpr) rather than\n * derived from CSS layout via {@link resizeGLEngine}. No-op on a disposed\n * engine. Never touches the viewport — `setViewport` owns that.\n *\n * @param engine - The engine to resize.\n * @param width - Target drawing-buffer width in physical pixels.\n * @param height - Target drawing-buffer height in physical pixels.\n */\nexport function setGLEngineSize(engine: GLEngineContext, width: number, height: number): void {\n if (engine._disposed) {\n return;\n }\n const canvas = engine.canvas;\n const w = Math.max(1, Math.floor(width / engine._hsl));\n const h = Math.max(1, Math.floor(height / engine._hsl));\n if (canvas.width !== w) {\n canvas.width = w;\n }\n if (canvas.height !== h) {\n canvas.height = h;\n }\n}\n\n/**\n * Invalidate lite-gl's cached GL state so the next state-setting call in each\n * category (program / buffer / texture / VAO / framebuffer bindings, blend,\n * depth, stencil, scissor, color-mask, viewport, unpack) is re-issued instead\n * of elided.\n *\n * Use this when a host application that SHARES this WebGL2 context mutates raw\n * `gl.*` state outside lite-gl — e.g. a save/restore wrapper that resets the\n * context to GL defaults around each render scope, or any interop layer that\n * issues GL calls directly. Without it, lite-gl's redundant-call elision would\n * skip the state changes needed to re-establish the scope, producing corrupted\n * output. Owned GPU resources (the shared quad, render targets, meshes,\n * effects, textures) are preserved — only the cached \"current GL state\" is\n * reset. Mirrors Babylon's `Engine.wipeCaches()`.\n *\n * No-op while the context is lost or the engine is disposed.\n */\nexport function wipeGLStateCache(engine: GLEngineContext): void {\n if (engine._disposed || engine._isLost) {\n return;\n }\n resetGLStateCache(engine._state);\n const invalidators = engine._stateCacheInvalidators;\n if (invalidators) {\n for (const invalidate of invalidators) {\n invalidate();\n }\n }\n}\n\n/** Drawing-buffer width in physical pixels (`canvas.width`). */\nexport function getRenderWidth(engine: GLEngineContext): number {\n return engine.canvas.width;\n}\n\n/** Drawing-buffer height in physical pixels (`canvas.height`). */\nexport function getRenderHeight(engine: GLEngineContext): number {\n return engine.canvas.height;\n}\n\n/** Number of live sampled textures managed by the context. */\nexport function getTextureCount(engine: GLEngineContext): number {\n return engine._textures.size;\n}\n\n/** Current drawing target, or null for the canvas framebuffer. */\nexport function getCurrentRenderTarget(engine: GLEngineContext): GLRenderTarget | null {\n return engine._currentRenderTarget;\n}\n\n/** Current hardware-scaling factor — drawing-buffer = clientSize × dpr / level. */\nexport function getHardwareScalingLevel(engine: GLEngineContext): number {\n return engine._hsl;\n}\n\n/** Updates the hardware-scaling factor and triggers a resize. */\nexport function setHardwareScalingLevel(engine: GLEngineContext, level: number): void {\n if (level <= 0 || !isFinite(level)) {\n return;\n }\n engine._hsl = level;\n resizeGLEngine(engine);\n}\n\n/** The backing canvas element (an `HTMLCanvasElement`, or an `OffscreenCanvas`\n * for worker render paths). */\nexport function getRenderingCanvas(engine: GLEngineContext): HTMLCanvasElement | OffscreenCanvas {\n return engine.canvas;\n}\n\n/** Register a `webglcontextlost` callback. Duplicate registrations are ignored. */\nexport function onContextLost(engine: GLEngineContext, cb: () => void): void {\n if (engine._onLost.indexOf(cb) === -1) {\n engine._onLost.push(cb);\n }\n}\n\n/** Remove a previously-registered context-lost callback. */\nexport function offContextLost(engine: GLEngineContext, cb: () => void): void {\n const i = engine._onLost.indexOf(cb);\n if (i !== -1) {\n engine._onLost.splice(i, 1);\n }\n}\n\n/** Register a `webglcontextrestored` callback. Duplicate registrations are ignored. */\nexport function onContextRestored(engine: GLEngineContext, cb: () => void): void {\n if (engine._onRestored.indexOf(cb) === -1) {\n engine._onRestored.push(cb);\n }\n}\n\n/** Remove a previously-registered context-restored callback. */\nexport function offContextRestored(engine: GLEngineContext, cb: () => void): void {\n const i = engine._onRestored.indexOf(cb);\n if (i !== -1) {\n engine._onRestored.splice(i, 1);\n }\n}\n\n/* ───────────────────────── internal: loss / restore ───────────────────── */\n\nfunction handleContextLost(engine: GLEngineContext, e: Event): void {\n // Opt-in to restore. Without preventDefault() the browser will NOT fire\n // webglcontextrestored later.\n e.preventDefault();\n if (engine._isLost || engine._disposed) {\n return;\n }\n engine._isLost = true;\n // `tick` clears `_rafId` while callbacks run, so a loss event delivered in\n // that window still represents an active loop when callbacks remain.\n engine._wasLoopActive = engine._loops.length > 0;\n if (engine._rafId !== 0) {\n cancelAnimationFrame(engine._rafId);\n engine._rafId = 0;\n }\n resetGLState(engine._state);\n engine._currentRenderTarget = null;\n for (const eff of engine._effects) {\n eff.isReady = false;\n eff._samplersAssigned = false;\n eff.uniformLocations = {};\n eff.attributeLocations = {};\n // Clear value caches so the first frame after restore re-uploads\n // every uniform into the freshly-linked program.\n clearObject(eff._lastF1);\n clearObject(eff._lastVec);\n clearObject(eff._lastI1);\n // Do NOT gl.deleteProgram — handle is already dead per WebGL spec.\n }\n for (const tex of engine._textures) {\n tex._wasReady = tex.isReady;\n tex.isReady = false;\n }\n const cbs = engine._onLost.slice();\n for (const cb of cbs) {\n try {\n cb();\n } catch (err) {\n console.error(\"lite-gl: onLost callback threw\", err);\n }\n }\n}\n\nfunction handleContextRestored(engine: GLEngineContext): void {\n if (engine._disposed) {\n return;\n }\n Object.assign(engine.caps, queryCaps(engine.gl));\n for (const eff of engine._effects) {\n if (!eff._disposed) {\n eff._restore(engine);\n }\n }\n for (const tex of engine._textures) {\n if (!tex._disposed) {\n const newHandle = engine.gl.createTexture();\n if (newHandle !== null) {\n tex.handle = newHandle;\n tex._upload(engine);\n tex._initializeParameters?.(engine);\n tex.isReady = tex._wasReady;\n }\n }\n }\n // Clear the lost flag BEFORE the render-target / buffer rebuilds: their\n // `_restore` closures route through the same guarded build/upload paths used\n // at create time (which no-op while `_isLost`), whereas the effect / texture\n // replay above is unguarded and unaffected by the flag's value.\n engine._isLost = false;\n // Render targets rebuild their own color texture + FBO + renderbuffer AFTER\n // the standalone texture replay above (an RT's color texture is owned by the\n // RT, not the `_textures` registry).\n for (const rt of engine._renderTargets) {\n if (!rt._disposed) {\n rt._restore(engine);\n }\n }\n // Mesh buffers re-upload their retained CPU data into fresh GL buffers.\n for (const buf of engine._buffers) {\n if (!buf._disposed) {\n buf._restore(engine);\n }\n }\n if (engine._wasLoopActive && engine._loops.length > 0 && engine._scheduleFrame !== null) {\n engine._scheduleFrame(engine);\n }\n const cbs = engine._onRestored.slice();\n for (const cb of cbs) {\n try {\n cb();\n } catch (err) {\n console.error(\"lite-gl: onRestored callback threw\", err);\n }\n }\n}\n\nfunction queryCaps(gl: WebGL2RenderingContext): GLEngineCaps {\n const parallelExt = gl.getExtension(\"KHR_parallel_shader_compile\") as { COMPLETION_STATUS_KHR: number } | null;\n // `getExtension` both queries and enables these capabilities, so they must\n // be reacquired after context restoration before resources are rebuilt.\n const colorBufferFloat = gl.getExtension(\"EXT_color_buffer_float\") !== null;\n const colorBufferHalfFloat = gl.getExtension(\"EXT_color_buffer_half_float\") !== null;\n const floatLinear = gl.getExtension(\"OES_texture_float_linear\") !== null;\n return {\n maxTextureSize: gl.getParameter(gl.MAX_TEXTURE_SIZE) as number,\n maxTextureUnits: gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS) as number,\n parallelShaderCompile: parallelExt,\n textureFloatRender: colorBufferFloat,\n textureFloatLinearFiltering: floatLinear,\n textureHalfFloatRender: colorBufferFloat || colorBufferHalfFloat,\n textureHalfFloatLinearFiltering: true,\n needPOTTextures: false,\n };\n}\n\nfunction clearObject(o: { [k: string]: unknown }): void {\n for (const key in o) {\n delete o[key];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context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AAE,WAAW;QAClC,kBAAkB,EAAE,gBAAgB;QACpC,2BAA2B,EAAE,WAAW;QACxC,sBAAsB,EAAE,gBAAgB,IAAI,oBAAoB;QAChE,+BAA+B,EAAE,IAAI;QACrC,eAAe,EAAE,KAAK;KACzB,CAAC;AACN,CAAC;AAED,SAAS,WAAW,CAAC,CAA2B;IAC5C,KAAK,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;AACL,CAAC","sourcesContent":["import type { GLEffect } from \"./effect.js\";\nimport type { GLTexture } from \"./texture.js\";\nimport type { GLTexture3D } from \"./texture-3d.js\";\nimport type { GLRenderTarget } from \"./render-target.js\";\nimport type { GLPerfCounter } from \"./gpu-frame-time.js\";\nimport { createGLState, resetGLState, resetGLStateCache, type GLState } from \"./state.js\";\n\n/**\n * Minimal shape of a context-restorable GL buffer (vertex / index), kept local\n * to this module so the public `GLEngineContext` type carries no dependency on\n * the tree-shakeable `mesh` entry. `mesh.ts`'s `GLVertexBuffer` /\n * `GLIndexBuffer` satisfy it structurally.\n * @internal\n */\nexport interface GLManagedBuffer {\n handle: WebGLBuffer;\n /** @internal */\n _disposed: boolean;\n /** @internal */\n _deleteGpu: (gl: WebGL2RenderingContext) => void;\n /** @internal */\n _restore?: (engine: GLEngineContext) => void;\n /** Retained upload source, absent when replay is disabled or disposed. @internal */\n _data?: ArrayBufferView;\n}\n\n/**\n * Per-frame begin / end hooks installed by opt-in modules (currently only\n * `captureGPUFrameTime`). Invoked by the render loop around its callbacks, or\n * by manual `beginFrame` / `endFrame` calls. Kept local so the context type\n * carries no runtime dependency on the tree-shakeable timing module.\n * @internal\n */\nexport interface GLFrameHooks {\n /** @internal */\n _begin: () => void;\n /** @internal */\n _end: () => void;\n /** Releases any GL resources owned by the hooks. @internal */\n _dispose: () => void;\n}\n\n/** Constructor options forwarded to `canvas.getContext('webgl2', …)`. */\nexport interface GLEngineOptions {\n /** Default: true. */\n alpha?: boolean;\n /** Default: true. */\n premultipliedAlpha?: boolean;\n /** Default: false. */\n antialias?: boolean;\n /** Default: false. */\n preserveDrawingBuffer?: boolean;\n /** Default: false — disabled for fullscreen-quad workloads. */\n depth?: boolean;\n /** Default: false. */\n stencil?: boolean;\n /** Default: \"default\". */\n powerPreference?: WebGLPowerPreference;\n /** Default: false. */\n failIfMajorPerformanceCaveat?: boolean;\n}\n\n/** Read-only WebGL2 capability limits, queried at creation and refreshed after\n * context restoration because extension objects do not survive context loss. */\nexport interface GLEngineCaps {\n /** `gl.MAX_TEXTURE_SIZE` — largest supported texture dimension, in texels. */\n readonly maxTextureSize: number;\n /** `gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS` — number of sampler binding slots. */\n readonly maxTextureUnits: number;\n /** The `KHR_parallel_shader_compile` extension used for async link polling,\n * or null when unsupported — linking is then treated as synchronous. */\n readonly parallelShaderCompile: { COMPLETION_STATUS_KHR: number } | null;\n /** True when 32-bit float color attachments are renderable\n * (`EXT_color_buffer_float`). Mirrors Babylon's `caps.textureFloatRender`. */\n readonly textureFloatRender: boolean;\n /** True when 32-bit float textures support linear filtering\n * (`OES_texture_float_linear`). Mirrors `caps.textureFloatLinearFiltering`. */\n readonly textureFloatLinearFiltering: boolean;\n /** True when 16-bit half-float color attachments are renderable\n * (`EXT_color_buffer_float` or `EXT_color_buffer_half_float`). Mirrors\n * `caps.textureHalfFloatRender`. */\n readonly textureHalfFloatRender: boolean;\n /** Half-float linear filtering — always `true` in WebGL2 (it is core).\n * Kept as a field to mirror Babylon's `caps.textureHalfFloatLinearFiltering`. */\n readonly textureHalfFloatLinearFiltering: boolean;\n /** Whether non-power-of-two textures need POT dimensions for mips / wrap.\n * Always `false` in WebGL2 (NPOT is core). Mirrors `engine.needPOTTextures`. */\n readonly needPOTTextures: boolean;\n}\n\n/**\n * Pure-state handle for a WebGL2 canvas + its cached GL state.\n *\n * INVARIANT: consumers MUST NOT mutate GL state directly through `engine.gl`.\n * Doing so silently corrupts the cache in `_state`. The package owns every\n * GL call. (`engine.gl` is exposed only so downstream code that already has the\n * pattern of poking `engine._gl.getExtension(...)` can do that, but must NOT\n * call `bindTexture`/`useProgram`/`bindBuffer`/`viewport`/etc.)\n */\nexport interface GLEngineContext {\n /** The canvas the WebGL2 context was acquired from. An `OffscreenCanvas` is\n * supported for worker render paths (e.g. the Lottie player); it has no CSS\n * box, so it must be sized explicitly via `setGLEngineSize` rather than the\n * CSS-derived `resizeGLEngine`. */\n readonly canvas: HTMLCanvasElement | OffscreenCanvas;\n /** The raw WebGL2 context. Do NOT mutate GL state through it — see the\n * type-level invariant above; the package owns every state-changing call. */\n readonly gl: WebGL2RenderingContext;\n /** Queried capability limits for this context. */\n readonly caps: GLEngineCaps;\n /**\n * Hardware-scaling-level — drawingBufferWidth = clientWidth * dpr / _hsl.\n * @internal\n */\n _hsl: number;\n /**\n * rAF id when a render loop is active, 0 otherwise.\n * @internal\n */\n _rafId: number;\n /**\n * Per-frame callbacks. `runRenderLoop` is a no-op if `fn` is already\n * registered (matches Babylon `AbstractEngine.runRenderLoop`).\n * @internal\n */\n _loops: ((dt: number) => void)[];\n /**\n * Timestamp of last frame for delta computation.\n * @internal\n */\n _prevNow: number;\n /**\n * Cached GL state. See §4 of 00-lite-gl.md.\n * @internal\n */\n _state: GLState;\n /**\n * Live effect registry — populated by `createEffect`, removed by\n * `disposeEffect`. Used by the context-restored protocol to rebuild\n * programs.\n * @internal\n */\n _effects: GLEffect[];\n /**\n * Per-engine effect cache keyed by source descriptor (vertex+fragment\n * source, defines, attribute/uniform/sampler names). `createEffect` returns\n * (and ref-counts) the cached `GLEffect` when an identical descriptor is\n * requested, so identical shaders share ONE WebGLProgram — letting\n * `useEffect`'s current-program cache elide redundant `gl.useProgram`.\n * @internal\n */\n _effectCache: Map<string, GLEffect>;\n /**\n * Live managed 2D/3D texture registry. Set deletion avoids linear searches\n * and array shifts during eviction; iteration preserves creation order\n * among survivors for context-restore replay.\n * @internal\n */\n _textures: Set<GLTexture | GLTexture3D>;\n /**\n * Live render-target registry — populated by `createRenderTarget`. Used by\n * the context-restored protocol to rebuild framebuffers + attachments after\n * their color textures have been replayed. Empty (and tree-shaken) when the\n * render-target module is unused.\n * @internal\n */\n _renderTargets: GLRenderTarget[];\n /**\n * The render target currently bound for drawing (`bindRenderTarget`), or\n * `null` for the default canvas framebuffer. Tracked so that leaving a\n * mipmapped target (`restoreDefaultFramebuffer(engine)` or switching to\n * another target) can regenerate its mip chain — mirroring Babylon's\n * auto-mipmap on `unBindFramebuffer`. Reset to `null` on context-lost.\n * @internal\n */\n _currentRenderTarget: GLRenderTarget | null;\n /**\n * Live vertex / index buffer registry — populated by `createVertexBuffer` /\n * `createIndexBuffer`. Used by the context-restored protocol to re-upload\n * the retained CPU data into fresh GL buffers. Empty (and tree-shaken) when\n * the mesh module is unused.\n * @internal\n */\n _buffers: GLManagedBuffer[];\n /** @internal */\n _onLost: (() => void)[];\n /** @internal */\n _onRestored: (() => void)[];\n /**\n * True after `webglcontextlost` until automatic recovery completes, or\n * permanently when recovery is disabled. While true, every `setEffect*` /\n * `bindTexture` / `drawEffect` is a no-op.\n * @internal\n */\n _isLost: boolean;\n /** Host-owned recovery policy, set only by `createHostOwnedGLEngine`;\n * not cached GL state. @internal */\n _noRestore?: true;\n /**\n * True once the context has been disposed; subsequent calls become no-ops.\n * @internal\n */\n _disposed: boolean;\n /**\n * DOM handlers — retained so dispose can `removeEventListener` them.\n * @internal\n */\n _lostHandler: (e: Event) => void;\n /** @internal */\n _restoredHandler: () => void;\n /**\n * True when a render loop was active at the moment of `webglcontextlost`,\n * so we can resume it from the restored handler.\n * @internal\n */\n _wasLoopActive: boolean;\n /**\n * Installed by `runRenderLoop` on first call. Lets the context-restored\n * handler resume a loop without a circular runtime import from render-loop.\n * Null if the render-loop module is tree-shaken out.\n * @internal\n */\n _scheduleFrame: ((engine: GLEngineContext) => void) | null;\n /** Optional feature-owned state-cache invalidators. Allocated lazily by the first feature that needs one.\n * @internal */\n _stateCacheInvalidators?: (() => void)[];\n /** Frame hooks installed while `captureGPUFrameTime(engine, true)` is active.\n * @internal */\n _frameHooks?: GLFrameHooks;\n /** GPU frame-time counter, created lazily by `getGPUFrameTimeCounter`.\n * @internal */\n _gpuFrameTime?: GLPerfCounter;\n /** Set by `setFramebufferValidation(engine, false)` to skip framebuffer\n * completeness checks. Configuration, not cached GL state: retained across\n * cache wipes/restores.\n * @internal */\n _skipFramebufferValidation?: boolean;\n /** Sample count of the canvas drawing buffer, queried lazily by `presentRenderTarget`.\n * @internal */\n _canvasSamples?: number;\n}\n\n/** Acquire a WebGL2 context on the canvas and build the pure-state handle.\n * Accepts an `HTMLCanvasElement` or an `OffscreenCanvas` (worker render paths —\n * e.g. the Lottie player — which size the drawing buffer via `setGLEngineSize`).\n * Throws if WebGL2 is unsupported. Resources recover automatically after\n * context loss; use `createHostOwnedGLEngine` when the host recreates instead. */\nexport function createGLEngine(canvas: HTMLCanvasElement | OffscreenCanvas, options?: GLEngineOptions): GLEngineContext {\n const o = options ?? {};\n const attrs: WebGLContextAttributes = {\n alpha: o.alpha ?? true,\n premultipliedAlpha: o.premultipliedAlpha ?? true,\n antialias: o.antialias ?? false,\n preserveDrawingBuffer: o.preserveDrawingBuffer ?? false,\n depth: o.depth ?? false,\n stencil: o.stencil ?? false,\n powerPreference: o.powerPreference ?? \"default\",\n failIfMajorPerformanceCaveat: o.failIfMajorPerformanceCaveat ?? false,\n };\n const gl = canvas.getContext(\"webgl2\", attrs) as WebGL2RenderingContext | null;\n if (gl === null) {\n throw new Error(\"lite-gl: WebGL2 is not supported on this canvas\");\n }\n\n const caps = queryCaps(gl);\n\n const engine: GLEngineContext = {\n canvas,\n gl,\n caps,\n _hsl: 1,\n _rafId: 0,\n _loops: [],\n _prevNow: 0,\n _state: createGLState(caps.maxTextureUnits),\n _effects: [],\n _effectCache: new Map(),\n _textures: new Set(),\n _renderTargets: [],\n _currentRenderTarget: null,\n _buffers: [],\n _onLost: [],\n _onRestored: [],\n _isLost: false,\n _disposed: false,\n _lostHandler: (e: Event) => handleContextLost(engine, e),\n _restoredHandler: () => handleContextRestored(engine),\n _wasLoopActive: false,\n _scheduleFrame: null,\n };\n\n canvas.addEventListener(\"webglcontextlost\", engine._lostHandler as EventListener, false);\n canvas.addEventListener(\"webglcontextrestored\", engine._restoredHandler, false);\n\n return engine;\n}\n\n/**\n * Create an engine whose context-loss recovery is owned by the host, matching\n * ThinEngine's `doNotHandleContextLost: true`. Same canvas/options contract as\n * {@link createGLEngine}, except:\n * - `webglcontextlost` still stops rendering, marks the engine lost and fires\n * `onContextLost` callbacks, but never calls `preventDefault()`, so the\n * browser does not restore the context; `onContextRestored` never fires;\n * - resources created on this engine retain no CPU replay sources (buffer\n * data, texture pixels, sprite indices) and install no restore hooks,\n * saving memory. Effects still keep their public `options` (including the\n * shader sources) and source-derived cache key, which serve readiness\n * diagnostics and effect deduplication rather than replay.\n *\n * After a loss the engine stays lost: dispose it and recreate the engine and\n * every resource (on a fresh canvas or once the host has a new context).\n *\n * @param canvas - An `HTMLCanvasElement` or `OffscreenCanvas`.\n * @param options - WebGL2 context attributes, as for {@link createGLEngine}.\n * @returns The engine. Throws if WebGL2 is unsupported.\n */\nexport function createHostOwnedGLEngine(canvas: HTMLCanvasElement | OffscreenCanvas, options?: GLEngineOptions): GLEngineContext {\n const engine = createGLEngine(canvas, options);\n engine._noRestore = true;\n canvas.removeEventListener(\"webglcontextlost\", engine._lostHandler as EventListener, false);\n canvas.removeEventListener(\"webglcontextrestored\", engine._restoredHandler, false);\n engine._lostHandler = () => handleContextLost(engine);\n canvas.addEventListener(\"webglcontextlost\", engine._lostHandler as EventListener, false);\n return engine;\n}\n\n/** Stops the render loop, removes DOM listeners, releases all known effects\n * and textures, then marks the context disposed. The browser-owned canvas\n * is left intact. */\nexport function disposeGLEngine(engine: GLEngineContext): void {\n if (engine._disposed) {\n return;\n }\n engine._disposed = true;\n if (engine._rafId !== 0) {\n cancelAnimationFrame(engine._rafId);\n engine._rafId = 0;\n }\n engine._loops.length = 0;\n engine._frameHooks?._dispose();\n engine._frameHooks = undefined;\n engine.canvas.removeEventListener(\"webglcontextlost\", engine._lostHandler as EventListener, false);\n engine.canvas.removeEventListener(\"webglcontextrestored\", engine._restoredHandler, false);\n\n const gl = engine.gl;\n const textures = Array.from(engine._textures);\n engine._textures.clear();\n // Iterate snapshots — dispose paths can mutate the live registries.\n const effects = engine._effects.slice();\n for (const eff of effects) {\n if (!eff._disposed) {\n eff._disposed = true;\n eff.isReady = false;\n gl.deleteProgram(eff.program);\n gl.deleteShader(eff._vs);\n gl.deleteShader(eff._fs);\n }\n }\n engine._effects.length = 0;\n engine._effectCache.clear();\n for (const tex of textures) {\n // The snapshot contains live textures only. Force-delete every handle,\n // even if reentrant disposal marks a later texture disposed first.\n tex._disposed = true;\n gl.deleteTexture(tex.handle);\n }\n // Render targets own their FBO + renderbuffer + color texture; free them via\n // the per-RT closure so context.ts needs no runtime import of render-target.\n const rts = engine._renderTargets.slice();\n for (const rt of rts) {\n if (!rt._disposed) {\n rt._disposed = true;\n rt._deleteGpu(gl);\n }\n }\n engine._renderTargets.length = 0;\n\n // Mesh vertex/index buffers own a single GL buffer each; free via closure.\n const buffers = engine._buffers.slice();\n for (const buf of buffers) {\n if (!buf._disposed) {\n buf._disposed = true;\n buf._deleteGpu(gl);\n buf._data = buf._restore = undefined;\n }\n }\n engine._buffers.length = 0;\n\n resetGLState(engine._state);\n engine._currentRenderTarget = null;\n engine._onLost.length = 0;\n engine._onRestored.length = 0;\n engine._stateCacheInvalidators?.splice(0);\n}\n\n/** Match drawing-buffer size to (clientSize × devicePixelRatio / _hsl). No-op\n * if size already matches. Never touches viewport — `setViewport` owns that. */\nexport function resizeGLEngine(engine: GLEngineContext): void {\n if (engine._disposed || engine._isLost) {\n return;\n }\n const canvas = engine.canvas;\n // An OffscreenCanvas has no CSS box (no clientWidth/clientHeight); it is sized\n // explicitly via setGLEngineSize, so CSS-derived auto-resize is a no-op for it.\n if (!(\"clientWidth\" in canvas)) {\n return;\n }\n const dpr = typeof devicePixelRatio === \"number\" ? devicePixelRatio : 1;\n const w = Math.max(1, Math.floor((canvas.clientWidth * dpr) / engine._hsl));\n const h = Math.max(1, Math.floor((canvas.clientHeight * dpr) / engine._hsl));\n if (canvas.width !== w) {\n canvas.width = w;\n }\n if (canvas.height !== h) {\n canvas.height = h;\n }\n}\n\n/**\n * Set the drawing-buffer size to an EXPLICIT width/height in physical pixels\n * (each divided by `_hsl`), independent of the canvas client/CSS size — the\n * counterpart of Babylon's `ThinEngine.setSize`. Use when the render resolution\n * is computed directly (e.g. animation dimensions × scale × dpr) rather than\n * derived from CSS layout via {@link resizeGLEngine}. No-op on a disposed\n * engine. Never touches the viewport — `setViewport` owns that.\n *\n * @param engine - The engine to resize.\n * @param width - Target drawing-buffer width in physical pixels.\n * @param height - Target drawing-buffer height in physical pixels.\n */\nexport function setGLEngineSize(engine: GLEngineContext, width: number, height: number): void {\n if (engine._disposed) {\n return;\n }\n const canvas = engine.canvas;\n const w = Math.max(1, Math.floor(width / engine._hsl));\n const h = Math.max(1, Math.floor(height / engine._hsl));\n if (canvas.width !== w) {\n canvas.width = w;\n }\n if (canvas.height !== h) {\n canvas.height = h;\n }\n}\n\n/**\n * Invalidate lite-gl's cached GL state so the next state-setting call in each\n * category (program / buffer / texture / VAO / framebuffer bindings, blend,\n * depth, stencil, scissor, color-mask, viewport, unpack) is re-issued instead\n * of elided.\n *\n * Use this when a host application that SHARES this WebGL2 context mutates raw\n * `gl.*` state outside lite-gl — e.g. a save/restore wrapper that resets the\n * context to GL defaults around each render scope, or any interop layer that\n * issues GL calls directly. Without it, lite-gl's redundant-call elision would\n * skip the state changes needed to re-establish the scope, producing corrupted\n * output. Owned GPU resources (the shared quad, render targets, meshes,\n * effects, textures) are preserved — only the cached \"current GL state\" is\n * reset. Mirrors Babylon's `Engine.wipeCaches(bruteForce)`.\n *\n * After a wipe the VAO / framebuffer bindings are UNKNOWN (not assumed to be\n * the defaults), so the next mesh / render-target call rebinds them even if the\n * host left its own objects bound. The current program is forgotten: call\n * `useEffect` again before drawing.\n *\n * `bruteForce` additionally normalizes, with raw GL calls, state lite-gl relies\n * on but never caches, back to WebGL2 defaults: the default VAO with every\n * vertex attribute array disabled, sampler objects unbound from every texture\n * unit, no `PIXEL_PACK` / `PIXEL_UNPACK` buffer, zero pack / unpack row and\n * skip layout, browser-default unpack colorspace conversion, `frontFace(CCW)`,\n * `depthRange(0, 1)`, `clearDepth(1)`, `clearStencil(0)`, `blendColor(0, 0, 0, 0)`\n * and `POLYGON_OFFSET_FILL` / `RASTERIZER_DISCARD` / `SAMPLE_COVERAGE` /\n * `SAMPLE_ALPHA_TO_COVERAGE` disabled. Use it when the host may leave arbitrary\n * state behind (it costs roughly `MAX_VERTEX_ATTRIBS + maxTextureUnits + 20`\n * GL calls); per-draw hand-offs with a known host should prefer the plain wipe\n * plus targeted resets.\n *\n * No-op while the context is lost or the engine is disposed.\n *\n * @param engine - The engine.\n * @param bruteForce - Also normalize untracked GL state (see above). Default `false`.\n */\nexport function wipeGLStateCache(engine: GLEngineContext, bruteForce = false): void {\n if (engine._disposed || engine._isLost) {\n return;\n }\n const s = engine._state;\n resetGLStateCache(s);\n // Brute force disables every attribute array below; a plain wipe leaves\n // host-enabled arrays unknown (ThinEngine's `_mustWipeVertexAttributes`).\n s._unknownAttribs = !bruteForce;\n const invalidators = engine._stateCacheInvalidators;\n if (invalidators) {\n for (const invalidate of invalidators) {\n invalidate();\n }\n }\n if (bruteForce) {\n const gl = engine.gl;\n gl.bindVertexArray(null);\n s.boundVao = null;\n const attribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS) as number;\n for (let i = 0; i < attribs; i++) {\n gl.disableVertexAttribArray(i);\n }\n for (let u = 0; u < s.boundTextures.length; u++) {\n gl.bindSampler(u, null);\n }\n gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, null);\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);\n for (const p of [\n gl.UNPACK_ROW_LENGTH,\n gl.UNPACK_IMAGE_HEIGHT,\n gl.UNPACK_SKIP_PIXELS,\n gl.UNPACK_SKIP_ROWS,\n gl.UNPACK_SKIP_IMAGES,\n gl.PACK_ROW_LENGTH,\n gl.PACK_SKIP_PIXELS,\n gl.PACK_SKIP_ROWS,\n ]) {\n gl.pixelStorei(p, 0);\n }\n gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.BROWSER_DEFAULT_WEBGL);\n gl.frontFace(gl.CCW);\n gl.depthRange(0, 1);\n gl.clearDepth(1);\n gl.clearStencil(0);\n gl.blendColor(0, 0, 0, 0);\n for (const cap of [gl.POLYGON_OFFSET_FILL, gl.RASTERIZER_DISCARD, gl.SAMPLE_COVERAGE, gl.SAMPLE_ALPHA_TO_COVERAGE]) {\n gl.disable(cap);\n }\n }\n}\n\n/** Drawing-buffer width in physical pixels (`canvas.width`). */\nexport function getRenderWidth(engine: GLEngineContext): number {\n return engine.canvas.width;\n}\n\n/** Drawing-buffer height in physical pixels (`canvas.height`). */\nexport function getRenderHeight(engine: GLEngineContext): number {\n return engine.canvas.height;\n}\n\n/** Number of live sampled textures managed by the context. */\nexport function getTextureCount(engine: GLEngineContext): number {\n return engine._textures.size;\n}\n\n/** Current drawing target, or null for the canvas framebuffer. */\nexport function getCurrentRenderTarget(engine: GLEngineContext): GLRenderTarget | null {\n return engine._currentRenderTarget;\n}\n\n/** Current hardware-scaling factor — drawing-buffer = clientSize × dpr / level. */\nexport function getHardwareScalingLevel(engine: GLEngineContext): number {\n return engine._hsl;\n}\n\n/** Updates the hardware-scaling factor and triggers a resize. */\nexport function setHardwareScalingLevel(engine: GLEngineContext, level: number): void {\n if (level <= 0 || !isFinite(level)) {\n return;\n }\n engine._hsl = level;\n resizeGLEngine(engine);\n}\n\n/** The backing canvas element (an `HTMLCanvasElement`, or an `OffscreenCanvas`\n * for worker render paths). */\nexport function getRenderingCanvas(engine: GLEngineContext): HTMLCanvasElement | OffscreenCanvas {\n return engine.canvas;\n}\n\n/** Register a `webglcontextlost` callback. Duplicate registrations are ignored. */\nexport function onContextLost(engine: GLEngineContext, cb: () => void): void {\n if (engine._onLost.indexOf(cb) === -1) {\n engine._onLost.push(cb);\n }\n}\n\n/** Remove a previously-registered context-lost callback. */\nexport function offContextLost(engine: GLEngineContext, cb: () => void): void {\n const i = engine._onLost.indexOf(cb);\n if (i !== -1) {\n engine._onLost.splice(i, 1);\n }\n}\n\n/** Register an automatic `webglcontextrestored` callback. Never fires on an\n * engine from `createHostOwnedGLEngine`. Duplicate registrations are ignored. */\nexport function onContextRestored(engine: GLEngineContext, cb: () => void): void {\n if (engine._onRestored.indexOf(cb) === -1) {\n engine._onRestored.push(cb);\n }\n}\n\n/** Remove a previously-registered context-restored callback. */\nexport function offContextRestored(engine: GLEngineContext, cb: () => void): void {\n const i = engine._onRestored.indexOf(cb);\n if (i !== -1) {\n engine._onRestored.splice(i, 1);\n }\n}\n\n/* ───────────────────────── internal: loss / restore ───────────────────── */\n\nfunction handleContextLost(engine: GLEngineContext, e?: Event): void {\n // Opt-in to restore. Without preventDefault() the browser will NOT fire\n // webglcontextrestored later. Host-owned engines pass no event.\n e?.preventDefault();\n if (engine._isLost || engine._disposed) {\n return;\n }\n engine._isLost = true;\n // `tick` clears `_rafId` while callbacks run, so a loss event delivered in\n // that window still represents an active loop when callbacks remain.\n engine._wasLoopActive = engine._loops.length > 0;\n if (engine._rafId !== 0) {\n cancelAnimationFrame(engine._rafId);\n engine._rafId = 0;\n }\n resetGLState(engine._state);\n engine._currentRenderTarget = null;\n for (const eff of engine._effects) {\n eff.isReady = false;\n eff._samplersAssigned = false;\n eff.uniformLocations = {};\n eff.attributeLocations = {};\n // Clear value caches so the first frame after restore re-uploads\n // every uniform into the freshly-linked program.\n clearObject(eff._lastF1);\n clearObject(eff._lastVec);\n clearObject(eff._lastI1);\n // Do NOT gl.deleteProgram — handle is already dead per WebGL spec.\n }\n for (const tex of engine._textures) {\n tex._wasReady = tex.isReady;\n tex.isReady = false;\n }\n const cbs = engine._onLost.slice();\n for (const cb of cbs) {\n try {\n cb();\n } catch (err) {\n console.error(\"lite-gl: onLost callback threw\", err);\n }\n }\n}\n\nfunction handleContextRestored(engine: GLEngineContext): void {\n if (engine._disposed) {\n return;\n }\n Object.assign(engine.caps, queryCaps(engine.gl));\n for (const eff of engine._effects) {\n if (!eff._disposed) {\n eff._restore!(engine);\n }\n }\n for (const tex of engine._textures) {\n if (!tex._disposed) {\n const newHandle = engine.gl.createTexture();\n if (newHandle !== null) {\n tex.handle = newHandle;\n tex._upload(engine);\n tex._initializeParameters?.(engine);\n tex.isReady = tex._wasReady;\n }\n }\n }\n // Clear the lost flag BEFORE the render-target / buffer rebuilds: their\n // `_restore` closures route through the same guarded build/upload paths used\n // at create time (which no-op while `_isLost`), whereas the effect / texture\n // replay above is unguarded and unaffected by the flag's value.\n engine._isLost = false;\n // Render targets rebuild their own color texture + FBO + renderbuffer AFTER\n // the standalone texture replay above (an RT's color texture is owned by the\n // RT, not the `_textures` registry).\n for (const rt of engine._renderTargets) {\n if (!rt._disposed) {\n rt._restore!(engine);\n }\n }\n // Mesh buffers re-upload their retained CPU data into fresh GL buffers.\n for (const buf of engine._buffers) {\n if (!buf._disposed) {\n buf._restore!(engine);\n }\n }\n if (engine._wasLoopActive && engine._loops.length > 0 && engine._scheduleFrame !== null) {\n engine._scheduleFrame(engine);\n }\n const cbs = engine._onRestored.slice();\n for (const cb of cbs) {\n try {\n cb();\n } catch (err) {\n console.error(\"lite-gl: onRestored callback threw\", err);\n }\n }\n}\n\nfunction queryCaps(gl: WebGL2RenderingContext): GLEngineCaps {\n const parallelExt = gl.getExtension(\"KHR_parallel_shader_compile\") as { COMPLETION_STATUS_KHR: number } | null;\n // `getExtension` both queries and enables these capabilities, so they must\n // be reacquired after context restoration before resources are rebuilt.\n const colorBufferFloat = gl.getExtension(\"EXT_color_buffer_float\") !== null;\n const colorBufferHalfFloat = gl.getExtension(\"EXT_color_buffer_half_float\") !== null;\n const floatLinear = gl.getExtension(\"OES_texture_float_linear\") !== null;\n return {\n maxTextureSize: gl.getParameter(gl.MAX_TEXTURE_SIZE) as number,\n maxTextureUnits: gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS) as number,\n parallelShaderCompile: parallelExt,\n textureFloatRender: colorBufferFloat,\n textureFloatLinearFiltering: floatLinear,\n textureHalfFloatRender: colorBufferFloat || colorBufferHalfFloat,\n textureHalfFloatLinearFiltering: true,\n needPOTTextures: false,\n };\n}\n\nfunction clearObject(o: { [k: string]: unknown }): void {\n for (const key in o) {\n delete o[key];\n }\n}\n"]}
|
package/depth-stencil.d.ts
CHANGED
|
@@ -155,8 +155,9 @@ export declare function clearEngine(engine: GLEngineContext, options: GLClearOpt
|
|
|
155
155
|
* — the common case, and the correct choice when the target was created with
|
|
156
156
|
* `generateDepthBuffer: true`. When `false` the attachment is stencil-only
|
|
157
157
|
* (`STENCIL_INDEX8` on `STENCIL_ATTACHMENT`).
|
|
158
|
-
* @throws If a renderbuffer handle could not be allocated or the framebuffer is
|
|
159
|
-
* incomplete after attaching
|
|
158
|
+
* @throws If a renderbuffer handle could not be allocated, or the framebuffer is
|
|
159
|
+
* incomplete after attaching (unless `setFramebufferValidation(engine, false)`
|
|
160
|
+
* opted out of completeness checks).
|
|
160
161
|
*/
|
|
161
162
|
export declare function generateRenderTargetStencil(rt: GLRenderTarget, options?: {
|
|
162
163
|
depth?: boolean;
|