@babylonjs/lite-gl 1.23.0 → 1.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +103 -6
- package/blend.d.ts +1 -1
- package/blend.js +1 -1
- package/blend.js.map +1 -1
- package/context.d.ts +52 -4
- package/context.js +108 -11
- package/context.js.map +1 -1
- package/depth-stencil.d.ts +4 -16
- package/depth-stencil.js +10 -11
- package/depth-stencil.js.map +1 -1
- package/dynamic-texture.d.ts +6 -3
- package/dynamic-texture.js +16 -4
- package/dynamic-texture.js.map +1 -1
- package/effect-renderer.d.ts +1 -11
- package/effect-renderer.js.map +1 -1
- package/effect.d.ts +16 -29
- package/effect.js +52 -19
- package/effect.js.map +1 -1
- package/family.d.ts +474 -0
- package/family.js +14 -0
- package/family.js.map +1 -0
- package/framebuffer-validation.d.ts +20 -0
- package/framebuffer-validation.js +37 -0
- package/framebuffer-validation.js.map +1 -0
- package/html-texture.d.ts +2 -2
- package/html-texture.js.map +1 -1
- package/index.d.ts +10 -7
- package/index.js +5 -4
- package/index.js.map +1 -1
- package/mesh.d.ts +72 -15
- package/mesh.js +221 -64
- package/mesh.js.map +1 -1
- package/native/command-stream.d.ts +1 -0
- package/native/command-stream.js +135 -0
- package/native/command-stream.js.map +1 -0
- package/native/context.d.ts +26 -0
- package/native/context.js +89 -0
- package/native/context.js.map +1 -0
- package/native/effect.d.ts +44 -0
- package/native/effect.js +276 -0
- package/native/effect.js.map +1 -0
- package/native/family.d.ts +75 -0
- package/native/family.js +2 -0
- package/native/family.js.map +1 -0
- package/native/identity.d.ts +11 -0
- package/native/identity.js +2 -0
- package/native/identity.js.map +1 -0
- package/native/index.d.ts +25 -0
- package/native/index.js +7 -0
- package/native/index.js.map +1 -0
- package/native/mesh.d.ts +53 -0
- package/native/mesh.js +137 -0
- package/native/mesh.js.map +1 -0
- package/native/render-target.d.ts +35 -0
- package/native/render-target.js +159 -0
- package/native/render-target.js.map +1 -0
- package/native/runtime.d.ts +1 -0
- package/native/runtime.js +12 -0
- package/native/runtime.js.map +1 -0
- package/native/state.d.ts +19 -0
- package/native/state.js +104 -0
- package/native/state.js.map +1 -0
- package/native/texture.d.ts +37 -0
- package/native/texture.js +86 -0
- package/native/texture.js.map +1 -0
- package/package.json +11 -3
- package/render-target.d.ts +18 -9
- package/render-target.js +84 -31
- package/render-target.js.map +1 -1
- package/scissor.d.ts +3 -3
- package/scissor.js +2 -2
- package/scissor.js.map +1 -1
- package/sprites.d.ts +5 -3
- package/sprites.js +24 -23
- package/sprites.js.map +1 -1
- package/state.d.ts +26 -13
- package/state.js +15 -15
- package/state.js.map +1 -1
- package/text/_gpu/text-instances.js +1 -1
- package/text/_gpu/text-instances.js.map +1 -1
- package/text/text-renderer.js.map +1 -1
- package/texture-3d.d.ts +2 -1
- package/texture-3d.js +7 -2
- package/texture-3d.js.map +1 -1
- package/texture-source.d.ts +4 -2
- package/texture-source.js +3 -2
- package/texture-source.js.map +1 -1
- package/texture.d.ts +18 -8
- package/texture.js +61 -35
- package/texture.js.map +1 -1
- package/web-family.d.ts +88 -0
- package/web-family.js +2 -0
- package/web-family.js.map +1 -0
package/dynamic-texture.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-texture.js","sourceRoot":"","sources":["../src/dynamic-texture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EACH,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,GAIjB,MAAM,cAAc,CAAC;AAGtB;;;;;;;;;;;;;;;;;0CAiB0C;AAC1C,MAAM,UAAU,oBAAoB,CAAC,MAAuB,EAAE,KAAa,EAAE,MAAc,EAAE,OAA0B;IACnH,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IACrB,MAAM,MAAM,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC;IAClC,IAAI,MAAM,KAAK,IAAI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C;AAED;;;;;;;;;;;;kCAYkC;AAClC,MAAM,UAAU,oBAAoB,CAAC,GAAc,EAAE,MAAsB,EAAE,OAAgC;IACzG,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC;IAC3B,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,SAAS,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;QACtD,OAAO;IACX,CAAC;IACD,GAAG,CAAC,UAAU,GAAG,MAAM,CAAC;IACxB,GAAG,CAAC,QAAQ,GAAG,OAAO,EAAE,OAAO,CAAC;IAChC,GAAG,CAAC,iBAAiB,GAAG,OAAO,EAAE,gBAAgB,CAAC;IAClD,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AACxB,CAAC;AAED;;;;;;;;sEAQsE;AACtE,MAAM,UAAU,yBAAyB,CAAC,GAAc;IACpD,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * Dynamic (canvas-/bitmap-backed) textures.\n *\n * Part of the public API via the `@babylonjs/lite-gl` barrel. The package is\n * `sideEffects: false`, so consumers that never push 2D pixel sources into a\n * texture tree-shake this code out.\n *\n * The WebGL counterpart of Babylon's `ThinEngine.createDynamicTexture` +\n * `updateDynamicTexture`. A dynamic texture is a blank RGBA8 allocation whose\n * pixels are pushed on demand from a canvas / `OffscreenCanvas` / image / video\n * / `ImageBitmap` / `ImageData` source. The most recent source is retained\n * internally and replayed into the fresh handle on `webglcontextrestored` by the\n * engine's standard context-restore protocol.\n */\nimport {\n bindTextureForUpload,\n setTexImageSourceSize,\n setBoundTextureParams,\n setUnpackState,\n type GLTexture,\n type GLTextureOptions,\n type GLTextureUpdateOptions,\n} from \"./texture.js\";\nimport type { GLEngineContext } from \"./context.js\";\n\n/** Create a texture backed by an empty (blank) `width × height` RGBA8\n * allocation, whose pixels are pushed on demand with\n * {@link updateDynamicTexture} — the WebGL counterpart of Babylon's\n * `ThinEngine.createDynamicTexture` + `ThinTexture` wrapper.\n *\n * The texture is immediately sampleable (reads as transparent black until the\n * first update). It is context-restore-safe: the most recent source pushed via\n * {@link updateDynamicTexture} is replayed into the fresh handle on\n * `webglcontextrestored` (and re-blanked if no update happened yet).\n *\n * @param engine - The engine to create GL resources on.\n * @param width - Texture width in texels (clamped to ≥ 1).\n * @param height - Texture height in texels (clamped to ≥ 1).\n * @param options - The shared {@link GLTextureOptions}. `invertY` /\n * `premultiplyAlpha` become the defaults of every {@link updateDynamicTexture}\n * call that omits them. For mipmaps, call `generateTextureMipMaps` once; every\n * later update rebuilds the chain.\n * @returns The new {@link GLTexture}. */\nexport function createDynamicTexture(engine: GLEngineContext, width: number, height: number, options?: GLTextureOptions): GLTexture {\n const gl = engine.gl;\n const handle = gl.createTexture();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createTexture returned null\");\n }\n const w = Math.max(1, width | 0);\n const h = Math.max(1, height | 0);\n const opts = options ?? {};\n const minFilter = opts.minFilter ?? gl.LINEAR;\n const magFilter = opts.magFilter ?? gl.LINEAR;\n const wrapS = opts.wrapS ?? gl.CLAMP_TO_EDGE;\n const wrapT = opts.wrapT ?? gl.CLAMP_TO_EDGE;\n const invertY = opts.invertY ?? false;\n const premultiplyAlpha = opts.premultiplyAlpha ?? false;\n\n // Single `_upload` closure used for both the initial allocation AND every\n // `webglcontextrestored` replay AND every `updateDynamicTexture`. The pixel\n // upload runs every time; the four `texParameteri` calls run ONLY when the\n // handle changed (initial create + restore install a fresh, GL-default\n // handle) — a per-frame pixel update keeps the same handle, whose filter/wrap\n // GL retains, so re-applying them would be a pure redundant cost.\n const upload = (target: GLEngineContext): void => {\n const g = target.gl;\n bindTextureForUpload(target, tex.handle);\n const src = tex._dynSource;\n if (src !== null && src !== undefined) {\n setUnpackState(target, tex._invertY ?? invertY, tex._premultiplyAlpha ?? premultiplyAlpha);\n g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, g.RGBA, g.UNSIGNED_BYTE, src);\n // `texImage2D(source)` resizes the GL storage to the source size.\n setTexImageSourceSize(tex, src);\n } else {\n setUnpackState(target, false, false);\n g.texImage2D(g.TEXTURE_2D, 0, g.RGBA8, w, h, 0, g.RGBA, g.UNSIGNED_BYTE, null);\n tex.width = w;\n tex.height = h;\n }\n if (tex._dynParamsHandle !== tex.handle) {\n setBoundTextureParams(g, minFilter, magFilter, wrapS, wrapT);\n tex._dynParamsHandle = tex.handle;\n }\n };\n\n const tex: GLTexture = {\n handle,\n target: gl.TEXTURE_2D,\n width: w,\n height: h,\n isReady: true,\n _engine: engine,\n _disposed: false,\n _refCount: 1,\n _upload: upload,\n _wasReady: true,\n _dynSource: null,\n };\n upload(engine);\n engine._textures.add(tex);\n return tex;\n}\n\n/** Push 2D pixels into a {@link createDynamicTexture} texture from a canvas /\n * `OffscreenCanvas` / image / video / `ImageBitmap` / `ImageData` source — the\n * WebGL counterpart of Babylon's `ThinEngine.updateDynamicTexture`. The source\n * is retained on the texture so it is replayed on `webglcontextrestored`, and\n * `tex.width` / `tex.height` follow the source's size (`texImage2D` resizes\n * the storage). No-op when the context is lost/disposed or the texture is\n * disposed.\n *\n * @param tex - A texture created by {@link createDynamicTexture}.\n * @param source - The 2D pixel source to upload.\n * @param options - Per-update `invertY` / `premultiplyAlpha`; each defaults to\n * the texture's creation value (like Babylon's `texture.invertY` fallback),\n * itself `false` by default. */\nexport function updateDynamicTexture(tex: GLTexture, source: TexImageSource, options?: GLTextureUpdateOptions): void {\n const engine = tex._engine;\n if (engine._isLost || engine._disposed || tex._disposed) {\n return;\n }\n tex._dynSource = source;\n tex._invertY = options?.invertY;\n tex._premultiplyAlpha = options?.premultiplyAlpha;\n tex._upload(engine);\n}\n\n/** Forget the source a dynamic texture retained for context-restore replay.\n * The current GPU pixels are kept (no re-upload), but the source reference is\n * dropped so it can be garbage-collected — and a subsequent\n * `webglcontextrestored` will re-blank the texture instead of replaying. Use\n * after the final {@link updateDynamicTexture} once the source (e.g. a large\n * atlas canvas) is no longer needed. No-op on a non-dynamic texture. No GL\n * call is made.\n *\n * @param tex - A texture created by {@link createDynamicTexture}. */\nexport function clearDynamicTextureSource(tex: GLTexture): void {\n tex._dynSource = null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dynamic-texture.js","sourceRoot":"","sources":["../src/dynamic-texture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EACH,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,GAIjB,MAAM,cAAc,CAAC;AAGtB;;;;;;;;;;;;;;;;;;0CAkB0C;AAC1C,MAAM,UAAU,oBAAoB,CAAC,MAAuB,EAAE,KAAa,EAAE,MAAc,EAAE,OAA0B;IACnH,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IACrB,MAAM,MAAM,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC;IAClC,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC/D,CAAC;IACD,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IACjC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;IAClC,MAAM,IAAI,GAAG,OAAO,IAAI,EAAE,CAAC;IAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,MAAM,CAAC;IAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,MAAM,CAAC;IAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC;IAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC;IACtC,MAAM,gBA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,MAAM,UAAU,yBAAyB,CAAC,GAAc;IACpD,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * Dynamic (canvas-/bitmap-backed) textures.\n *\n * Part of the public API via the `@babylonjs/lite-gl` barrel. The package is\n * `sideEffects: false`, so consumers that never push 2D pixel sources into a\n * texture tree-shake this code out.\n *\n * The WebGL counterpart of Babylon's `ThinEngine.createDynamicTexture` +\n * `updateDynamicTexture`. A dynamic texture is a blank RGBA8 allocation whose\n * pixels are pushed on demand from a canvas / `OffscreenCanvas` / image / video\n * / `ImageBitmap` / `ImageData` source. The most recent source is retained\n * internally and replayed into the fresh handle on `webglcontextrestored` by the\n * engine's standard context-restore protocol unless the engine is host-owned\n * (`createHostOwnedGLEngine`); that mode drops the source reference after each upload.\n */\nimport {\n bindTextureForUpload,\n setTexImageSourceSize,\n setBoundTextureParams,\n setUnpackState,\n type GLTexture,\n type GLTextureOptions,\n type GLTextureUpdateOptions,\n} from \"./texture.js\";\nimport type { GLEngineContext } from \"./context.js\";\n\n/** Create a texture backed by an empty (blank) `width × height` RGBA8\n * allocation, whose pixels are pushed on demand with\n * {@link updateDynamicTexture} — the WebGL counterpart of Babylon's\n * `ThinEngine.createDynamicTexture` + `ThinTexture` wrapper.\n *\n * The texture is immediately sampleable (reads as transparent black until the\n * first update). It is context-restore-safe: the most recent source pushed via\n * {@link updateDynamicTexture} is replayed into the fresh handle on\n * `webglcontextrestored` (and re-blanked if no update happened yet), unless\n * the engine is host-owned (`createHostOwnedGLEngine`).\n *\n * @param engine - The engine to create GL resources on.\n * @param width - Texture width in texels (clamped to ≥ 1).\n * @param height - Texture height in texels (clamped to ≥ 1).\n * @param options - The shared {@link GLTextureOptions}. `invertY` /\n * `premultiplyAlpha` become the defaults of every {@link updateDynamicTexture}\n * call that omits them. For mipmaps, call `generateTextureMipMaps` once; every\n * later update rebuilds the chain.\n * @returns The new {@link GLTexture}. */\nexport function createDynamicTexture(engine: GLEngineContext, width: number, height: number, options?: GLTextureOptions): GLTexture {\n const gl = engine.gl;\n const handle = gl.createTexture();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createTexture returned null\");\n }\n const w = Math.max(1, width | 0);\n const h = Math.max(1, height | 0);\n const opts = options ?? {};\n const minFilter = opts.minFilter ?? gl.LINEAR;\n const magFilter = opts.magFilter ?? gl.LINEAR;\n const wrapS = opts.wrapS ?? gl.CLAMP_TO_EDGE;\n const wrapT = opts.wrapT ?? gl.CLAMP_TO_EDGE;\n const invertY = opts.invertY ?? false;\n const premultiplyAlpha = opts.premultiplyAlpha ?? false;\n\n // Single `_upload` closure used for both the initial allocation AND every\n // `webglcontextrestored` replay AND every `updateDynamicTexture`. The pixel\n // upload runs every time; the four `texParameteri` calls run ONLY when the\n // handle changed (initial create + restore install a fresh, GL-default\n // handle) — a per-frame pixel update keeps the same handle, whose filter/wrap\n // GL retains, so re-applying them would be a pure redundant cost.\n const upload = (target: GLEngineContext): void => {\n const g = target.gl;\n bindTextureForUpload(target, tex.handle);\n const src = tex._dynSource;\n if (src !== null && src !== undefined) {\n setUnpackState(target, tex._invertY ?? invertY, tex._premultiplyAlpha ?? premultiplyAlpha);\n g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, g.RGBA, g.UNSIGNED_BYTE, src);\n // `texImage2D(source)` resizes the GL storage to the source size.\n setTexImageSourceSize(tex, src);\n } else {\n setUnpackState(target, false, false);\n g.texImage2D(g.TEXTURE_2D, 0, g.RGBA8, w, h, 0, g.RGBA, g.UNSIGNED_BYTE, null);\n tex.width = w;\n tex.height = h;\n }\n if (tex._dynParamsHandle !== tex.handle) {\n setBoundTextureParams(g, minFilter, magFilter, wrapS, wrapT);\n tex._dynParamsHandle = tex.handle;\n }\n };\n\n const tex: GLTexture = {\n handle,\n target: gl.TEXTURE_2D,\n width: w,\n height: h,\n isReady: true,\n _engine: engine,\n _disposed: false,\n _refCount: 1,\n _upload: upload,\n _wasReady: true,\n _dynSource: null,\n };\n upload(engine);\n engine._textures.add(tex);\n return tex;\n}\n\n/** Push 2D pixels into a {@link createDynamicTexture} texture from a canvas /\n * `OffscreenCanvas` / image / video / `ImageBitmap` / `ImageData` source — the\n * WebGL counterpart of Babylon's `ThinEngine.updateDynamicTexture`. The source\n * is retained on the texture for `webglcontextrestored` unless the engine is\n * host-owned (`createHostOwnedGLEngine`), and\n * `tex.width` / `tex.height` follow the source's size (`texImage2D` resizes\n * the storage). No-op when the context is lost/disposed or the texture is\n * disposed.\n *\n * @param tex - A texture created by {@link createDynamicTexture}.\n * @param source - The 2D pixel source to upload.\n * @param options - Per-update `invertY` / `premultiplyAlpha`; each defaults to\n * the texture's creation value (like Babylon's `texture.invertY` fallback),\n * itself `false` by default. */\nexport function updateDynamicTexture(tex: GLTexture, source: TexImageSource, options?: GLTextureUpdateOptions): void {\n const engine = tex._engine;\n if (engine._isLost || engine._disposed || tex._disposed) {\n return;\n }\n tex._dynSource = source;\n tex._invertY = options?.invertY;\n tex._premultiplyAlpha = options?.premultiplyAlpha;\n try {\n tex._upload(engine);\n } finally {\n // Also on a throwing upload (e.g. a cross-origin source): a host-owned\n // engine never replays, so it must not keep the source alive.\n if (engine._noRestore) {\n tex._dynSource = null;\n }\n }\n}\n\n/** Forget the source a dynamic texture retained for context-restore replay.\n * The current GPU pixels are kept (no re-upload), but the source reference is\n * dropped so it can be garbage-collected — and a subsequent\n * `webglcontextrestored` will re-blank the texture instead of replaying. Use\n * after the final {@link updateDynamicTexture} once the source (e.g. a large\n * atlas canvas) is no longer needed. No-op on a non-dynamic texture. No GL\n * call is made.\n *\n * @param tex - A texture created by {@link createDynamicTexture}. */\nexport function clearDynamicTextureSource(tex: GLTexture): void {\n tex._dynSource = null;\n}\n"]}
|
package/effect-renderer.d.ts
CHANGED
|
@@ -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
|
package/effect-renderer.js.map
CHANGED
|
@@ -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,I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C;IAChB,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;IAC5C,CAAC,CAAC,kBAAkB,GAAG,GAAG,CAAC;IAC3B,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,oBAAoB,EAAE,YAAY,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC;IAErE,EAAE,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;IAC9B,EAAE,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;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 { 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,IAA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,8CAA8C,CAAC,CAAC;IACpE,CAAC;IACD,CAAC,CAAC,OAAO,GAAG,GAAG,CAAC;IAChB,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;IAC5C,CAAC,CAAC,kBAAkB,GAAG,GAAG,CAAC;IAC3B,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,oBAAoB,EAAE,YAAY,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC;IAErE,EAAE,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;IAC9B,EAAE,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;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*`
|
|
@@ -121,8 +95,8 @@ export declare function setEffectVector2(effect: GLEffect, name: string, v: {
|
|
|
121
95
|
/** Cached `gl.uniform4f` from an r/g/b/a color WITHOUT premultiplication — the
|
|
122
96
|
* lite-gl equivalent of Babylon's `Effect.setDirectColor4`. Delegates to
|
|
123
97
|
* `setEffectFloat4` (lite-gl never premultiplies in the uniform setters, so
|
|
124
|
-
* this matches `setEffectColor4`; the distinct name eases
|
|
125
|
-
*
|
|
98
|
+
* this matches `setEffectColor4`; the distinct name eases `ThinEngine`
|
|
99
|
+
* ports). */
|
|
126
100
|
export declare function setEffectDirectColor4(effect: GLEffect, name: string, c: {
|
|
127
101
|
r: number;
|
|
128
102
|
g: number;
|
|
@@ -141,6 +115,19 @@ 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
|
+
/**
|
|
121
|
+
* Upload packed XYZ triples with `gl.uniform3fv` (`Effect.setFloatArray3` /
|
|
122
|
+
* `setArray3`). Not value-cached; in-place edits are uploaded on every call.
|
|
123
|
+
* Bind the effect first. No-op on a lost/disposed engine, a disposed/unready
|
|
124
|
+
* effect, or a missing uniform. After restore, finalize/bind the effect again.
|
|
125
|
+
*
|
|
126
|
+
* @param effect - The effect receiving the uniform.
|
|
127
|
+
* @param name - The uniform name.
|
|
128
|
+
* @param array - Packed triples; its length must be a multiple of three.
|
|
129
|
+
*/
|
|
130
|
+
export declare function setEffectFloatArray3(effect: GLEffect, name: string, array: Float32Array | number[]): void;
|
|
144
131
|
/** `gl.uniform4fv` — an array of `vec4`s (`Effect.setFloatArray4` / `setArray4`).
|
|
145
132
|
* Not value-cached. */
|
|
146
133
|
export declare function setEffectFloatArray4(effect: GLEffect, name: string, array: Float32Array | number[]): void;
|
package/effect.js
CHANGED
|
@@ -43,23 +43,24 @@ export function createEffect(engine, options) {
|
|
|
43
43
|
_refCount: 1,
|
|
44
44
|
_cacheKey: cacheKey,
|
|
45
45
|
_onCompiled: [],
|
|
46
|
-
_restore: () => { },
|
|
47
|
-
};
|
|
48
|
-
effect._restore = (target) => {
|
|
49
|
-
const restored = compileEffectProgram(target.gl, options, attribs);
|
|
50
|
-
if (typeof restored === "string") {
|
|
51
|
-
recordCompilationError(effect, `context-restore: ${restored}`);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
effect.program = restored.program;
|
|
55
|
-
effect._vs = restored.vs;
|
|
56
|
-
effect._fs = restored.fs;
|
|
57
|
-
effect.isReady = false;
|
|
58
|
-
effect._samplersAssigned = false;
|
|
59
|
-
effect.uniformLocations = {};
|
|
60
|
-
effect.attributeLocations = {};
|
|
61
|
-
effect._compileError = null;
|
|
62
46
|
};
|
|
47
|
+
if (!engine._noRestore) {
|
|
48
|
+
effect._restore = (target) => {
|
|
49
|
+
const restored = compileEffectProgram(target.gl, options, attribs);
|
|
50
|
+
if (typeof restored === "string") {
|
|
51
|
+
recordCompilationError(effect, `context-restore: ${restored}`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
effect.program = restored.program;
|
|
55
|
+
effect._vs = restored.vs;
|
|
56
|
+
effect._fs = restored.fs;
|
|
57
|
+
effect.isReady = false;
|
|
58
|
+
effect._samplersAssigned = false;
|
|
59
|
+
effect.uniformLocations = {};
|
|
60
|
+
effect.attributeLocations = {};
|
|
61
|
+
effect._compileError = null;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
63
64
|
engine._effects.push(effect);
|
|
64
65
|
engine._effectCache.set(cacheKey, effect);
|
|
65
66
|
return effect;
|
|
@@ -339,8 +340,8 @@ export function setEffectVector2(effect, name, v) {
|
|
|
339
340
|
/** Cached `gl.uniform4f` from an r/g/b/a color WITHOUT premultiplication — the
|
|
340
341
|
* lite-gl equivalent of Babylon's `Effect.setDirectColor4`. Delegates to
|
|
341
342
|
* `setEffectFloat4` (lite-gl never premultiplies in the uniform setters, so
|
|
342
|
-
* this matches `setEffectColor4`; the distinct name eases
|
|
343
|
-
*
|
|
343
|
+
* this matches `setEffectColor4`; the distinct name eases `ThinEngine`
|
|
344
|
+
* ports). */
|
|
344
345
|
export function setEffectDirectColor4(effect, name, c) {
|
|
345
346
|
setEffectFloat4(effect, name, c.r, c.g, c.b, c.a);
|
|
346
347
|
}
|
|
@@ -365,7 +366,7 @@ export function setEffectInt(effect, name, x) {
|
|
|
365
366
|
*
|
|
366
367
|
* Matrices and arrays usually change every frame; element-wise caching would
|
|
367
368
|
* cost more than the upload it saves, so these always issue the GL call (the
|
|
368
|
-
* location lookup + ready guards still apply). They cover
|
|
369
|
+
* location lookup + ready guards still apply). They cover Babylon's `Effect`
|
|
369
370
|
* surface (`setMatrix3x3`, `setFloatArray`, `setFloatArray4`) plus a general
|
|
370
371
|
* 4×4 matrix setter for any future mesh consumer. */
|
|
371
372
|
/** `gl.uniformMatrix4fv` from a column-major 4×4 matrix — the lite-gl
|
|
@@ -407,6 +408,38 @@ export function setEffectFloatArray(effect, name, array) {
|
|
|
407
408
|
}
|
|
408
409
|
engine.gl.uniform1fv(loc, array);
|
|
409
410
|
}
|
|
411
|
+
/** `gl.uniform2fv` — an array of `vec2`s. Not value-cached. */
|
|
412
|
+
export function setEffectFloatArray2(effect, name, array) {
|
|
413
|
+
const engine = effect._engine;
|
|
414
|
+
if (engine._isLost || !effect.isReady) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
const location = effect.uniformLocations[name];
|
|
418
|
+
if (location !== null && location !== undefined) {
|
|
419
|
+
engine.gl.uniform2fv(location, array);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Upload packed XYZ triples with `gl.uniform3fv` (`Effect.setFloatArray3` /
|
|
424
|
+
* `setArray3`). Not value-cached; in-place edits are uploaded on every call.
|
|
425
|
+
* Bind the effect first. No-op on a lost/disposed engine, a disposed/unready
|
|
426
|
+
* effect, or a missing uniform. After restore, finalize/bind the effect again.
|
|
427
|
+
*
|
|
428
|
+
* @param effect - The effect receiving the uniform.
|
|
429
|
+
* @param name - The uniform name.
|
|
430
|
+
* @param array - Packed triples; its length must be a multiple of three.
|
|
431
|
+
*/
|
|
432
|
+
export function setEffectFloatArray3(effect, name, array) {
|
|
433
|
+
const engine = effect._engine;
|
|
434
|
+
if (engine._isLost || engine._disposed || !effect.isReady || effect._disposed) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
const loc = effect.uniformLocations[name];
|
|
438
|
+
if (loc === null || loc === undefined) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
engine.gl.uniform3fv(loc, array);
|
|
442
|
+
}
|
|
410
443
|
/** `gl.uniform4fv` — an array of `vec4`s (`Effect.setFloatArray4` / `setArray4`).
|
|
411
444
|
* Not value-cached. */
|
|
412
445
|
export function setEffectFloatArray4(effect, name, array) {
|
package/effect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect.js","sourceRoot":"","sources":["../src/effect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EAAE,cAAc,EAAkB,MAAM,cAAc,CAAC;AAiH9D;;;0EAG0E;AAC1E,MAAM,UAAU,YAAY,CAAC,MAAuB,EAAE,OAAwB;IAC1E,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,IAAI,CAAC,UAAU,CAAC,CAAC;IACvD,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IAErB,yEAAyE;IACzE,mEAAmE;IACnE,uEAAuE;IACvE,wEAAwE;IACxE,6EAA6E;IAC7E,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAC1K,QAAQ,CACX,CAAC;IACF,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACjD,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC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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"]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AC;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 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 };\n\n if (!engine._noRestore) {\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\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 `ThinEngine`\n * ports). */\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 Babylon's `Effect`\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/**\n * Upload packed XYZ triples with `gl.uniform3fv` (`Effect.setFloatArray3` /\n * `setArray3`). Not value-cached; in-place edits are uploaded on every call.\n * Bind the effect first. No-op on a lost/disposed engine, a disposed/unready\n * effect, or a missing uniform. After restore, finalize/bind the effect again.\n *\n * @param effect - The effect receiving the uniform.\n * @param name - The uniform name.\n * @param array - Packed triples; its length must be a multiple of three.\n */\nexport function setEffectFloatArray3(effect: GLEffect, name: string, array: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || engine._disposed || !effect.isReady || effect._disposed) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniform3fv(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"]}
|