@babylonjs/lite-gl 1.22.0 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +98 -2
  3. package/context.d.ts +5 -0
  4. package/context.js +8 -0
  5. package/context.js.map +1 -1
  6. package/depth-stencil.d.ts +1 -14
  7. package/depth-stencil.js.map +1 -1
  8. package/effect-renderer.d.ts +1 -11
  9. package/effect-renderer.js.map +1 -1
  10. package/effect.d.ts +5 -27
  11. package/effect.js +22 -0
  12. package/effect.js.map +1 -1
  13. package/family.d.ts +470 -0
  14. package/family.js +14 -0
  15. package/family.js.map +1 -0
  16. package/index.d.ts +8 -6
  17. package/index.js +3 -3
  18. package/index.js.map +1 -1
  19. package/mesh.d.ts +4 -1
  20. package/mesh.js +10 -3
  21. package/mesh.js.map +1 -1
  22. package/native/command-stream.d.ts +1 -0
  23. package/native/command-stream.js +135 -0
  24. package/native/command-stream.js.map +1 -0
  25. package/native/context.d.ts +26 -0
  26. package/native/context.js +89 -0
  27. package/native/context.js.map +1 -0
  28. package/native/effect.d.ts +44 -0
  29. package/native/effect.js +276 -0
  30. package/native/effect.js.map +1 -0
  31. package/native/family.d.ts +75 -0
  32. package/native/family.js +2 -0
  33. package/native/family.js.map +1 -0
  34. package/native/identity.d.ts +11 -0
  35. package/native/identity.js +2 -0
  36. package/native/identity.js.map +1 -0
  37. package/native/index.d.ts +25 -0
  38. package/native/index.js +7 -0
  39. package/native/index.js.map +1 -0
  40. package/native/mesh.d.ts +53 -0
  41. package/native/mesh.js +137 -0
  42. package/native/mesh.js.map +1 -0
  43. package/native/render-target.d.ts +35 -0
  44. package/native/render-target.js +159 -0
  45. package/native/render-target.js.map +1 -0
  46. package/native/runtime.d.ts +1 -0
  47. package/native/runtime.js +12 -0
  48. package/native/runtime.js.map +1 -0
  49. package/native/state.d.ts +19 -0
  50. package/native/state.js +104 -0
  51. package/native/state.js.map +1 -0
  52. package/native/texture.d.ts +37 -0
  53. package/native/texture.js +86 -0
  54. package/native/texture.js.map +1 -0
  55. package/package.json +11 -3
  56. package/render-target.d.ts +7 -0
  57. package/render-target.js +38 -0
  58. package/render-target.js.map +1 -1
  59. package/scissor.d.ts +2 -2
  60. package/scissor.js +2 -2
  61. package/scissor.js.map +1 -1
  62. package/state.d.ts +1 -0
  63. package/state.js +2 -5
  64. package/state.js.map +1 -1
  65. package/text/text-renderer.js.map +1 -1
  66. package/web-family.d.ts +87 -0
  67. package/web-family.js +2 -0
  68. package/web-family.js.map +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"depth-stencil.js","sourceRoot":"","sources":["../src/depth-stencil.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EACH,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,eAAe,EACf,YAAY,EACZ,aAAa,EACb,aAAa,EACb,aAAa,EACb,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,GAClB,MAAM,YAAY,CAAC;AAEpB,yCAAyC;AACzC,qBAAqB;AACrB,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,+DAA+D;AAC/D,0BAA0B;AAC1B,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,yBAAyB;AACzB,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,oBAAoB;AACpB,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,qBAAqB;AACrB,MAAM,KAAK,GAAG,MAAM,CAAC;AACrB,oBAAoB;AACpB,MAAM,IAAI,GAAG,M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AAM,CAAC,MAAM,CAAC,gBAAgB,CAAC;IAC9C,EAAE,CAAC,eAAe,CAAC,WAAW,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC;IACjD,MAAM,CAAC,MAAM,CAAC,gBAAgB,GAAG,EAAE,CAAC,YAAY,CAAC;IACjD,EAAE,CAAC,uBAAuB,CAAC,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;IACrF,IAAI,MAAM,CAAC,MAAM,CAAC,gBAAgB,KAAK,MAAM,EAAE,CAAC;QAC5C,EAAE,CAAC,eAAe,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACxC,MAAM,CAAC,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC;IAC5C,CAAC;AACL,CAAC","sourcesContent":["/**\n * Depth, stencil, color-mask and clear state — the lite-gl counterpart of\n * Babylon's `_depthCullingState` / `_stencilState` / `setColorWrite` / `clear`.\n *\n * Like Babylon, these setters are DEFERRED: they buffer the requested values\n * into the DESIRED (`d*`) mirror fields of `GLState` and raise `statesDirty`,\n * issuing NO `gl.*` calls themselves. `applyGLStates` (apply-states.ts) flushes\n * the diff to GL right before each draw (and before `clearEngine`'s `gl.clear`,\n * since a clear respects the current write masks). Every field is reconciled\n * independently, so a flush that changes only one sub-state (e.g. just the\n * stencil op triple) issues only that GL call. Omitted setter fields leave the\n * corresponding desired value untouched (merge-from-desired).\n *\n * All setters are no-ops on a lost/disposed context.\n *\n * This module also hosts {@link generateRenderTargetStencil} — the tree-shakeable\n * opt-in that gives a `/render-target` {@link GLRenderTarget} a stencil (or packed\n * depth+stencil) attachment. Keeping the STENCIL_INDEX8 / DEPTH24_STENCIL8\n * renderbuffer code here (rather than in the render-target core) means a consumer\n * that only needs a depth buffer never ships it. The one-way type import below\n * (`depth-stencil` importing `render-target`) introduces NO cycle: render-target\n * must not import this module.\n */\nimport type { GLEngineContext } from \"./context.js\";\nimport type { GLRenderTarget } from \"./render-target.js\";\nimport { applyGLStates } from \"./apply-states.js\";\nimport {\n RS_CLEAR_A,\n RS_CLEAR_B,\n RS_CLEAR_G,\n RS_CLEAR_R,\n RS_COLOR_MASK,\n RS_CULL_ENABLED,\n RS_CULL_FACE,\n RS_DEPTH_FUNC,\n RS_DEPTH_MASK,\n RS_DEPTH_TEST,\n RS_DESIRED,\n RS_STENCIL_FUNC_FUNC,\n RS_STENCIL_FUNC_MASK,\n RS_STENCIL_FUNC_REF,\n RS_STENCIL_MASK,\n RS_STENCIL_OP_FAIL,\n RS_STENCIL_OP_ZFAIL,\n RS_STENCIL_OP_ZPASS,\n RS_STENCIL_TEST,\n} from \"./state.js\";\n\n// ── Clear bits (used by `clearEngine`).\n/** GL clear bits. */\nconst COLOR_BUFFER_BIT = 0x4000;\nconst DEPTH_BUFFER_BIT = 0x0100;\nconst STENCIL_BUFFER_BIT = 0x0400;\n\n// ── Test-enable enums for the per-category reconcilers below.\n/** GL `gl.DEPTH_TEST`. */\nconst DEPTH_TEST = 0x0b71;\n/** GL `gl.CULL_FACE`. */\nconst CULL_FACE = 0x0b44;\n/** GL `gl.STENCIL_TEST`. */\nconst STENCIL_TEST = 0x0b90;\n/** GL `gl.KEEP`. */\nconst KEEP = 0x1e00;\n/** GL `gl.FRONT`. */\nconst FRONT = 0x0404;\n/** GL `gl.BACK`. */\nconst BACK = 0x0405;\n/** GL `gl.FRONT_AND_BACK`. */\nconst FRONT_AND_BACK = 0x0408;\n// Two-sided mode appends actual slots 46..48 and desired slots 49..51 to the\n// compact 46-slot state array. Base indices remain unchanged.\nconst BACK_OP_FAIL = 46;\nconst BACK_OP_ZFAIL = 47;\nconst BACK_OP_ZPASS = 48;\nconst BACK_DESIRED = 3;\n\n// ── Framebuffer / renderbuffer enums (used only by generateRenderTargetStencil).\n// Module-local consts mirror render-target.ts's constant style. Because the\n// render-target core no longer references the stencil/packed enums, they live\n// here and tree-shake away for consumers that never opt into a stencil buffer.\n/** GL `gl.FRAMEBUFFER`. */\nconst FRAMEBUFFER = 0x8d40;\n/** GL `gl.RENDERBUFFER`. */\nconst RENDERBUFFER = 0x8d41;\n/** GL `gl.DEPTH24_STENCIL8` — packed depth+stencil sized format. */\nconst DEPTH24_STENCIL8 = 0x88f0;\n/** GL `gl.STENCIL_INDEX8` — stencil-only sized format. */\nconst STENCIL_INDEX8 = 0x8d48;\n/** GL `gl.DEPTH_STENCIL_ATTACHMENT`. */\nconst DEPTH_STENCIL_ATTACHMENT = 0x821a;\n/** GL `gl.STENCIL_ATTACHMENT`. */\nconst STENCIL_ATTACHMENT = 0x8d20;\n/** GL `gl.DEPTH_ATTACHMENT` — where the render-target core attaches its depth-only\n * renderbuffer (re-established when rolling back a failed stencil attach). */\nconst DEPTH_ATTACHMENT = 0x8d00;\n/** GL `gl.FRAMEBUFFER_COMPLETE`. */\nconst FRAMEBUFFER_COMPLETE = 0x8cd5;\n\n/** Depth-buffer configuration for {@link setDepthState}. Omitted fields are\n * left unchanged. */\nexport interface GLDepthState {\n /** Enable/disable the depth test (`gl.enable/disable(DEPTH_TEST)`). */\n test?: boolean;\n /** Enable/disable depth writes (`gl.depthMask`). */\n write?: boolean;\n /** Depth comparison function (`gl.depthFunc`), e.g. `gl.LESS`. */\n func?: GLenum;\n}\n\n/** Stencil configuration for {@link setStencilState}. Omitted fields are left\n * unchanged. Operation fields update both front and back faces; use\n * {@link setStencilOpSeparate} for per-face values. */\nexport interface GLStencilState {\n /** Enable/disable the stencil test (`gl.enable/disable(STENCIL_TEST)`). */\n test?: boolean;\n /** Comparison function (`gl.stencilFunc` arg 1), e.g. `gl.ALWAYS`. */\n func?: GLenum;\n /** Reference value (`gl.stencilFunc` arg 2). */\n ref?: number;\n /** Comparison mask (`gl.stencilFunc` arg 3). */\n funcMask?: number;\n /** Stencil write mask (`gl.stencilMask`). */\n mask?: number;\n /** Op when the stencil test fails (`gl.stencilOp` arg 1). */\n opFail?: GLenum;\n /** Op when the stencil test passes but depth fails (`gl.stencilOp` arg 2). */\n opZFail?: GLenum;\n /** Op when both stencil and depth pass (`gl.stencilOp` arg 3). */\n opZPass?: GLenum;\n}\n\n/** Per-face stencil operations for {@link setStencilOpSeparate}. Omitted fields\n * retain that face's desired value. */\nexport interface GLStencilOpState {\n /** Op when the stencil test fails (`gl.stencilOpSeparate` arg 2). */\n opFail?: GLenum;\n /** Op when the stencil test passes but depth fails (`gl.stencilOpSeparate` arg 3). */\n opZFail?: GLenum;\n /** Op when both stencil and depth pass (`gl.stencilOpSeparate` arg 4). */\n opZPass?: GLenum;\n}\n\n/** Seed the shared desired op tuple with WebGL's KEEP defaults. */\nfunction ensureStencilOpCacheInitialized(rs: Float64Array): void {\n if (rs[RS_STENCIL_OP_FAIL + RS_DESIRED] !== -1) {\n return;\n }\n rs[RS_STENCIL_OP_FAIL + RS_DESIRED] = KEEP;\n rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED] = KEEP;\n rs[RS_STENCIL_OP_ZPASS + RS_DESIRED] = KEEP;\n}\n\nfunction setDesiredStencilOps(rs: Float64Array, state: GLStencilOpState): void {\n if ((state.opFail ?? state.opZFail ?? state.opZPass) === undefined) {\n return;\n }\n ensureStencilOpCacheInitialized(rs);\n if (state.opFail !== undefined) {\n rs[RS_STENCIL_OP_FAIL + RS_DESIRED] = state.opFail;\n }\n if (state.opZFail !== undefined) {\n rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED] = state.opZFail;\n }\n if (state.opZPass !== undefined) {\n rs[RS_STENCIL_OP_ZPASS + RS_DESIRED] = state.opZPass;\n }\n}\n\n/** Store one complete GL operation tuple starting at `opIndex`. */\nfunction setStencilOps(rs: Float64Array, opIndex: number, fail: GLenum, zfail: GLenum, zpass: GLenum): void {\n rs[opIndex] = fail;\n rs[opIndex + 1] = zfail;\n rs[opIndex + 2] = zpass;\n}\n\nfunction resetStencilBack(rs: Float64Array): void {\n ensureStencilOpCacheInitialized(rs);\n setStencilOps(rs, BACK_OP_FAIL, rs[RS_STENCIL_OP_FAIL]!, rs[RS_STENCIL_OP_ZFAIL]!, rs[RS_STENCIL_OP_ZPASS]!);\n setStencilOps(rs, BACK_OP_FAIL + BACK_DESIRED, rs[RS_STENCIL_OP_FAIL + RS_DESIRED]!, rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED]!, rs[RS_STENCIL_OP_ZPASS + RS_DESIRED]!);\n}\n\nfunction ensureStencilBackCacheInitialized(rs: Float64Array): void {\n if (rs[RS_STENCIL_OP_FAIL + RS_DESIRED] === -1) {\n resetStencilBack(rs);\n }\n}\n\nfunction setDesiredStencilBackOps(rs: Float64Array, state: GLStencilOpState): void {\n if (state.opFail !== undefined) {\n rs[BACK_OP_FAIL + BACK_DESIRED] = state.opFail;\n }\n if (state.opZFail !== undefined) {\n rs[BACK_OP_ZFAIL + BACK_DESIRED] = state.opZFail;\n }\n if (state.opZPass !== undefined) {\n rs[BACK_OP_ZPASS + BACK_DESIRED] = state.opZPass;\n }\n}\n\n/** Mirror a shared stencil-op update to the lazily allocated back-face cache. */\nfunction mirrorSharedStencilOpsToBack(s: GLEngineContext[\"_state\"], state: GLStencilOpState): void {\n if ((state.opFail ?? state.opZFail ?? state.opZPass) === undefined) {\n return;\n }\n ensureStencilBackCacheInitialized(s.rs);\n setDesiredStencilBackOps(s.rs, state);\n}\n\n/** Lazily install back-face storage and the two-sided reconciler. */\nfunction enableSeparateStencil(s: GLEngineContext[\"_state\"]): void {\n if (s._setStencilBack !== undefined) {\n return;\n }\n const rs = new Float64Array(52);\n rs.set(s.rs);\n s.rs = rs;\n resetStencilBack(rs);\n s._setStencilBack = mirrorSharedStencilOpsToBack;\n s._flushStencil = flushStencilSeparate;\n}\n\n/** Options for {@link clearEngine}. */\nexport interface GLClearOptions {\n /** When set, clears the color buffer to this RGBA color (alpha default 1). */\n color?: { r: number; g: number; b: number; a?: number };\n /** Clear the depth buffer (respects the current depth write mask). */\n depth?: boolean;\n /** Clear the stencil buffer (respects the current stencil write mask). */\n stencil?: boolean;\n}\n\n/**\n * Buffer depth-buffer state (test enable, write mask, comparison function) into\n * the DESIRED state — the lite-gl equivalent of mutating Babylon's\n * `engine.depthCullingState.{depthTest,depthMask,depthFunc}`. Flushed to GL by\n * `applyGLStates` before the next draw / clear; omitted fields are untouched.\n *\n * @param engine - The engine.\n * @param state - The depth fields to change. Omitted fields are untouched.\n */\nexport function setDepthState(engine: GLEngineContext, state: GLDepthState): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n if (state.test !== undefined) {\n s.rs[RS_DEPTH_TEST + RS_DESIRED] = state.test ? 1 : 0;\n }\n if (state.write !== undefined) {\n s.rs[RS_DEPTH_MASK + RS_DESIRED] = state.write ? 1 : 0;\n }\n if (state.func !== undefined) {\n s.rs[RS_DEPTH_FUNC + RS_DESIRED] = state.func;\n }\n s._flushDepthCull = flushDepthCull;\n s.statesDirty = true;\n}\n\n/**\n * Enable/disable face culling and (optionally) set the cull face — the lite-gl\n * equivalent of `engine.depthCullingState.cull` + `cullFace`.\n *\n * @param engine - The engine.\n * @param enabled - Enable (`true`) or disable (`false`) `gl.CULL_FACE`.\n * @param face - Optional cull face (`gl.BACK` / `gl.FRONT` / `gl.FRONT_AND_BACK`).\n */\nexport function setCullState(engine: GLEngineContext, enabled: boolean, face?: GLenum): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n s.rs[RS_CULL_ENABLED + RS_DESIRED] = enabled ? 1 : 0;\n if (face !== undefined) {\n s.rs[RS_CULL_FACE + RS_DESIRED] = face;\n }\n s._flushDepthCull = flushDepthCull;\n s.statesDirty = true;\n}\n\n/**\n * Buffer stencil state (test enable, write mask, comparison func triple, op\n * triple) into the DESIRED state — the lite-gl equivalent of mutating Babylon's\n * `engine.stencilState.*`. Flushed by `applyGLStates` before the next draw /\n * clear; omitted fields are untouched (merge-from-desired).\n *\n * @param engine - The engine.\n * @param state - The stencil fields to change. Omitted fields are untouched.\n */\nexport function setStencilState(engine: GLEngineContext, state: GLStencilState): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n if (state.test !== undefined) {\n s.rs[RS_STENCIL_TEST + RS_DESIRED] = state.test ? 1 : 0;\n }\n if (state.func !== undefined) {\n s.rs[RS_STENCIL_FUNC_FUNC + RS_DESIRED] = state.func;\n }\n if (state.ref !== undefined) {\n s.rs[RS_STENCIL_FUNC_REF + RS_DESIRED] = state.ref;\n }\n if (state.funcMask !== undefined) {\n s.rs[RS_STENCIL_FUNC_MASK + RS_DESIRED] = state.funcMask;\n }\n if (state.mask !== undefined) {\n s.rs[RS_STENCIL_MASK + RS_DESIRED] = state.mask;\n }\n s._setStencilBack?.(s, state);\n if ((state.opFail ?? state.opZFail ?? state.opZPass) !== undefined) {\n ensureStencilOpCacheInitialized(s.rs);\n if (state.opFail !== undefined) {\n s.rs[RS_STENCIL_OP_FAIL + RS_DESIRED] = state.opFail;\n }\n if (state.opZFail !== undefined) {\n s.rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED] = state.opZFail;\n }\n if (state.opZPass !== undefined) {\n s.rs[RS_STENCIL_OP_ZPASS + RS_DESIRED] = state.opZPass;\n }\n }\n s._flushStencil ??= flushStencil;\n s.statesDirty = true;\n}\n\n/**\n * Buffer stencil operations for one face into the DESIRED state. This is the\n * deferred lite-gl counterpart of `gl.stencilOpSeparate`; use it to apply\n * different winding operations to front and back faces in one draw. A\n * `FRONT_AND_BACK` update applies each provided operation to both faces while\n * leaving omitted operations unchanged on each face.\n *\n * @param engine - The engine.\n * @param face - `gl.FRONT`, `gl.BACK`, or `gl.FRONT_AND_BACK`.\n * @param state - The operation fields to change for the selected face(s).\n * @throws If `face` is not `gl.FRONT`, `gl.BACK`, or `gl.FRONT_AND_BACK`.\n */\nexport function setStencilOpSeparate(engine: GLEngineContext, face: GLenum, state: GLStencilOpState): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n if (face !== FRONT && face !== BACK && face !== FRONT_AND_BACK) {\n throw new Error(\"lite-gl: invalid face\");\n }\n if ((state.opFail ?? state.opZFail ?? state.opZPass) === undefined) {\n return;\n }\n enableSeparateStencil(s);\n ensureStencilBackCacheInitialized(s.rs);\n if (face !== BACK) {\n setDesiredStencilOps(s.rs, state);\n }\n if (face !== FRONT) {\n setDesiredStencilBackOps(s.rs, state);\n }\n s.statesDirty = true;\n}\n\n/**\n * Buffer the color write mask into the DESIRED state — the lite-gl equivalent of\n * Babylon's `setColorWrite` (which passes the same flag to all four channels).\n * Flushed to GL (`gl.colorMask`) by `applyGLStates` before the next draw /\n * clear.\n *\n * @param engine - The engine.\n * @param r - Write red.\n * @param g - Write green.\n * @param b - Write blue.\n * @param a - Write alpha.\n */\nexport function setColorMask(engine: GLEngineContext, r: boolean, g: boolean, b: boolean, a: boolean): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const packed = (r ? 8 : 0) | (g ? 4 : 0) | (b ? 2 : 0) | (a ? 1 : 0);\n const s = engine._state;\n s.rs[RS_COLOR_MASK + RS_DESIRED] = packed;\n s._flushColorMask = flushColorMask;\n s.statesDirty = true;\n}\n\n/**\n * Clear the currently-bound framebuffer's color / depth / stencil buffers — the\n * lite-gl equivalent of Babylon's `clear(color, backBuffer, depth, stencil)`.\n * Depth/stencil clears respect the current write masks (set them first via\n * {@link setDepthState} / {@link setStencilState}). No-op when nothing is\n * requested or the context is lost/disposed.\n *\n * @param engine - The engine.\n * @param options - Which buffers to clear (and the color value).\n */\nexport function clearEngine(engine: GLEngineContext, options: GLClearOptions): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n let mask = 0;\n if (options.color !== undefined) {\n const c = options.color;\n const a = c.a ?? 1;\n const rs = engine._state.rs;\n // Cached: gl.clearColor is per-context state GL retains, so only re-issue\n // it when the requested color actually changes (Babylon re-sets it every\n // clear; this elides the redundant JS↔native call for constant backgrounds).\n if (rs[RS_CLEAR_R] !== c.r || rs[RS_CLEAR_G] !== c.g || rs[RS_CLEAR_B] !== c.b || rs[RS_CLEAR_A] !== a) {\n gl.clearColor(c.r, c.g, c.b, a);\n rs[RS_CLEAR_R] = c.r;\n rs[RS_CLEAR_G] = c.g;\n rs[RS_CLEAR_B] = c.b;\n rs[RS_CLEAR_A] = a;\n }\n mask |= COLOR_BUFFER_BIT;\n }\n if (options.depth === true) {\n mask |= DEPTH_BUFFER_BIT;\n }\n if (options.stencil === true) {\n mask |= STENCIL_BUFFER_BIT;\n }\n if (mask !== 0) {\n // Babylon parity: a clear respects the current depth/stencil/color write\n // masks, so flush any deferred state before clearing.\n applyGLStates(engine);\n gl.clear(mask);\n }\n}\n\n/* ─────────────────── deferred render-state reconcilers ──────────────────────\n * The per-category half of `applyGLStates`. Each setter above installs the\n * matching reconciler onto its `_state._flush*` slot; `applyGLStates`\n * (apply-states.ts) dispatches ONLY through those slots. Co-locating them with\n * their setters makes each one reachable solely when its setter is in the bundle,\n * so a scene that never touches depth/cull, stencil, or color-mask tree-shakes\n * the corresponding reconciler — and its GL code — away entirely. Each reconciles\n * its DESIRED (`rs[RS_X + RS_DESIRED]`) slots against the ACTUAL twins (`rs[RS_X]`)\n * and issues only the `gl.*` calls that changed, in the same order and with the\n * same elision rules as the former monolithic flush. */\n\n/** Reconcile depth + cull (Babylon's `_depthCullingState.apply`). @internal */\nfunction flushDepthCull(engine: GLEngineContext): void {\n const gl = engine.gl;\n const rs = engine._state.rs;\n const dTest = rs[RS_DEPTH_TEST + RS_DESIRED]!;\n if (dTest !== rs[RS_DEPTH_TEST]) {\n rs[RS_DEPTH_TEST] = dTest;\n if (dTest === 1) {\n gl.enable(DEPTH_TEST);\n } else {\n gl.disable(DEPTH_TEST);\n }\n }\n const dMask = rs[RS_DEPTH_MASK + RS_DESIRED]!;\n if (dMask !== rs[RS_DEPTH_MASK]) {\n rs[RS_DEPTH_MASK] = dMask;\n gl.depthMask(dMask === 1);\n }\n const dFunc = rs[RS_DEPTH_FUNC + RS_DESIRED]!;\n if (dFunc !== rs[RS_DEPTH_FUNC]) {\n rs[RS_DEPTH_FUNC] = dFunc;\n gl.depthFunc(dFunc);\n }\n const dCull = rs[RS_CULL_ENABLED + RS_DESIRED]!;\n if (dCull !== rs[RS_CULL_ENABLED]) {\n rs[RS_CULL_ENABLED] = dCull;\n if (dCull === 1) {\n gl.enable(CULL_FACE);\n } else {\n gl.disable(CULL_FACE);\n }\n }\n const dCullFace = rs[RS_CULL_FACE + RS_DESIRED]!;\n if (dCullFace !== rs[RS_CULL_FACE]) {\n rs[RS_CULL_FACE] = dCullFace;\n gl.cullFace(dCullFace);\n }\n}\n\nfunction flushStencilCommon(engine: GLEngineContext): void {\n const gl = engine.gl;\n const rs = engine._state.rs;\n const dTest = rs[RS_STENCIL_TEST + RS_DESIRED]!;\n if (dTest !== rs[RS_STENCIL_TEST]) {\n rs[RS_STENCIL_TEST] = dTest;\n if (dTest === 1) {\n gl.enable(STENCIL_TEST);\n } else {\n gl.disable(STENCIL_TEST);\n }\n }\n const dMask = rs[RS_STENCIL_MASK + RS_DESIRED]!;\n if (dMask !== rs[RS_STENCIL_MASK]) {\n rs[RS_STENCIL_MASK] = dMask;\n gl.stencilMask(dMask);\n }\n const dFuncFunc = rs[RS_STENCIL_FUNC_FUNC + RS_DESIRED]!;\n const dFuncRef = rs[RS_STENCIL_FUNC_REF + RS_DESIRED]!;\n const dFuncMask = rs[RS_STENCIL_FUNC_MASK + RS_DESIRED]!;\n if (dFuncFunc !== rs[RS_STENCIL_FUNC_FUNC] || dFuncRef !== rs[RS_STENCIL_FUNC_REF] || dFuncMask !== rs[RS_STENCIL_FUNC_MASK]) {\n rs[RS_STENCIL_FUNC_FUNC] = dFuncFunc;\n rs[RS_STENCIL_FUNC_REF] = dFuncRef;\n rs[RS_STENCIL_FUNC_MASK] = dFuncMask;\n gl.stencilFunc(dFuncFunc, dFuncRef, dFuncMask);\n }\n}\n\n/** Reconcile the compact shared stencil state. @internal */\nfunction flushStencil(engine: GLEngineContext): void {\n flushStencilCommon(engine);\n const gl = engine.gl;\n const rs = engine._state.rs;\n const frontOpFail = rs[RS_STENCIL_OP_FAIL + RS_DESIRED]!;\n if (frontOpFail === -1) {\n return;\n }\n const frontOpZFail = rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED]!;\n const frontOpZPass = rs[RS_STENCIL_OP_ZPASS + RS_DESIRED]!;\n const frontChanged = frontOpFail !== rs[RS_STENCIL_OP_FAIL] || frontOpZFail !== rs[RS_STENCIL_OP_ZFAIL] || frontOpZPass !== rs[RS_STENCIL_OP_ZPASS];\n if (frontChanged) {\n rs[RS_STENCIL_OP_FAIL] = frontOpFail;\n rs[RS_STENCIL_OP_ZFAIL] = frontOpZFail;\n rs[RS_STENCIL_OP_ZPASS] = frontOpZPass;\n gl.stencilOp(frontOpFail, frontOpZFail, frontOpZPass);\n }\n}\n\n/** Reconcile independently cached front/back stencil operation tuples. */\nfunction flushStencilSeparate(engine: GLEngineContext): void {\n flushStencilCommon(engine);\n const gl = engine.gl;\n const rs = engine._state.rs;\n const frontOpFail = rs[RS_STENCIL_OP_FAIL + RS_DESIRED]!;\n if (frontOpFail === -1) {\n return;\n }\n const frontOpZFail = rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED]!;\n const frontOpZPass = rs[RS_STENCIL_OP_ZPASS + RS_DESIRED]!;\n const backOpFail = rs[BACK_OP_FAIL + BACK_DESIRED]!;\n const backOpZFail = rs[BACK_OP_ZFAIL + BACK_DESIRED]!;\n const backOpZPass = rs[BACK_OP_ZPASS + BACK_DESIRED]!;\n const frontChanged = frontOpFail !== rs[RS_STENCIL_OP_FAIL] || frontOpZFail !== rs[RS_STENCIL_OP_ZFAIL] || frontOpZPass !== rs[RS_STENCIL_OP_ZPASS];\n const backChanged = backOpFail !== rs[BACK_OP_FAIL] || backOpZFail !== rs[BACK_OP_ZFAIL] || backOpZPass !== rs[BACK_OP_ZPASS];\n if (!frontChanged && !backChanged) {\n return;\n }\n const facesMatch = frontOpFail === backOpFail && frontOpZFail === backOpZFail && frontOpZPass === backOpZPass;\n if (facesMatch) {\n setStencilOps(rs, RS_STENCIL_OP_FAIL, frontOpFail, frontOpZFail, frontOpZPass);\n setStencilOps(rs, BACK_OP_FAIL, backOpFail, backOpZFail, backOpZPass);\n gl.stencilOp(frontOpFail, frontOpZFail, frontOpZPass);\n return;\n }\n if (frontChanged) {\n setStencilOps(rs, RS_STENCIL_OP_FAIL, frontOpFail, frontOpZFail, frontOpZPass);\n gl.stencilOpSeparate(FRONT, frontOpFail, frontOpZFail, frontOpZPass);\n }\n if (backChanged) {\n setStencilOps(rs, BACK_OP_FAIL, backOpFail, backOpZFail, backOpZPass);\n gl.stencilOpSeparate(BACK, backOpFail, backOpZFail, backOpZPass);\n }\n}\n\n/** Reconcile the packed color-write mask (Babylon's `setColorWrite`). @internal */\nfunction flushColorMask(engine: GLEngineContext): void {\n const rs = engine._state.rs;\n const dColorMask = rs[RS_COLOR_MASK + RS_DESIRED]!;\n if (dColorMask !== rs[RS_COLOR_MASK]) {\n rs[RS_COLOR_MASK] = dColorMask;\n engine.gl.colorMask((dColorMask & 8) !== 0, (dColorMask & 4) !== 0, (dColorMask & 2) !== 0, (dColorMask & 1) !== 0);\n }\n}\n\n/**\n * Opt-in: give a `/render-target` {@link GLRenderTarget} a stencil attachment,\n * replacing the core's depth-only `DEPTH_COMPONENT16` renderbuffer with either a\n * packed **`DEPTH24_STENCIL8`** buffer (default — depth *and* stencil) or a\n * stencil-only **`STENCIL_INDEX8`** buffer.\n *\n * Stencil is intentionally NOT a {@link createRenderTarget} option: keeping this\n * helper in the depth-stencil module means the stencil/packed renderbuffer\n * code tree-shakes out of every bundle that only needs a color (and optional\n * depth) target.\n *\n * The attachment is **restore-correct**: it is rebuilt automatically — at the new\n * size on {@link resizeRenderTarget}, and into the fresh framebuffer after a\n * `webglcontextrestored` event — so the stencil survives for the life of the\n * target, and {@link disposeRenderTarget} releases it along with the target.\n *\n * No-op on a lost/disposed context or a disposed target.\n *\n * @param rt - The render target to attach the stencil buffer to.\n * @param options - `depth` (default `true`): when `true` the attachment is a\n * packed depth+stencil buffer (`DEPTH24_STENCIL8` on `DEPTH_STENCIL_ATTACHMENT`)\n * — the common case, and the correct choice when the target was created with\n * `generateDepthBuffer: true`. When `false` the attachment is stencil-only\n * (`STENCIL_INDEX8` on `STENCIL_ATTACHMENT`).\n * @throws If a renderbuffer handle could not be allocated or the framebuffer is\n * incomplete after attaching.\n */\nexport function generateRenderTargetStencil(rt: GLRenderTarget, options?: { depth?: boolean }): void {\n const engine = rt._engine;\n if (engine._isLost || engine._disposed || rt._disposed) {\n return;\n }\n const packDepth = options?.depth ?? true;\n const attachment = packDepth ? DEPTH_STENCIL_ATTACHMENT : STENCIL_ATTACHMENT;\n const format = packDepth ? DEPTH24_STENCIL8 : STENCIL_INDEX8;\n\n const build = (e: GLEngineContext): void => {\n const gl = e.gl;\n // Capture the caller's draw target so this helper is STATE-NEUTRAL: it must\n // not silently redirect subsequent draws to `rt` (during an internal\n // rebuild `prevFb` is `rt._framebuffer`, which the core re-checks next).\n const prevFb = e._state.boundFramebuffer;\n const newRb = gl.createRenderbuffer();\n if (newRb === null) {\n throw new Error(\"lite-gl: gl.createRenderbuffer returned null (render target stencil)\");\n }\n let committed = false;\n try {\n gl.bindFramebuffer(FRAMEBUFFER, rt._framebuffer);\n e._state.boundFramebuffer = rt._framebuffer;\n gl.bindRenderbuffer(RENDERBUFFER, newRb);\n gl.renderbufferStorage(RENDERBUFFER, format, rt.width, rt.height);\n gl.framebufferRenderbuffer(FRAMEBUFFER, attachment, RENDERBUFFER, newRb);\n gl.bindRenderbuffer(RENDERBUFFER, null);\n const status = gl.checkFramebufferStatus(FRAMEBUFFER);\n if (status !== FRAMEBUFFER_COMPLETE) {\n throw new Error(`lite-gl: render target framebuffer incomplete after stencil attach (status 0x${status.toString(16)})`);\n }\n // Commit only after a complete attachment: release the buffer we\n // replaced (the core depth-only one, or our own from a prior rebuild).\n if (rt._depthStencil !== null) {\n gl.deleteRenderbuffer(rt._depthStencil);\n }\n rt._depthStencil = newRb;\n committed = true;\n } finally {\n if (!committed) {\n // Any non-committed exit (incomplete framebuffer OR an unexpected\n // GL throw): detach + delete the buffer we couldn't adopt so it\n // never leaks, leaving the attachment point empty for the\n // caller-level rollback to re-establish the prior buffer.\n gl.framebufferRenderbuffer(FRAMEBUFFER, attachment, RENDERBUFFER, null);\n gl.deleteRenderbuffer(newRb);\n }\n // Restore the caller's draw target + the bound-framebuffer cache.\n if (e._state.boundFramebuffer !== prevFb) {\n gl.bindFramebuffer(FRAMEBUFFER, prevFb);\n e._state.boundFramebuffer = prevFb;\n }\n }\n };\n\n // Build once now, but COMMIT the resize/restore hook only if it succeeds — a\n // failed opt-in must leave the target exactly as it was. The packed attach\n // above can clear the core `DEPTH_ATTACHMENT`, so on failure restore the prior\n // hook AND re-establish the prior depth/stencil attachment (the prior hook's,\n // or the core depth-only buffer).\n const prevHook = rt._rebuildDepthStencil;\n const prevDepthStencil = rt._depthStencil;\n try {\n build(engine);\n } catch (err) {\n rt._rebuildDepthStencil = prevHook;\n try {\n if (prevHook !== undefined) {\n prevHook(engine);\n } else if (prevDepthStencil !== null) {\n reattachCoreDepthBuffer(engine, rt, prevDepthStencil);\n }\n } catch {\n // Best-effort restore; surface the original failure below.\n }\n throw err;\n }\n rt._rebuildDepthStencil = build;\n}\n\n/**\n * Re-attach a core depth-only renderbuffer at `DEPTH_ATTACHMENT` — used to roll a\n * render target back when a packed {@link generateRenderTargetStencil} attach\n * fails completeness (attaching at `DEPTH_STENCIL_ATTACHMENT` clears the core\n * `DEPTH_ATTACHMENT`). State-neutral: restores the caller's bound framebuffer.\n * @internal\n */\nfunction reattachCoreDepthBuffer(engine: GLEngineContext, rt: GLRenderTarget, depthBuffer: WebGLRenderbuffer): void {\n const gl = engine.gl;\n const prevFb = engine._state.boundFramebuffer;\n gl.bindFramebuffer(FRAMEBUFFER, rt._framebuffer);\n engine._state.boundFramebuffer = rt._framebuffer;\n gl.framebufferRenderbuffer(FRAMEBUFFER, DEPTH_ATTACHMENT, RENDERBUFFER, depthBuffer);\n if (engine._state.boundFramebuffer !== prevFb) {\n gl.bindFramebuffer(FRAMEBUFFER, prevFb);\n engine._state.boundFramebuffer = prevFb;\n }\n}\n"]}
1
+ {"version":3,"file":"depth-stencil.js","sourceRoot":"","sources":["../src/depth-stencil.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EACH,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,eAAe,EACf,YAAY,EACZ,aAAa,EACb,aAAa,EACb,aAAa,EACb,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,GAClB,MAAM,YAAY,CAAC;AAEpB,yCAAyC;AACzC,qBAAqB;AACrB,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,+DAA+D;AAC/D,0BAA0B;AAC1B,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,yBAAyB;AACzB,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,oBAAoB;AACpB,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,qBAAqB;AACrB,MAAM,KAAK,GAAG,MAAM,CAAC;AACrB,oBAAoB;AACpB,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,8BAA8B;AAC9B,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,6EAA6E;AAC7E,8DAA8D;AAC9D,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB,kFAAkF;AAClF,4EAA4E;AAC5E,8EAA8E;AAC9E,+EAA+E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AC,gBAAgB,KAAK,MAAM,EAAE,CAAC;QAC5C,EAAE,CAAC,eAAe,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACxC,MAAM,CAAC,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC;IAC5C,CAAC;AACL,CAAC","sourcesContent":["/**\n * Depth, stencil, color-mask and clear state — the lite-gl counterpart of\n * Babylon's `_depthCullingState` / `_stencilState` / `setColorWrite` / `clear`.\n *\n * Like Babylon, these setters are DEFERRED: they buffer the requested values\n * into the DESIRED (`d*`) mirror fields of `GLState` and raise `statesDirty`,\n * issuing NO `gl.*` calls themselves. `applyGLStates` (apply-states.ts) flushes\n * the diff to GL right before each draw (and before `clearEngine`'s `gl.clear`,\n * since a clear respects the current write masks). Every field is reconciled\n * independently, so a flush that changes only one sub-state (e.g. just the\n * stencil op triple) issues only that GL call. Omitted setter fields leave the\n * corresponding desired value untouched (merge-from-desired).\n *\n * All setters are no-ops on a lost/disposed context.\n *\n * This module also hosts {@link generateRenderTargetStencil} — the tree-shakeable\n * opt-in that gives a `/render-target` {@link GLRenderTarget} a stencil (or packed\n * depth+stencil) attachment. Keeping the STENCIL_INDEX8 / DEPTH24_STENCIL8\n * renderbuffer code here (rather than in the render-target core) means a consumer\n * that only needs a depth buffer never ships it. The one-way type import below\n * (`depth-stencil` importing `render-target`) introduces NO cycle: render-target\n * must not import this module.\n */\nimport type { GLEngineContext } from \"./context.js\";\nimport type { GLClearOptions } from \"./family.js\";\nimport type { GLRenderTarget } from \"./render-target.js\";\nimport { applyGLStates } from \"./apply-states.js\";\nimport {\n RS_CLEAR_A,\n RS_CLEAR_B,\n RS_CLEAR_G,\n RS_CLEAR_R,\n RS_COLOR_MASK,\n RS_CULL_ENABLED,\n RS_CULL_FACE,\n RS_DEPTH_FUNC,\n RS_DEPTH_MASK,\n RS_DEPTH_TEST,\n RS_DESIRED,\n RS_STENCIL_FUNC_FUNC,\n RS_STENCIL_FUNC_MASK,\n RS_STENCIL_FUNC_REF,\n RS_STENCIL_MASK,\n RS_STENCIL_OP_FAIL,\n RS_STENCIL_OP_ZFAIL,\n RS_STENCIL_OP_ZPASS,\n RS_STENCIL_TEST,\n} from \"./state.js\";\n\n// ── Clear bits (used by `clearEngine`).\n/** GL clear bits. */\nconst COLOR_BUFFER_BIT = 0x4000;\nconst DEPTH_BUFFER_BIT = 0x0100;\nconst STENCIL_BUFFER_BIT = 0x0400;\n\n// ── Test-enable enums for the per-category reconcilers below.\n/** GL `gl.DEPTH_TEST`. */\nconst DEPTH_TEST = 0x0b71;\n/** GL `gl.CULL_FACE`. */\nconst CULL_FACE = 0x0b44;\n/** GL `gl.STENCIL_TEST`. */\nconst STENCIL_TEST = 0x0b90;\n/** GL `gl.KEEP`. */\nconst KEEP = 0x1e00;\n/** GL `gl.FRONT`. */\nconst FRONT = 0x0404;\n/** GL `gl.BACK`. */\nconst BACK = 0x0405;\n/** GL `gl.FRONT_AND_BACK`. */\nconst FRONT_AND_BACK = 0x0408;\n// Two-sided mode appends actual slots 46..48 and desired slots 49..51 to the\n// compact 46-slot state array. Base indices remain unchanged.\nconst BACK_OP_FAIL = 46;\nconst BACK_OP_ZFAIL = 47;\nconst BACK_OP_ZPASS = 48;\nconst BACK_DESIRED = 3;\n\n// ── Framebuffer / renderbuffer enums (used only by generateRenderTargetStencil).\n// Module-local consts mirror render-target.ts's constant style. Because the\n// render-target core no longer references the stencil/packed enums, they live\n// here and tree-shake away for consumers that never opt into a stencil buffer.\n/** GL `gl.FRAMEBUFFER`. */\nconst FRAMEBUFFER = 0x8d40;\n/** GL `gl.RENDERBUFFER`. */\nconst RENDERBUFFER = 0x8d41;\n/** GL `gl.DEPTH24_STENCIL8` — packed depth+stencil sized format. */\nconst DEPTH24_STENCIL8 = 0x88f0;\n/** GL `gl.STENCIL_INDEX8` — stencil-only sized format. */\nconst STENCIL_INDEX8 = 0x8d48;\n/** GL `gl.DEPTH_STENCIL_ATTACHMENT`. */\nconst DEPTH_STENCIL_ATTACHMENT = 0x821a;\n/** GL `gl.STENCIL_ATTACHMENT`. */\nconst STENCIL_ATTACHMENT = 0x8d20;\n/** GL `gl.DEPTH_ATTACHMENT` — where the render-target core attaches its depth-only\n * renderbuffer (re-established when rolling back a failed stencil attach). */\nconst DEPTH_ATTACHMENT = 0x8d00;\n/** GL `gl.FRAMEBUFFER_COMPLETE`. */\nconst FRAMEBUFFER_COMPLETE = 0x8cd5;\n\n/** Depth-buffer configuration for {@link setDepthState}. Omitted fields are\n * left unchanged. */\nexport interface GLDepthState {\n /** Enable/disable the depth test (`gl.enable/disable(DEPTH_TEST)`). */\n test?: boolean;\n /** Enable/disable depth writes (`gl.depthMask`). */\n write?: boolean;\n /** Depth comparison function (`gl.depthFunc`), e.g. `gl.LESS`. */\n func?: GLenum;\n}\n\n/** Stencil configuration for {@link setStencilState}. Omitted fields are left\n * unchanged. Operation fields update both front and back faces; use\n * {@link setStencilOpSeparate} for per-face values. */\nexport interface GLStencilState {\n /** Enable/disable the stencil test (`gl.enable/disable(STENCIL_TEST)`). */\n test?: boolean;\n /** Comparison function (`gl.stencilFunc` arg 1), e.g. `gl.ALWAYS`. */\n func?: GLenum;\n /** Reference value (`gl.stencilFunc` arg 2). */\n ref?: number;\n /** Comparison mask (`gl.stencilFunc` arg 3). */\n funcMask?: number;\n /** Stencil write mask (`gl.stencilMask`). */\n mask?: number;\n /** Op when the stencil test fails (`gl.stencilOp` arg 1). */\n opFail?: GLenum;\n /** Op when the stencil test passes but depth fails (`gl.stencilOp` arg 2). */\n opZFail?: GLenum;\n /** Op when both stencil and depth pass (`gl.stencilOp` arg 3). */\n opZPass?: GLenum;\n}\n\n/** Per-face stencil operations for {@link setStencilOpSeparate}. Omitted fields\n * retain that face's desired value. */\nexport interface GLStencilOpState {\n /** Op when the stencil test fails (`gl.stencilOpSeparate` arg 2). */\n opFail?: GLenum;\n /** Op when the stencil test passes but depth fails (`gl.stencilOpSeparate` arg 3). */\n opZFail?: GLenum;\n /** Op when both stencil and depth pass (`gl.stencilOpSeparate` arg 4). */\n opZPass?: GLenum;\n}\n\n/** Seed the shared desired op tuple with WebGL's KEEP defaults. */\nfunction ensureStencilOpCacheInitialized(rs: Float64Array): void {\n if (rs[RS_STENCIL_OP_FAIL + RS_DESIRED] !== -1) {\n return;\n }\n rs[RS_STENCIL_OP_FAIL + RS_DESIRED] = KEEP;\n rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED] = KEEP;\n rs[RS_STENCIL_OP_ZPASS + RS_DESIRED] = KEEP;\n}\n\nfunction setDesiredStencilOps(rs: Float64Array, state: GLStencilOpState): void {\n if ((state.opFail ?? state.opZFail ?? state.opZPass) === undefined) {\n return;\n }\n ensureStencilOpCacheInitialized(rs);\n if (state.opFail !== undefined) {\n rs[RS_STENCIL_OP_FAIL + RS_DESIRED] = state.opFail;\n }\n if (state.opZFail !== undefined) {\n rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED] = state.opZFail;\n }\n if (state.opZPass !== undefined) {\n rs[RS_STENCIL_OP_ZPASS + RS_DESIRED] = state.opZPass;\n }\n}\n\n/** Store one complete GL operation tuple starting at `opIndex`. */\nfunction setStencilOps(rs: Float64Array, opIndex: number, fail: GLenum, zfail: GLenum, zpass: GLenum): void {\n rs[opIndex] = fail;\n rs[opIndex + 1] = zfail;\n rs[opIndex + 2] = zpass;\n}\n\nfunction resetStencilBack(rs: Float64Array): void {\n ensureStencilOpCacheInitialized(rs);\n setStencilOps(rs, BACK_OP_FAIL, rs[RS_STENCIL_OP_FAIL]!, rs[RS_STENCIL_OP_ZFAIL]!, rs[RS_STENCIL_OP_ZPASS]!);\n setStencilOps(rs, BACK_OP_FAIL + BACK_DESIRED, rs[RS_STENCIL_OP_FAIL + RS_DESIRED]!, rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED]!, rs[RS_STENCIL_OP_ZPASS + RS_DESIRED]!);\n}\n\nfunction ensureStencilBackCacheInitialized(rs: Float64Array): void {\n if (rs[RS_STENCIL_OP_FAIL + RS_DESIRED] === -1) {\n resetStencilBack(rs);\n }\n}\n\nfunction setDesiredStencilBackOps(rs: Float64Array, state: GLStencilOpState): void {\n if (state.opFail !== undefined) {\n rs[BACK_OP_FAIL + BACK_DESIRED] = state.opFail;\n }\n if (state.opZFail !== undefined) {\n rs[BACK_OP_ZFAIL + BACK_DESIRED] = state.opZFail;\n }\n if (state.opZPass !== undefined) {\n rs[BACK_OP_ZPASS + BACK_DESIRED] = state.opZPass;\n }\n}\n\n/** Mirror a shared stencil-op update to the lazily allocated back-face cache. */\nfunction mirrorSharedStencilOpsToBack(s: GLEngineContext[\"_state\"], state: GLStencilOpState): void {\n if ((state.opFail ?? state.opZFail ?? state.opZPass) === undefined) {\n return;\n }\n ensureStencilBackCacheInitialized(s.rs);\n setDesiredStencilBackOps(s.rs, state);\n}\n\n/** Lazily install back-face storage and the two-sided reconciler. */\nfunction enableSeparateStencil(s: GLEngineContext[\"_state\"]): void {\n if (s._setStencilBack !== undefined) {\n return;\n }\n const rs = new Float64Array(52);\n rs.set(s.rs);\n s.rs = rs;\n resetStencilBack(rs);\n s._setStencilBack = mirrorSharedStencilOpsToBack;\n s._flushStencil = flushStencilSeparate;\n}\n\n/**\n * Buffer depth-buffer state (test enable, write mask, comparison function) into\n * the DESIRED state — the lite-gl equivalent of mutating Babylon's\n * `engine.depthCullingState.{depthTest,depthMask,depthFunc}`. Flushed to GL by\n * `applyGLStates` before the next draw / clear; omitted fields are untouched.\n *\n * @param engine - The engine.\n * @param state - The depth fields to change. Omitted fields are untouched.\n */\nexport function setDepthState(engine: GLEngineContext, state: GLDepthState): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n if (state.test !== undefined) {\n s.rs[RS_DEPTH_TEST + RS_DESIRED] = state.test ? 1 : 0;\n }\n if (state.write !== undefined) {\n s.rs[RS_DEPTH_MASK + RS_DESIRED] = state.write ? 1 : 0;\n }\n if (state.func !== undefined) {\n s.rs[RS_DEPTH_FUNC + RS_DESIRED] = state.func;\n }\n s._flushDepthCull = flushDepthCull;\n s.statesDirty = true;\n}\n\n/**\n * Enable/disable face culling and (optionally) set the cull face — the lite-gl\n * equivalent of `engine.depthCullingState.cull` + `cullFace`.\n *\n * @param engine - The engine.\n * @param enabled - Enable (`true`) or disable (`false`) `gl.CULL_FACE`.\n * @param face - Optional cull face (`gl.BACK` / `gl.FRONT` / `gl.FRONT_AND_BACK`).\n */\nexport function setCullState(engine: GLEngineContext, enabled: boolean, face?: GLenum): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n s.rs[RS_CULL_ENABLED + RS_DESIRED] = enabled ? 1 : 0;\n if (face !== undefined) {\n s.rs[RS_CULL_FACE + RS_DESIRED] = face;\n }\n s._flushDepthCull = flushDepthCull;\n s.statesDirty = true;\n}\n\n/**\n * Buffer stencil state (test enable, write mask, comparison func triple, op\n * triple) into the DESIRED state — the lite-gl equivalent of mutating Babylon's\n * `engine.stencilState.*`. Flushed by `applyGLStates` before the next draw /\n * clear; omitted fields are untouched (merge-from-desired).\n *\n * @param engine - The engine.\n * @param state - The stencil fields to change. Omitted fields are untouched.\n */\nexport function setStencilState(engine: GLEngineContext, state: GLStencilState): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n if (state.test !== undefined) {\n s.rs[RS_STENCIL_TEST + RS_DESIRED] = state.test ? 1 : 0;\n }\n if (state.func !== undefined) {\n s.rs[RS_STENCIL_FUNC_FUNC + RS_DESIRED] = state.func;\n }\n if (state.ref !== undefined) {\n s.rs[RS_STENCIL_FUNC_REF + RS_DESIRED] = state.ref;\n }\n if (state.funcMask !== undefined) {\n s.rs[RS_STENCIL_FUNC_MASK + RS_DESIRED] = state.funcMask;\n }\n if (state.mask !== undefined) {\n s.rs[RS_STENCIL_MASK + RS_DESIRED] = state.mask;\n }\n s._setStencilBack?.(s, state);\n if ((state.opFail ?? state.opZFail ?? state.opZPass) !== undefined) {\n ensureStencilOpCacheInitialized(s.rs);\n if (state.opFail !== undefined) {\n s.rs[RS_STENCIL_OP_FAIL + RS_DESIRED] = state.opFail;\n }\n if (state.opZFail !== undefined) {\n s.rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED] = state.opZFail;\n }\n if (state.opZPass !== undefined) {\n s.rs[RS_STENCIL_OP_ZPASS + RS_DESIRED] = state.opZPass;\n }\n }\n s._flushStencil ??= flushStencil;\n s.statesDirty = true;\n}\n\n/**\n * Buffer stencil operations for one face into the DESIRED state. This is the\n * deferred lite-gl counterpart of `gl.stencilOpSeparate`; use it to apply\n * different winding operations to front and back faces in one draw. A\n * `FRONT_AND_BACK` update applies each provided operation to both faces while\n * leaving omitted operations unchanged on each face.\n *\n * @param engine - The engine.\n * @param face - `gl.FRONT`, `gl.BACK`, or `gl.FRONT_AND_BACK`.\n * @param state - The operation fields to change for the selected face(s).\n * @throws If `face` is not `gl.FRONT`, `gl.BACK`, or `gl.FRONT_AND_BACK`.\n */\nexport function setStencilOpSeparate(engine: GLEngineContext, face: GLenum, state: GLStencilOpState): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n if (face !== FRONT && face !== BACK && face !== FRONT_AND_BACK) {\n throw new Error(\"lite-gl: invalid face\");\n }\n if ((state.opFail ?? state.opZFail ?? state.opZPass) === undefined) {\n return;\n }\n enableSeparateStencil(s);\n ensureStencilBackCacheInitialized(s.rs);\n if (face !== BACK) {\n setDesiredStencilOps(s.rs, state);\n }\n if (face !== FRONT) {\n setDesiredStencilBackOps(s.rs, state);\n }\n s.statesDirty = true;\n}\n\n/**\n * Buffer the color write mask into the DESIRED state — the lite-gl equivalent of\n * Babylon's `setColorWrite` (which passes the same flag to all four channels).\n * Flushed to GL (`gl.colorMask`) by `applyGLStates` before the next draw /\n * clear.\n *\n * @param engine - The engine.\n * @param r - Write red.\n * @param g - Write green.\n * @param b - Write blue.\n * @param a - Write alpha.\n */\nexport function setColorMask(engine: GLEngineContext, r: boolean, g: boolean, b: boolean, a: boolean): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const packed = (r ? 8 : 0) | (g ? 4 : 0) | (b ? 2 : 0) | (a ? 1 : 0);\n const s = engine._state;\n s.rs[RS_COLOR_MASK + RS_DESIRED] = packed;\n s._flushColorMask = flushColorMask;\n s.statesDirty = true;\n}\n\n/**\n * Clear the currently-bound framebuffer's color / depth / stencil buffers — the\n * lite-gl equivalent of Babylon's `clear(color, backBuffer, depth, stencil)`.\n * Depth/stencil clears respect the current write masks (set them first via\n * {@link setDepthState} / {@link setStencilState}). No-op when nothing is\n * requested or the context is lost/disposed.\n *\n * @param engine - The engine.\n * @param options - Which buffers to clear (and the color value).\n */\nexport function clearEngine(engine: GLEngineContext, options: GLClearOptions): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n let mask = 0;\n if (options.color !== undefined) {\n const c = options.color;\n const a = c.a ?? 1;\n const rs = engine._state.rs;\n // Cached: gl.clearColor is per-context state GL retains, so only re-issue\n // it when the requested color actually changes (Babylon re-sets it every\n // clear; this elides the redundant JS↔native call for constant backgrounds).\n if (rs[RS_CLEAR_R] !== c.r || rs[RS_CLEAR_G] !== c.g || rs[RS_CLEAR_B] !== c.b || rs[RS_CLEAR_A] !== a) {\n gl.clearColor(c.r, c.g, c.b, a);\n rs[RS_CLEAR_R] = c.r;\n rs[RS_CLEAR_G] = c.g;\n rs[RS_CLEAR_B] = c.b;\n rs[RS_CLEAR_A] = a;\n }\n mask |= COLOR_BUFFER_BIT;\n }\n if (options.depth === true) {\n mask |= DEPTH_BUFFER_BIT;\n }\n if (options.stencil === true) {\n mask |= STENCIL_BUFFER_BIT;\n }\n if (mask !== 0) {\n // Babylon parity: a clear respects the current depth/stencil/color write\n // masks, so flush any deferred state before clearing.\n applyGLStates(engine);\n gl.clear(mask);\n }\n}\n\n/* ─────────────────── deferred render-state reconcilers ──────────────────────\n * The per-category half of `applyGLStates`. Each setter above installs the\n * matching reconciler onto its `_state._flush*` slot; `applyGLStates`\n * (apply-states.ts) dispatches ONLY through those slots. Co-locating them with\n * their setters makes each one reachable solely when its setter is in the bundle,\n * so a scene that never touches depth/cull, stencil, or color-mask tree-shakes\n * the corresponding reconciler — and its GL code — away entirely. Each reconciles\n * its DESIRED (`rs[RS_X + RS_DESIRED]`) slots against the ACTUAL twins (`rs[RS_X]`)\n * and issues only the `gl.*` calls that changed, in the same order and with the\n * same elision rules as the former monolithic flush. */\n\n/** Reconcile depth + cull (Babylon's `_depthCullingState.apply`). @internal */\nfunction flushDepthCull(engine: GLEngineContext): void {\n const gl = engine.gl;\n const rs = engine._state.rs;\n const dTest = rs[RS_DEPTH_TEST + RS_DESIRED]!;\n if (dTest !== rs[RS_DEPTH_TEST]) {\n rs[RS_DEPTH_TEST] = dTest;\n if (dTest === 1) {\n gl.enable(DEPTH_TEST);\n } else {\n gl.disable(DEPTH_TEST);\n }\n }\n const dMask = rs[RS_DEPTH_MASK + RS_DESIRED]!;\n if (dMask !== rs[RS_DEPTH_MASK]) {\n rs[RS_DEPTH_MASK] = dMask;\n gl.depthMask(dMask === 1);\n }\n const dFunc = rs[RS_DEPTH_FUNC + RS_DESIRED]!;\n if (dFunc !== rs[RS_DEPTH_FUNC]) {\n rs[RS_DEPTH_FUNC] = dFunc;\n gl.depthFunc(dFunc);\n }\n const dCull = rs[RS_CULL_ENABLED + RS_DESIRED]!;\n if (dCull !== rs[RS_CULL_ENABLED]) {\n rs[RS_CULL_ENABLED] = dCull;\n if (dCull === 1) {\n gl.enable(CULL_FACE);\n } else {\n gl.disable(CULL_FACE);\n }\n }\n const dCullFace = rs[RS_CULL_FACE + RS_DESIRED]!;\n if (dCullFace !== rs[RS_CULL_FACE]) {\n rs[RS_CULL_FACE] = dCullFace;\n gl.cullFace(dCullFace);\n }\n}\n\nfunction flushStencilCommon(engine: GLEngineContext): void {\n const gl = engine.gl;\n const rs = engine._state.rs;\n const dTest = rs[RS_STENCIL_TEST + RS_DESIRED]!;\n if (dTest !== rs[RS_STENCIL_TEST]) {\n rs[RS_STENCIL_TEST] = dTest;\n if (dTest === 1) {\n gl.enable(STENCIL_TEST);\n } else {\n gl.disable(STENCIL_TEST);\n }\n }\n const dMask = rs[RS_STENCIL_MASK + RS_DESIRED]!;\n if (dMask !== rs[RS_STENCIL_MASK]) {\n rs[RS_STENCIL_MASK] = dMask;\n gl.stencilMask(dMask);\n }\n const dFuncFunc = rs[RS_STENCIL_FUNC_FUNC + RS_DESIRED]!;\n const dFuncRef = rs[RS_STENCIL_FUNC_REF + RS_DESIRED]!;\n const dFuncMask = rs[RS_STENCIL_FUNC_MASK + RS_DESIRED]!;\n if (dFuncFunc !== rs[RS_STENCIL_FUNC_FUNC] || dFuncRef !== rs[RS_STENCIL_FUNC_REF] || dFuncMask !== rs[RS_STENCIL_FUNC_MASK]) {\n rs[RS_STENCIL_FUNC_FUNC] = dFuncFunc;\n rs[RS_STENCIL_FUNC_REF] = dFuncRef;\n rs[RS_STENCIL_FUNC_MASK] = dFuncMask;\n gl.stencilFunc(dFuncFunc, dFuncRef, dFuncMask);\n }\n}\n\n/** Reconcile the compact shared stencil state. @internal */\nfunction flushStencil(engine: GLEngineContext): void {\n flushStencilCommon(engine);\n const gl = engine.gl;\n const rs = engine._state.rs;\n const frontOpFail = rs[RS_STENCIL_OP_FAIL + RS_DESIRED]!;\n if (frontOpFail === -1) {\n return;\n }\n const frontOpZFail = rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED]!;\n const frontOpZPass = rs[RS_STENCIL_OP_ZPASS + RS_DESIRED]!;\n const frontChanged = frontOpFail !== rs[RS_STENCIL_OP_FAIL] || frontOpZFail !== rs[RS_STENCIL_OP_ZFAIL] || frontOpZPass !== rs[RS_STENCIL_OP_ZPASS];\n if (frontChanged) {\n rs[RS_STENCIL_OP_FAIL] = frontOpFail;\n rs[RS_STENCIL_OP_ZFAIL] = frontOpZFail;\n rs[RS_STENCIL_OP_ZPASS] = frontOpZPass;\n gl.stencilOp(frontOpFail, frontOpZFail, frontOpZPass);\n }\n}\n\n/** Reconcile independently cached front/back stencil operation tuples. */\nfunction flushStencilSeparate(engine: GLEngineContext): void {\n flushStencilCommon(engine);\n const gl = engine.gl;\n const rs = engine._state.rs;\n const frontOpFail = rs[RS_STENCIL_OP_FAIL + RS_DESIRED]!;\n if (frontOpFail === -1) {\n return;\n }\n const frontOpZFail = rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED]!;\n const frontOpZPass = rs[RS_STENCIL_OP_ZPASS + RS_DESIRED]!;\n const backOpFail = rs[BACK_OP_FAIL + BACK_DESIRED]!;\n const backOpZFail = rs[BACK_OP_ZFAIL + BACK_DESIRED]!;\n const backOpZPass = rs[BACK_OP_ZPASS + BACK_DESIRED]!;\n const frontChanged = frontOpFail !== rs[RS_STENCIL_OP_FAIL] || frontOpZFail !== rs[RS_STENCIL_OP_ZFAIL] || frontOpZPass !== rs[RS_STENCIL_OP_ZPASS];\n const backChanged = backOpFail !== rs[BACK_OP_FAIL] || backOpZFail !== rs[BACK_OP_ZFAIL] || backOpZPass !== rs[BACK_OP_ZPASS];\n if (!frontChanged && !backChanged) {\n return;\n }\n const facesMatch = frontOpFail === backOpFail && frontOpZFail === backOpZFail && frontOpZPass === backOpZPass;\n if (facesMatch) {\n setStencilOps(rs, RS_STENCIL_OP_FAIL, frontOpFail, frontOpZFail, frontOpZPass);\n setStencilOps(rs, BACK_OP_FAIL, backOpFail, backOpZFail, backOpZPass);\n gl.stencilOp(frontOpFail, frontOpZFail, frontOpZPass);\n return;\n }\n if (frontChanged) {\n setStencilOps(rs, RS_STENCIL_OP_FAIL, frontOpFail, frontOpZFail, frontOpZPass);\n gl.stencilOpSeparate(FRONT, frontOpFail, frontOpZFail, frontOpZPass);\n }\n if (backChanged) {\n setStencilOps(rs, BACK_OP_FAIL, backOpFail, backOpZFail, backOpZPass);\n gl.stencilOpSeparate(BACK, backOpFail, backOpZFail, backOpZPass);\n }\n}\n\n/** Reconcile the packed color-write mask (Babylon's `setColorWrite`). @internal */\nfunction flushColorMask(engine: GLEngineContext): void {\n const rs = engine._state.rs;\n const dColorMask = rs[RS_COLOR_MASK + RS_DESIRED]!;\n if (dColorMask !== rs[RS_COLOR_MASK]) {\n rs[RS_COLOR_MASK] = dColorMask;\n engine.gl.colorMask((dColorMask & 8) !== 0, (dColorMask & 4) !== 0, (dColorMask & 2) !== 0, (dColorMask & 1) !== 0);\n }\n}\n\n/**\n * Opt-in: give a `/render-target` {@link GLRenderTarget} a stencil attachment,\n * replacing the core's depth-only `DEPTH_COMPONENT16` renderbuffer with either a\n * packed **`DEPTH24_STENCIL8`** buffer (default — depth *and* stencil) or a\n * stencil-only **`STENCIL_INDEX8`** buffer.\n *\n * Stencil is intentionally NOT a {@link createRenderTarget} option: keeping this\n * helper in the depth-stencil module means the stencil/packed renderbuffer\n * code tree-shakes out of every bundle that only needs a color (and optional\n * depth) target.\n *\n * The attachment is **restore-correct**: it is rebuilt automatically — at the new\n * size on {@link resizeRenderTarget}, and into the fresh framebuffer after a\n * `webglcontextrestored` event — so the stencil survives for the life of the\n * target, and {@link disposeRenderTarget} releases it along with the target.\n *\n * No-op on a lost/disposed context or a disposed target.\n *\n * @param rt - The render target to attach the stencil buffer to.\n * @param options - `depth` (default `true`): when `true` the attachment is a\n * packed depth+stencil buffer (`DEPTH24_STENCIL8` on `DEPTH_STENCIL_ATTACHMENT`)\n * — the common case, and the correct choice when the target was created with\n * `generateDepthBuffer: true`. When `false` the attachment is stencil-only\n * (`STENCIL_INDEX8` on `STENCIL_ATTACHMENT`).\n * @throws If a renderbuffer handle could not be allocated or the framebuffer is\n * incomplete after attaching.\n */\nexport function generateRenderTargetStencil(rt: GLRenderTarget, options?: { depth?: boolean }): void {\n const engine = rt._engine;\n if (engine._isLost || engine._disposed || rt._disposed) {\n return;\n }\n const packDepth = options?.depth ?? true;\n const attachment = packDepth ? DEPTH_STENCIL_ATTACHMENT : STENCIL_ATTACHMENT;\n const format = packDepth ? DEPTH24_STENCIL8 : STENCIL_INDEX8;\n\n const build = (e: GLEngineContext): void => {\n const gl = e.gl;\n // Capture the caller's draw target so this helper is STATE-NEUTRAL: it must\n // not silently redirect subsequent draws to `rt` (during an internal\n // rebuild `prevFb` is `rt._framebuffer`, which the core re-checks next).\n const prevFb = e._state.boundFramebuffer;\n const newRb = gl.createRenderbuffer();\n if (newRb === null) {\n throw new Error(\"lite-gl: gl.createRenderbuffer returned null (render target stencil)\");\n }\n let committed = false;\n try {\n gl.bindFramebuffer(FRAMEBUFFER, rt._framebuffer);\n e._state.boundFramebuffer = rt._framebuffer;\n gl.bindRenderbuffer(RENDERBUFFER, newRb);\n gl.renderbufferStorage(RENDERBUFFER, format, rt.width, rt.height);\n gl.framebufferRenderbuffer(FRAMEBUFFER, attachment, RENDERBUFFER, newRb);\n gl.bindRenderbuffer(RENDERBUFFER, null);\n const status = gl.checkFramebufferStatus(FRAMEBUFFER);\n if (status !== FRAMEBUFFER_COMPLETE) {\n throw new Error(`lite-gl: render target framebuffer incomplete after stencil attach (status 0x${status.toString(16)})`);\n }\n // Commit only after a complete attachment: release the buffer we\n // replaced (the core depth-only one, or our own from a prior rebuild).\n if (rt._depthStencil !== null) {\n gl.deleteRenderbuffer(rt._depthStencil);\n }\n rt._depthStencil = newRb;\n committed = true;\n } finally {\n if (!committed) {\n // Any non-committed exit (incomplete framebuffer OR an unexpected\n // GL throw): detach + delete the buffer we couldn't adopt so it\n // never leaks, leaving the attachment point empty for the\n // caller-level rollback to re-establish the prior buffer.\n gl.framebufferRenderbuffer(FRAMEBUFFER, attachment, RENDERBUFFER, null);\n gl.deleteRenderbuffer(newRb);\n }\n // Restore the caller's draw target + the bound-framebuffer cache.\n if (e._state.boundFramebuffer !== prevFb) {\n gl.bindFramebuffer(FRAMEBUFFER, prevFb);\n e._state.boundFramebuffer = prevFb;\n }\n }\n };\n\n // Build once now, but COMMIT the resize/restore hook only if it succeeds — a\n // failed opt-in must leave the target exactly as it was. The packed attach\n // above can clear the core `DEPTH_ATTACHMENT`, so on failure restore the prior\n // hook AND re-establish the prior depth/stencil attachment (the prior hook's,\n // or the core depth-only buffer).\n const prevHook = rt._rebuildDepthStencil;\n const prevDepthStencil = rt._depthStencil;\n try {\n build(engine);\n } catch (err) {\n rt._rebuildDepthStencil = prevHook;\n try {\n if (prevHook !== undefined) {\n prevHook(engine);\n } else if (prevDepthStencil !== null) {\n reattachCoreDepthBuffer(engine, rt, prevDepthStencil);\n }\n } catch {\n // Best-effort restore; surface the original failure below.\n }\n throw err;\n }\n rt._rebuildDepthStencil = build;\n}\n\n/**\n * Re-attach a core depth-only renderbuffer at `DEPTH_ATTACHMENT` — used to roll a\n * render target back when a packed {@link generateRenderTargetStencil} attach\n * fails completeness (attaching at `DEPTH_STENCIL_ATTACHMENT` clears the core\n * `DEPTH_ATTACHMENT`). State-neutral: restores the caller's bound framebuffer.\n * @internal\n */\nfunction reattachCoreDepthBuffer(engine: GLEngineContext, rt: GLRenderTarget, depthBuffer: WebGLRenderbuffer): void {\n const gl = engine.gl;\n const prevFb = engine._state.boundFramebuffer;\n gl.bindFramebuffer(FRAMEBUFFER, rt._framebuffer);\n engine._state.boundFramebuffer = rt._framebuffer;\n gl.framebufferRenderbuffer(FRAMEBUFFER, DEPTH_ATTACHMENT, RENDERBUFFER, depthBuffer);\n if (engine._state.boundFramebuffer !== prevFb) {\n gl.bindFramebuffer(FRAMEBUFFER, prevFb);\n engine._state.boundFramebuffer = prevFb;\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import type { GLEngineContext } from "./context.js";
2
2
  import { type GLEffect } from "./effect.js";
3
+ import type { GLViewport } from "./family.js";
3
4
  /** Inputs to `createEffectWrapper`. Mirrors lite's `EffectWrapperOptions`: the
4
5
  * wrapper compiles and OWNS the effect built from this shader source. */
5
6
  export interface GLEffectWrapperOptions {
@@ -43,17 +44,6 @@ export declare function createEffectWrapper(engine: GLEngineContext, options: GL
43
44
  *
44
45
  * @param wrapper - The wrapper to dispose. */
45
46
  export declare function disposeEffectWrapper(wrapper: GLEffectWrapper): void;
46
- /** Pixel-space viewport rectangle passed to `setViewport`. */
47
- export interface GLViewport {
48
- /** Lower-left X origin in physical pixels. */
49
- x: number;
50
- /** Lower-left Y origin in physical pixels. */
51
- y: number;
52
- /** Width in physical pixels. */
53
- w: number;
54
- /** Height in physical pixels. */
55
- h: number;
56
- }
57
47
  /** Cached `gl.viewport`. Defaults to the full canvas in pixel coordinates. */
58
48
  export declare function setViewport(engine: GLEngineContext, viewport?: GLViewport): void;
59
49
  /** Make `wrapper.effect` current — the counterpart of Babylon's
@@ -1 +1 @@
1
- {"version":3,"file":"effect-renderer.js","sourceRoot":"","sources":["../src/effect-renderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAiB,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;6BAI6B;AAC7B,MAAM,gCAAgC,GAAG;;;;;;EAMvC,CAAC;AAwCH;;;yDAGyD;AACzD,MAAM,UAAU,mBAAmB,CAAC,MAAuB,EAAE,OAA+B;IACxF,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,gBAAgB,CAAC;IAC9C,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE;QAChC,IAAI;QACJ,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,gCAAgC;QACtE,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,EAAE;QACxC,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,EAAE;QACxC,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,OAAO,EAAE,OAAO,CAAC,OAAO;KAC3B,CAAC,CAAC;IACH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAC9C,CAAC;AAED;;+CAE+C;AAC/C,MAAM,UAAU,oBAAoB,CAAC,OAAwB;IACzD,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;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C,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACtE,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\nimport { createEffect, disposeEffect, type GLEffect, isEffectReady, useEffect } from \"./effect.js\";\nimport { applyGLStates } from \"./apply-states.js\";\n\n/** Built-in fullscreen-quad vertex shader, used when `GLEffectWrapperOptions`\n * omits `vertexSource`. Maps the package's fullscreen-quad positions\n * (attribute location 0) to clip space and forwards a 0..1 `vUv` varying —\n * the WebGL counterpart of lite's default `vertexWGSL`, so callers can pass\n * only `fragmentSource`. */\nconst DEFAULT_FULLSCREEN_VERTEX_SOURCE = `#version 300 es\nlayout(location = 0) in vec2 position;\nout vec2 vUv;\nvoid main() {\n vUv = position * 0.5 + 0.5;\n gl_Position = vec4(position, 0.0, 1.0);\n}`;\n\n/** Inputs to `createEffectWrapper`. Mirrors lite's `EffectWrapperOptions`: the\n * wrapper compiles and OWNS the effect built from this shader source. */\nexport interface GLEffectWrapperOptions {\n /** Human-readable label for the wrapper and its effect. Defaults to\n * `\"effect-wrapper\"`. */\n name?: string;\n /** GLSL ES 3.00 vertex source. Defaults to a built-in fullscreen-quad\n * vertex shader (exposing a `vUv` varying), mirroring lite's default\n * `vertexWGSL`. */\n vertexSource?: string;\n /** GLSL ES 3.00 fragment source (≙ lite's `fragmentWGSL`). Required. */\n fragmentSource: string;\n /** Declared uniform names. Defaults to none. */\n uniformNames?: readonly string[];\n /** Declared sampler names, in unit-assignment order. Defaults to none. */\n samplerNames?: readonly string[];\n /** Attribute names; the first is bound to location 0. Defaults to\n * `[\"position\"]`. */\n attributeNames?: readonly string[];\n /** Optional `#define` block prepended to both shader stages. */\n defines?: string;\n}\n\n/** A reusable fullscreen effect that compiles and OWNS its `GLEffect` — the\n * WebGL counterpart of lite's `EffectWrapper`. Like lite, the wrapper functions\n * take the wrapper alone (the engine is derived from its effect):\n * `applyEffectWrapper(wrapper)` / `disposeEffectWrapper(wrapper)`. */\nexport interface GLEffectWrapper {\n /** Name alias for the wrapper (and its effect). */\n readonly name: string;\n /** The compiled effect this wrapper owns. Exposed so the per-uniform\n * setters (`setEffectFloat`/`setEffectTexture`/…) can target it — the\n * WebGL divergence from lite's UBO-based `setEffectUniforms(wrapper, …)`. */\n readonly effect: GLEffect;\n /** @internal */\n _disposed: boolean;\n}\n\n/** Compile a fullscreen effect from shader source and wrap it; the wrapper OWNS\n * the resulting `GLEffect`. Mirrors lite's `createEffectWrapper(engine, options)`.\n * When `vertexSource` is omitted, a built-in fullscreen-quad vertex shader is\n * used, so callers can supply only `fragmentSource`. */\nexport function createEffectWrapper(engine: GLEngineContext, options: GLEffectWrapperOptions): GLEffectWrapper {\n const name = options.name ?? \"effect-wrapper\";\n const effect = createEffect(engine, {\n name,\n vertexSource: options.vertexSource ?? DEFAULT_FULLSCREEN_VERTEX_SOURCE,\n fragmentSource: options.fragmentSource,\n uniformNames: options.uniformNames ?? [],\n samplerNames: options.samplerNames ?? [],\n attributeNames: options.attributeNames,\n defines: options.defines,\n });\n return { name, effect, _disposed: false };\n}\n\n/** Dispose the wrapper and the effect it owns (idempotent).\n *\n * @param wrapper - The wrapper to dispose. */\nexport function disposeEffectWrapper(wrapper: GLEffectWrapper): void {\n if (wrapper._disposed) {\n return;\n }\n wrapper._disposed = true;\n disposeEffect(wrapper.effect);\n}\n\n/** Pixel-space viewport rectangle passed to `setViewport`. */\nexport interface GLViewport {\n /** Lower-left X origin in physical pixels. */\n x: number;\n /** Lower-left Y origin in physical pixels. */\n y: number;\n /** Width in physical pixels. */\n w: number;\n /** Height in physical pixels. */\n h: number;\n}\n\n/** Cached `gl.viewport`. Defaults to the full canvas in pixel coordinates. */\nexport function setViewport(engine: GLEngineContext, viewport?: GLViewport): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const x = viewport?.x ?? 0;\n const y = viewport?.y ?? 0;\n const w = viewport?.w ?? engine.canvas.width;\n const h = viewport?.h ?? engine.canvas.height;\n const s = engine._state;\n if (s.viewportX === x && s.viewportY === y && s.viewportW === w && s.viewportH === h) {\n return;\n }\n s.viewportX = x;\n s.viewportY = y;\n s.viewportW = w;\n s.viewportH = h;\n engine.gl.viewport(x, y, w, h);\n}\n\n/** Make `wrapper.effect` current — the counterpart of Babylon's\n * `EffectRenderer.applyEffectWrapper` (lite-gl has no `setEffectWrapper`;\n * this is the only wrapper \"activate\" call). The shared fullscreen quad is\n * bound by {@link drawEffect}, so an existing `GLEffect` needs no wrapper:\n * `if (isEffectReady(e)) { useEffect(e); …setters…; drawEffect(engine); }`.\n *\n * The wrapper's effect must be ready: this polls {@link isEffectReady} itself\n * (finalizing the effect on its first ready poll) and returns `false` without\n * binding anything while the shaders are still compiling, failed to compile,\n * or the context is lost/disposed — skip the frame's `setEffect*` /\n * `drawEffect` calls in that case, otherwise they target whatever program\n * was current before.\n *\n * This MUST be called BEFORE any `setEffect*` call for the same effect in the\n * current frame (uniform setters write to the currently bound program).\n * Typical frame:\n * `if (!applyEffectWrapper(w)) return;` →\n * `setEffectFloat(w.effect, …)` → `drawEffect(engine)`.\n *\n * @param wrapper - The wrapper whose effect to make current.\n * @returns `true` when the effect is ready and now current; `false` when\n * nothing was bound. */\nexport function applyEffectWrapper(wrapper: GLEffectWrapper): boolean {\n // Bail before polling so a disposed wrapper sharing a live effect can't\n // finalize it (useProgram + callbacks); re-check after the poll because\n // ready callbacks it fires may dispose the wrapper.\n if (wrapper._disposed || !isEffectReady(wrapper.effect) || wrapper._disposed) {\n return false;\n }\n useEffect(wrapper.effect);\n return true;\n}\n\n/** Draw the shared fullscreen quad with the current program (from\n * {@link applyEffectWrapper} or `useEffect`) — the counterpart of Babylon's\n * `EffectRenderer.draw`. Lazily creates the quad on first use (and after\n * context restore), binds its VAO (cached), flushes the deferred GL states and\n * issues `gl.drawElements(TRIANGLES, 6, UNSIGNED_SHORT, 0)`. The program's\n * vertex shader must read the quad positions at attribute location 0 (as\n * `createEffectWrapper`'s default vertex shader does). No-op when the context\n * is lost/disposed or there is no current program.\n *\n * @param engine - The engine. */\nexport function drawEffect(engine: GLEngineContext): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n if (engine._state.currentProgram === null) {\n return;\n }\n ensureQuad(engine);\n applyGLStates(engine);\n engine.gl.drawElements(engine.gl.TRIANGLES, 6, engine.gl.UNSIGNED_SHORT, 0);\n}\n\n/** Lazy fullscreen quad. Built on first call; thereafter the VAO is cached on\n * `_state.quadVao` and rebinding is a single cached call. Cleared by\n * `webglcontextlost` and transparently rebuilt by the next\n * `drawEffect` after restore.\n *\n * Position attribute is enabled at location 0 — every effect's\n * `createEffect` calls `gl.bindAttribLocation(program, 0, attributeNames[0])`\n * BEFORE link, so the shared VAO is correct across all programs. */\nfunction ensureQuad(engine: GLEngineContext): void {\n const s = engine._state;\n const gl = engine.gl;\n if (s.quadVao !== null) {\n if (s.boundVao !== s.quadVao) {\n gl.bindVertexArray(s.quadVao);\n s.boundVao = s.quadVao;\n }\n return;\n }\n const vao = gl.createVertexArray();\n if (vao === null) {\n throw new Error(\"lite-gl: gl.createVertexArray returned null\");\n }\n s.quadVao = vao;\n gl.bindVertexArray(vao);\n s.boundVao = vao;\n\n const vbo = gl.createBuffer();\n if (vbo === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (VBO)\");\n }\n s.quadVbo = vbo;\n gl.bindBuffer(gl.ARRAY_BUFFER, vbo);\n s.boundArrayBuffer = vbo;\n gl.bufferData(gl.ARRAY_BUFFER, QUAD_POSITIONS, gl.STATIC_DRAW);\n\n const ibo = gl.createBuffer();\n if (ibo === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (IBO)\");\n }\n s.quadIbo = ibo;\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);\n s.boundElementBuffer = ibo;\n gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, QUAD_INDICES, gl.STATIC_DRAW);\n\n gl.enableVertexAttribArray(0);\n gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n}\n\n/** Typed-array literal — pure per bundler convention. Matches Babylon's\n * `EffectRenderer` default geometry exactly. */\nconst QUAD_POSITIONS = new Float32Array([1, 1, -1, 1, -1, -1, 1, -1]);\nconst QUAD_INDICES = new Uint16Array([0, 1, 2, 0, 2, 3]);\n"]}
1
+ {"version":3,"file":"effect-renderer.js","sourceRoot":"","sources":["../src/effect-renderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAiB,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEnG,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;6BAI6B;AAC7B,MAAM,gCAAgC,GAAG;;;;;;EAMvC,CAAC;AAwCH;;;yDAGyD;AACzD,MAAM,UAAU,mBAAmB,CAAC,MAAuB,EAAE,OAA+B;IACxF,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,gBAAgB,CAAC;IAC9C,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE;QAChC,IAAI;QACJ,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,gCAAgC;QACtE,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,EAAE;QACxC,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,EAAE;QACxC,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,OAAO,EAAE,OAAO,CAAC,OAAO;KAC3B,CAAC,CAAC;IACH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAC9C,CAAC;AAED;;+CAE+C;AAC/C,MAAM,UAA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;AACxD,CAAC;AAED;iDACiD;AACjD,MAAM,cAAc,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACtE,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\nimport { createEffect, disposeEffect, type GLEffect, isEffectReady, useEffect } from \"./effect.js\";\nimport type { GLViewport } from \"./family.js\";\nimport { applyGLStates } from \"./apply-states.js\";\n\n/** Built-in fullscreen-quad vertex shader, used when `GLEffectWrapperOptions`\n * omits `vertexSource`. Maps the package's fullscreen-quad positions\n * (attribute location 0) to clip space and forwards a 0..1 `vUv` varying —\n * the WebGL counterpart of lite's default `vertexWGSL`, so callers can pass\n * only `fragmentSource`. */\nconst DEFAULT_FULLSCREEN_VERTEX_SOURCE = `#version 300 es\nlayout(location = 0) in vec2 position;\nout vec2 vUv;\nvoid main() {\n vUv = position * 0.5 + 0.5;\n gl_Position = vec4(position, 0.0, 1.0);\n}`;\n\n/** Inputs to `createEffectWrapper`. Mirrors lite's `EffectWrapperOptions`: the\n * wrapper compiles and OWNS the effect built from this shader source. */\nexport interface GLEffectWrapperOptions {\n /** Human-readable label for the wrapper and its effect. Defaults to\n * `\"effect-wrapper\"`. */\n name?: string;\n /** GLSL ES 3.00 vertex source. Defaults to a built-in fullscreen-quad\n * vertex shader (exposing a `vUv` varying), mirroring lite's default\n * `vertexWGSL`. */\n vertexSource?: string;\n /** GLSL ES 3.00 fragment source (≙ lite's `fragmentWGSL`). Required. */\n fragmentSource: string;\n /** Declared uniform names. Defaults to none. */\n uniformNames?: readonly string[];\n /** Declared sampler names, in unit-assignment order. Defaults to none. */\n samplerNames?: readonly string[];\n /** Attribute names; the first is bound to location 0. Defaults to\n * `[\"position\"]`. */\n attributeNames?: readonly string[];\n /** Optional `#define` block prepended to both shader stages. */\n defines?: string;\n}\n\n/** A reusable fullscreen effect that compiles and OWNS its `GLEffect` — the\n * WebGL counterpart of lite's `EffectWrapper`. Like lite, the wrapper functions\n * take the wrapper alone (the engine is derived from its effect):\n * `applyEffectWrapper(wrapper)` / `disposeEffectWrapper(wrapper)`. */\nexport interface GLEffectWrapper {\n /** Name alias for the wrapper (and its effect). */\n readonly name: string;\n /** The compiled effect this wrapper owns. Exposed so the per-uniform\n * setters (`setEffectFloat`/`setEffectTexture`/…) can target it — the\n * WebGL divergence from lite's UBO-based `setEffectUniforms(wrapper, …)`. */\n readonly effect: GLEffect;\n /** @internal */\n _disposed: boolean;\n}\n\n/** Compile a fullscreen effect from shader source and wrap it; the wrapper OWNS\n * the resulting `GLEffect`. Mirrors lite's `createEffectWrapper(engine, options)`.\n * When `vertexSource` is omitted, a built-in fullscreen-quad vertex shader is\n * used, so callers can supply only `fragmentSource`. */\nexport function createEffectWrapper(engine: GLEngineContext, options: GLEffectWrapperOptions): GLEffectWrapper {\n const name = options.name ?? \"effect-wrapper\";\n const effect = createEffect(engine, {\n name,\n vertexSource: options.vertexSource ?? DEFAULT_FULLSCREEN_VERTEX_SOURCE,\n fragmentSource: options.fragmentSource,\n uniformNames: options.uniformNames ?? [],\n samplerNames: options.samplerNames ?? [],\n attributeNames: options.attributeNames,\n defines: options.defines,\n });\n return { name, effect, _disposed: false };\n}\n\n/** Dispose the wrapper and the effect it owns (idempotent).\n *\n * @param wrapper - The wrapper to dispose. */\nexport function disposeEffectWrapper(wrapper: GLEffectWrapper): void {\n if (wrapper._disposed) {\n return;\n }\n wrapper._disposed = true;\n disposeEffect(wrapper.effect);\n}\n\n/** Cached `gl.viewport`. Defaults to the full canvas in pixel coordinates. */\nexport function setViewport(engine: GLEngineContext, viewport?: GLViewport): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const x = viewport?.x ?? 0;\n const y = viewport?.y ?? 0;\n const w = viewport?.w ?? engine.canvas.width;\n const h = viewport?.h ?? engine.canvas.height;\n const s = engine._state;\n if (s.viewportX === x && s.viewportY === y && s.viewportW === w && s.viewportH === h) {\n return;\n }\n s.viewportX = x;\n s.viewportY = y;\n s.viewportW = w;\n s.viewportH = h;\n engine.gl.viewport(x, y, w, h);\n}\n\n/** Make `wrapper.effect` current — the counterpart of Babylon's\n * `EffectRenderer.applyEffectWrapper` (lite-gl has no `setEffectWrapper`;\n * this is the only wrapper \"activate\" call). The shared fullscreen quad is\n * bound by {@link drawEffect}, so an existing `GLEffect` needs no wrapper:\n * `if (isEffectReady(e)) { useEffect(e); …setters…; drawEffect(engine); }`.\n *\n * The wrapper's effect must be ready: this polls {@link isEffectReady} itself\n * (finalizing the effect on its first ready poll) and returns `false` without\n * binding anything while the shaders are still compiling, failed to compile,\n * or the context is lost/disposed — skip the frame's `setEffect*` /\n * `drawEffect` calls in that case, otherwise they target whatever program\n * was current before.\n *\n * This MUST be called BEFORE any `setEffect*` call for the same effect in the\n * current frame (uniform setters write to the currently bound program).\n * Typical frame:\n * `if (!applyEffectWrapper(w)) return;` →\n * `setEffectFloat(w.effect, …)` → `drawEffect(engine)`.\n *\n * @param wrapper - The wrapper whose effect to make current.\n * @returns `true` when the effect is ready and now current; `false` when\n * nothing was bound. */\nexport function applyEffectWrapper(wrapper: GLEffectWrapper): boolean {\n // Bail before polling so a disposed wrapper sharing a live effect can't\n // finalize it (useProgram + callbacks); re-check after the poll because\n // ready callbacks it fires may dispose the wrapper.\n if (wrapper._disposed || !isEffectReady(wrapper.effect) || wrapper._disposed) {\n return false;\n }\n useEffect(wrapper.effect);\n return true;\n}\n\n/** Draw the shared fullscreen quad with the current program (from\n * {@link applyEffectWrapper} or `useEffect`) — the counterpart of Babylon's\n * `EffectRenderer.draw`. Lazily creates the quad on first use (and after\n * context restore), binds its VAO (cached), flushes the deferred GL states and\n * issues `gl.drawElements(TRIANGLES, 6, UNSIGNED_SHORT, 0)`. The program's\n * vertex shader must read the quad positions at attribute location 0 (as\n * `createEffectWrapper`'s default vertex shader does). No-op when the context\n * is lost/disposed or there is no current program.\n *\n * @param engine - The engine. */\nexport function drawEffect(engine: GLEngineContext): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n if (engine._state.currentProgram === null) {\n return;\n }\n ensureQuad(engine);\n applyGLStates(engine);\n engine.gl.drawElements(engine.gl.TRIANGLES, 6, engine.gl.UNSIGNED_SHORT, 0);\n}\n\n/** Lazy fullscreen quad. Built on first call; thereafter the VAO is cached on\n * `_state.quadVao` and rebinding is a single cached call. Cleared by\n * `webglcontextlost` and transparently rebuilt by the next\n * `drawEffect` after restore.\n *\n * Position attribute is enabled at location 0 — every effect's\n * `createEffect` calls `gl.bindAttribLocation(program, 0, attributeNames[0])`\n * BEFORE link, so the shared VAO is correct across all programs. */\nfunction ensureQuad(engine: GLEngineContext): void {\n const s = engine._state;\n const gl = engine.gl;\n if (s.quadVao !== null) {\n if (s.boundVao !== s.quadVao) {\n gl.bindVertexArray(s.quadVao);\n s.boundVao = s.quadVao;\n }\n return;\n }\n const vao = gl.createVertexArray();\n if (vao === null) {\n throw new Error(\"lite-gl: gl.createVertexArray returned null\");\n }\n s.quadVao = vao;\n gl.bindVertexArray(vao);\n s.boundVao = vao;\n\n const vbo = gl.createBuffer();\n if (vbo === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (VBO)\");\n }\n s.quadVbo = vbo;\n gl.bindBuffer(gl.ARRAY_BUFFER, vbo);\n s.boundArrayBuffer = vbo;\n gl.bufferData(gl.ARRAY_BUFFER, QUAD_POSITIONS, gl.STATIC_DRAW);\n\n const ibo = gl.createBuffer();\n if (ibo === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (IBO)\");\n }\n s.quadIbo = ibo;\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);\n s.boundElementBuffer = ibo;\n gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, QUAD_INDICES, gl.STATIC_DRAW);\n\n gl.enableVertexAttribArray(0);\n gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n}\n\n/** Typed-array literal — pure per bundler convention. Matches Babylon's\n * `EffectRenderer` default geometry exactly. */\nconst QUAD_POSITIONS = new Float32Array([1, 1, -1, 1, -1, -1, 1, -1]);\nconst QUAD_INDICES = new Uint16Array([0, 1, 2, 0, 2, 3]);\n"]}
package/effect.d.ts CHANGED
@@ -1,32 +1,6 @@
1
1
  import type { GLEngineContext } from "./context.js";
2
+ import type { GLEffectOptions } from "./family.js";
2
3
  import { type GLTexture } from "./texture.js";
3
- /** Inputs to `createEffect`: shader sources plus the uniform, sampler and
4
- * attribute names whose locations are resolved during readiness finalization. */
5
- export interface GLEffectOptions {
6
- /** Human-readable label, surfaced in compile/link error messages. */
7
- name: string;
8
- /** GLSL ES 3.00 source, ready for `gl.shaderSource`. */
9
- vertexSource: string;
10
- /** GLSL ES 3.00 source, ready for `gl.shaderSource`. */
11
- fragmentSource: string;
12
- /** Declared uniform names. Locations are resolved during readiness
13
- * finalization. Names not declared here are legal but allocate cache
14
- * slots lazily on first setter use. */
15
- uniformNames: readonly string[];
16
- /** Declared sampler names, in unit-assignment order. Each gets a fixed
17
- * texture unit assigned during readiness finalization, and
18
- * `gl.uniform1i(loc, unit)` is called exactly once per program lifetime
19
- * (re-run after `webglcontextrestored`). */
20
- samplerNames: readonly string[];
21
- /** Default `["position"]`. The first attribute is bound to location 0 via
22
- * `gl.bindAttribLocation(program, 0, name)` BEFORE link, so the shared
23
- * fullscreen-quad VAO always feeds the same location. */
24
- attributeNames?: readonly string[];
25
- /** Optional `#define` block. Each unique `defines` string must be paired
26
- * with the same vertex/fragment source via a separate `createEffect` call —
27
- * the package does NOT cache compiled variants. */
28
- defines?: string;
29
- }
30
4
  /** A compiled + linked shader program with cached uniform, sampler and
31
5
  * attribute locations. Created by `createEffect`; most fields are managed
32
6
  * internally — drive it via `isEffectReady` / `useEffect` / the `setEffect*`
@@ -141,6 +115,10 @@ export declare function setEffectMatrix3x3(effect: GLEffect, name: string, matri
141
115
  /** `gl.uniform1fv` — a flat float array (`Effect.setFloatArray` / `setArray`).
142
116
  * Not value-cached. */
143
117
  export declare function setEffectFloatArray(effect: GLEffect, name: string, array: Float32Array | number[]): void;
118
+ /** `gl.uniform2fv` — an array of `vec2`s. Not value-cached. */
119
+ export declare function setEffectFloatArray2(effect: GLEffect, name: string, array: Float32Array | number[]): void;
120
+ /** `gl.uniform3fv` — an array of `vec3`s. Not value-cached. */
121
+ export declare function setEffectFloatArray3(effect: GLEffect, name: string, array: Float32Array | number[]): void;
144
122
  /** `gl.uniform4fv` — an array of `vec4`s (`Effect.setFloatArray4` / `setArray4`).
145
123
  * Not value-cached. */
146
124
  export declare function setEffectFloatArray4(effect: GLEffect, name: string, array: Float32Array | number[]): void;
package/effect.js CHANGED
@@ -407,6 +407,28 @@ export function setEffectFloatArray(effect, name, array) {
407
407
  }
408
408
  engine.gl.uniform1fv(loc, array);
409
409
  }
410
+ /** `gl.uniform2fv` — an array of `vec2`s. Not value-cached. */
411
+ export function setEffectFloatArray2(effect, name, array) {
412
+ const engine = effect._engine;
413
+ if (engine._isLost || !effect.isReady) {
414
+ return;
415
+ }
416
+ const location = effect.uniformLocations[name];
417
+ if (location !== null && location !== undefined) {
418
+ engine.gl.uniform2fv(location, array);
419
+ }
420
+ }
421
+ /** `gl.uniform3fv` — an array of `vec3`s. Not value-cached. */
422
+ export function setEffectFloatArray3(effect, name, array) {
423
+ const engine = effect._engine;
424
+ if (engine._isLost || !effect.isReady) {
425
+ return;
426
+ }
427
+ const location = effect.uniformLocations[name];
428
+ if (location !== null && location !== undefined) {
429
+ engine.gl.uniform3fv(location, array);
430
+ }
431
+ }
410
432
  /** `gl.uniform4fv` — an array of `vec4`s (`Effect.setFloatArray4` / `setArray4`).
411
433
  * Not value-cached. */
412
434
  export function setEffectFloatArray4(effect, name, array) {
package/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,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACnC,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;QACb,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9E,CAAC;IACD,0EAA0E;IAC1E,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,SAAS;QACb,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YACrE,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;IACL,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\nimport { compileShader, getLinkError, isLinkComplete, linkProgram } from \"./shader.js\";\nimport { bindTextureRaw, type GLTexture } from \"./texture.js\";\n\n/** Inputs to `createEffect`: shader sources plus the uniform, sampler and\n * attribute names whose locations are resolved during readiness finalization. */\nexport interface GLEffectOptions {\n /** Human-readable label, surfaced in compile/link error messages. */\n name: string;\n /** GLSL ES 3.00 source, ready for `gl.shaderSource`. */\n vertexSource: string;\n /** GLSL ES 3.00 source, ready for `gl.shaderSource`. */\n fragmentSource: string;\n /** Declared uniform names. Locations are resolved during readiness\n * finalization. Names not declared here are legal but allocate cache\n * slots lazily on first setter use. */\n uniformNames: readonly string[];\n /** Declared sampler names, in unit-assignment order. Each gets a fixed\n * texture unit assigned during readiness finalization, and\n * `gl.uniform1i(loc, unit)` is called exactly once per program lifetime\n * (re-run after `webglcontextrestored`). */\n samplerNames: readonly string[];\n /** Default `[\"position\"]`. The first attribute is bound to location 0 via\n * `gl.bindAttribLocation(program, 0, name)` BEFORE link, so the shared\n * fullscreen-quad VAO always feeds the same location. */\n attributeNames?: readonly string[];\n /** Optional `#define` block. Each unique `defines` string must be paired\n * with the same vertex/fragment source via a separate `createEffect` call —\n * the package does NOT cache compiled variants. */\n defines?: string;\n}\n\n/** A compiled + linked shader program with cached uniform, sampler and\n * attribute locations. Created by `createEffect`; most fields are managed\n * internally — drive it via `isEffectReady` / `useEffect` / the `setEffect*`\n * setters rather than mutating it directly. */\nexport interface GLEffect {\n /** The `name` from the originating `GLEffectOptions`. */\n readonly name: string;\n /** The options this effect was created from (retained for context-restore). */\n readonly options: GLEffectOptions;\n /** The live `WebGLProgram`. Swapped for a fresh handle after context-restore. */\n program: WebGLProgram;\n /** @internal */\n _vs: WebGLShader;\n /** @internal */\n _fs: WebGLShader;\n /** Resolved during readiness finalization. Missing names map to `null` —\n * setters with a `null` location are silent no-ops (matches Babylon). */\n uniformLocations: { [name: string]: WebGLUniformLocation | null };\n /** Fixed unit assignment for declared samplers, index into\n * `_state.boundTextures`. */\n samplerUnits: { [name: string]: number };\n /**\n * True once `gl.uniform1i(samplerLoc, unit)` has been issued for every\n * declared sampler. Cleared on context-lost so finalization re-runs.\n * @internal\n */\n _samplersAssigned: boolean;\n /** Resolved attribute locations, keyed by attribute name. */\n attributeLocations: { [name: string]: number };\n /**\n * Last-UPLOADED scalar floats. A setter that skips the upload must NOT\n * update this — otherwise a later real set with the same value would\n * incorrectly elide and the GPU would keep stale data.\n * @internal\n */\n readonly _lastF1: { [name: string]: number };\n /**\n * Last-UPLOADED vector floats (vec2/vec3/vec4). Plain `number[]` (NOT\n * `Float32Array`) so values like `0.1` compare equal across frames.\n * @internal\n */\n readonly _lastVec: { [name: string]: number[] };\n /** @internal */\n readonly _lastI1: { [name: string]: number };\n /** True once the program has linked and finalization has run; the\n * `setEffect*` setters are no-ops until then. Poll `isEffectReady` to advance it. */\n isReady: boolean;\n /** The engine that created (and owns) this effect. Effect operations derive\n * their engine from it, so they take the effect alone. @internal */\n _engine: GLEngineContext;\n /** @internal */\n _compileError: string | null;\n /** @internal */\n _disposed: boolean;\n /**\n * Number of live `createEffect` callers sharing this effect (and its one\n * `WebGLProgram`). `createEffect` returns the cached effect and bumps this\n * when an identical descriptor is requested; `disposeEffect` decrements it\n * and only tears the program down when it reaches 0.\n * @internal\n */\n _refCount: number;\n /**\n * The `_effectCache` key this effect was stored under (the source\n * descriptor). Used by `disposeEffect` to evict the cache entry at refcount\n * 0.\n * @internal\n */\n _cacheKey: string;\n /**\n * Callbacks fired exactly once on the first transition to ready.\n * @internal\n */\n readonly _onCompiled: ((effect: GLEffect) => void)[];\n /**\n * Replay closure for context-restore. Re-compiles + relinks into a fresh\n * `program` field. Finalization happens lazily on the next `isEffectReady`\n * poll.\n * @internal\n */\n _restore: (engine: GLEngineContext) => void;\n}\n\n/** Submit compilation + linking without querying their results. `isReady`\n * starts false; poll `isEffectReady` or opt into `waitForEffect` to finalize.\n * Allocation failures throw synchronously. Shader syntax/link errors are\n * recorded during polling and exposed by `getEffectCompilationError`. */\nexport function createEffect(engine: GLEngineContext, options: GLEffectOptions): GLEffect {\n const attribs = options.attributeNames ?? [\"position\"];\n const gl = engine.gl;\n\n // Per-engine cache keyed by the source descriptor. Identical descriptors\n // share ONE GLEffect (and thus one WebGLProgram), so `useEffect`'s\n // current-program cache can elide redundant `gl.useProgram` across the\n // consumers. The key covers every input that affects the program or its\n // readiness finalization, joined by a NUL separator (cannot appear in GLSL).\n const cacheKey = [options.vertexSource, options.fragmentSource, options.defines ?? \"\", attribs.join(\",\"), options.uniformNames.join(\",\"), options.samplerNames.join(\",\")].join(\n \"\\u0000\"\n );\n const cached = engine._effectCache.get(cacheKey);\n if (cached !== undefined && !cached._disposed) {\n cached._refCount++;\n return cached;\n }\n\n const compiled = compileEffectProgram(gl, options, attribs);\n if (typeof compiled === \"string\") {\n throw new Error(`lite-gl: ${options.name} ${compiled}`);\n }\n const { vs, fs, program } = compiled;\n\n const effect: GLEffect = {\n name: options.name,\n options,\n program,\n _vs: vs,\n _fs: fs,\n uniformLocations: {},\n samplerUnits: {},\n _samplersAssigned: false,\n attributeLocations: {},\n _lastF1: {},\n _lastVec: {},\n _lastI1: {},\n isReady: false,\n _engine: engine,\n _compileError: null,\n _disposed: false,\n _refCount: 1,\n _cacheKey: cacheKey,\n _onCompiled: [],\n _restore: () => {},\n };\n\n effect._restore = (target: GLEngineContext): void => {\n const restored = compileEffectProgram(target.gl, options, attribs);\n if (typeof restored === \"string\") {\n recordCompilationError(effect, `context-restore: ${restored}`);\n return;\n }\n effect.program = restored.program;\n effect._vs = restored.vs;\n effect._fs = restored.fs;\n effect.isReady = false;\n effect._samplersAssigned = false;\n effect.uniformLocations = {};\n effect.attributeLocations = {};\n effect._compileError = null;\n };\n\n engine._effects.push(effect);\n engine._effectCache.set(cacheKey, effect);\n return effect;\n}\n\n/** Shader/program handles allocated as one unit on creation and restoration. */\ninterface EffectProgram {\n vs: WebGLShader;\n fs: WebGLShader;\n program: WebGLProgram;\n}\n\n/** Share allocation and partial-failure cleanup between initial creation and\n * context restoration. Returns a diagnostic on allocation failure; compile\n * and link results are deliberately left to readiness polling. */\nfunction compileEffectProgram(gl: WebGL2RenderingContext, options: GLEffectOptions, attribs: readonly string[]): EffectProgram | string {\n const vs = compileShader(gl, applyDefines(options.vertexSource, options.defines), gl.VERTEX_SHADER);\n if (vs === null) {\n return \"vertex shader allocation failed\";\n }\n const fs = compileShader(gl, applyDefines(options.fragmentSource, options.defines), gl.FRAGMENT_SHADER);\n if (fs === null) {\n gl.deleteShader(vs);\n return \"fragment shader allocation failed\";\n }\n const program = linkProgram(gl, vs, fs, attribs);\n if (program === null) {\n gl.deleteShader(vs);\n gl.deleteShader(fs);\n return \"program allocation failed\";\n }\n return { vs, fs, program };\n}\n\n/** Poll the link state and, on first success, run finalization (uniform-\n * location resolution + one-shot sampler-unit `uniform1i` assignment +\n * `_onCompiled` callbacks). Returns `true` once the effect is usable. */\nexport function isEffectReady(effect: GLEffect): boolean {\n const engine = effect._engine;\n if (\n !effect.isReady &&\n !effect._disposed &&\n !engine._isLost &&\n !engine._disposed &&\n effect._compileError === null &&\n isLinkComplete(engine.gl, effect.program, engine.caps.parallelShaderCompile)\n ) {\n const linkErr = getLinkError(engine.gl, effect.program, effect._vs, effect._fs);\n if (linkErr !== null) {\n recordCompilationError(effect, linkErr);\n } else {\n finalizeEffect(engine, effect);\n }\n }\n // Read back rather than returning `true` after finalization: a ready\n // callback may have disposed the effect or engine (or lost the context).\n return effect.isReady;\n}\n\n/** Poll readiness once and return the recorded compile/link/restore diagnostic.\n * Returns null while pending or when no failure has been recorded; this is\n * not a readiness guarantee. Does not schedule polling. A successful restore\n * allocation clears the previous diagnostic before the new link is checked. */\nexport function getEffectCompilationError(effect: GLEffect): string | null {\n isEffectReady(effect);\n return effect._compileError;\n}\n\nfunction recordCompilationError(effect: GLEffect, error: string): void {\n effect._compileError = error;\n effect.isReady = false;\n console.error(`lite-gl: ${effect.name} ${error}`);\n}\n\n/** Resolves uniform/attribute locations, binds the program (cached), and\n * issues the one-time `gl.uniform1i(samplerLoc, unit)` per declared sampler. */\nfunction finalizeEffect(engine: GLEngineContext, effect: GLEffect): void {\n const gl = engine.gl;\n const program = effect.program;\n for (const name of effect.options.uniformNames) {\n effect.uniformLocations[name] = gl.getUniformLocation(program, name);\n }\n const attribs = effect.options.attributeNames ?? [\"position\"];\n for (const name of attribs) {\n effect.attributeLocations[name] = gl.getAttribLocation(program, name);\n }\n // Switch to this program via the cached helper so _state.currentProgram\n // stays consistent — no raw gl.useProgram outside useEffect.\n useEffect(effect);\n let unit = 0;\n for (const name of effect.options.samplerNames) {\n const loc = gl.getUniformLocation(program, name);\n if (loc !== null) {\n gl.uniform1i(loc, unit);\n }\n effect.samplerUnits[name] = unit;\n unit++;\n }\n effect._samplersAssigned = true;\n effect.isReady = true;\n // Fire and clear the one-shot ready callbacks.\n const cbs = effect._onCompiled.slice();\n effect._onCompiled.length = 0;\n for (const cb of cbs) {\n try {\n cb(effect);\n } catch (err) {\n console.error(`lite-gl: ${effect.name} onCompiled callback threw`, err);\n }\n }\n}\n\n/** Fires `cb` synchronously if the effect is already ready; otherwise queues\n * it for the next finalization. Does not start polling: call `isEffectReady`\n * from the render loop or opt into `waitForEffect`. */\nexport function executeWhenCompiled(effect: GLEffect, cb: (e: GLEffect) => void): void {\n if (isEffectReady(effect)) {\n cb(effect);\n return;\n }\n effect._onCompiled.push(cb);\n}\n\n/** Decrement the share count and, on the last release, delete the effect's\n * program + shaders, unregister it from the context + cache, and clear the\n * cached current-program if it pointed at this effect. A shared effect (still\n * referenced by another `createEffect` caller) is kept alive. Call exactly ONCE\n * per `createEffect` (each call decrements the ref count); safe (no-op) once the\n * effect is fully torn down. */\nexport function disposeEffect(effect: GLEffect): void {\n const engine = effect._engine;\n if (effect._disposed) {\n return;\n }\n if (--effect._refCount > 0) {\n return;\n }\n effect._disposed = true;\n effect.isReady = false;\n const i = engine._effects.indexOf(effect);\n if (i !== -1) {\n engine._effects.splice(i, 1);\n }\n engine._effectCache.delete(effect._cacheKey);\n if (!engine._isLost && !engine._disposed) {\n engine.gl.deleteProgram(effect.program);\n engine.gl.deleteShader(effect._vs);\n engine.gl.deleteShader(effect._fs);\n }\n if (engine._state.currentProgram === effect.program) {\n engine._state.currentProgram = null;\n }\n effect._onCompiled.length = 0;\n}\n\n/** Cached `gl.useProgram`. Low-level: it does NOT check readiness, so poll\n * {@link isEffectReady} first (binding a still-linking program can stall, and\n * a failed one fails the next draw). `applyEffectWrapper` does that poll for\n * wrappers. No-op when the effect is already current, disposed, or the\n * context is lost/disposed. */\nexport function useEffect(effect: GLEffect): void {\n const engine = effect._engine;\n if (engine._isLost || engine._disposed || effect._disposed) {\n return;\n }\n if (engine._state.currentProgram === effect.program) {\n return;\n }\n engine.gl.useProgram(effect.program);\n engine._state.currentProgram = effect.program;\n}\n\n/* ──────────────────────────── cached setters ────────────────────────────\n *\n * Each setter has the shape:\n * 1. bail when context lost / effect not ready (no cache write)\n * 2. lookup uniform location; bail on null (no cache write)\n * 3. compare against last-UPLOADED value; bail on equality\n * 4. write to cache, issue gl.uniform*\n *\n * Step 3's comparison is intentionally bit-equal (===) — NaN inputs re-upload\n * every frame because `NaN !== NaN`, which is the correct safety net for\n * caller bugs.\n */\n\n/** Cached `gl.uniform1f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat(effect: GLEffect, name: string, x: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n if (effect._lastF1[name] === x) {\n return;\n }\n effect._lastF1[name] = x;\n engine.gl.uniform1f(loc, x);\n}\n\n/** Cached `gl.uniform2f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat2(effect: GLEffect, name: string, x: number, y: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n let v = effect._lastVec[name];\n if (v !== undefined && v[0] === x && v[1] === y) {\n return;\n }\n if (v === undefined) {\n v = [x, y];\n effect._lastVec[name] = v;\n } else {\n v[0] = x;\n v[1] = y;\n }\n engine.gl.uniform2f(loc, x, y);\n}\n\n/** Cached `gl.uniform3f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat3(effect: GLEffect, name: string, x: number, y: number, z: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n let v = effect._lastVec[name];\n if (v !== undefined && v[0] === x && v[1] === y && v[2] === z) {\n return;\n }\n if (v === undefined) {\n v = [x, y, z];\n effect._lastVec[name] = v;\n } else {\n v[0] = x;\n v[1] = y;\n v[2] = z;\n }\n engine.gl.uniform3f(loc, x, y, z);\n}\n\n/** Cached `gl.uniform4f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat4(effect: GLEffect, name: string, x: number, y: number, z: number, w: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n let v = effect._lastVec[name];\n if (v !== undefined && v[0] === x && v[1] === y && v[2] === z && v[3] === w) {\n return;\n }\n if (v === undefined) {\n v = [x, y, z, w];\n effect._lastVec[name] = v;\n } else {\n v[0] = x;\n v[1] = y;\n v[2] = z;\n v[3] = w;\n }\n engine.gl.uniform4f(loc, x, y, z, w);\n}\n\n/** Cached `gl.uniform3f` from an r/g/b color object. Delegates to `setEffectFloat3`. */\nexport function setEffectColor3(effect: GLEffect, name: string, c: { r: number; g: number; b: number }): void {\n setEffectFloat3(effect, name, c.r, c.g, c.b);\n}\n\n/** Cached `gl.uniform4f` from an r/g/b/a color object. Delegates to `setEffectFloat4`. */\nexport function setEffectColor4(effect: GLEffect, name: string, c: { r: number; g: number; b: number; a: number }): void {\n setEffectFloat4(effect, name, c.r, c.g, c.b, c.a);\n}\n\n/** Cached `gl.uniform2f` from an `{x,y}` vector object — the lite-gl equivalent\n * of Babylon's `Effect.setVector2`. Delegates to `setEffectFloat2`. */\nexport function setEffectVector2(effect: GLEffect, name: string, v: { x: number; y: number }): void {\n setEffectFloat2(effect, name, v.x, v.y);\n}\n\n/** Cached `gl.uniform4f` from an r/g/b/a color WITHOUT premultiplication — the\n * lite-gl equivalent of Babylon's `Effect.setDirectColor4`. Delegates to\n * `setEffectFloat4` (lite-gl never premultiplies in the uniform setters, so\n * this matches `setEffectColor4`; the distinct name eases the ShapeBuilder\n * port). */\nexport function setEffectDirectColor4(effect: GLEffect, name: string, c: { r: number; g: number; b: number; a: number }): void {\n setEffectFloat4(effect, name, c.r, c.g, c.b, c.a);\n}\n\n/** Cached `gl.uniform1i`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectInt(effect: GLEffect, name: string, x: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n if (effect._lastI1[name] === x) {\n return;\n }\n effect._lastI1[name] = x;\n engine.gl.uniform1i(loc, x);\n}\n\n/* ── Matrix / array setters (uploaded every call — not value-cached) ──────────\n *\n * Matrices and arrays usually change every frame; element-wise caching would\n * cost more than the upload it saves, so these always issue the GL call (the\n * location lookup + ready guards still apply). They cover the ShapeBuilder\n * surface (`setMatrix3x3`, `setFloatArray`, `setFloatArray4`) plus a general\n * 4×4 matrix setter for any future mesh consumer. */\n\n/** `gl.uniformMatrix4fv` from a column-major 4×4 matrix — the lite-gl\n * equivalent of Babylon's `Effect.setMatrix`. Not value-cached. */\nexport function setEffectMatrix(effect: GLEffect, name: string, matrix: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniformMatrix4fv(loc, false, matrix);\n}\n\n/** `gl.uniformMatrix3fv` from a column-major 3×3 matrix — the lite-gl\n * equivalent of Babylon's `Effect.setMatrix3x3`. Not value-cached. */\nexport function setEffectMatrix3x3(effect: GLEffect, name: string, matrix: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniformMatrix3fv(loc, false, matrix);\n}\n\n/** `gl.uniform1fv` — a flat float array (`Effect.setFloatArray` / `setArray`).\n * Not value-cached. */\nexport function setEffectFloatArray(effect: GLEffect, name: string, array: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniform1fv(loc, array);\n}\n\n/** `gl.uniform4fv` — an array of `vec4`s (`Effect.setFloatArray4` / `setArray4`).\n * Not value-cached. */\nexport function setEffectFloatArray4(effect: GLEffect, name: string, array: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniform4fv(loc, array);\n}\n\n/** `gl.uniform1iv` — a flat int array (`Effect.setIntArray`). Not value-cached. */\nexport function setEffectIntArray(effect: GLEffect, name: string, array: Int32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniform1iv(loc, array);\n}\n\n/** Bind a texture to the sampler's pre-assigned unit, or pass `null` to unbind\n * that unit (§4.4). NO `gl.uniform1i` is issued — that was done exactly once per program lifetime during\n * finalization. This is the key win over Babylon's `Effect.setTexture` which\n * re-issues the sampler binding on every call. */\nexport function setEffectTexture(effect: GLEffect, samplerName: string, tex: GLTexture | null): void {\n const engine = effect._engine;\n if (engine._isLost || engine._disposed || !effect.isReady) {\n return;\n }\n const unit = effect.samplerUnits[samplerName];\n if (unit === undefined || tex?._disposed) {\n return;\n }\n bindTextureRaw(engine, unit, tex === null ? null : tex.handle);\n}\n\n/** Resolve (and cache) a vertex-attribute location by name — the lite-gl\n * equivalent of Babylon's `Effect.getAttributeLocationByName`. Locations for\n * declared `attributeNames` are resolved during finalization; this also serves\n * the mesh / instancing path, where attribute names are not declared up-front.\n * Returns `-1` when the attribute is absent (matching `gl.getAttribLocation`).\n * @internal */\nexport function getEffectAttributeLocation(effect: GLEffect, name: string): number {\n const engine = effect._engine;\n const cached = effect.attributeLocations[name];\n if (cached !== undefined) {\n return cached;\n }\n const loc = engine.gl.getAttribLocation(effect.program, name);\n effect.attributeLocations[name] = loc;\n return loc;\n}\n\n/* ──────────────────────────── internal helpers ──────────────────────────── */\n\n/** Inject `options.defines` between the `#version`/precision header and the\n * user shader body. Supports a `// __DEFINES__` marker (preferred — keeps the\n * runtime regex-free, per spec §6.2) OR auto-detects the end of the leading\n * preprocessor / precision lines. */\nfunction applyDefines(source: string, defines: string | undefined): string {\n if (defines === undefined || defines.length === 0) {\n return source;\n }\n const marker = \"// __DEFINES__\";\n const idx = source.indexOf(marker);\n if (idx !== -1) {\n return source.slice(0, idx) + defines + source.slice(idx + marker.length);\n }\n // Fallback: insert after the last `precision` line (or after `#version`).\n const lines = source.split(\"\\n\");\n let insertAt = 0;\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line === undefined) {\n continue;\n }\n const trimmed = line.trim();\n if (trimmed.startsWith(\"#version\") || trimmed.startsWith(\"precision \")) {\n insertAt = i + 1;\n }\n }\n lines.splice(insertAt, 0, defines);\n return lines.join(\"\\n\");\n}\n"]}
1
+ {"version":3,"file":"effect.js","sourceRoot":"","sources":["../src/effect.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EAAE,cAAc,EAAkB,MAAM,cAAc,CAAC;AAqF9D;;;0EAG0E;AAC1E,MAAM,UAAU,YAAY,CAAC,MAAuB,EAAE,OAAwB;IAC1E,MAAM,OAAO,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CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YACrE,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;IACL,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\nimport type { GLEffectOptions } from \"./family.js\";\nimport { compileShader, getLinkError, isLinkComplete, linkProgram } from \"./shader.js\";\nimport { bindTextureRaw, type GLTexture } from \"./texture.js\";\n\n/** A compiled + linked shader program with cached uniform, sampler and\n * attribute locations. Created by `createEffect`; most fields are managed\n * internally — drive it via `isEffectReady` / `useEffect` / the `setEffect*`\n * setters rather than mutating it directly. */\nexport interface GLEffect {\n /** The `name` from the originating `GLEffectOptions`. */\n readonly name: string;\n /** The options this effect was created from (retained for context-restore). */\n readonly options: GLEffectOptions;\n /** The live `WebGLProgram`. Swapped for a fresh handle after context-restore. */\n program: WebGLProgram;\n /** @internal */\n _vs: WebGLShader;\n /** @internal */\n _fs: WebGLShader;\n /** Resolved during readiness finalization. Missing names map to `null` —\n * setters with a `null` location are silent no-ops (matches Babylon). */\n uniformLocations: { [name: string]: WebGLUniformLocation | null };\n /** Fixed unit assignment for declared samplers, index into\n * `_state.boundTextures`. */\n samplerUnits: { [name: string]: number };\n /**\n * True once `gl.uniform1i(samplerLoc, unit)` has been issued for every\n * declared sampler. Cleared on context-lost so finalization re-runs.\n * @internal\n */\n _samplersAssigned: boolean;\n /** Resolved attribute locations, keyed by attribute name. */\n attributeLocations: { [name: string]: number };\n /**\n * Last-UPLOADED scalar floats. A setter that skips the upload must NOT\n * update this — otherwise a later real set with the same value would\n * incorrectly elide and the GPU would keep stale data.\n * @internal\n */\n readonly _lastF1: { [name: string]: number };\n /**\n * Last-UPLOADED vector floats (vec2/vec3/vec4). Plain `number[]` (NOT\n * `Float32Array`) so values like `0.1` compare equal across frames.\n * @internal\n */\n readonly _lastVec: { [name: string]: number[] };\n /** @internal */\n readonly _lastI1: { [name: string]: number };\n /** True once the program has linked and finalization has run; the\n * `setEffect*` setters are no-ops until then. Poll `isEffectReady` to advance it. */\n isReady: boolean;\n /** The engine that created (and owns) this effect. Effect operations derive\n * their engine from it, so they take the effect alone. @internal */\n _engine: GLEngineContext;\n /** @internal */\n _compileError: string | null;\n /** @internal */\n _disposed: boolean;\n /**\n * Number of live `createEffect` callers sharing this effect (and its one\n * `WebGLProgram`). `createEffect` returns the cached effect and bumps this\n * when an identical descriptor is requested; `disposeEffect` decrements it\n * and only tears the program down when it reaches 0.\n * @internal\n */\n _refCount: number;\n /**\n * The `_effectCache` key this effect was stored under (the source\n * descriptor). Used by `disposeEffect` to evict the cache entry at refcount\n * 0.\n * @internal\n */\n _cacheKey: string;\n /**\n * Callbacks fired exactly once on the first transition to ready.\n * @internal\n */\n readonly _onCompiled: ((effect: GLEffect) => void)[];\n /**\n * Replay closure for context-restore. Re-compiles + relinks into a fresh\n * `program` field. Finalization happens lazily on the next `isEffectReady`\n * poll.\n * @internal\n */\n _restore: (engine: GLEngineContext) => void;\n}\n\n/** Submit compilation + linking without querying their results. `isReady`\n * starts false; poll `isEffectReady` or opt into `waitForEffect` to finalize.\n * Allocation failures throw synchronously. Shader syntax/link errors are\n * recorded during polling and exposed by `getEffectCompilationError`. */\nexport function createEffect(engine: GLEngineContext, options: GLEffectOptions): GLEffect {\n const attribs = options.attributeNames ?? [\"position\"];\n const gl = engine.gl;\n\n // Per-engine cache keyed by the source descriptor. Identical descriptors\n // share ONE GLEffect (and thus one WebGLProgram), so `useEffect`'s\n // current-program cache can elide redundant `gl.useProgram` across the\n // consumers. The key covers every input that affects the program or its\n // readiness finalization, joined by a NUL separator (cannot appear in GLSL).\n const cacheKey = [options.vertexSource, options.fragmentSource, options.defines ?? \"\", attribs.join(\",\"), options.uniformNames.join(\",\"), options.samplerNames.join(\",\")].join(\n \"\\u0000\"\n );\n const cached = engine._effectCache.get(cacheKey);\n if (cached !== undefined && !cached._disposed) {\n cached._refCount++;\n return cached;\n }\n\n const compiled = compileEffectProgram(gl, options, attribs);\n if (typeof compiled === \"string\") {\n throw new Error(`lite-gl: ${options.name} ${compiled}`);\n }\n const { vs, fs, program } = compiled;\n\n const effect: GLEffect = {\n name: options.name,\n options,\n program,\n _vs: vs,\n _fs: fs,\n uniformLocations: {},\n samplerUnits: {},\n _samplersAssigned: false,\n attributeLocations: {},\n _lastF1: {},\n _lastVec: {},\n _lastI1: {},\n isReady: false,\n _engine: engine,\n _compileError: null,\n _disposed: false,\n _refCount: 1,\n _cacheKey: cacheKey,\n _onCompiled: [],\n _restore: () => {},\n };\n\n effect._restore = (target: GLEngineContext): void => {\n const restored = compileEffectProgram(target.gl, options, attribs);\n if (typeof restored === \"string\") {\n recordCompilationError(effect, `context-restore: ${restored}`);\n return;\n }\n effect.program = restored.program;\n effect._vs = restored.vs;\n effect._fs = restored.fs;\n effect.isReady = false;\n effect._samplersAssigned = false;\n effect.uniformLocations = {};\n effect.attributeLocations = {};\n effect._compileError = null;\n };\n\n engine._effects.push(effect);\n engine._effectCache.set(cacheKey, effect);\n return effect;\n}\n\n/** Shader/program handles allocated as one unit on creation and restoration. */\ninterface EffectProgram {\n vs: WebGLShader;\n fs: WebGLShader;\n program: WebGLProgram;\n}\n\n/** Share allocation and partial-failure cleanup between initial creation and\n * context restoration. Returns a diagnostic on allocation failure; compile\n * and link results are deliberately left to readiness polling. */\nfunction compileEffectProgram(gl: WebGL2RenderingContext, options: GLEffectOptions, attribs: readonly string[]): EffectProgram | string {\n const vs = compileShader(gl, applyDefines(options.vertexSource, options.defines), gl.VERTEX_SHADER);\n if (vs === null) {\n return \"vertex shader allocation failed\";\n }\n const fs = compileShader(gl, applyDefines(options.fragmentSource, options.defines), gl.FRAGMENT_SHADER);\n if (fs === null) {\n gl.deleteShader(vs);\n return \"fragment shader allocation failed\";\n }\n const program = linkProgram(gl, vs, fs, attribs);\n if (program === null) {\n gl.deleteShader(vs);\n gl.deleteShader(fs);\n return \"program allocation failed\";\n }\n return { vs, fs, program };\n}\n\n/** Poll the link state and, on first success, run finalization (uniform-\n * location resolution + one-shot sampler-unit `uniform1i` assignment +\n * `_onCompiled` callbacks). Returns `true` once the effect is usable. */\nexport function isEffectReady(effect: GLEffect): boolean {\n const engine = effect._engine;\n if (\n !effect.isReady &&\n !effect._disposed &&\n !engine._isLost &&\n !engine._disposed &&\n effect._compileError === null &&\n isLinkComplete(engine.gl, effect.program, engine.caps.parallelShaderCompile)\n ) {\n const linkErr = getLinkError(engine.gl, effect.program, effect._vs, effect._fs);\n if (linkErr !== null) {\n recordCompilationError(effect, linkErr);\n } else {\n finalizeEffect(engine, effect);\n }\n }\n // Read back rather than returning `true` after finalization: a ready\n // callback may have disposed the effect or engine (or lost the context).\n return effect.isReady;\n}\n\n/** Poll readiness once and return the recorded compile/link/restore diagnostic.\n * Returns null while pending or when no failure has been recorded; this is\n * not a readiness guarantee. Does not schedule polling. A successful restore\n * allocation clears the previous diagnostic before the new link is checked. */\nexport function getEffectCompilationError(effect: GLEffect): string | null {\n isEffectReady(effect);\n return effect._compileError;\n}\n\nfunction recordCompilationError(effect: GLEffect, error: string): void {\n effect._compileError = error;\n effect.isReady = false;\n console.error(`lite-gl: ${effect.name} ${error}`);\n}\n\n/** Resolves uniform/attribute locations, binds the program (cached), and\n * issues the one-time `gl.uniform1i(samplerLoc, unit)` per declared sampler. */\nfunction finalizeEffect(engine: GLEngineContext, effect: GLEffect): void {\n const gl = engine.gl;\n const program = effect.program;\n for (const name of effect.options.uniformNames) {\n effect.uniformLocations[name] = gl.getUniformLocation(program, name);\n }\n const attribs = effect.options.attributeNames ?? [\"position\"];\n for (const name of attribs) {\n effect.attributeLocations[name] = gl.getAttribLocation(program, name);\n }\n // Switch to this program via the cached helper so _state.currentProgram\n // stays consistent — no raw gl.useProgram outside useEffect.\n useEffect(effect);\n let unit = 0;\n for (const name of effect.options.samplerNames) {\n const loc = gl.getUniformLocation(program, name);\n if (loc !== null) {\n gl.uniform1i(loc, unit);\n }\n effect.samplerUnits[name] = unit;\n unit++;\n }\n effect._samplersAssigned = true;\n effect.isReady = true;\n // Fire and clear the one-shot ready callbacks.\n const cbs = effect._onCompiled.slice();\n effect._onCompiled.length = 0;\n for (const cb of cbs) {\n try {\n cb(effect);\n } catch (err) {\n console.error(`lite-gl: ${effect.name} onCompiled callback threw`, err);\n }\n }\n}\n\n/** Fires `cb` synchronously if the effect is already ready; otherwise queues\n * it for the next finalization. Does not start polling: call `isEffectReady`\n * from the render loop or opt into `waitForEffect`. */\nexport function executeWhenCompiled(effect: GLEffect, cb: (e: GLEffect) => void): void {\n if (isEffectReady(effect)) {\n cb(effect);\n return;\n }\n effect._onCompiled.push(cb);\n}\n\n/** Decrement the share count and, on the last release, delete the effect's\n * program + shaders, unregister it from the context + cache, and clear the\n * cached current-program if it pointed at this effect. A shared effect (still\n * referenced by another `createEffect` caller) is kept alive. Call exactly ONCE\n * per `createEffect` (each call decrements the ref count); safe (no-op) once the\n * effect is fully torn down. */\nexport function disposeEffect(effect: GLEffect): void {\n const engine = effect._engine;\n if (effect._disposed) {\n return;\n }\n if (--effect._refCount > 0) {\n return;\n }\n effect._disposed = true;\n effect.isReady = false;\n const i = engine._effects.indexOf(effect);\n if (i !== -1) {\n engine._effects.splice(i, 1);\n }\n engine._effectCache.delete(effect._cacheKey);\n if (!engine._isLost && !engine._disposed) {\n engine.gl.deleteProgram(effect.program);\n engine.gl.deleteShader(effect._vs);\n engine.gl.deleteShader(effect._fs);\n }\n if (engine._state.currentProgram === effect.program) {\n engine._state.currentProgram = null;\n }\n effect._onCompiled.length = 0;\n}\n\n/** Cached `gl.useProgram`. Low-level: it does NOT check readiness, so poll\n * {@link isEffectReady} first (binding a still-linking program can stall, and\n * a failed one fails the next draw). `applyEffectWrapper` does that poll for\n * wrappers. No-op when the effect is already current, disposed, or the\n * context is lost/disposed. */\nexport function useEffect(effect: GLEffect): void {\n const engine = effect._engine;\n if (engine._isLost || engine._disposed || effect._disposed) {\n return;\n }\n if (engine._state.currentProgram === effect.program) {\n return;\n }\n engine.gl.useProgram(effect.program);\n engine._state.currentProgram = effect.program;\n}\n\n/* ──────────────────────────── cached setters ────────────────────────────\n *\n * Each setter has the shape:\n * 1. bail when context lost / effect not ready (no cache write)\n * 2. lookup uniform location; bail on null (no cache write)\n * 3. compare against last-UPLOADED value; bail on equality\n * 4. write to cache, issue gl.uniform*\n *\n * Step 3's comparison is intentionally bit-equal (===) — NaN inputs re-upload\n * every frame because `NaN !== NaN`, which is the correct safety net for\n * caller bugs.\n */\n\n/** Cached `gl.uniform1f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat(effect: GLEffect, name: string, x: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n if (effect._lastF1[name] === x) {\n return;\n }\n effect._lastF1[name] = x;\n engine.gl.uniform1f(loc, x);\n}\n\n/** Cached `gl.uniform2f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat2(effect: GLEffect, name: string, x: number, y: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n let v = effect._lastVec[name];\n if (v !== undefined && v[0] === x && v[1] === y) {\n return;\n }\n if (v === undefined) {\n v = [x, y];\n effect._lastVec[name] = v;\n } else {\n v[0] = x;\n v[1] = y;\n }\n engine.gl.uniform2f(loc, x, y);\n}\n\n/** Cached `gl.uniform3f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat3(effect: GLEffect, name: string, x: number, y: number, z: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n let v = effect._lastVec[name];\n if (v !== undefined && v[0] === x && v[1] === y && v[2] === z) {\n return;\n }\n if (v === undefined) {\n v = [x, y, z];\n effect._lastVec[name] = v;\n } else {\n v[0] = x;\n v[1] = y;\n v[2] = z;\n }\n engine.gl.uniform3f(loc, x, y, z);\n}\n\n/** Cached `gl.uniform4f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat4(effect: GLEffect, name: string, x: number, y: number, z: number, w: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n let v = effect._lastVec[name];\n if (v !== undefined && v[0] === x && v[1] === y && v[2] === z && v[3] === w) {\n return;\n }\n if (v === undefined) {\n v = [x, y, z, w];\n effect._lastVec[name] = v;\n } else {\n v[0] = x;\n v[1] = y;\n v[2] = z;\n v[3] = w;\n }\n engine.gl.uniform4f(loc, x, y, z, w);\n}\n\n/** Cached `gl.uniform3f` from an r/g/b color object. Delegates to `setEffectFloat3`. */\nexport function setEffectColor3(effect: GLEffect, name: string, c: { r: number; g: number; b: number }): void {\n setEffectFloat3(effect, name, c.r, c.g, c.b);\n}\n\n/** Cached `gl.uniform4f` from an r/g/b/a color object. Delegates to `setEffectFloat4`. */\nexport function setEffectColor4(effect: GLEffect, name: string, c: { r: number; g: number; b: number; a: number }): void {\n setEffectFloat4(effect, name, c.r, c.g, c.b, c.a);\n}\n\n/** Cached `gl.uniform2f` from an `{x,y}` vector object — the lite-gl equivalent\n * of Babylon's `Effect.setVector2`. Delegates to `setEffectFloat2`. */\nexport function setEffectVector2(effect: GLEffect, name: string, v: { x: number; y: number }): void {\n setEffectFloat2(effect, name, v.x, v.y);\n}\n\n/** Cached `gl.uniform4f` from an r/g/b/a color WITHOUT premultiplication — the\n * lite-gl equivalent of Babylon's `Effect.setDirectColor4`. Delegates to\n * `setEffectFloat4` (lite-gl never premultiplies in the uniform setters, so\n * this matches `setEffectColor4`; the distinct name eases the ShapeBuilder\n * port). */\nexport function setEffectDirectColor4(effect: GLEffect, name: string, c: { r: number; g: number; b: number; a: number }): void {\n setEffectFloat4(effect, name, c.r, c.g, c.b, c.a);\n}\n\n/** Cached `gl.uniform1i`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectInt(effect: GLEffect, name: string, x: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n if (effect._lastI1[name] === x) {\n return;\n }\n effect._lastI1[name] = x;\n engine.gl.uniform1i(loc, x);\n}\n\n/* ── Matrix / array setters (uploaded every call — not value-cached) ──────────\n *\n * Matrices and arrays usually change every frame; element-wise caching would\n * cost more than the upload it saves, so these always issue the GL call (the\n * location lookup + ready guards still apply). They cover the ShapeBuilder\n * surface (`setMatrix3x3`, `setFloatArray`, `setFloatArray4`) plus a general\n * 4×4 matrix setter for any future mesh consumer. */\n\n/** `gl.uniformMatrix4fv` from a column-major 4×4 matrix — the lite-gl\n * equivalent of Babylon's `Effect.setMatrix`. Not value-cached. */\nexport function setEffectMatrix(effect: GLEffect, name: string, matrix: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniformMatrix4fv(loc, false, matrix);\n}\n\n/** `gl.uniformMatrix3fv` from a column-major 3×3 matrix — the lite-gl\n * equivalent of Babylon's `Effect.setMatrix3x3`. Not value-cached. */\nexport function setEffectMatrix3x3(effect: GLEffect, name: string, matrix: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniformMatrix3fv(loc, false, matrix);\n}\n\n/** `gl.uniform1fv` — a flat float array (`Effect.setFloatArray` / `setArray`).\n * Not value-cached. */\nexport function setEffectFloatArray(effect: GLEffect, name: string, array: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniform1fv(loc, array);\n}\n\n/** `gl.uniform2fv` — an array of `vec2`s. Not value-cached. */\nexport function setEffectFloatArray2(effect: GLEffect, name: string, array: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const location = effect.uniformLocations[name];\n if (location !== null && location !== undefined) {\n engine.gl.uniform2fv(location, array);\n }\n}\n\n/** `gl.uniform3fv` — an array of `vec3`s. Not value-cached. */\nexport function setEffectFloatArray3(effect: GLEffect, name: string, array: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const location = effect.uniformLocations[name];\n if (location !== null && location !== undefined) {\n engine.gl.uniform3fv(location, array);\n }\n}\n\n/** `gl.uniform4fv` — an array of `vec4`s (`Effect.setFloatArray4` / `setArray4`).\n * Not value-cached. */\nexport function setEffectFloatArray4(effect: GLEffect, name: string, array: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniform4fv(loc, array);\n}\n\n/** `gl.uniform1iv` — a flat int array (`Effect.setIntArray`). Not value-cached. */\nexport function setEffectIntArray(effect: GLEffect, name: string, array: Int32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniform1iv(loc, array);\n}\n\n/** Bind a texture to the sampler's pre-assigned unit, or pass `null` to unbind\n * that unit (§4.4). NO `gl.uniform1i` is issued — that was done exactly once per program lifetime during\n * finalization. This is the key win over Babylon's `Effect.setTexture` which\n * re-issues the sampler binding on every call. */\nexport function setEffectTexture(effect: GLEffect, samplerName: string, tex: GLTexture | null): void {\n const engine = effect._engine;\n if (engine._isLost || engine._disposed || !effect.isReady) {\n return;\n }\n const unit = effect.samplerUnits[samplerName];\n if (unit === undefined || tex?._disposed) {\n return;\n }\n bindTextureRaw(engine, unit, tex === null ? null : tex.handle);\n}\n\n/** Resolve (and cache) a vertex-attribute location by name — the lite-gl\n * equivalent of Babylon's `Effect.getAttributeLocationByName`. Locations for\n * declared `attributeNames` are resolved during finalization; this also serves\n * the mesh / instancing path, where attribute names are not declared up-front.\n * Returns `-1` when the attribute is absent (matching `gl.getAttribLocation`).\n * @internal */\nexport function getEffectAttributeLocation(effect: GLEffect, name: string): number {\n const engine = effect._engine;\n const cached = effect.attributeLocations[name];\n if (cached !== undefined) {\n return cached;\n }\n const loc = engine.gl.getAttribLocation(effect.program, name);\n effect.attributeLocations[name] = loc;\n return loc;\n}\n\n/* ──────────────────────────── internal helpers ──────────────────────────── */\n\n/** Inject `options.defines` between the `#version`/precision header and the\n * user shader body. Supports a `// __DEFINES__` marker (preferred — keeps the\n * runtime regex-free, per spec §6.2) OR auto-detects the end of the leading\n * preprocessor / precision lines. */\nfunction applyDefines(source: string, defines: string | undefined): string {\n if (defines === undefined || defines.length === 0) {\n return source;\n }\n const marker = \"// __DEFINES__\";\n const idx = source.indexOf(marker);\n if (idx !== -1) {\n return source.slice(0, idx) + defines + source.slice(idx + marker.length);\n }\n // Fallback: insert after the last `precision` line (or after `#version`).\n const lines = source.split(\"\\n\");\n let insertAt = 0;\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line === undefined) {\n continue;\n }\n const trimmed = line.trim();\n if (trimmed.startsWith(\"#version\") || trimmed.startsWith(\"precision \")) {\n insertAt = i + 1;\n }\n }\n lines.splice(insertAt, 0, defines);\n return lines.join(\"\\n\");\n}\n"]}