@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/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAgB,MAAM,YAAY,CAAC;AA+N1F;;;uCAGuC;AACvC,MAAM,UAAU,cAAc,CAAC,MAA2C,EAAE,OAAyB;IACjG,MAAM,CAAC,GAAG,OAAO,IAAI,EAAE,CAAC;IACxB,MAAM,KAAK,GAA2B;QAClC,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI;QACtB,kBAAkB,EAAE,CAAC,CAAC,kBAAkB,IAAI,IAAI;QAChD,SAAS,EAAE,CAAC,CAAC,SAAS,IAAI,KAAK;QAC/B,qBAAqB,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,CAAC;YACD,EAAE,EAAE,CAAC;QACT,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,GAAG,CAAC,CAAC;QAC7D,CAAC;IACL,CAAC;AACL,CAAC;AAED,SAAS,SAAS,CAAC,EAA0B;IACzC,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,6BAA6B,CAA6C,CAAC;IAC/G,2EAA2E;IAC3E,wEAAwE;IACxE,MAAM,gBAAgB,GAAG,EAAE,CAAC,YAAY,CAAC,wBAAwB,CAAC,KAAK,IAAI,CAAC;IAC5E,MAAM,oBAAoB,GAAG,EAAE,CAAC,YAAY,CAAC,6BAA6B,CAAC,KAAK,IAAI,CAAC;IACrF,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,0BAA0B,CAAC,KAAK,IAAI,CAAC;IACzE,OAAO;QACH,cAAc,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,gBAAgB,CAAW;QAC9D,eAAe,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,gCAAgC,CAAW;QAC/E,qBAAqB,EAAE,WAAW;QAClC,kBAAkB,EAAE,gBAAgB;QACpC,2BAA2B,EAAE,WAAW;QACxC,sBAAsB,EAAE,gBAAgB,IAAI,oBAAoB;QAChE,+BAA+B,EAAE,IAAI;QACrC,eAAe,EAAE,KAAK;KACzB,CAAC;AACN,CAAC;AAED,SAAS,WAAW,CAAC,CAA2B;IAC5C,KAAK,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;AACL,CAAC","sourcesContent":["import type { GLEffect } from \"./effect.js\";\nimport type { GLTexture } from \"./texture.js\";\nimport type { GLTexture3D } from \"./texture-3d.js\";\nimport type { GLRenderTarget } from \"./render-target.js\";\nimport type { GLPerfCounter } from \"./gpu-frame-time.js\";\nimport { createGLState, resetGLState, resetGLStateCache, type GLState } from \"./state.js\";\n\n/**\n * Minimal shape of a context-restorable GL buffer (vertex / index), kept local\n * to this module so the public `GLEngineContext` type carries no dependency on\n * the tree-shakeable `mesh` entry. `mesh.ts`'s `GLVertexBuffer` /\n * `GLIndexBuffer` satisfy it structurally.\n * @internal\n */\nexport interface GLManagedBuffer {\n handle: WebGLBuffer;\n /** @internal */\n _disposed: boolean;\n /** @internal */\n _deleteGpu: (gl: WebGL2RenderingContext) => void;\n /** @internal */\n _restore: (engine: GLEngineContext) => void;\n}\n\n/**\n * Per-frame begin / end hooks installed by opt-in modules (currently only\n * `captureGPUFrameTime`). Invoked by the render loop around its callbacks, or\n * by manual `beginFrame` / `endFrame` calls. Kept local so the context type\n * carries no runtime dependency on the tree-shakeable timing module.\n * @internal\n */\nexport interface GLFrameHooks {\n /** @internal */\n _begin: () => void;\n /** @internal */\n _end: () => void;\n /** Releases any GL resources owned by the hooks. @internal */\n _dispose: () => void;\n}\n\n/** Constructor options forwarded to `canvas.getContext('webgl2', …)`. */\nexport interface GLEngineOptions {\n /** Default: true. */\n alpha?: boolean;\n /** Default: true. */\n premultipliedAlpha?: boolean;\n /** Default: false. */\n antialias?: boolean;\n /** Default: false. */\n preserveDrawingBuffer?: boolean;\n /** Default: false — disabled for fullscreen-quad workloads. */\n depth?: boolean;\n /** Default: false. */\n stencil?: boolean;\n /** Default: \"default\". */\n powerPreference?: WebGLPowerPreference;\n /** Default: false. */\n failIfMajorPerformanceCaveat?: boolean;\n}\n\n/** Read-only WebGL2 capability limits, queried at creation and refreshed after\n * context restoration because extension objects do not survive context loss. */\nexport interface GLEngineCaps {\n /** `gl.MAX_TEXTURE_SIZE` — largest supported texture dimension, in texels. */\n readonly maxTextureSize: number;\n /** `gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS` — number of sampler binding slots. */\n readonly maxTextureUnits: number;\n /** The `KHR_parallel_shader_compile` extension used for async link polling,\n * or null when unsupported — linking is then treated as synchronous. */\n readonly parallelShaderCompile: { COMPLETION_STATUS_KHR: number } | null;\n /** True when 32-bit float color attachments are renderable\n * (`EXT_color_buffer_float`). Mirrors Babylon's `caps.textureFloatRender`. */\n readonly textureFloatRender: boolean;\n /** True when 32-bit float textures support linear filtering\n * (`OES_texture_float_linear`). Mirrors `caps.textureFloatLinearFiltering`. */\n readonly textureFloatLinearFiltering: boolean;\n /** True when 16-bit half-float color attachments are renderable\n * (`EXT_color_buffer_float` or `EXT_color_buffer_half_float`). Mirrors\n * `caps.textureHalfFloatRender`. */\n readonly textureHalfFloatRender: boolean;\n /** Half-float linear filtering — always `true` in WebGL2 (it is core).\n * Kept as a field to mirror Babylon's `caps.textureHalfFloatLinearFiltering`. */\n readonly textureHalfFloatLinearFiltering: boolean;\n /** Whether non-power-of-two textures need POT dimensions for mips / wrap.\n * Always `false` in WebGL2 (NPOT is core). Mirrors `engine.needPOTTextures`. */\n readonly needPOTTextures: boolean;\n}\n\n/**\n * Pure-state handle for a WebGL2 canvas + its cached GL state.\n *\n * INVARIANT: consumers MUST NOT mutate GL state directly through `engine.gl`.\n * Doing so silently corrupts the cache in `_state`. The package owns every\n * GL call. (`engine.gl` is exposed only so downstream code that already has the\n * pattern of poking `engine._gl.getExtension(...)` can do that, but must NOT\n * call `bindTexture`/`useProgram`/`bindBuffer`/`viewport`/etc.)\n */\nexport interface GLEngineContext {\n /** The canvas the WebGL2 context was acquired from. An `OffscreenCanvas` is\n * supported for worker render paths (e.g. the Lottie player); it has no CSS\n * box, so it must be sized explicitly via `setGLEngineSize` rather than the\n * CSS-derived `resizeGLEngine`. */\n readonly canvas: HTMLCanvasElement | OffscreenCanvas;\n /** The raw WebGL2 context. Do NOT mutate GL state through it — see the\n * type-level invariant above; the package owns every state-changing call. */\n readonly gl: WebGL2RenderingContext;\n /** Queried capability limits for this context. */\n readonly caps: GLEngineCaps;\n /**\n * Hardware-scaling-level — drawingBufferWidth = clientWidth * dpr / _hsl.\n * @internal\n */\n _hsl: number;\n /**\n * rAF id when a render loop is active, 0 otherwise.\n * @internal\n */\n _rafId: number;\n /**\n * Per-frame callbacks. `runRenderLoop` is a no-op if `fn` is already\n * registered (matches Babylon `AbstractEngine.runRenderLoop`).\n * @internal\n */\n _loops: ((dt: number) => void)[];\n /**\n * Timestamp of last frame for delta computation.\n * @internal\n */\n _prevNow: number;\n /**\n * Cached GL state. See §4 of 00-lite-gl.md.\n * @internal\n */\n _state: GLState;\n /**\n * Live effect registry — populated by `createEffect`, removed by\n * `disposeEffect`. Used by the context-restored protocol to rebuild\n * programs.\n * @internal\n */\n _effects: GLEffect[];\n /**\n * Per-engine effect cache keyed by source descriptor (vertex+fragment\n * source, defines, attribute/uniform/sampler names). `createEffect` returns\n * (and ref-counts) the cached `GLEffect` when an identical descriptor is\n * requested, so identical shaders share ONE WebGLProgram — letting\n * `useEffect`'s current-program cache elide redundant `gl.useProgram`.\n * @internal\n */\n _effectCache: Map<string, GLEffect>;\n /**\n * Live managed 2D/3D texture registry. Set deletion avoids linear searches\n * and array shifts during eviction; iteration preserves creation order\n * among survivors for context-restore replay.\n * @internal\n */\n _textures: Set<GLTexture | GLTexture3D>;\n /**\n * Live render-target registry — populated by `createRenderTarget`. Used by\n * the context-restored protocol to rebuild framebuffers + attachments after\n * their color textures have been replayed. Empty (and tree-shaken) when the\n * render-target module is unused.\n * @internal\n */\n _renderTargets: GLRenderTarget[];\n /**\n * The render target currently bound for drawing (`bindRenderTarget`), or\n * `null` for the default canvas framebuffer. Tracked so that leaving a\n * mipmapped target (`restoreDefaultFramebuffer(engine)` or switching to\n * another target) can regenerate its mip chain — mirroring Babylon's\n * auto-mipmap on `unBindFramebuffer`. Reset to `null` on context-lost.\n * @internal\n */\n _currentRenderTarget: GLRenderTarget | null;\n /**\n * Live vertex / index buffer registry — populated by `createVertexBuffer` /\n * `createIndexBuffer`. Used by the context-restored protocol to re-upload\n * the retained CPU data into fresh GL buffers. Empty (and tree-shaken) when\n * the mesh module is unused.\n * @internal\n */\n _buffers: GLManagedBuffer[];\n /** @internal */\n _onLost: (() => void)[];\n /** @internal */\n _onRestored: (() => void)[];\n /**\n * True between `webglcontextlost` and `webglcontextrestored`. While\n * true, every `setEffect*` / `bindTexture` / `drawEffect` is a no-op.\n * @internal\n */\n _isLost: boolean;\n /**\n * True once the context has been disposed; subsequent calls become no-ops.\n * @internal\n */\n _disposed: boolean;\n /**\n * DOM handlers — retained so dispose can `removeEventListener` them.\n * @internal\n */\n _lostHandler: (e: Event) => void;\n /** @internal */\n _restoredHandler: () => void;\n /**\n * True when a render loop was active at the moment of `webglcontextlost`,\n * so we can resume it from the restored handler.\n * @internal\n */\n _wasLoopActive: boolean;\n /**\n * Installed by `runRenderLoop` on first call. Lets the context-restored\n * handler resume a loop without a circular runtime import from render-loop.\n * Null if the render-loop module is tree-shaken out.\n * @internal\n */\n _scheduleFrame: ((engine: GLEngineContext) => void) | null;\n /** Optional feature-owned state-cache invalidators. Allocated lazily by the first feature that needs one.\n * @internal */\n _stateCacheInvalidators?: (() => void)[];\n /** Frame hooks installed while `captureGPUFrameTime(engine, true)` is active.\n * @internal */\n _frameHooks?: GLFrameHooks;\n /** GPU frame-time counter, created lazily by `getGPUFrameTimeCounter`.\n * @internal */\n _gpuFrameTime?: GLPerfCounter;\n}\n\n/** Acquire a WebGL2 context on the canvas and build the pure-state handle.\n * Accepts an `HTMLCanvasElement` or an `OffscreenCanvas` (worker render paths —\n * e.g. the Lottie player — which size the drawing buffer via `setGLEngineSize`).\n * Throws if WebGL2 is unsupported. */\nexport function createGLEngine(canvas: HTMLCanvasElement | OffscreenCanvas, options?: GLEngineOptions): GLEngineContext {\n const o = options ?? {};\n const attrs: WebGLContextAttributes = {\n alpha: o.alpha ?? true,\n premultipliedAlpha: o.premultipliedAlpha ?? true,\n antialias: o.antialias ?? false,\n preserveDrawingBuffer: o.preserveDrawingBuffer ?? false,\n depth: o.depth ?? false,\n stencil: o.stencil ?? false,\n powerPreference: o.powerPreference ?? \"default\",\n failIfMajorPerformanceCaveat: o.failIfMajorPerformanceCaveat ?? false,\n };\n const gl = canvas.getContext(\"webgl2\", attrs) as WebGL2RenderingContext | null;\n if (gl === null) {\n throw new Error(\"lite-gl: WebGL2 is not supported on this canvas\");\n }\n\n const caps = queryCaps(gl);\n\n const engine: GLEngineContext = {\n canvas,\n gl,\n caps,\n _hsl: 1,\n _rafId: 0,\n _loops: [],\n _prevNow: 0,\n _state: createGLState(caps.maxTextureUnits),\n _effects: [],\n _effectCache: new Map(),\n _textures: new Set(),\n _renderTargets: [],\n _currentRenderTarget: null,\n _buffers: [],\n _onLost: [],\n _onRestored: [],\n _isLost: false,\n _disposed: false,\n _lostHandler: () => {},\n _restoredHandler: () => {},\n _wasLoopActive: false,\n _scheduleFrame: null,\n };\n\n engine._lostHandler = (e: Event) => handleContextLost(engine, e);\n engine._restoredHandler = () => handleContextRestored(engine);\n canvas.addEventListener(\"webglcontextlost\", engine._lostHandler as EventListener, false);\n canvas.addEventListener(\"webglcontextrestored\", engine._restoredHandler, false);\n\n return engine;\n}\n\n/** Stops the render loop, removes DOM listeners, releases all known effects\n * and textures, then marks the context disposed. The browser-owned canvas\n * is left intact. */\nexport function disposeGLEngine(engine: GLEngineContext): void {\n if (engine._disposed) {\n return;\n }\n engine._disposed = true;\n if (engine._rafId !== 0) {\n cancelAnimationFrame(engine._rafId);\n engine._rafId = 0;\n }\n engine._loops.length = 0;\n engine._frameHooks?._dispose();\n engine._frameHooks = undefined;\n engine.canvas.removeEventListener(\"webglcontextlost\", engine._lostHandler as EventListener, false);\n engine.canvas.removeEventListener(\"webglcontextrestored\", engine._restoredHandler, false);\n\n const gl = engine.gl;\n const textures = Array.from(engine._textures);\n engine._textures.clear();\n // Iterate snapshots — dispose paths can mutate the live registries.\n const effects = engine._effects.slice();\n for (const eff of effects) {\n if (!eff._disposed) {\n eff._disposed = true;\n eff.isReady = false;\n gl.deleteProgram(eff.program);\n gl.deleteShader(eff._vs);\n gl.deleteShader(eff._fs);\n }\n }\n engine._effects.length = 0;\n engine._effectCache.clear();\n for (const tex of textures) {\n // The snapshot contains live textures only. Force-delete every handle,\n // even if reentrant disposal marks a later texture disposed first.\n tex._disposed = true;\n gl.deleteTexture(tex.handle);\n }\n // Render targets own their FBO + renderbuffer + color texture; free them via\n // the per-RT closure so context.ts needs no runtime import of render-target.\n const rts = engine._renderTargets.slice();\n for (const rt of rts) {\n if (!rt._disposed) {\n rt._disposed = true;\n rt._deleteGpu(gl);\n }\n }\n engine._renderTargets.length = 0;\n\n // Mesh vertex/index buffers own a single GL buffer each; free via closure.\n const buffers = engine._buffers.slice();\n for (const buf of buffers) {\n if (!buf._disposed) {\n buf._disposed = true;\n buf._deleteGpu(gl);\n }\n }\n engine._buffers.length = 0;\n\n resetGLState(engine._state);\n engine._currentRenderTarget = null;\n engine._onLost.length = 0;\n engine._onRestored.length = 0;\n engine._stateCacheInvalidators?.splice(0);\n}\n\n/** Match drawing-buffer size to (clientSize × devicePixelRatio / _hsl). No-op\n * if size already matches. Never touches viewport — `setViewport` owns that. */\nexport function resizeGLEngine(engine: GLEngineContext): void {\n if (engine._disposed || engine._isLost) {\n return;\n }\n const canvas = engine.canvas;\n // An OffscreenCanvas has no CSS box (no clientWidth/clientHeight); it is sized\n // explicitly via setGLEngineSize, so CSS-derived auto-resize is a no-op for it.\n if (!(\"clientWidth\" in canvas)) {\n return;\n }\n const dpr = typeof devicePixelRatio === \"number\" ? devicePixelRatio : 1;\n const w = Math.max(1, Math.floor((canvas.clientWidth * dpr) / engine._hsl));\n const h = Math.max(1, Math.floor((canvas.clientHeight * dpr) / engine._hsl));\n if (canvas.width !== w) {\n canvas.width = w;\n }\n if (canvas.height !== h) {\n canvas.height = h;\n }\n}\n\n/**\n * Set the drawing-buffer size to an EXPLICIT width/height in physical pixels\n * (each divided by `_hsl`), independent of the canvas client/CSS size — the\n * counterpart of Babylon's `ThinEngine.setSize`. Use when the render resolution\n * is computed directly (e.g. animation dimensions × scale × dpr) rather than\n * derived from CSS layout via {@link resizeGLEngine}. No-op on a disposed\n * engine. Never touches the viewport — `setViewport` owns that.\n *\n * @param engine - The engine to resize.\n * @param width - Target drawing-buffer width in physical pixels.\n * @param height - Target drawing-buffer height in physical pixels.\n */\nexport function setGLEngineSize(engine: GLEngineContext, width: number, height: number): void {\n if (engine._disposed) {\n return;\n }\n const canvas = engine.canvas;\n const w = Math.max(1, Math.floor(width / engine._hsl));\n const h = Math.max(1, Math.floor(height / engine._hsl));\n if (canvas.width !== w) {\n canvas.width = w;\n }\n if (canvas.height !== h) {\n canvas.height = h;\n }\n}\n\n/**\n * Invalidate lite-gl's cached GL state so the next state-setting call in each\n * category (program / buffer / texture / VAO / framebuffer bindings, blend,\n * depth, stencil, scissor, color-mask, viewport, unpack) is re-issued instead\n * of elided.\n *\n * Use this when a host application that SHARES this WebGL2 context mutates raw\n * `gl.*` state outside lite-gl — e.g. a save/restore wrapper that resets the\n * context to GL defaults around each render scope, or any interop layer that\n * issues GL calls directly. Without it, lite-gl's redundant-call elision would\n * skip the state changes needed to re-establish the scope, producing corrupted\n * output. Owned GPU resources (the shared quad, render targets, meshes,\n * effects, textures) are preserved — only the cached \"current GL state\" is\n * reset. Mirrors Babylon's `Engine.wipeCaches()`.\n *\n * No-op while the context is lost or the engine is disposed.\n */\nexport function wipeGLStateCache(engine: GLEngineContext): void {\n if (engine._disposed || engine._isLost) {\n return;\n }\n resetGLStateCache(engine._state);\n const invalidators = engine._stateCacheInvalidators;\n if (invalidators) {\n for (const invalidate of invalidators) {\n invalidate();\n }\n }\n}\n\n/** Drawing-buffer width in physical pixels (`canvas.width`). */\nexport function getRenderWidth(engine: GLEngineContext): number {\n return engine.canvas.width;\n}\n\n/** Drawing-buffer height in physical pixels (`canvas.height`). */\nexport function getRenderHeight(engine: GLEngineContext): number {\n return engine.canvas.height;\n}\n\n/** Current hardware-scaling factor — drawing-buffer = clientSize × dpr / level. */\nexport function getHardwareScalingLevel(engine: GLEngineContext): number {\n return engine._hsl;\n}\n\n/** Updates the hardware-scaling factor and triggers a resize. */\nexport function setHardwareScalingLevel(engine: GLEngineContext, level: number): void {\n if (level <= 0 || !isFinite(level)) {\n return;\n }\n engine._hsl = level;\n resizeGLEngine(engine);\n}\n\n/** The backing canvas element (an `HTMLCanvasElement`, or an `OffscreenCanvas`\n * for worker render paths). */\nexport function getRenderingCanvas(engine: GLEngineContext): HTMLCanvasElement | OffscreenCanvas {\n return engine.canvas;\n}\n\n/** Register a `webglcontextlost` callback. Duplicate registrations are ignored. */\nexport function onContextLost(engine: GLEngineContext, cb: () => void): void {\n if (engine._onLost.indexOf(cb) === -1) {\n engine._onLost.push(cb);\n }\n}\n\n/** Remove a previously-registered context-lost callback. */\nexport function offContextLost(engine: GLEngineContext, cb: () => void): void {\n const i = engine._onLost.indexOf(cb);\n if (i !== -1) {\n engine._onLost.splice(i, 1);\n }\n}\n\n/** Register a `webglcontextrestored` callback. Duplicate registrations are ignored. */\nexport function onContextRestored(engine: GLEngineContext, cb: () => void): void {\n if (engine._onRestored.indexOf(cb) === -1) {\n engine._onRestored.push(cb);\n }\n}\n\n/** Remove a previously-registered context-restored callback. */\nexport function offContextRestored(engine: GLEngineContext, cb: () => void): void {\n const i = engine._onRestored.indexOf(cb);\n if (i !== -1) {\n engine._onRestored.splice(i, 1);\n }\n}\n\n/* ───────────────────────── internal: loss / restore ───────────────────── */\n\nfunction handleContextLost(engine: GLEngineContext, e: Event): void {\n // Opt-in to restore. Without preventDefault() the browser will NOT fire\n // webglcontextrestored later.\n e.preventDefault();\n if (engine._isLost || engine._disposed) {\n return;\n }\n engine._isLost = true;\n // `tick` clears `_rafId` while callbacks run, so a loss event delivered in\n // that window still represents an active loop when callbacks remain.\n engine._wasLoopActive = engine._loops.length > 0;\n if (engine._rafId !== 0) {\n cancelAnimationFrame(engine._rafId);\n engine._rafId = 0;\n }\n resetGLState(engine._state);\n engine._currentRenderTarget = null;\n for (const eff of engine._effects) {\n eff.isReady = false;\n eff._samplersAssigned = false;\n eff.uniformLocations = {};\n eff.attributeLocations = {};\n // Clear value caches so the first frame after restore re-uploads\n // every uniform into the freshly-linked program.\n clearObject(eff._lastF1);\n clearObject(eff._lastVec);\n clearObject(eff._lastI1);\n // Do NOT gl.deleteProgram — handle is already dead per WebGL spec.\n }\n for (const tex of engine._textures) {\n tex._wasReady = tex.isReady;\n tex.isReady = false;\n }\n const cbs = engine._onLost.slice();\n for (const cb of cbs) {\n try {\n cb();\n } catch (err) {\n console.error(\"lite-gl: onLost callback threw\", err);\n }\n }\n}\n\nfunction handleContextRestored(engine: GLEngineContext): void {\n if (engine._disposed) {\n return;\n }\n Object.assign(engine.caps, queryCaps(engine.gl));\n for (const eff of engine._effects) {\n if (!eff._disposed) {\n eff._restore(engine);\n }\n }\n for (const tex of engine._textures) {\n if (!tex._disposed) {\n const newHandle = engine.gl.createTexture();\n if (newHandle !== null) {\n tex.handle = newHandle;\n tex._upload(engine);\n tex._initializeParameters?.(engine);\n tex.isReady = tex._wasReady;\n }\n }\n }\n // Clear the lost flag BEFORE the render-target / buffer rebuilds: their\n // `_restore` closures route through the same guarded build/upload paths used\n // at create time (which no-op while `_isLost`), whereas the effect / texture\n // replay above is unguarded and unaffected by the flag's value.\n engine._isLost = false;\n // Render targets rebuild their own color texture + FBO + renderbuffer AFTER\n // the standalone texture replay above (an RT's color texture is owned by the\n // RT, not the `_textures` registry).\n for (const rt of engine._renderTargets) {\n if (!rt._disposed) {\n rt._restore(engine);\n }\n }\n // Mesh buffers re-upload their retained CPU data into fresh GL buffers.\n for (const buf of engine._buffers) {\n if (!buf._disposed) {\n buf._restore(engine);\n }\n }\n if (engine._wasLoopActive && engine._loops.length > 0 && engine._scheduleFrame !== null) {\n engine._scheduleFrame(engine);\n }\n const cbs = engine._onRestored.slice();\n for (const cb of cbs) {\n try {\n cb();\n } catch (err) {\n console.error(\"lite-gl: onRestored callback threw\", err);\n }\n }\n}\n\nfunction queryCaps(gl: WebGL2RenderingContext): GLEngineCaps {\n const parallelExt = gl.getExtension(\"KHR_parallel_shader_compile\") as { COMPLETION_STATUS_KHR: number } | null;\n // `getExtension` both queries and enables these capabilities, so they must\n // be reacquired after context restoration before resources are rebuilt.\n const colorBufferFloat = gl.getExtension(\"EXT_color_buffer_float\") !== null;\n const colorBufferHalfFloat = gl.getExtension(\"EXT_color_buffer_half_float\") !== null;\n const floatLinear = gl.getExtension(\"OES_texture_float_linear\") !== null;\n return {\n maxTextureSize: gl.getParameter(gl.MAX_TEXTURE_SIZE) as number,\n maxTextureUnits: gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS) as number,\n parallelShaderCompile: parallelExt,\n textureFloatRender: colorBufferFloat,\n textureFloatLinearFiltering: floatLinear,\n textureHalfFloatRender: colorBufferFloat || colorBufferHalfFloat,\n textureHalfFloatLinearFiltering: true,\n needPOTTextures: false,\n };\n}\n\nfunction clearObject(o: { [k: string]: unknown }): void {\n for (const key in o) {\n delete o[key];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAgB,MAAM,YAAY,CAAC;AA6O1F;;;;mFAImF;AACnF,MAAM,UAAU,cAAc,CAAC,MAA2C,EAAE,OAAyB;IACjG,MAAM,CAAC,GAAG,OAAO,IAAI,EAAE,CAAC;IACxB,MAAM,KAAK,GAA2B;QAClC,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI;QACtB,kBAAkB,EAAE,CAAC,CAAC,kBAAkB,IAAI,IAAI;QAChD,SAAS,EAAE,CAAC,CAAC,SAAS,IAAI,KAAK;QAC/B,qBAAqB,EAAE,CAAC,CAAC,qBAAqB,IAAI,KAAK;QACvD,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,KAAK;QACvB,OAAO,EAAE,CAAC,CAAC,OAAO,IAAI,KAAK;QAC3B,eAAe,EAAE,CAAC,CAAC,eAAe,IAAI,SAAS;QAC/C,4BAA4B,EAAE,CAAC,CAAC,4BAA4B,IAAI,K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AG,CAAC,CAAC;QAC7D,CAAC;IACL,CAAC;AACL,CAAC;AAED,SAAS,SAAS,CAAC,EAA0B;IACzC,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,6BAA6B,CAA6C,CAAC;IAC/G,2EAA2E;IAC3E,wEAAwE;IACxE,MAAM,gBAAgB,GAAG,EAAE,CAAC,YAAY,CAAC,wBAAwB,CAAC,KAAK,IAAI,CAAC;IAC5E,MAAM,oBAAoB,GAAG,EAAE,CAAC,YAAY,CAAC,6BAA6B,CAAC,KAAK,IAAI,CAAC;IACrF,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,0BAA0B,CAAC,KAAK,IAAI,CAAC;IACzE,OAAO;QACH,cAAc,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,gBAAgB,CAAW;QAC9D,eAAe,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,gCAAgC,CAAW;QAC/E,qBAAqB,EAAE,WAAW;QAClC,kBAAkB,EAAE,gBAAgB;QACpC,2BAA2B,EAAE,WAAW;QACxC,sBAAsB,EAAE,gBAAgB,IAAI,oBAAoB;QAChE,+BAA+B,EAAE,IAAI;QACrC,eAAe,EAAE,KAAK;KACzB,CAAC;AACN,CAAC;AAED,SAAS,WAAW,CAAC,CAA2B;IAC5C,KAAK,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;AACL,CAAC","sourcesContent":["import type { GLEffect } from \"./effect.js\";\nimport type { GLTexture } from \"./texture.js\";\nimport type { GLTexture3D } from \"./texture-3d.js\";\nimport type { GLRenderTarget } from \"./render-target.js\";\nimport type { GLPerfCounter } from \"./gpu-frame-time.js\";\nimport { createGLState, resetGLState, resetGLStateCache, type GLState } from \"./state.js\";\n\n/**\n * Minimal shape of a context-restorable GL buffer (vertex / index), kept local\n * to this module so the public `GLEngineContext` type carries no dependency on\n * the tree-shakeable `mesh` entry. `mesh.ts`'s `GLVertexBuffer` /\n * `GLIndexBuffer` satisfy it structurally.\n * @internal\n */\nexport interface GLManagedBuffer {\n handle: WebGLBuffer;\n /** @internal */\n _disposed: boolean;\n /** @internal */\n _deleteGpu: (gl: WebGL2RenderingContext) => void;\n /** @internal */\n _restore?: (engine: GLEngineContext) => void;\n /** Retained upload source, absent when replay is disabled or disposed. @internal */\n _data?: ArrayBufferView;\n}\n\n/**\n * Per-frame begin / end hooks installed by opt-in modules (currently only\n * `captureGPUFrameTime`). Invoked by the render loop around its callbacks, or\n * by manual `beginFrame` / `endFrame` calls. Kept local so the context type\n * carries no runtime dependency on the tree-shakeable timing module.\n * @internal\n */\nexport interface GLFrameHooks {\n /** @internal */\n _begin: () => void;\n /** @internal */\n _end: () => void;\n /** Releases any GL resources owned by the hooks. @internal */\n _dispose: () => void;\n}\n\n/** Constructor options forwarded to `canvas.getContext('webgl2', …)`. */\nexport interface GLEngineOptions {\n /** Default: true. */\n alpha?: boolean;\n /** Default: true. */\n premultipliedAlpha?: boolean;\n /** Default: false. */\n antialias?: boolean;\n /** Default: false. */\n preserveDrawingBuffer?: boolean;\n /** Default: false — disabled for fullscreen-quad workloads. */\n depth?: boolean;\n /** Default: false. */\n stencil?: boolean;\n /** Default: \"default\". */\n powerPreference?: WebGLPowerPreference;\n /** Default: false. */\n failIfMajorPerformanceCaveat?: boolean;\n}\n\n/** Read-only WebGL2 capability limits, queried at creation and refreshed after\n * context restoration because extension objects do not survive context loss. */\nexport interface GLEngineCaps {\n /** `gl.MAX_TEXTURE_SIZE` — largest supported texture dimension, in texels. */\n readonly maxTextureSize: number;\n /** `gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS` — number of sampler binding slots. */\n readonly maxTextureUnits: number;\n /** The `KHR_parallel_shader_compile` extension used for async link polling,\n * or null when unsupported — linking is then treated as synchronous. */\n readonly parallelShaderCompile: { COMPLETION_STATUS_KHR: number } | null;\n /** True when 32-bit float color attachments are renderable\n * (`EXT_color_buffer_float`). Mirrors Babylon's `caps.textureFloatRender`. */\n readonly textureFloatRender: boolean;\n /** True when 32-bit float textures support linear filtering\n * (`OES_texture_float_linear`). Mirrors `caps.textureFloatLinearFiltering`. */\n readonly textureFloatLinearFiltering: boolean;\n /** True when 16-bit half-float color attachments are renderable\n * (`EXT_color_buffer_float` or `EXT_color_buffer_half_float`). Mirrors\n * `caps.textureHalfFloatRender`. */\n readonly textureHalfFloatRender: boolean;\n /** Half-float linear filtering — always `true` in WebGL2 (it is core).\n * Kept as a field to mirror Babylon's `caps.textureHalfFloatLinearFiltering`. */\n readonly textureHalfFloatLinearFiltering: boolean;\n /** Whether non-power-of-two textures need POT dimensions for mips / wrap.\n * Always `false` in WebGL2 (NPOT is core). Mirrors `engine.needPOTTextures`. */\n readonly needPOTTextures: boolean;\n}\n\n/**\n * Pure-state handle for a WebGL2 canvas + its cached GL state.\n *\n * INVARIANT: consumers MUST NOT mutate GL state directly through `engine.gl`.\n * Doing so silently corrupts the cache in `_state`. The package owns every\n * GL call. (`engine.gl` is exposed only so downstream code that already has the\n * pattern of poking `engine._gl.getExtension(...)` can do that, but must NOT\n * call `bindTexture`/`useProgram`/`bindBuffer`/`viewport`/etc.)\n */\nexport interface GLEngineContext {\n /** The canvas the WebGL2 context was acquired from. An `OffscreenCanvas` is\n * supported for worker render paths (e.g. the Lottie player); it has no CSS\n * box, so it must be sized explicitly via `setGLEngineSize` rather than the\n * CSS-derived `resizeGLEngine`. */\n readonly canvas: HTMLCanvasElement | OffscreenCanvas;\n /** The raw WebGL2 context. Do NOT mutate GL state through it — see the\n * type-level invariant above; the package owns every state-changing call. */\n readonly gl: WebGL2RenderingContext;\n /** Queried capability limits for this context. */\n readonly caps: GLEngineCaps;\n /**\n * Hardware-scaling-level — drawingBufferWidth = clientWidth * dpr / _hsl.\n * @internal\n */\n _hsl: number;\n /**\n * rAF id when a render loop is active, 0 otherwise.\n * @internal\n */\n _rafId: number;\n /**\n * Per-frame callbacks. `runRenderLoop` is a no-op if `fn` is already\n * registered (matches Babylon `AbstractEngine.runRenderLoop`).\n * @internal\n */\n _loops: ((dt: number) => void)[];\n /**\n * Timestamp of last frame for delta computation.\n * @internal\n */\n _prevNow: number;\n /**\n * Cached GL state. See §4 of 00-lite-gl.md.\n * @internal\n */\n _state: GLState;\n /**\n * Live effect registry — populated by `createEffect`, removed by\n * `disposeEffect`. Used by the context-restored protocol to rebuild\n * programs.\n * @internal\n */\n _effects: GLEffect[];\n /**\n * Per-engine effect cache keyed by source descriptor (vertex+fragment\n * source, defines, attribute/uniform/sampler names). `createEffect` returns\n * (and ref-counts) the cached `GLEffect` when an identical descriptor is\n * requested, so identical shaders share ONE WebGLProgram — letting\n * `useEffect`'s current-program cache elide redundant `gl.useProgram`.\n * @internal\n */\n _effectCache: Map<string, GLEffect>;\n /**\n * Live managed 2D/3D texture registry. Set deletion avoids linear searches\n * and array shifts during eviction; iteration preserves creation order\n * among survivors for context-restore replay.\n * @internal\n */\n _textures: Set<GLTexture | GLTexture3D>;\n /**\n * Live render-target registry — populated by `createRenderTarget`. Used by\n * the context-restored protocol to rebuild framebuffers + attachments after\n * their color textures have been replayed. Empty (and tree-shaken) when the\n * render-target module is unused.\n * @internal\n */\n _renderTargets: GLRenderTarget[];\n /**\n * The render target currently bound for drawing (`bindRenderTarget`), or\n * `null` for the default canvas framebuffer. Tracked so that leaving a\n * mipmapped target (`restoreDefaultFramebuffer(engine)` or switching to\n * another target) can regenerate its mip chain — mirroring Babylon's\n * auto-mipmap on `unBindFramebuffer`. Reset to `null` on context-lost.\n * @internal\n */\n _currentRenderTarget: GLRenderTarget | null;\n /**\n * Live vertex / index buffer registry — populated by `createVertexBuffer` /\n * `createIndexBuffer`. Used by the context-restored protocol to re-upload\n * the retained CPU data into fresh GL buffers. Empty (and tree-shaken) when\n * the mesh module is unused.\n * @internal\n */\n _buffers: GLManagedBuffer[];\n /** @internal */\n _onLost: (() => void)[];\n /** @internal */\n _onRestored: (() => void)[];\n /**\n * True after `webglcontextlost` until automatic recovery completes, or\n * permanently when recovery is disabled. While true, every `setEffect*` /\n * `bindTexture` / `drawEffect` is a no-op.\n * @internal\n */\n _isLost: boolean;\n /** Host-owned recovery policy, set only by `createHostOwnedGLEngine`;\n * not cached GL state. @internal */\n _noRestore?: true;\n /**\n * True once the context has been disposed; subsequent calls become no-ops.\n * @internal\n */\n _disposed: boolean;\n /**\n * DOM handlers — retained so dispose can `removeEventListener` them.\n * @internal\n */\n _lostHandler: (e: Event) => void;\n /** @internal */\n _restoredHandler: () => void;\n /**\n * True when a render loop was active at the moment of `webglcontextlost`,\n * so we can resume it from the restored handler.\n * @internal\n */\n _wasLoopActive: boolean;\n /**\n * Installed by `runRenderLoop` on first call. Lets the context-restored\n * handler resume a loop without a circular runtime import from render-loop.\n * Null if the render-loop module is tree-shaken out.\n * @internal\n */\n _scheduleFrame: ((engine: GLEngineContext) => void) | null;\n /** Optional feature-owned state-cache invalidators. Allocated lazily by the first feature that needs one.\n * @internal */\n _stateCacheInvalidators?: (() => void)[];\n /** Frame hooks installed while `captureGPUFrameTime(engine, true)` is active.\n * @internal */\n _frameHooks?: GLFrameHooks;\n /** GPU frame-time counter, created lazily by `getGPUFrameTimeCounter`.\n * @internal */\n _gpuFrameTime?: GLPerfCounter;\n /** Set by `setFramebufferValidation(engine, false)` to skip framebuffer\n * completeness checks. Configuration, not cached GL state: retained across\n * cache wipes/restores.\n * @internal */\n _skipFramebufferValidation?: boolean;\n /** Sample count of the canvas drawing buffer, queried lazily by `presentRenderTarget`.\n * @internal */\n _canvasSamples?: number;\n}\n\n/** Acquire a WebGL2 context on the canvas and build the pure-state handle.\n * Accepts an `HTMLCanvasElement` or an `OffscreenCanvas` (worker render paths —\n * e.g. the Lottie player — which size the drawing buffer via `setGLEngineSize`).\n * Throws if WebGL2 is unsupported. Resources recover automatically after\n * context loss; use `createHostOwnedGLEngine` when the host recreates instead. */\nexport function createGLEngine(canvas: HTMLCanvasElement | OffscreenCanvas, options?: GLEngineOptions): GLEngineContext {\n const o = options ?? {};\n const attrs: WebGLContextAttributes = {\n alpha: o.alpha ?? true,\n premultipliedAlpha: o.premultipliedAlpha ?? true,\n antialias: o.antialias ?? false,\n preserveDrawingBuffer: o.preserveDrawingBuffer ?? false,\n depth: o.depth ?? false,\n stencil: o.stencil ?? false,\n powerPreference: o.powerPreference ?? \"default\",\n failIfMajorPerformanceCaveat: o.failIfMajorPerformanceCaveat ?? false,\n };\n const gl = canvas.getContext(\"webgl2\", attrs) as WebGL2RenderingContext | null;\n if (gl === null) {\n throw new Error(\"lite-gl: WebGL2 is not supported on this canvas\");\n }\n\n const caps = queryCaps(gl);\n\n const engine: GLEngineContext = {\n canvas,\n gl,\n caps,\n _hsl: 1,\n _rafId: 0,\n _loops: [],\n _prevNow: 0,\n _state: createGLState(caps.maxTextureUnits),\n _effects: [],\n _effectCache: new Map(),\n _textures: new Set(),\n _renderTargets: [],\n _currentRenderTarget: null,\n _buffers: [],\n _onLost: [],\n _onRestored: [],\n _isLost: false,\n _disposed: false,\n _lostHandler: (e: Event) => handleContextLost(engine, e),\n _restoredHandler: () => handleContextRestored(engine),\n _wasLoopActive: false,\n _scheduleFrame: null,\n };\n\n canvas.addEventListener(\"webglcontextlost\", engine._lostHandler as EventListener, false);\n canvas.addEventListener(\"webglcontextrestored\", engine._restoredHandler, false);\n\n return engine;\n}\n\n/**\n * Create an engine whose context-loss recovery is owned by the host, matching\n * ThinEngine's `doNotHandleContextLost: true`. Same canvas/options contract as\n * {@link createGLEngine}, except:\n * - `webglcontextlost` still stops rendering, marks the engine lost and fires\n * `onContextLost` callbacks, but never calls `preventDefault()`, so the\n * browser does not restore the context; `onContextRestored` never fires;\n * - resources created on this engine retain no CPU replay sources (buffer\n * data, texture pixels, sprite indices) and install no restore hooks,\n * saving memory. Effects still keep their public `options` (including the\n * shader sources) and source-derived cache key, which serve readiness\n * diagnostics and effect deduplication rather than replay.\n *\n * After a loss the engine stays lost: dispose it and recreate the engine and\n * every resource (on a fresh canvas or once the host has a new context).\n *\n * @param canvas - An `HTMLCanvasElement` or `OffscreenCanvas`.\n * @param options - WebGL2 context attributes, as for {@link createGLEngine}.\n * @returns The engine. Throws if WebGL2 is unsupported.\n */\nexport function createHostOwnedGLEngine(canvas: HTMLCanvasElement | OffscreenCanvas, options?: GLEngineOptions): GLEngineContext {\n const engine = createGLEngine(canvas, options);\n engine._noRestore = true;\n canvas.removeEventListener(\"webglcontextlost\", engine._lostHandler as EventListener, false);\n canvas.removeEventListener(\"webglcontextrestored\", engine._restoredHandler, false);\n engine._lostHandler = () => handleContextLost(engine);\n canvas.addEventListener(\"webglcontextlost\", engine._lostHandler as EventListener, false);\n return engine;\n}\n\n/** Stops the render loop, removes DOM listeners, releases all known effects\n * and textures, then marks the context disposed. The browser-owned canvas\n * is left intact. */\nexport function disposeGLEngine(engine: GLEngineContext): void {\n if (engine._disposed) {\n return;\n }\n engine._disposed = true;\n if (engine._rafId !== 0) {\n cancelAnimationFrame(engine._rafId);\n engine._rafId = 0;\n }\n engine._loops.length = 0;\n engine._frameHooks?._dispose();\n engine._frameHooks = undefined;\n engine.canvas.removeEventListener(\"webglcontextlost\", engine._lostHandler as EventListener, false);\n engine.canvas.removeEventListener(\"webglcontextrestored\", engine._restoredHandler, false);\n\n const gl = engine.gl;\n const textures = Array.from(engine._textures);\n engine._textures.clear();\n // Iterate snapshots — dispose paths can mutate the live registries.\n const effects = engine._effects.slice();\n for (const eff of effects) {\n if (!eff._disposed) {\n eff._disposed = true;\n eff.isReady = false;\n gl.deleteProgram(eff.program);\n gl.deleteShader(eff._vs);\n gl.deleteShader(eff._fs);\n }\n }\n engine._effects.length = 0;\n engine._effectCache.clear();\n for (const tex of textures) {\n // The snapshot contains live textures only. Force-delete every handle,\n // even if reentrant disposal marks a later texture disposed first.\n tex._disposed = true;\n gl.deleteTexture(tex.handle);\n }\n // Render targets own their FBO + renderbuffer + color texture; free them via\n // the per-RT closure so context.ts needs no runtime import of render-target.\n const rts = engine._renderTargets.slice();\n for (const rt of rts) {\n if (!rt._disposed) {\n rt._disposed = true;\n rt._deleteGpu(gl);\n }\n }\n engine._renderTargets.length = 0;\n\n // Mesh vertex/index buffers own a single GL buffer each; free via closure.\n const buffers = engine._buffers.slice();\n for (const buf of buffers) {\n if (!buf._disposed) {\n buf._disposed = true;\n buf._deleteGpu(gl);\n buf._data = buf._restore = undefined;\n }\n }\n engine._buffers.length = 0;\n\n resetGLState(engine._state);\n engine._currentRenderTarget = null;\n engine._onLost.length = 0;\n engine._onRestored.length = 0;\n engine._stateCacheInvalidators?.splice(0);\n}\n\n/** Match drawing-buffer size to (clientSize × devicePixelRatio / _hsl). No-op\n * if size already matches. Never touches viewport — `setViewport` owns that. */\nexport function resizeGLEngine(engine: GLEngineContext): void {\n if (engine._disposed || engine._isLost) {\n return;\n }\n const canvas = engine.canvas;\n // An OffscreenCanvas has no CSS box (no clientWidth/clientHeight); it is sized\n // explicitly via setGLEngineSize, so CSS-derived auto-resize is a no-op for it.\n if (!(\"clientWidth\" in canvas)) {\n return;\n }\n const dpr = typeof devicePixelRatio === \"number\" ? devicePixelRatio : 1;\n const w = Math.max(1, Math.floor((canvas.clientWidth * dpr) / engine._hsl));\n const h = Math.max(1, Math.floor((canvas.clientHeight * dpr) / engine._hsl));\n if (canvas.width !== w) {\n canvas.width = w;\n }\n if (canvas.height !== h) {\n canvas.height = h;\n }\n}\n\n/**\n * Set the drawing-buffer size to an EXPLICIT width/height in physical pixels\n * (each divided by `_hsl`), independent of the canvas client/CSS size — the\n * counterpart of Babylon's `ThinEngine.setSize`. Use when the render resolution\n * is computed directly (e.g. animation dimensions × scale × dpr) rather than\n * derived from CSS layout via {@link resizeGLEngine}. No-op on a disposed\n * engine. Never touches the viewport — `setViewport` owns that.\n *\n * @param engine - The engine to resize.\n * @param width - Target drawing-buffer width in physical pixels.\n * @param height - Target drawing-buffer height in physical pixels.\n */\nexport function setGLEngineSize(engine: GLEngineContext, width: number, height: number): void {\n if (engine._disposed) {\n return;\n }\n const canvas = engine.canvas;\n const w = Math.max(1, Math.floor(width / engine._hsl));\n const h = Math.max(1, Math.floor(height / engine._hsl));\n if (canvas.width !== w) {\n canvas.width = w;\n }\n if (canvas.height !== h) {\n canvas.height = h;\n }\n}\n\n/**\n * Invalidate lite-gl's cached GL state so the next state-setting call in each\n * category (program / buffer / texture / VAO / framebuffer bindings, blend,\n * depth, stencil, scissor, color-mask, viewport, unpack) is re-issued instead\n * of elided.\n *\n * Use this when a host application that SHARES this WebGL2 context mutates raw\n * `gl.*` state outside lite-gl — e.g. a save/restore wrapper that resets the\n * context to GL defaults around each render scope, or any interop layer that\n * issues GL calls directly. Without it, lite-gl's redundant-call elision would\n * skip the state changes needed to re-establish the scope, producing corrupted\n * output. Owned GPU resources (the shared quad, render targets, meshes,\n * effects, textures) are preserved — only the cached \"current GL state\" is\n * reset. Mirrors Babylon's `Engine.wipeCaches(bruteForce)`.\n *\n * After a wipe the VAO / framebuffer bindings are UNKNOWN (not assumed to be\n * the defaults), so the next mesh / render-target call rebinds them even if the\n * host left its own objects bound. The current program is forgotten: call\n * `useEffect` again before drawing.\n *\n * `bruteForce` additionally normalizes, with raw GL calls, state lite-gl relies\n * on but never caches, back to WebGL2 defaults: the default VAO with every\n * vertex attribute array disabled, sampler objects unbound from every texture\n * unit, no `PIXEL_PACK` / `PIXEL_UNPACK` buffer, zero pack / unpack row and\n * skip layout, browser-default unpack colorspace conversion, `frontFace(CCW)`,\n * `depthRange(0, 1)`, `clearDepth(1)`, `clearStencil(0)`, `blendColor(0, 0, 0, 0)`\n * and `POLYGON_OFFSET_FILL` / `RASTERIZER_DISCARD` / `SAMPLE_COVERAGE` /\n * `SAMPLE_ALPHA_TO_COVERAGE` disabled. Use it when the host may leave arbitrary\n * state behind (it costs roughly `MAX_VERTEX_ATTRIBS + maxTextureUnits + 20`\n * GL calls); per-draw hand-offs with a known host should prefer the plain wipe\n * plus targeted resets.\n *\n * No-op while the context is lost or the engine is disposed.\n *\n * @param engine - The engine.\n * @param bruteForce - Also normalize untracked GL state (see above). Default `false`.\n */\nexport function wipeGLStateCache(engine: GLEngineContext, bruteForce = false): void {\n if (engine._disposed || engine._isLost) {\n return;\n }\n const s = engine._state;\n resetGLStateCache(s);\n // Brute force disables every attribute array below; a plain wipe leaves\n // host-enabled arrays unknown (ThinEngine's `_mustWipeVertexAttributes`).\n s._unknownAttribs = !bruteForce;\n const invalidators = engine._stateCacheInvalidators;\n if (invalidators) {\n for (const invalidate of invalidators) {\n invalidate();\n }\n }\n if (bruteForce) {\n const gl = engine.gl;\n gl.bindVertexArray(null);\n s.boundVao = null;\n const attribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS) as number;\n for (let i = 0; i < attribs; i++) {\n gl.disableVertexAttribArray(i);\n }\n for (let u = 0; u < s.boundTextures.length; u++) {\n gl.bindSampler(u, null);\n }\n gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, null);\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);\n for (const p of [\n gl.UNPACK_ROW_LENGTH,\n gl.UNPACK_IMAGE_HEIGHT,\n gl.UNPACK_SKIP_PIXELS,\n gl.UNPACK_SKIP_ROWS,\n gl.UNPACK_SKIP_IMAGES,\n gl.PACK_ROW_LENGTH,\n gl.PACK_SKIP_PIXELS,\n gl.PACK_SKIP_ROWS,\n ]) {\n gl.pixelStorei(p, 0);\n }\n gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.BROWSER_DEFAULT_WEBGL);\n gl.frontFace(gl.CCW);\n gl.depthRange(0, 1);\n gl.clearDepth(1);\n gl.clearStencil(0);\n gl.blendColor(0, 0, 0, 0);\n for (const cap of [gl.POLYGON_OFFSET_FILL, gl.RASTERIZER_DISCARD, gl.SAMPLE_COVERAGE, gl.SAMPLE_ALPHA_TO_COVERAGE]) {\n gl.disable(cap);\n }\n }\n}\n\n/** Drawing-buffer width in physical pixels (`canvas.width`). */\nexport function getRenderWidth(engine: GLEngineContext): number {\n return engine.canvas.width;\n}\n\n/** Drawing-buffer height in physical pixels (`canvas.height`). */\nexport function getRenderHeight(engine: GLEngineContext): number {\n return engine.canvas.height;\n}\n\n/** Number of live sampled textures managed by the context. */\nexport function getTextureCount(engine: GLEngineContext): number {\n return engine._textures.size;\n}\n\n/** Current drawing target, or null for the canvas framebuffer. */\nexport function getCurrentRenderTarget(engine: GLEngineContext): GLRenderTarget | null {\n return engine._currentRenderTarget;\n}\n\n/** Current hardware-scaling factor — drawing-buffer = clientSize × dpr / level. */\nexport function getHardwareScalingLevel(engine: GLEngineContext): number {\n return engine._hsl;\n}\n\n/** Updates the hardware-scaling factor and triggers a resize. */\nexport function setHardwareScalingLevel(engine: GLEngineContext, level: number): void {\n if (level <= 0 || !isFinite(level)) {\n return;\n }\n engine._hsl = level;\n resizeGLEngine(engine);\n}\n\n/** The backing canvas element (an `HTMLCanvasElement`, or an `OffscreenCanvas`\n * for worker render paths). */\nexport function getRenderingCanvas(engine: GLEngineContext): HTMLCanvasElement | OffscreenCanvas {\n return engine.canvas;\n}\n\n/** Register a `webglcontextlost` callback. Duplicate registrations are ignored. */\nexport function onContextLost(engine: GLEngineContext, cb: () => void): void {\n if (engine._onLost.indexOf(cb) === -1) {\n engine._onLost.push(cb);\n }\n}\n\n/** Remove a previously-registered context-lost callback. */\nexport function offContextLost(engine: GLEngineContext, cb: () => void): void {\n const i = engine._onLost.indexOf(cb);\n if (i !== -1) {\n engine._onLost.splice(i, 1);\n }\n}\n\n/** Register an automatic `webglcontextrestored` callback. Never fires on an\n * engine from `createHostOwnedGLEngine`. Duplicate registrations are ignored. */\nexport function onContextRestored(engine: GLEngineContext, cb: () => void): void {\n if (engine._onRestored.indexOf(cb) === -1) {\n engine._onRestored.push(cb);\n }\n}\n\n/** Remove a previously-registered context-restored callback. */\nexport function offContextRestored(engine: GLEngineContext, cb: () => void): void {\n const i = engine._onRestored.indexOf(cb);\n if (i !== -1) {\n engine._onRestored.splice(i, 1);\n }\n}\n\n/* ───────────────────────── internal: loss / restore ───────────────────── */\n\nfunction handleContextLost(engine: GLEngineContext, e?: Event): void {\n // Opt-in to restore. Without preventDefault() the browser will NOT fire\n // webglcontextrestored later. Host-owned engines pass no event.\n e?.preventDefault();\n if (engine._isLost || engine._disposed) {\n return;\n }\n engine._isLost = true;\n // `tick` clears `_rafId` while callbacks run, so a loss event delivered in\n // that window still represents an active loop when callbacks remain.\n engine._wasLoopActive = engine._loops.length > 0;\n if (engine._rafId !== 0) {\n cancelAnimationFrame(engine._rafId);\n engine._rafId = 0;\n }\n resetGLState(engine._state);\n engine._currentRenderTarget = null;\n for (const eff of engine._effects) {\n eff.isReady = false;\n eff._samplersAssigned = false;\n eff.uniformLocations = {};\n eff.attributeLocations = {};\n // Clear value caches so the first frame after restore re-uploads\n // every uniform into the freshly-linked program.\n clearObject(eff._lastF1);\n clearObject(eff._lastVec);\n clearObject(eff._lastI1);\n // Do NOT gl.deleteProgram — handle is already dead per WebGL spec.\n }\n for (const tex of engine._textures) {\n tex._wasReady = tex.isReady;\n tex.isReady = false;\n }\n const cbs = engine._onLost.slice();\n for (const cb of cbs) {\n try {\n cb();\n } catch (err) {\n console.error(\"lite-gl: onLost callback threw\", err);\n }\n }\n}\n\nfunction handleContextRestored(engine: GLEngineContext): void {\n if (engine._disposed) {\n return;\n }\n Object.assign(engine.caps, queryCaps(engine.gl));\n for (const eff of engine._effects) {\n if (!eff._disposed) {\n eff._restore!(engine);\n }\n }\n for (const tex of engine._textures) {\n if (!tex._disposed) {\n const newHandle = engine.gl.createTexture();\n if (newHandle !== null) {\n tex.handle = newHandle;\n tex._upload(engine);\n tex._initializeParameters?.(engine);\n tex.isReady = tex._wasReady;\n }\n }\n }\n // Clear the lost flag BEFORE the render-target / buffer rebuilds: their\n // `_restore` closures route through the same guarded build/upload paths used\n // at create time (which no-op while `_isLost`), whereas the effect / texture\n // replay above is unguarded and unaffected by the flag's value.\n engine._isLost = false;\n // Render targets rebuild their own color texture + FBO + renderbuffer AFTER\n // the standalone texture replay above (an RT's color texture is owned by the\n // RT, not the `_textures` registry).\n for (const rt of engine._renderTargets) {\n if (!rt._disposed) {\n rt._restore!(engine);\n }\n }\n // Mesh buffers re-upload their retained CPU data into fresh GL buffers.\n for (const buf of engine._buffers) {\n if (!buf._disposed) {\n buf._restore!(engine);\n }\n }\n if (engine._wasLoopActive && engine._loops.length > 0 && engine._scheduleFrame !== null) {\n engine._scheduleFrame(engine);\n }\n const cbs = engine._onRestored.slice();\n for (const cb of cbs) {\n try {\n cb();\n } catch (err) {\n console.error(\"lite-gl: onRestored callback threw\", err);\n }\n }\n}\n\nfunction queryCaps(gl: WebGL2RenderingContext): GLEngineCaps {\n const parallelExt = gl.getExtension(\"KHR_parallel_shader_compile\") as { COMPLETION_STATUS_KHR: number } | null;\n // `getExtension` both queries and enables these capabilities, so they must\n // be reacquired after context restoration before resources are rebuilt.\n const colorBufferFloat = gl.getExtension(\"EXT_color_buffer_float\") !== null;\n const colorBufferHalfFloat = gl.getExtension(\"EXT_color_buffer_half_float\") !== null;\n const floatLinear = gl.getExtension(\"OES_texture_float_linear\") !== null;\n return {\n maxTextureSize: gl.getParameter(gl.MAX_TEXTURE_SIZE) as number,\n maxTextureUnits: gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS) as number,\n parallelShaderCompile: parallelExt,\n textureFloatRender: colorBufferFloat,\n textureFloatLinearFiltering: floatLinear,\n textureHalfFloatRender: colorBufferFloat || colorBufferHalfFloat,\n textureHalfFloatLinearFiltering: true,\n needPOTTextures: false,\n };\n}\n\nfunction clearObject(o: { [k: string]: unknown }): void {\n for (const key in o) {\n delete o[key];\n }\n}\n"]}
|
package/depth-stencil.d.ts
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* must not import this module.
|
|
23
23
|
*/
|
|
24
24
|
import type { GLEngineContext } from "./context.js";
|
|
25
|
+
import type { GLClearOptions } from "./family.js";
|
|
25
26
|
import type { GLRenderTarget } from "./render-target.js";
|
|
26
27
|
/** Depth-buffer configuration for {@link setDepthState}. Omitted fields are
|
|
27
28
|
* left unchanged. */
|
|
@@ -64,20 +65,6 @@ export interface GLStencilOpState {
|
|
|
64
65
|
/** Op when both stencil and depth pass (`gl.stencilOpSeparate` arg 4). */
|
|
65
66
|
opZPass?: GLenum;
|
|
66
67
|
}
|
|
67
|
-
/** Options for {@link clearEngine}. */
|
|
68
|
-
export interface GLClearOptions {
|
|
69
|
-
/** When set, clears the color buffer to this RGBA color (alpha default 1). */
|
|
70
|
-
color?: {
|
|
71
|
-
r: number;
|
|
72
|
-
g: number;
|
|
73
|
-
b: number;
|
|
74
|
-
a?: number;
|
|
75
|
-
};
|
|
76
|
-
/** Clear the depth buffer (respects the current depth write mask). */
|
|
77
|
-
depth?: boolean;
|
|
78
|
-
/** Clear the stencil buffer (respects the current stencil write mask). */
|
|
79
|
-
stencil?: boolean;
|
|
80
|
-
}
|
|
81
68
|
/**
|
|
82
69
|
* Buffer depth-buffer state (test enable, write mask, comparison function) into
|
|
83
70
|
* the DESIRED state — the lite-gl equivalent of mutating Babylon's
|
|
@@ -168,8 +155,9 @@ export declare function clearEngine(engine: GLEngineContext, options: GLClearOpt
|
|
|
168
155
|
* — the common case, and the correct choice when the target was created with
|
|
169
156
|
* `generateDepthBuffer: true`. When `false` the attachment is stencil-only
|
|
170
157
|
* (`STENCIL_INDEX8` on `STENCIL_ATTACHMENT`).
|
|
171
|
-
* @throws If a renderbuffer handle could not be allocated or the framebuffer is
|
|
172
|
-
* incomplete after attaching
|
|
158
|
+
* @throws If a renderbuffer handle could not be allocated, or the framebuffer is
|
|
159
|
+
* incomplete after attaching (unless `setFramebufferValidation(engine, false)`
|
|
160
|
+
* opted out of completeness checks).
|
|
173
161
|
*/
|
|
174
162
|
export declare function generateRenderTargetStencil(rt: GLRenderTarget, options?: {
|
|
175
163
|
depth?: boolean;
|
package/depth-stencil.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateFramebuffer } from "./framebuffer-validation.js";
|
|
1
2
|
import { applyGLStates } from "./apply-states.js";
|
|
2
3
|
import { RS_CLEAR_A, RS_CLEAR_B, RS_CLEAR_G, RS_CLEAR_R, RS_COLOR_MASK, RS_CULL_ENABLED, RS_CULL_FACE, RS_DEPTH_FUNC, RS_DEPTH_MASK, RS_DEPTH_TEST, RS_DESIRED, RS_STENCIL_FUNC_FUNC, RS_STENCIL_FUNC_MASK, RS_STENCIL_FUNC_REF, RS_STENCIL_MASK, RS_STENCIL_OP_FAIL, RS_STENCIL_OP_ZFAIL, RS_STENCIL_OP_ZPASS, RS_STENCIL_TEST, } from "./state.js";
|
|
3
4
|
// ── Clear bits (used by `clearEngine`).
|
|
@@ -45,8 +46,6 @@ const STENCIL_ATTACHMENT = 0x8d20;
|
|
|
45
46
|
/** GL `gl.DEPTH_ATTACHMENT` — where the render-target core attaches its depth-only
|
|
46
47
|
* renderbuffer (re-established when rolling back a failed stencil attach). */
|
|
47
48
|
const DEPTH_ATTACHMENT = 0x8d00;
|
|
48
|
-
/** GL `gl.FRAMEBUFFER_COMPLETE`. */
|
|
49
|
-
const FRAMEBUFFER_COMPLETE = 0x8cd5;
|
|
50
49
|
/** Seed the shared desired op tuple with WebGL's KEEP defaults. */
|
|
51
50
|
function ensureStencilOpCacheInitialized(rs) {
|
|
52
51
|
if (rs[RS_STENCIL_OP_FAIL + RS_DESIRED] !== -1) {
|
|
@@ -474,8 +473,9 @@ function flushColorMask(engine) {
|
|
|
474
473
|
* — the common case, and the correct choice when the target was created with
|
|
475
474
|
* `generateDepthBuffer: true`. When `false` the attachment is stencil-only
|
|
476
475
|
* (`STENCIL_INDEX8` on `STENCIL_ATTACHMENT`).
|
|
477
|
-
* @throws If a renderbuffer handle could not be allocated or the framebuffer is
|
|
478
|
-
* incomplete after attaching
|
|
476
|
+
* @throws If a renderbuffer handle could not be allocated, or the framebuffer is
|
|
477
|
+
* incomplete after attaching (unless `setFramebufferValidation(engine, false)`
|
|
478
|
+
* opted out of completeness checks).
|
|
479
479
|
*/
|
|
480
480
|
export function generateRenderTargetStencil(rt, options) {
|
|
481
481
|
const engine = rt._engine;
|
|
@@ -489,8 +489,10 @@ export function generateRenderTargetStencil(rt, options) {
|
|
|
489
489
|
const gl = e.gl;
|
|
490
490
|
// Capture the caller's draw target so this helper is STATE-NEUTRAL: it must
|
|
491
491
|
// not silently redirect subsequent draws to `rt` (during an internal
|
|
492
|
-
// rebuild `prevFb` is `rt._framebuffer`, which the core re-checks next
|
|
493
|
-
|
|
492
|
+
// rebuild `prevFb` is `rt._framebuffer`, which the core re-checks next
|
|
493
|
+
// unless validation was opted out).
|
|
494
|
+
// An unknown (wiped) binding is restored as the canvas.
|
|
495
|
+
const prevFb = e._state.boundFramebuffer ?? null;
|
|
494
496
|
const newRb = gl.createRenderbuffer();
|
|
495
497
|
if (newRb === null) {
|
|
496
498
|
throw new Error("lite-gl: gl.createRenderbuffer returned null (render target stencil)");
|
|
@@ -503,10 +505,7 @@ export function generateRenderTargetStencil(rt, options) {
|
|
|
503
505
|
gl.renderbufferStorage(RENDERBUFFER, format, rt.width, rt.height);
|
|
504
506
|
gl.framebufferRenderbuffer(FRAMEBUFFER, attachment, RENDERBUFFER, newRb);
|
|
505
507
|
gl.bindRenderbuffer(RENDERBUFFER, null);
|
|
506
|
-
|
|
507
|
-
if (status !== FRAMEBUFFER_COMPLETE) {
|
|
508
|
-
throw new Error(`lite-gl: render target framebuffer incomplete after stencil attach (status 0x${status.toString(16)})`);
|
|
509
|
-
}
|
|
508
|
+
validateFramebuffer(e, true);
|
|
510
509
|
// Commit only after a complete attachment: release the buffer we
|
|
511
510
|
// replaced (the core depth-only one, or our own from a prior rebuild).
|
|
512
511
|
if (rt._depthStencil !== null) {
|
|
@@ -567,7 +566,7 @@ export function generateRenderTargetStencil(rt, options) {
|
|
|
567
566
|
*/
|
|
568
567
|
function reattachCoreDepthBuffer(engine, rt, depthBuffer) {
|
|
569
568
|
const gl = engine.gl;
|
|
570
|
-
const prevFb = engine._state.boundFramebuffer;
|
|
569
|
+
const prevFb = engine._state.boundFramebuffer ?? null;
|
|
571
570
|
gl.bindFramebuffer(FRAMEBUFFER, rt._framebuffer);
|
|
572
571
|
engine._state.boundFramebuffer = rt._framebuffer;
|
|
573
572
|
gl.framebufferRenderbuffer(FRAMEBUFFER, DEPTH_ATTACHMENT, RENDERBUFFER, depthBuffer);
|
package/depth-stencil.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"depth-stencil.js","sourceRoot":"","sources":["../src/depth-stencil.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EACH,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,eAAe,EACf,YAAY,EACZ,aAAa,EACb,aAAa,EACb,aAAa,EACb,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,GAClB,MAAM,YAAY,CAAC;AAEpB,yCAAyC;AACzC,qBAAqB;AACrB,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,+DAA+D;AAC/D,0BAA0B;AAC1B,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,yBAAyB;AACzB,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,oBAAoB;AACpB,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,qBAAqB;AACrB,MAAM,KAAK,GAAG,MAAM,CAAC;AACrB,oBAAoB;AACpB,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,8BAA8B;AAC9B,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,6EAA6E;AAC7E,8DAA8D;AAC9D,MAAM,YAAY,GAAG,EAAE,CAA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MAAM,CAAC,gBAAgB,GAAG,EAAE,CAAC,YAAY,CAAC;IACjD,EAAE,CAAC,uBAAuB,CAAC,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;IACrF,IAAI,MAAM,CAAC,MAAM,CAAC,gBAAgB,KAAK,MAAM,EAAE,CAAC;QAC5C,EAAE,CAAC,eAAe,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACxC,MAAM,CAAC,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC;IAC5C,CAAC;AACL,CAAC","sourcesContent":["/**\n * Depth, stencil, color-mask and clear state — the lite-gl counterpart of\n * Babylon's `_depthCullingState` / `_stencilState` / `setColorWrite` / `clear`.\n *\n * Like Babylon, these setters are DEFERRED: they buffer the requested values\n * into the DESIRED (`d*`) mirror fields of `GLState` and raise `statesDirty`,\n * issuing NO `gl.*` calls themselves. `applyGLStates` (apply-states.ts) flushes\n * the diff to GL right before each draw (and before `clearEngine`'s `gl.clear`,\n * since a clear respects the current write masks). Every field is reconciled\n * independently, so a flush that changes only one sub-state (e.g. just the\n * stencil op triple) issues only that GL call. Omitted setter fields leave the\n * corresponding desired value untouched (merge-from-desired).\n *\n * All setters are no-ops on a lost/disposed context.\n *\n * This module also hosts {@link generateRenderTargetStencil} — the tree-shakeable\n * opt-in that gives a `/render-target` {@link GLRenderTarget} a stencil (or packed\n * depth+stencil) attachment. Keeping the STENCIL_INDEX8 / DEPTH24_STENCIL8\n * renderbuffer code here (rather than in the render-target core) means a consumer\n * that only needs a depth buffer never ships it. The one-way type import below\n * (`depth-stencil` importing `render-target`) introduces NO cycle: render-target\n * must not import this module.\n */\nimport type { GLEngineContext } from \"./context.js\";\nimport type { GLRenderTarget } from \"./render-target.js\";\nimport { applyGLStates } from \"./apply-states.js\";\nimport {\n RS_CLEAR_A,\n RS_CLEAR_B,\n RS_CLEAR_G,\n RS_CLEAR_R,\n RS_COLOR_MASK,\n RS_CULL_ENABLED,\n RS_CULL_FACE,\n RS_DEPTH_FUNC,\n RS_DEPTH_MASK,\n RS_DEPTH_TEST,\n RS_DESIRED,\n RS_STENCIL_FUNC_FUNC,\n RS_STENCIL_FUNC_MASK,\n RS_STENCIL_FUNC_REF,\n RS_STENCIL_MASK,\n RS_STENCIL_OP_FAIL,\n RS_STENCIL_OP_ZFAIL,\n RS_STENCIL_OP_ZPASS,\n RS_STENCIL_TEST,\n} from \"./state.js\";\n\n// ── Clear bits (used by `clearEngine`).\n/** GL clear bits. */\nconst COLOR_BUFFER_BIT = 0x4000;\nconst DEPTH_BUFFER_BIT = 0x0100;\nconst STENCIL_BUFFER_BIT = 0x0400;\n\n// ── Test-enable enums for the per-category reconcilers below.\n/** GL `gl.DEPTH_TEST`. */\nconst DEPTH_TEST = 0x0b71;\n/** GL `gl.CULL_FACE`. */\nconst CULL_FACE = 0x0b44;\n/** GL `gl.STENCIL_TEST`. */\nconst STENCIL_TEST = 0x0b90;\n/** GL `gl.KEEP`. */\nconst KEEP = 0x1e00;\n/** GL `gl.FRONT`. */\nconst FRONT = 0x0404;\n/** GL `gl.BACK`. */\nconst BACK = 0x0405;\n/** GL `gl.FRONT_AND_BACK`. */\nconst FRONT_AND_BACK = 0x0408;\n// Two-sided mode appends actual slots 46..48 and desired slots 49..51 to the\n// compact 46-slot state array. Base indices remain unchanged.\nconst BACK_OP_FAIL = 46;\nconst BACK_OP_ZFAIL = 47;\nconst BACK_OP_ZPASS = 48;\nconst BACK_DESIRED = 3;\n\n// ── Framebuffer / renderbuffer enums (used only by generateRenderTargetStencil).\n// Module-local consts mirror render-target.ts's constant style. Because the\n// render-target core no longer references the stencil/packed enums, they live\n// here and tree-shake away for consumers that never opt into a stencil buffer.\n/** GL `gl.FRAMEBUFFER`. */\nconst FRAMEBUFFER = 0x8d40;\n/** GL `gl.RENDERBUFFER`. */\nconst RENDERBUFFER = 0x8d41;\n/** GL `gl.DEPTH24_STENCIL8` — packed depth+stencil sized format. */\nconst DEPTH24_STENCIL8 = 0x88f0;\n/** GL `gl.STENCIL_INDEX8` — stencil-only sized format. */\nconst STENCIL_INDEX8 = 0x8d48;\n/** GL `gl.DEPTH_STENCIL_ATTACHMENT`. */\nconst DEPTH_STENCIL_ATTACHMENT = 0x821a;\n/** GL `gl.STENCIL_ATTACHMENT`. */\nconst STENCIL_ATTACHMENT = 0x8d20;\n/** GL `gl.DEPTH_ATTACHMENT` — where the render-target core attaches its depth-only\n * renderbuffer (re-established when rolling back a failed stencil attach). */\nconst DEPTH_ATTACHMENT = 0x8d00;\n/** GL `gl.FRAMEBUFFER_COMPLETE`. */\nconst FRAMEBUFFER_COMPLETE = 0x8cd5;\n\n/** Depth-buffer configuration for {@link setDepthState}. Omitted fields are\n * left unchanged. */\nexport interface GLDepthState {\n /** Enable/disable the depth test (`gl.enable/disable(DEPTH_TEST)`). */\n test?: boolean;\n /** Enable/disable depth writes (`gl.depthMask`). */\n write?: boolean;\n /** Depth comparison function (`gl.depthFunc`), e.g. `gl.LESS`. */\n func?: GLenum;\n}\n\n/** Stencil configuration for {@link setStencilState}. Omitted fields are left\n * unchanged. Operation fields update both front and back faces; use\n * {@link setStencilOpSeparate} for per-face values. */\nexport interface GLStencilState {\n /** Enable/disable the stencil test (`gl.enable/disable(STENCIL_TEST)`). */\n test?: boolean;\n /** Comparison function (`gl.stencilFunc` arg 1), e.g. `gl.ALWAYS`. */\n func?: GLenum;\n /** Reference value (`gl.stencilFunc` arg 2). */\n ref?: number;\n /** Comparison mask (`gl.stencilFunc` arg 3). */\n funcMask?: number;\n /** Stencil write mask (`gl.stencilMask`). */\n mask?: number;\n /** Op when the stencil test fails (`gl.stencilOp` arg 1). */\n opFail?: GLenum;\n /** Op when the stencil test passes but depth fails (`gl.stencilOp` arg 2). */\n opZFail?: GLenum;\n /** Op when both stencil and depth pass (`gl.stencilOp` arg 3). */\n opZPass?: GLenum;\n}\n\n/** Per-face stencil operations for {@link setStencilOpSeparate}. Omitted fields\n * retain that face's desired value. */\nexport interface GLStencilOpState {\n /** Op when the stencil test fails (`gl.stencilOpSeparate` arg 2). */\n opFail?: GLenum;\n /** Op when the stencil test passes but depth fails (`gl.stencilOpSeparate` arg 3). */\n opZFail?: GLenum;\n /** Op when both stencil and depth pass (`gl.stencilOpSeparate` arg 4). */\n opZPass?: GLenum;\n}\n\n/** Seed the shared desired op tuple with WebGL's KEEP defaults. */\nfunction ensureStencilOpCacheInitialized(rs: Float64Array): void {\n if (rs[RS_STENCIL_OP_FAIL + RS_DESIRED] !== -1) {\n return;\n }\n rs[RS_STENCIL_OP_FAIL + RS_DESIRED] = KEEP;\n rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED] = KEEP;\n rs[RS_STENCIL_OP_ZPASS + RS_DESIRED] = KEEP;\n}\n\nfunction setDesiredStencilOps(rs: Float64Array, state: GLStencilOpState): void {\n if ((state.opFail ?? state.opZFail ?? state.opZPass) === undefined) {\n return;\n }\n ensureStencilOpCacheInitialized(rs);\n if (state.opFail !== undefined) {\n rs[RS_STENCIL_OP_FAIL + RS_DESIRED] = state.opFail;\n }\n if (state.opZFail !== undefined) {\n rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED] = state.opZFail;\n }\n if (state.opZPass !== undefined) {\n rs[RS_STENCIL_OP_ZPASS + RS_DESIRED] = state.opZPass;\n }\n}\n\n/** Store one complete GL operation tuple starting at `opIndex`. */\nfunction setStencilOps(rs: Float64Array, opIndex: number, fail: GLenum, zfail: GLenum, zpass: GLenum): void {\n rs[opIndex] = fail;\n rs[opIndex + 1] = zfail;\n rs[opIndex + 2] = zpass;\n}\n\nfunction resetStencilBack(rs: Float64Array): void {\n ensureStencilOpCacheInitialized(rs);\n setStencilOps(rs, BACK_OP_FAIL, rs[RS_STENCIL_OP_FAIL]!, rs[RS_STENCIL_OP_ZFAIL]!, rs[RS_STENCIL_OP_ZPASS]!);\n setStencilOps(rs, BACK_OP_FAIL + BACK_DESIRED, rs[RS_STENCIL_OP_FAIL + RS_DESIRED]!, rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED]!, rs[RS_STENCIL_OP_ZPASS + RS_DESIRED]!);\n}\n\nfunction ensureStencilBackCacheInitialized(rs: Float64Array): void {\n if (rs[RS_STENCIL_OP_FAIL + RS_DESIRED] === -1) {\n resetStencilBack(rs);\n }\n}\n\nfunction setDesiredStencilBackOps(rs: Float64Array, state: GLStencilOpState): void {\n if (state.opFail !== undefined) {\n rs[BACK_OP_FAIL + BACK_DESIRED] = state.opFail;\n }\n if (state.opZFail !== undefined) {\n rs[BACK_OP_ZFAIL + BACK_DESIRED] = state.opZFail;\n }\n if (state.opZPass !== undefined) {\n rs[BACK_OP_ZPASS + BACK_DESIRED] = state.opZPass;\n }\n}\n\n/** Mirror a shared stencil-op update to the lazily allocated back-face cache. */\nfunction mirrorSharedStencilOpsToBack(s: GLEngineContext[\"_state\"], state: GLStencilOpState): void {\n if ((state.opFail ?? state.opZFail ?? state.opZPass) === undefined) {\n return;\n }\n ensureStencilBackCacheInitialized(s.rs);\n setDesiredStencilBackOps(s.rs, state);\n}\n\n/** Lazily install back-face storage and the two-sided reconciler. */\nfunction enableSeparateStencil(s: GLEngineContext[\"_state\"]): void {\n if (s._setStencilBack !== undefined) {\n return;\n }\n const rs = new Float64Array(52);\n rs.set(s.rs);\n s.rs = rs;\n resetStencilBack(rs);\n s._setStencilBack = mirrorSharedStencilOpsToBack;\n s._flushStencil = flushStencilSeparate;\n}\n\n/** Options for {@link clearEngine}. */\nexport interface GLClearOptions {\n /** When set, clears the color buffer to this RGBA color (alpha default 1). */\n color?: { r: number; g: number; b: number; a?: number };\n /** Clear the depth buffer (respects the current depth write mask). */\n depth?: boolean;\n /** Clear the stencil buffer (respects the current stencil write mask). */\n stencil?: boolean;\n}\n\n/**\n * Buffer depth-buffer state (test enable, write mask, comparison function) into\n * the DESIRED state — the lite-gl equivalent of mutating Babylon's\n * `engine.depthCullingState.{depthTest,depthMask,depthFunc}`. Flushed to GL by\n * `applyGLStates` before the next draw / clear; omitted fields are untouched.\n *\n * @param engine - The engine.\n * @param state - The depth fields to change. Omitted fields are untouched.\n */\nexport function setDepthState(engine: GLEngineContext, state: GLDepthState): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n if (state.test !== undefined) {\n s.rs[RS_DEPTH_TEST + RS_DESIRED] = state.test ? 1 : 0;\n }\n if (state.write !== undefined) {\n s.rs[RS_DEPTH_MASK + RS_DESIRED] = state.write ? 1 : 0;\n }\n if (state.func !== undefined) {\n s.rs[RS_DEPTH_FUNC + RS_DESIRED] = state.func;\n }\n s._flushDepthCull = flushDepthCull;\n s.statesDirty = true;\n}\n\n/**\n * Enable/disable face culling and (optionally) set the cull face — the lite-gl\n * equivalent of `engine.depthCullingState.cull` + `cullFace`.\n *\n * @param engine - The engine.\n * @param enabled - Enable (`true`) or disable (`false`) `gl.CULL_FACE`.\n * @param face - Optional cull face (`gl.BACK` / `gl.FRONT` / `gl.FRONT_AND_BACK`).\n */\nexport function setCullState(engine: GLEngineContext, enabled: boolean, face?: GLenum): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n s.rs[RS_CULL_ENABLED + RS_DESIRED] = enabled ? 1 : 0;\n if (face !== undefined) {\n s.rs[RS_CULL_FACE + RS_DESIRED] = face;\n }\n s._flushDepthCull = flushDepthCull;\n s.statesDirty = true;\n}\n\n/**\n * Buffer stencil state (test enable, write mask, comparison func triple, op\n * triple) into the DESIRED state — the lite-gl equivalent of mutating Babylon's\n * `engine.stencilState.*`. Flushed by `applyGLStates` before the next draw /\n * clear; omitted fields are untouched (merge-from-desired).\n *\n * @param engine - The engine.\n * @param state - The stencil fields to change. Omitted fields are untouched.\n */\nexport function setStencilState(engine: GLEngineContext, state: GLStencilState): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n if (state.test !== undefined) {\n s.rs[RS_STENCIL_TEST + RS_DESIRED] = state.test ? 1 : 0;\n }\n if (state.func !== undefined) {\n s.rs[RS_STENCIL_FUNC_FUNC + RS_DESIRED] = state.func;\n }\n if (state.ref !== undefined) {\n s.rs[RS_STENCIL_FUNC_REF + RS_DESIRED] = state.ref;\n }\n if (state.funcMask !== undefined) {\n s.rs[RS_STENCIL_FUNC_MASK + RS_DESIRED] = state.funcMask;\n }\n if (state.mask !== undefined) {\n s.rs[RS_STENCIL_MASK + RS_DESIRED] = state.mask;\n }\n s._setStencilBack?.(s, state);\n if ((state.opFail ?? state.opZFail ?? state.opZPass) !== undefined) {\n ensureStencilOpCacheInitialized(s.rs);\n if (state.opFail !== undefined) {\n s.rs[RS_STENCIL_OP_FAIL + RS_DESIRED] = state.opFail;\n }\n if (state.opZFail !== undefined) {\n s.rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED] = state.opZFail;\n }\n if (state.opZPass !== undefined) {\n s.rs[RS_STENCIL_OP_ZPASS + RS_DESIRED] = state.opZPass;\n }\n }\n s._flushStencil ??= flushStencil;\n s.statesDirty = true;\n}\n\n/**\n * Buffer stencil operations for one face into the DESIRED state. This is the\n * deferred lite-gl counterpart of `gl.stencilOpSeparate`; use it to apply\n * different winding operations to front and back faces in one draw. A\n * `FRONT_AND_BACK` update applies each provided operation to both faces while\n * leaving omitted operations unchanged on each face.\n *\n * @param engine - The engine.\n * @param face - `gl.FRONT`, `gl.BACK`, or `gl.FRONT_AND_BACK`.\n * @param state - The operation fields to change for the selected face(s).\n * @throws If `face` is not `gl.FRONT`, `gl.BACK`, or `gl.FRONT_AND_BACK`.\n */\nexport function setStencilOpSeparate(engine: GLEngineContext, face: GLenum, state: GLStencilOpState): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n if (face !== FRONT && face !== BACK && face !== FRONT_AND_BACK) {\n throw new Error(\"lite-gl: invalid face\");\n }\n if ((state.opFail ?? state.opZFail ?? state.opZPass) === undefined) {\n return;\n }\n enableSeparateStencil(s);\n ensureStencilBackCacheInitialized(s.rs);\n if (face !== BACK) {\n setDesiredStencilOps(s.rs, state);\n }\n if (face !== FRONT) {\n setDesiredStencilBackOps(s.rs, state);\n }\n s.statesDirty = true;\n}\n\n/**\n * Buffer the color write mask into the DESIRED state — the lite-gl equivalent of\n * Babylon's `setColorWrite` (which passes the same flag to all four channels).\n * Flushed to GL (`gl.colorMask`) by `applyGLStates` before the next draw /\n * clear.\n *\n * @param engine - The engine.\n * @param r - Write red.\n * @param g - Write green.\n * @param b - Write blue.\n * @param a - Write alpha.\n */\nexport function setColorMask(engine: GLEngineContext, r: boolean, g: boolean, b: boolean, a: boolean): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const packed = (r ? 8 : 0) | (g ? 4 : 0) | (b ? 2 : 0) | (a ? 1 : 0);\n const s = engine._state;\n s.rs[RS_COLOR_MASK + RS_DESIRED] = packed;\n s._flushColorMask = flushColorMask;\n s.statesDirty = true;\n}\n\n/**\n * Clear the currently-bound framebuffer's color / depth / stencil buffers — the\n * lite-gl equivalent of Babylon's `clear(color, backBuffer, depth, stencil)`.\n * Depth/stencil clears respect the current write masks (set them first via\n * {@link setDepthState} / {@link setStencilState}). No-op when nothing is\n * requested or the context is lost/disposed.\n *\n * @param engine - The engine.\n * @param options - Which buffers to clear (and the color value).\n */\nexport function clearEngine(engine: GLEngineContext, options: GLClearOptions): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n let mask = 0;\n if (options.color !== undefined) {\n const c = options.color;\n const a = c.a ?? 1;\n const rs = engine._state.rs;\n // Cached: gl.clearColor is per-context state GL retains, so only re-issue\n // it when the requested color actually changes (Babylon re-sets it every\n // clear; this elides the redundant JS↔native call for constant backgrounds).\n if (rs[RS_CLEAR_R] !== c.r || rs[RS_CLEAR_G] !== c.g || rs[RS_CLEAR_B] !== c.b || rs[RS_CLEAR_A] !== a) {\n gl.clearColor(c.r, c.g, c.b, a);\n rs[RS_CLEAR_R] = c.r;\n rs[RS_CLEAR_G] = c.g;\n rs[RS_CLEAR_B] = c.b;\n rs[RS_CLEAR_A] = a;\n }\n mask |= COLOR_BUFFER_BIT;\n }\n if (options.depth === true) {\n mask |= DEPTH_BUFFER_BIT;\n }\n if (options.stencil === true) {\n mask |= STENCIL_BUFFER_BIT;\n }\n if (mask !== 0) {\n // Babylon parity: a clear respects the current depth/stencil/color write\n // masks, so flush any deferred state before clearing.\n applyGLStates(engine);\n gl.clear(mask);\n }\n}\n\n/* ─────────────────── deferred render-state reconcilers ──────────────────────\n * The per-category half of `applyGLStates`. Each setter above installs the\n * matching reconciler onto its `_state._flush*` slot; `applyGLStates`\n * (apply-states.ts) dispatches ONLY through those slots. Co-locating them with\n * their setters makes each one reachable solely when its setter is in the bundle,\n * so a scene that never touches depth/cull, stencil, or color-mask tree-shakes\n * the corresponding reconciler — and its GL code — away entirely. Each reconciles\n * its DESIRED (`rs[RS_X + RS_DESIRED]`) slots against the ACTUAL twins (`rs[RS_X]`)\n * and issues only the `gl.*` calls that changed, in the same order and with the\n * same elision rules as the former monolithic flush. */\n\n/** Reconcile depth + cull (Babylon's `_depthCullingState.apply`). @internal */\nfunction flushDepthCull(engine: GLEngineContext): void {\n const gl = engine.gl;\n const rs = engine._state.rs;\n const dTest = rs[RS_DEPTH_TEST + RS_DESIRED]!;\n if (dTest !== rs[RS_DEPTH_TEST]) {\n rs[RS_DEPTH_TEST] = dTest;\n if (dTest === 1) {\n gl.enable(DEPTH_TEST);\n } else {\n gl.disable(DEPTH_TEST);\n }\n }\n const dMask = rs[RS_DEPTH_MASK + RS_DESIRED]!;\n if (dMask !== rs[RS_DEPTH_MASK]) {\n rs[RS_DEPTH_MASK] = dMask;\n gl.depthMask(dMask === 1);\n }\n const dFunc = rs[RS_DEPTH_FUNC + RS_DESIRED]!;\n if (dFunc !== rs[RS_DEPTH_FUNC]) {\n rs[RS_DEPTH_FUNC] = dFunc;\n gl.depthFunc(dFunc);\n }\n const dCull = rs[RS_CULL_ENABLED + RS_DESIRED]!;\n if (dCull !== rs[RS_CULL_ENABLED]) {\n rs[RS_CULL_ENABLED] = dCull;\n if (dCull === 1) {\n gl.enable(CULL_FACE);\n } else {\n gl.disable(CULL_FACE);\n }\n }\n const dCullFace = rs[RS_CULL_FACE + RS_DESIRED]!;\n if (dCullFace !== rs[RS_CULL_FACE]) {\n rs[RS_CULL_FACE] = dCullFace;\n gl.cullFace(dCullFace);\n }\n}\n\nfunction flushStencilCommon(engine: GLEngineContext): void {\n const gl = engine.gl;\n const rs = engine._state.rs;\n const dTest = rs[RS_STENCIL_TEST + RS_DESIRED]!;\n if (dTest !== rs[RS_STENCIL_TEST]) {\n rs[RS_STENCIL_TEST] = dTest;\n if (dTest === 1) {\n gl.enable(STENCIL_TEST);\n } else {\n gl.disable(STENCIL_TEST);\n }\n }\n const dMask = rs[RS_STENCIL_MASK + RS_DESIRED]!;\n if (dMask !== rs[RS_STENCIL_MASK]) {\n rs[RS_STENCIL_MASK] = dMask;\n gl.stencilMask(dMask);\n }\n const dFuncFunc = rs[RS_STENCIL_FUNC_FUNC + RS_DESIRED]!;\n const dFuncRef = rs[RS_STENCIL_FUNC_REF + RS_DESIRED]!;\n const dFuncMask = rs[RS_STENCIL_FUNC_MASK + RS_DESIRED]!;\n if (dFuncFunc !== rs[RS_STENCIL_FUNC_FUNC] || dFuncRef !== rs[RS_STENCIL_FUNC_REF] || dFuncMask !== rs[RS_STENCIL_FUNC_MASK]) {\n rs[RS_STENCIL_FUNC_FUNC] = dFuncFunc;\n rs[RS_STENCIL_FUNC_REF] = dFuncRef;\n rs[RS_STENCIL_FUNC_MASK] = dFuncMask;\n gl.stencilFunc(dFuncFunc, dFuncRef, dFuncMask);\n }\n}\n\n/** Reconcile the compact shared stencil state. @internal */\nfunction flushStencil(engine: GLEngineContext): void {\n flushStencilCommon(engine);\n const gl = engine.gl;\n const rs = engine._state.rs;\n const frontOpFail = rs[RS_STENCIL_OP_FAIL + RS_DESIRED]!;\n if (frontOpFail === -1) {\n return;\n }\n const frontOpZFail = rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED]!;\n const frontOpZPass = rs[RS_STENCIL_OP_ZPASS + RS_DESIRED]!;\n const frontChanged = frontOpFail !== rs[RS_STENCIL_OP_FAIL] || frontOpZFail !== rs[RS_STENCIL_OP_ZFAIL] || frontOpZPass !== rs[RS_STENCIL_OP_ZPASS];\n if (frontChanged) {\n rs[RS_STENCIL_OP_FAIL] = frontOpFail;\n rs[RS_STENCIL_OP_ZFAIL] = frontOpZFail;\n rs[RS_STENCIL_OP_ZPASS] = frontOpZPass;\n gl.stencilOp(frontOpFail, frontOpZFail, frontOpZPass);\n }\n}\n\n/** Reconcile independently cached front/back stencil operation tuples. */\nfunction flushStencilSeparate(engine: GLEngineContext): void {\n flushStencilCommon(engine);\n const gl = engine.gl;\n const rs = engine._state.rs;\n const frontOpFail = rs[RS_STENCIL_OP_FAIL + RS_DESIRED]!;\n if (frontOpFail === -1) {\n return;\n }\n const frontOpZFail = rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED]!;\n const frontOpZPass = rs[RS_STENCIL_OP_ZPASS + RS_DESIRED]!;\n const backOpFail = rs[BACK_OP_FAIL + BACK_DESIRED]!;\n const backOpZFail = rs[BACK_OP_ZFAIL + BACK_DESIRED]!;\n const backOpZPass = rs[BACK_OP_ZPASS + BACK_DESIRED]!;\n const frontChanged = frontOpFail !== rs[RS_STENCIL_OP_FAIL] || frontOpZFail !== rs[RS_STENCIL_OP_ZFAIL] || frontOpZPass !== rs[RS_STENCIL_OP_ZPASS];\n const backChanged = backOpFail !== rs[BACK_OP_FAIL] || backOpZFail !== rs[BACK_OP_ZFAIL] || backOpZPass !== rs[BACK_OP_ZPASS];\n if (!frontChanged && !backChanged) {\n return;\n }\n const facesMatch = frontOpFail === backOpFail && frontOpZFail === backOpZFail && frontOpZPass === backOpZPass;\n if (facesMatch) {\n setStencilOps(rs, RS_STENCIL_OP_FAIL, frontOpFail, frontOpZFail, frontOpZPass);\n setStencilOps(rs, BACK_OP_FAIL, backOpFail, backOpZFail, backOpZPass);\n gl.stencilOp(frontOpFail, frontOpZFail, frontOpZPass);\n return;\n }\n if (frontChanged) {\n setStencilOps(rs, RS_STENCIL_OP_FAIL, frontOpFail, frontOpZFail, frontOpZPass);\n gl.stencilOpSeparate(FRONT, frontOpFail, frontOpZFail, frontOpZPass);\n }\n if (backChanged) {\n setStencilOps(rs, BACK_OP_FAIL, backOpFail, backOpZFail, backOpZPass);\n gl.stencilOpSeparate(BACK, backOpFail, backOpZFail, backOpZPass);\n }\n}\n\n/** Reconcile the packed color-write mask (Babylon's `setColorWrite`). @internal */\nfunction flushColorMask(engine: GLEngineContext): void {\n const rs = engine._state.rs;\n const dColorMask = rs[RS_COLOR_MASK + RS_DESIRED]!;\n if (dColorMask !== rs[RS_COLOR_MASK]) {\n rs[RS_COLOR_MASK] = dColorMask;\n engine.gl.colorMask((dColorMask & 8) !== 0, (dColorMask & 4) !== 0, (dColorMask & 2) !== 0, (dColorMask & 1) !== 0);\n }\n}\n\n/**\n * Opt-in: give a `/render-target` {@link GLRenderTarget} a stencil attachment,\n * replacing the core's depth-only `DEPTH_COMPONENT16` renderbuffer with either a\n * packed **`DEPTH24_STENCIL8`** buffer (default — depth *and* stencil) or a\n * stencil-only **`STENCIL_INDEX8`** buffer.\n *\n * Stencil is intentionally NOT a {@link createRenderTarget} option: keeping this\n * helper in the depth-stencil module means the stencil/packed renderbuffer\n * code tree-shakes out of every bundle that only needs a color (and optional\n * depth) target.\n *\n * The attachment is **restore-correct**: it is rebuilt automatically — at the new\n * size on {@link resizeRenderTarget}, and into the fresh framebuffer after a\n * `webglcontextrestored` event — so the stencil survives for the life of the\n * target, and {@link disposeRenderTarget} releases it along with the target.\n *\n * No-op on a lost/disposed context or a disposed target.\n *\n * @param rt - The render target to attach the stencil buffer to.\n * @param options - `depth` (default `true`): when `true` the attachment is a\n * packed depth+stencil buffer (`DEPTH24_STENCIL8` on `DEPTH_STENCIL_ATTACHMENT`)\n * — the common case, and the correct choice when the target was created with\n * `generateDepthBuffer: true`. When `false` the attachment is stencil-only\n * (`STENCIL_INDEX8` on `STENCIL_ATTACHMENT`).\n * @throws If a renderbuffer handle could not be allocated or the framebuffer is\n * incomplete after attaching.\n */\nexport function generateRenderTargetStencil(rt: GLRenderTarget, options?: { depth?: boolean }): void {\n const engine = rt._engine;\n if (engine._isLost || engine._disposed || rt._disposed) {\n return;\n }\n const packDepth = options?.depth ?? true;\n const attachment = packDepth ? DEPTH_STENCIL_ATTACHMENT : STENCIL_ATTACHMENT;\n const format = packDepth ? DEPTH24_STENCIL8 : STENCIL_INDEX8;\n\n const build = (e: GLEngineContext): void => {\n const gl = e.gl;\n // Capture the caller's draw target so this helper is STATE-NEUTRAL: it must\n // not silently redirect subsequent draws to `rt` (during an internal\n // rebuild `prevFb` is `rt._framebuffer`, which the core re-checks next).\n const prevFb = e._state.boundFramebuffer;\n const newRb = gl.createRenderbuffer();\n if (newRb === null) {\n throw new Error(\"lite-gl: gl.createRenderbuffer returned null (render target stencil)\");\n }\n let committed = false;\n try {\n gl.bindFramebuffer(FRAMEBUFFER, rt._framebuffer);\n e._state.boundFramebuffer = rt._framebuffer;\n gl.bindRenderbuffer(RENDERBUFFER, newRb);\n gl.renderbufferStorage(RENDERBUFFER, format, rt.width, rt.height);\n gl.framebufferRenderbuffer(FRAMEBUFFER, attachment, RENDERBUFFER, newRb);\n gl.bindRenderbuffer(RENDERBUFFER, null);\n const status = gl.checkFramebufferStatus(FRAMEBUFFER);\n if (status !== FRAMEBUFFER_COMPLETE) {\n throw new Error(`lite-gl: render target framebuffer incomplete after stencil attach (status 0x${status.toString(16)})`);\n }\n // Commit only after a complete attachment: release the buffer we\n // replaced (the core depth-only one, or our own from a prior rebuild).\n if (rt._depthStencil !== null) {\n gl.deleteRenderbuffer(rt._depthStencil);\n }\n rt._depthStencil = newRb;\n committed = true;\n } finally {\n if (!committed) {\n // Any non-committed exit (incomplete framebuffer OR an unexpected\n // GL throw): detach + delete the buffer we couldn't adopt so it\n // never leaks, leaving the attachment point empty for the\n // caller-level rollback to re-establish the prior buffer.\n gl.framebufferRenderbuffer(FRAMEBUFFER, attachment, RENDERBUFFER, null);\n gl.deleteRenderbuffer(newRb);\n }\n // Restore the caller's draw target + the bound-framebuffer cache.\n if (e._state.boundFramebuffer !== prevFb) {\n gl.bindFramebuffer(FRAMEBUFFER, prevFb);\n e._state.boundFramebuffer = prevFb;\n }\n }\n };\n\n // Build once now, but COMMIT the resize/restore hook only if it succeeds — a\n // failed opt-in must leave the target exactly as it was. The packed attach\n // above can clear the core `DEPTH_ATTACHMENT`, so on failure restore the prior\n // hook AND re-establish the prior depth/stencil attachment (the prior hook's,\n // or the core depth-only buffer).\n const prevHook = rt._rebuildDepthStencil;\n const prevDepthStencil = rt._depthStencil;\n try {\n build(engine);\n } catch (err) {\n rt._rebuildDepthStencil = prevHook;\n try {\n if (prevHook !== undefined) {\n prevHook(engine);\n } else if (prevDepthStencil !== null) {\n reattachCoreDepthBuffer(engine, rt, prevDepthStencil);\n }\n } catch {\n // Best-effort restore; surface the original failure below.\n }\n throw err;\n }\n rt._rebuildDepthStencil = build;\n}\n\n/**\n * Re-attach a core depth-only renderbuffer at `DEPTH_ATTACHMENT` — used to roll a\n * render target back when a packed {@link generateRenderTargetStencil} attach\n * fails completeness (attaching at `DEPTH_STENCIL_ATTACHMENT` clears the core\n * `DEPTH_ATTACHMENT`). State-neutral: restores the caller's bound framebuffer.\n * @internal\n */\nfunction reattachCoreDepthBuffer(engine: GLEngineContext, rt: GLRenderTarget, depthBuffer: WebGLRenderbuffer): void {\n const gl = engine.gl;\n const prevFb = engine._state.boundFramebuffer;\n gl.bindFramebuffer(FRAMEBUFFER, rt._framebuffer);\n engine._state.boundFramebuffer = rt._framebuffer;\n gl.framebufferRenderbuffer(FRAMEBUFFER, DEPTH_ATTACHMENT, RENDERBUFFER, depthBuffer);\n if (engine._state.boundFramebuffer !== prevFb) {\n gl.bindFramebuffer(FRAMEBUFFER, prevFb);\n engine._state.boundFramebuffer = prevFb;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"depth-stencil.js","sourceRoot":"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`_depthCullingState` / `_stencilState` / `setColorWrite` / `clear`.\n *\n * Like Babylon, these setters are DEFERRED: they buffer the requested values\n * into the DESIRED (`d*`) mirror fields of `GLState` and raise `statesDirty`,\n * issuing NO `gl.*` calls themselves. `applyGLStates` (apply-states.ts) flushes\n * the diff to GL right before each draw (and before `clearEngine`'s `gl.clear`,\n * since a clear respects the current write masks). Every field is reconciled\n * independently, so a flush that changes only one sub-state (e.g. just the\n * stencil op triple) issues only that GL call. Omitted setter fields leave the\n * corresponding desired value untouched (merge-from-desired).\n *\n * All setters are no-ops on a lost/disposed context.\n *\n * This module also hosts {@link generateRenderTargetStencil} — the tree-shakeable\n * opt-in that gives a `/render-target` {@link GLRenderTarget} a stencil (or packed\n * depth+stencil) attachment. Keeping the STENCIL_INDEX8 / DEPTH24_STENCIL8\n * renderbuffer code here (rather than in the render-target core) means a consumer\n * that only needs a depth buffer never ships it. The one-way type import below\n * (`depth-stencil` importing `render-target`) introduces NO cycle: render-target\n * must not import this module.\n */\nimport type { GLEngineContext } from \"./context.js\";\nimport type { GLClearOptions } from \"./family.js\";\nimport type { GLRenderTarget } from \"./render-target.js\";\nimport { validateFramebuffer } from \"./framebuffer-validation.js\";\nimport { applyGLStates } from \"./apply-states.js\";\nimport {\n RS_CLEAR_A,\n RS_CLEAR_B,\n RS_CLEAR_G,\n RS_CLEAR_R,\n RS_COLOR_MASK,\n RS_CULL_ENABLED,\n RS_CULL_FACE,\n RS_DEPTH_FUNC,\n RS_DEPTH_MASK,\n RS_DEPTH_TEST,\n RS_DESIRED,\n RS_STENCIL_FUNC_FUNC,\n RS_STENCIL_FUNC_MASK,\n RS_STENCIL_FUNC_REF,\n RS_STENCIL_MASK,\n RS_STENCIL_OP_FAIL,\n RS_STENCIL_OP_ZFAIL,\n RS_STENCIL_OP_ZPASS,\n RS_STENCIL_TEST,\n} from \"./state.js\";\n\n// ── Clear bits (used by `clearEngine`).\n/** GL clear bits. */\nconst COLOR_BUFFER_BIT = 0x4000;\nconst DEPTH_BUFFER_BIT = 0x0100;\nconst STENCIL_BUFFER_BIT = 0x0400;\n\n// ── Test-enable enums for the per-category reconcilers below.\n/** GL `gl.DEPTH_TEST`. */\nconst DEPTH_TEST = 0x0b71;\n/** GL `gl.CULL_FACE`. */\nconst CULL_FACE = 0x0b44;\n/** GL `gl.STENCIL_TEST`. */\nconst STENCIL_TEST = 0x0b90;\n/** GL `gl.KEEP`. */\nconst KEEP = 0x1e00;\n/** GL `gl.FRONT`. */\nconst FRONT = 0x0404;\n/** GL `gl.BACK`. */\nconst BACK = 0x0405;\n/** GL `gl.FRONT_AND_BACK`. */\nconst FRONT_AND_BACK = 0x0408;\n// Two-sided mode appends actual slots 46..48 and desired slots 49..51 to the\n// compact 46-slot state array. Base indices remain unchanged.\nconst BACK_OP_FAIL = 46;\nconst BACK_OP_ZFAIL = 47;\nconst BACK_OP_ZPASS = 48;\nconst BACK_DESIRED = 3;\n\n// ── Framebuffer / renderbuffer enums (used only by generateRenderTargetStencil).\n// Module-local consts mirror render-target.ts's constant style. Because the\n// render-target core no longer references the stencil/packed enums, they live\n// here and tree-shake away for consumers that never opt into a stencil buffer.\n/** GL `gl.FRAMEBUFFER`. */\nconst FRAMEBUFFER = 0x8d40;\n/** GL `gl.RENDERBUFFER`. */\nconst RENDERBUFFER = 0x8d41;\n/** GL `gl.DEPTH24_STENCIL8` — packed depth+stencil sized format. */\nconst DEPTH24_STENCIL8 = 0x88f0;\n/** GL `gl.STENCIL_INDEX8` — stencil-only sized format. */\nconst STENCIL_INDEX8 = 0x8d48;\n/** GL `gl.DEPTH_STENCIL_ATTACHMENT`. */\nconst DEPTH_STENCIL_ATTACHMENT = 0x821a;\n/** GL `gl.STENCIL_ATTACHMENT`. */\nconst STENCIL_ATTACHMENT = 0x8d20;\n/** GL `gl.DEPTH_ATTACHMENT` — where the render-target core attaches its depth-only\n * renderbuffer (re-established when rolling back a failed stencil attach). */\nconst DEPTH_ATTACHMENT = 0x8d00;\n\n/** Depth-buffer configuration for {@link setDepthState}. Omitted fields are\n * left unchanged. */\nexport interface GLDepthState {\n /** Enable/disable the depth test (`gl.enable/disable(DEPTH_TEST)`). */\n test?: boolean;\n /** Enable/disable depth writes (`gl.depthMask`). */\n write?: boolean;\n /** Depth comparison function (`gl.depthFunc`), e.g. `gl.LESS`. */\n func?: GLenum;\n}\n\n/** Stencil configuration for {@link setStencilState}. Omitted fields are left\n * unchanged. Operation fields update both front and back faces; use\n * {@link setStencilOpSeparate} for per-face values. */\nexport interface GLStencilState {\n /** Enable/disable the stencil test (`gl.enable/disable(STENCIL_TEST)`). */\n test?: boolean;\n /** Comparison function (`gl.stencilFunc` arg 1), e.g. `gl.ALWAYS`. */\n func?: GLenum;\n /** Reference value (`gl.stencilFunc` arg 2). */\n ref?: number;\n /** Comparison mask (`gl.stencilFunc` arg 3). */\n funcMask?: number;\n /** Stencil write mask (`gl.stencilMask`). */\n mask?: number;\n /** Op when the stencil test fails (`gl.stencilOp` arg 1). */\n opFail?: GLenum;\n /** Op when the stencil test passes but depth fails (`gl.stencilOp` arg 2). */\n opZFail?: GLenum;\n /** Op when both stencil and depth pass (`gl.stencilOp` arg 3). */\n opZPass?: GLenum;\n}\n\n/** Per-face stencil operations for {@link setStencilOpSeparate}. Omitted fields\n * retain that face's desired value. */\nexport interface GLStencilOpState {\n /** Op when the stencil test fails (`gl.stencilOpSeparate` arg 2). */\n opFail?: GLenum;\n /** Op when the stencil test passes but depth fails (`gl.stencilOpSeparate` arg 3). */\n opZFail?: GLenum;\n /** Op when both stencil and depth pass (`gl.stencilOpSeparate` arg 4). */\n opZPass?: GLenum;\n}\n\n/** Seed the shared desired op tuple with WebGL's KEEP defaults. */\nfunction ensureStencilOpCacheInitialized(rs: Float64Array): void {\n if (rs[RS_STENCIL_OP_FAIL + RS_DESIRED] !== -1) {\n return;\n }\n rs[RS_STENCIL_OP_FAIL + RS_DESIRED] = KEEP;\n rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED] = KEEP;\n rs[RS_STENCIL_OP_ZPASS + RS_DESIRED] = KEEP;\n}\n\nfunction setDesiredStencilOps(rs: Float64Array, state: GLStencilOpState): void {\n if ((state.opFail ?? state.opZFail ?? state.opZPass) === undefined) {\n return;\n }\n ensureStencilOpCacheInitialized(rs);\n if (state.opFail !== undefined) {\n rs[RS_STENCIL_OP_FAIL + RS_DESIRED] = state.opFail;\n }\n if (state.opZFail !== undefined) {\n rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED] = state.opZFail;\n }\n if (state.opZPass !== undefined) {\n rs[RS_STENCIL_OP_ZPASS + RS_DESIRED] = state.opZPass;\n }\n}\n\n/** Store one complete GL operation tuple starting at `opIndex`. */\nfunction setStencilOps(rs: Float64Array, opIndex: number, fail: GLenum, zfail: GLenum, zpass: GLenum): void {\n rs[opIndex] = fail;\n rs[opIndex + 1] = zfail;\n rs[opIndex + 2] = zpass;\n}\n\nfunction resetStencilBack(rs: Float64Array): void {\n ensureStencilOpCacheInitialized(rs);\n setStencilOps(rs, BACK_OP_FAIL, rs[RS_STENCIL_OP_FAIL]!, rs[RS_STENCIL_OP_ZFAIL]!, rs[RS_STENCIL_OP_ZPASS]!);\n setStencilOps(rs, BACK_OP_FAIL + BACK_DESIRED, rs[RS_STENCIL_OP_FAIL + RS_DESIRED]!, rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED]!, rs[RS_STENCIL_OP_ZPASS + RS_DESIRED]!);\n}\n\nfunction ensureStencilBackCacheInitialized(rs: Float64Array): void {\n if (rs[RS_STENCIL_OP_FAIL + RS_DESIRED] === -1) {\n resetStencilBack(rs);\n }\n}\n\nfunction setDesiredStencilBackOps(rs: Float64Array, state: GLStencilOpState): void {\n if (state.opFail !== undefined) {\n rs[BACK_OP_FAIL + BACK_DESIRED] = state.opFail;\n }\n if (state.opZFail !== undefined) {\n rs[BACK_OP_ZFAIL + BACK_DESIRED] = state.opZFail;\n }\n if (state.opZPass !== undefined) {\n rs[BACK_OP_ZPASS + BACK_DESIRED] = state.opZPass;\n }\n}\n\n/** Mirror a shared stencil-op update to the lazily allocated back-face cache. */\nfunction mirrorSharedStencilOpsToBack(s: GLEngineContext[\"_state\"], state: GLStencilOpState): void {\n if ((state.opFail ?? state.opZFail ?? state.opZPass) === undefined) {\n return;\n }\n ensureStencilBackCacheInitialized(s.rs);\n setDesiredStencilBackOps(s.rs, state);\n}\n\n/** Lazily install back-face storage and the two-sided reconciler. */\nfunction enableSeparateStencil(s: GLEngineContext[\"_state\"]): void {\n if (s._setStencilBack !== undefined) {\n return;\n }\n const rs = new Float64Array(52);\n rs.set(s.rs);\n s.rs = rs;\n resetStencilBack(rs);\n s._setStencilBack = mirrorSharedStencilOpsToBack;\n s._flushStencil = flushStencilSeparate;\n}\n\n/**\n * Buffer depth-buffer state (test enable, write mask, comparison function) into\n * the DESIRED state — the lite-gl equivalent of mutating Babylon's\n * `engine.depthCullingState.{depthTest,depthMask,depthFunc}`. Flushed to GL by\n * `applyGLStates` before the next draw / clear; omitted fields are untouched.\n *\n * @param engine - The engine.\n * @param state - The depth fields to change. Omitted fields are untouched.\n */\nexport function setDepthState(engine: GLEngineContext, state: GLDepthState): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n if (state.test !== undefined) {\n s.rs[RS_DEPTH_TEST + RS_DESIRED] = state.test ? 1 : 0;\n }\n if (state.write !== undefined) {\n s.rs[RS_DEPTH_MASK + RS_DESIRED] = state.write ? 1 : 0;\n }\n if (state.func !== undefined) {\n s.rs[RS_DEPTH_FUNC + RS_DESIRED] = state.func;\n }\n s._flushDepthCull = flushDepthCull;\n s.statesDirty = true;\n}\n\n/**\n * Enable/disable face culling and (optionally) set the cull face — the lite-gl\n * equivalent of `engine.depthCullingState.cull` + `cullFace`.\n *\n * @param engine - The engine.\n * @param enabled - Enable (`true`) or disable (`false`) `gl.CULL_FACE`.\n * @param face - Optional cull face (`gl.BACK` / `gl.FRONT` / `gl.FRONT_AND_BACK`).\n */\nexport function setCullState(engine: GLEngineContext, enabled: boolean, face?: GLenum): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n s.rs[RS_CULL_ENABLED + RS_DESIRED] = enabled ? 1 : 0;\n if (face !== undefined) {\n s.rs[RS_CULL_FACE + RS_DESIRED] = face;\n }\n s._flushDepthCull = flushDepthCull;\n s.statesDirty = true;\n}\n\n/**\n * Buffer stencil state (test enable, write mask, comparison func triple, op\n * triple) into the DESIRED state — the lite-gl equivalent of mutating Babylon's\n * `engine.stencilState.*`. Flushed by `applyGLStates` before the next draw /\n * clear; omitted fields are untouched (merge-from-desired).\n *\n * @param engine - The engine.\n * @param state - The stencil fields to change. Omitted fields are untouched.\n */\nexport function setStencilState(engine: GLEngineContext, state: GLStencilState): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n if (state.test !== undefined) {\n s.rs[RS_STENCIL_TEST + RS_DESIRED] = state.test ? 1 : 0;\n }\n if (state.func !== undefined) {\n s.rs[RS_STENCIL_FUNC_FUNC + RS_DESIRED] = state.func;\n }\n if (state.ref !== undefined) {\n s.rs[RS_STENCIL_FUNC_REF + RS_DESIRED] = state.ref;\n }\n if (state.funcMask !== undefined) {\n s.rs[RS_STENCIL_FUNC_MASK + RS_DESIRED] = state.funcMask;\n }\n if (state.mask !== undefined) {\n s.rs[RS_STENCIL_MASK + RS_DESIRED] = state.mask;\n }\n s._setStencilBack?.(s, state);\n if ((state.opFail ?? state.opZFail ?? state.opZPass) !== undefined) {\n ensureStencilOpCacheInitialized(s.rs);\n if (state.opFail !== undefined) {\n s.rs[RS_STENCIL_OP_FAIL + RS_DESIRED] = state.opFail;\n }\n if (state.opZFail !== undefined) {\n s.rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED] = state.opZFail;\n }\n if (state.opZPass !== undefined) {\n s.rs[RS_STENCIL_OP_ZPASS + RS_DESIRED] = state.opZPass;\n }\n }\n s._flushStencil ??= flushStencil;\n s.statesDirty = true;\n}\n\n/**\n * Buffer stencil operations for one face into the DESIRED state. This is the\n * deferred lite-gl counterpart of `gl.stencilOpSeparate`; use it to apply\n * different winding operations to front and back faces in one draw. A\n * `FRONT_AND_BACK` update applies each provided operation to both faces while\n * leaving omitted operations unchanged on each face.\n *\n * @param engine - The engine.\n * @param face - `gl.FRONT`, `gl.BACK`, or `gl.FRONT_AND_BACK`.\n * @param state - The operation fields to change for the selected face(s).\n * @throws If `face` is not `gl.FRONT`, `gl.BACK`, or `gl.FRONT_AND_BACK`.\n */\nexport function setStencilOpSeparate(engine: GLEngineContext, face: GLenum, state: GLStencilOpState): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n if (face !== FRONT && face !== BACK && face !== FRONT_AND_BACK) {\n throw new Error(\"lite-gl: invalid face\");\n }\n if ((state.opFail ?? state.opZFail ?? state.opZPass) === undefined) {\n return;\n }\n enableSeparateStencil(s);\n ensureStencilBackCacheInitialized(s.rs);\n if (face !== BACK) {\n setDesiredStencilOps(s.rs, state);\n }\n if (face !== FRONT) {\n setDesiredStencilBackOps(s.rs, state);\n }\n s.statesDirty = true;\n}\n\n/**\n * Buffer the color write mask into the DESIRED state — the lite-gl equivalent of\n * Babylon's `setColorWrite` (which passes the same flag to all four channels).\n * Flushed to GL (`gl.colorMask`) by `applyGLStates` before the next draw /\n * clear.\n *\n * @param engine - The engine.\n * @param r - Write red.\n * @param g - Write green.\n * @param b - Write blue.\n * @param a - Write alpha.\n */\nexport function setColorMask(engine: GLEngineContext, r: boolean, g: boolean, b: boolean, a: boolean): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const packed = (r ? 8 : 0) | (g ? 4 : 0) | (b ? 2 : 0) | (a ? 1 : 0);\n const s = engine._state;\n s.rs[RS_COLOR_MASK + RS_DESIRED] = packed;\n s._flushColorMask = flushColorMask;\n s.statesDirty = true;\n}\n\n/**\n * Clear the currently-bound framebuffer's color / depth / stencil buffers — the\n * lite-gl equivalent of Babylon's `clear(color, backBuffer, depth, stencil)`.\n * Depth/stencil clears respect the current write masks (set them first via\n * {@link setDepthState} / {@link setStencilState}). No-op when nothing is\n * requested or the context is lost/disposed.\n *\n * @param engine - The engine.\n * @param options - Which buffers to clear (and the color value).\n */\nexport function clearEngine(engine: GLEngineContext, options: GLClearOptions): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n let mask = 0;\n if (options.color !== undefined) {\n const c = options.color;\n const a = c.a ?? 1;\n const rs = engine._state.rs;\n // Cached: gl.clearColor is per-context state GL retains, so only re-issue\n // it when the requested color actually changes (Babylon re-sets it every\n // clear; this elides the redundant JS↔native call for constant backgrounds).\n if (rs[RS_CLEAR_R] !== c.r || rs[RS_CLEAR_G] !== c.g || rs[RS_CLEAR_B] !== c.b || rs[RS_CLEAR_A] !== a) {\n gl.clearColor(c.r, c.g, c.b, a);\n rs[RS_CLEAR_R] = c.r;\n rs[RS_CLEAR_G] = c.g;\n rs[RS_CLEAR_B] = c.b;\n rs[RS_CLEAR_A] = a;\n }\n mask |= COLOR_BUFFER_BIT;\n }\n if (options.depth === true) {\n mask |= DEPTH_BUFFER_BIT;\n }\n if (options.stencil === true) {\n mask |= STENCIL_BUFFER_BIT;\n }\n if (mask !== 0) {\n // Babylon parity: a clear respects the current depth/stencil/color write\n // masks, so flush any deferred state before clearing.\n applyGLStates(engine);\n gl.clear(mask);\n }\n}\n\n/* ─────────────────── deferred render-state reconcilers ──────────────────────\n * The per-category half of `applyGLStates`. Each setter above installs the\n * matching reconciler onto its `_state._flush*` slot; `applyGLStates`\n * (apply-states.ts) dispatches ONLY through those slots. Co-locating them with\n * their setters makes each one reachable solely when its setter is in the bundle,\n * so a scene that never touches depth/cull, stencil, or color-mask tree-shakes\n * the corresponding reconciler — and its GL code — away entirely. Each reconciles\n * its DESIRED (`rs[RS_X + RS_DESIRED]`) slots against the ACTUAL twins (`rs[RS_X]`)\n * and issues only the `gl.*` calls that changed, in the same order and with the\n * same elision rules as the former monolithic flush. */\n\n/** Reconcile depth + cull (Babylon's `_depthCullingState.apply`). @internal */\nfunction flushDepthCull(engine: GLEngineContext): void {\n const gl = engine.gl;\n const rs = engine._state.rs;\n const dTest = rs[RS_DEPTH_TEST + RS_DESIRED]!;\n if (dTest !== rs[RS_DEPTH_TEST]) {\n rs[RS_DEPTH_TEST] = dTest;\n if (dTest === 1) {\n gl.enable(DEPTH_TEST);\n } else {\n gl.disable(DEPTH_TEST);\n }\n }\n const dMask = rs[RS_DEPTH_MASK + RS_DESIRED]!;\n if (dMask !== rs[RS_DEPTH_MASK]) {\n rs[RS_DEPTH_MASK] = dMask;\n gl.depthMask(dMask === 1);\n }\n const dFunc = rs[RS_DEPTH_FUNC + RS_DESIRED]!;\n if (dFunc !== rs[RS_DEPTH_FUNC]) {\n rs[RS_DEPTH_FUNC] = dFunc;\n gl.depthFunc(dFunc);\n }\n const dCull = rs[RS_CULL_ENABLED + RS_DESIRED]!;\n if (dCull !== rs[RS_CULL_ENABLED]) {\n rs[RS_CULL_ENABLED] = dCull;\n if (dCull === 1) {\n gl.enable(CULL_FACE);\n } else {\n gl.disable(CULL_FACE);\n }\n }\n const dCullFace = rs[RS_CULL_FACE + RS_DESIRED]!;\n if (dCullFace !== rs[RS_CULL_FACE]) {\n rs[RS_CULL_FACE] = dCullFace;\n gl.cullFace(dCullFace);\n }\n}\n\nfunction flushStencilCommon(engine: GLEngineContext): void {\n const gl = engine.gl;\n const rs = engine._state.rs;\n const dTest = rs[RS_STENCIL_TEST + RS_DESIRED]!;\n if (dTest !== rs[RS_STENCIL_TEST]) {\n rs[RS_STENCIL_TEST] = dTest;\n if (dTest === 1) {\n gl.enable(STENCIL_TEST);\n } else {\n gl.disable(STENCIL_TEST);\n }\n }\n const dMask = rs[RS_STENCIL_MASK + RS_DESIRED]!;\n if (dMask !== rs[RS_STENCIL_MASK]) {\n rs[RS_STENCIL_MASK] = dMask;\n gl.stencilMask(dMask);\n }\n const dFuncFunc = rs[RS_STENCIL_FUNC_FUNC + RS_DESIRED]!;\n const dFuncRef = rs[RS_STENCIL_FUNC_REF + RS_DESIRED]!;\n const dFuncMask = rs[RS_STENCIL_FUNC_MASK + RS_DESIRED]!;\n if (dFuncFunc !== rs[RS_STENCIL_FUNC_FUNC] || dFuncRef !== rs[RS_STENCIL_FUNC_REF] || dFuncMask !== rs[RS_STENCIL_FUNC_MASK]) {\n rs[RS_STENCIL_FUNC_FUNC] = dFuncFunc;\n rs[RS_STENCIL_FUNC_REF] = dFuncRef;\n rs[RS_STENCIL_FUNC_MASK] = dFuncMask;\n gl.stencilFunc(dFuncFunc, dFuncRef, dFuncMask);\n }\n}\n\n/** Reconcile the compact shared stencil state. @internal */\nfunction flushStencil(engine: GLEngineContext): void {\n flushStencilCommon(engine);\n const gl = engine.gl;\n const rs = engine._state.rs;\n const frontOpFail = rs[RS_STENCIL_OP_FAIL + RS_DESIRED]!;\n if (frontOpFail === -1) {\n return;\n }\n const frontOpZFail = rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED]!;\n const frontOpZPass = rs[RS_STENCIL_OP_ZPASS + RS_DESIRED]!;\n const frontChanged = frontOpFail !== rs[RS_STENCIL_OP_FAIL] || frontOpZFail !== rs[RS_STENCIL_OP_ZFAIL] || frontOpZPass !== rs[RS_STENCIL_OP_ZPASS];\n if (frontChanged) {\n rs[RS_STENCIL_OP_FAIL] = frontOpFail;\n rs[RS_STENCIL_OP_ZFAIL] = frontOpZFail;\n rs[RS_STENCIL_OP_ZPASS] = frontOpZPass;\n gl.stencilOp(frontOpFail, frontOpZFail, frontOpZPass);\n }\n}\n\n/** Reconcile independently cached front/back stencil operation tuples. */\nfunction flushStencilSeparate(engine: GLEngineContext): void {\n flushStencilCommon(engine);\n const gl = engine.gl;\n const rs = engine._state.rs;\n const frontOpFail = rs[RS_STENCIL_OP_FAIL + RS_DESIRED]!;\n if (frontOpFail === -1) {\n return;\n }\n const frontOpZFail = rs[RS_STENCIL_OP_ZFAIL + RS_DESIRED]!;\n const frontOpZPass = rs[RS_STENCIL_OP_ZPASS + RS_DESIRED]!;\n const backOpFail = rs[BACK_OP_FAIL + BACK_DESIRED]!;\n const backOpZFail = rs[BACK_OP_ZFAIL + BACK_DESIRED]!;\n const backOpZPass = rs[BACK_OP_ZPASS + BACK_DESIRED]!;\n const frontChanged = frontOpFail !== rs[RS_STENCIL_OP_FAIL] || frontOpZFail !== rs[RS_STENCIL_OP_ZFAIL] || frontOpZPass !== rs[RS_STENCIL_OP_ZPASS];\n const backChanged = backOpFail !== rs[BACK_OP_FAIL] || backOpZFail !== rs[BACK_OP_ZFAIL] || backOpZPass !== rs[BACK_OP_ZPASS];\n if (!frontChanged && !backChanged) {\n return;\n }\n const facesMatch = frontOpFail === backOpFail && frontOpZFail === backOpZFail && frontOpZPass === backOpZPass;\n if (facesMatch) {\n setStencilOps(rs, RS_STENCIL_OP_FAIL, frontOpFail, frontOpZFail, frontOpZPass);\n setStencilOps(rs, BACK_OP_FAIL, backOpFail, backOpZFail, backOpZPass);\n gl.stencilOp(frontOpFail, frontOpZFail, frontOpZPass);\n return;\n }\n if (frontChanged) {\n setStencilOps(rs, RS_STENCIL_OP_FAIL, frontOpFail, frontOpZFail, frontOpZPass);\n gl.stencilOpSeparate(FRONT, frontOpFail, frontOpZFail, frontOpZPass);\n }\n if (backChanged) {\n setStencilOps(rs, BACK_OP_FAIL, backOpFail, backOpZFail, backOpZPass);\n gl.stencilOpSeparate(BACK, backOpFail, backOpZFail, backOpZPass);\n }\n}\n\n/** Reconcile the packed color-write mask (Babylon's `setColorWrite`). @internal */\nfunction flushColorMask(engine: GLEngineContext): void {\n const rs = engine._state.rs;\n const dColorMask = rs[RS_COLOR_MASK + RS_DESIRED]!;\n if (dColorMask !== rs[RS_COLOR_MASK]) {\n rs[RS_COLOR_MASK] = dColorMask;\n engine.gl.colorMask((dColorMask & 8) !== 0, (dColorMask & 4) !== 0, (dColorMask & 2) !== 0, (dColorMask & 1) !== 0);\n }\n}\n\n/**\n * Opt-in: give a `/render-target` {@link GLRenderTarget} a stencil attachment,\n * replacing the core's depth-only `DEPTH_COMPONENT16` renderbuffer with either a\n * packed **`DEPTH24_STENCIL8`** buffer (default — depth *and* stencil) or a\n * stencil-only **`STENCIL_INDEX8`** buffer.\n *\n * Stencil is intentionally NOT a {@link createRenderTarget} option: keeping this\n * helper in the depth-stencil module means the stencil/packed renderbuffer\n * code tree-shakes out of every bundle that only needs a color (and optional\n * depth) target.\n *\n * The attachment is **restore-correct**: it is rebuilt automatically — at the new\n * size on {@link resizeRenderTarget}, and into the fresh framebuffer after a\n * `webglcontextrestored` event — so the stencil survives for the life of the\n * target, and {@link disposeRenderTarget} releases it along with the target.\n *\n * No-op on a lost/disposed context or a disposed target.\n *\n * @param rt - The render target to attach the stencil buffer to.\n * @param options - `depth` (default `true`): when `true` the attachment is a\n * packed depth+stencil buffer (`DEPTH24_STENCIL8` on `DEPTH_STENCIL_ATTACHMENT`)\n * — the common case, and the correct choice when the target was created with\n * `generateDepthBuffer: true`. When `false` the attachment is stencil-only\n * (`STENCIL_INDEX8` on `STENCIL_ATTACHMENT`).\n * @throws If a renderbuffer handle could not be allocated, or the framebuffer is\n * incomplete after attaching (unless `setFramebufferValidation(engine, false)`\n * opted out of completeness checks).\n */\nexport function generateRenderTargetStencil(rt: GLRenderTarget, options?: { depth?: boolean }): void {\n const engine = rt._engine;\n if (engine._isLost || engine._disposed || rt._disposed) {\n return;\n }\n const packDepth = options?.depth ?? true;\n const attachment = packDepth ? DEPTH_STENCIL_ATTACHMENT : STENCIL_ATTACHMENT;\n const format = packDepth ? DEPTH24_STENCIL8 : STENCIL_INDEX8;\n\n const build = (e: GLEngineContext): void => {\n const gl = e.gl;\n // Capture the caller's draw target so this helper is STATE-NEUTRAL: it must\n // not silently redirect subsequent draws to `rt` (during an internal\n // rebuild `prevFb` is `rt._framebuffer`, which the core re-checks next\n // unless validation was opted out).\n // An unknown (wiped) binding is restored as the canvas.\n const prevFb = e._state.boundFramebuffer ?? null;\n const newRb = gl.createRenderbuffer();\n if (newRb === null) {\n throw new Error(\"lite-gl: gl.createRenderbuffer returned null (render target stencil)\");\n }\n let committed = false;\n try {\n gl.bindFramebuffer(FRAMEBUFFER, rt._framebuffer);\n e._state.boundFramebuffer = rt._framebuffer;\n gl.bindRenderbuffer(RENDERBUFFER, newRb);\n gl.renderbufferStorage(RENDERBUFFER, format, rt.width, rt.height);\n gl.framebufferRenderbuffer(FRAMEBUFFER, attachment, RENDERBUFFER, newRb);\n gl.bindRenderbuffer(RENDERBUFFER, null);\n validateFramebuffer(e, true);\n // Commit only after a complete attachment: release the buffer we\n // replaced (the core depth-only one, or our own from a prior rebuild).\n if (rt._depthStencil !== null) {\n gl.deleteRenderbuffer(rt._depthStencil);\n }\n rt._depthStencil = newRb;\n committed = true;\n } finally {\n if (!committed) {\n // Any non-committed exit (incomplete framebuffer OR an unexpected\n // GL throw): detach + delete the buffer we couldn't adopt so it\n // never leaks, leaving the attachment point empty for the\n // caller-level rollback to re-establish the prior buffer.\n gl.framebufferRenderbuffer(FRAMEBUFFER, attachment, RENDERBUFFER, null);\n gl.deleteRenderbuffer(newRb);\n }\n // Restore the caller's draw target + the bound-framebuffer cache.\n if (e._state.boundFramebuffer !== prevFb) {\n gl.bindFramebuffer(FRAMEBUFFER, prevFb);\n e._state.boundFramebuffer = prevFb;\n }\n }\n };\n\n // Build once now, but COMMIT the resize/restore hook only if it succeeds — a\n // failed opt-in must leave the target exactly as it was. The packed attach\n // above can clear the core `DEPTH_ATTACHMENT`, so on failure restore the prior\n // hook AND re-establish the prior depth/stencil attachment (the prior hook's,\n // or the core depth-only buffer).\n const prevHook = rt._rebuildDepthStencil;\n const prevDepthStencil = rt._depthStencil;\n try {\n build(engine);\n } catch (err) {\n rt._rebuildDepthStencil = prevHook;\n try {\n if (prevHook !== undefined) {\n prevHook(engine);\n } else if (prevDepthStencil !== null) {\n reattachCoreDepthBuffer(engine, rt, prevDepthStencil);\n }\n } catch {\n // Best-effort restore; surface the original failure below.\n }\n throw err;\n }\n rt._rebuildDepthStencil = build;\n}\n\n/**\n * Re-attach a core depth-only renderbuffer at `DEPTH_ATTACHMENT` — used to roll a\n * render target back when a packed {@link generateRenderTargetStencil} attach\n * fails completeness (attaching at `DEPTH_STENCIL_ATTACHMENT` clears the core\n * `DEPTH_ATTACHMENT`). State-neutral: restores the caller's bound framebuffer.\n * @internal\n */\nfunction reattachCoreDepthBuffer(engine: GLEngineContext, rt: GLRenderTarget, depthBuffer: WebGLRenderbuffer): void {\n const gl = engine.gl;\n const prevFb = engine._state.boundFramebuffer ?? null;\n gl.bindFramebuffer(FRAMEBUFFER, rt._framebuffer);\n engine._state.boundFramebuffer = rt._framebuffer;\n gl.framebufferRenderbuffer(FRAMEBUFFER, DEPTH_ATTACHMENT, RENDERBUFFER, depthBuffer);\n if (engine._state.boundFramebuffer !== prevFb) {\n gl.bindFramebuffer(FRAMEBUFFER, prevFb);\n engine._state.boundFramebuffer = prevFb;\n }\n}\n"]}
|
package/dynamic-texture.d.ts
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* pixels are pushed on demand from a canvas / `OffscreenCanvas` / image / video
|
|
11
11
|
* / `ImageBitmap` / `ImageData` source. The most recent source is retained
|
|
12
12
|
* internally and replayed into the fresh handle on `webglcontextrestored` by the
|
|
13
|
-
* engine's standard context-restore protocol
|
|
13
|
+
* engine's standard context-restore protocol unless the engine is host-owned
|
|
14
|
+
* (`createHostOwnedGLEngine`); that mode drops the source reference after each upload.
|
|
14
15
|
*/
|
|
15
16
|
import { type GLTexture, type GLTextureOptions, type GLTextureUpdateOptions } from "./texture.js";
|
|
16
17
|
import type { GLEngineContext } from "./context.js";
|
|
@@ -22,7 +23,8 @@ import type { GLEngineContext } from "./context.js";
|
|
|
22
23
|
* The texture is immediately sampleable (reads as transparent black until the
|
|
23
24
|
* first update). It is context-restore-safe: the most recent source pushed via
|
|
24
25
|
* {@link updateDynamicTexture} is replayed into the fresh handle on
|
|
25
|
-
* `webglcontextrestored` (and re-blanked if no update happened yet)
|
|
26
|
+
* `webglcontextrestored` (and re-blanked if no update happened yet), unless
|
|
27
|
+
* the engine is host-owned (`createHostOwnedGLEngine`).
|
|
26
28
|
*
|
|
27
29
|
* @param engine - The engine to create GL resources on.
|
|
28
30
|
* @param width - Texture width in texels (clamped to ≥ 1).
|
|
@@ -36,7 +38,8 @@ export declare function createDynamicTexture(engine: GLEngineContext, width: num
|
|
|
36
38
|
/** Push 2D pixels into a {@link createDynamicTexture} texture from a canvas /
|
|
37
39
|
* `OffscreenCanvas` / image / video / `ImageBitmap` / `ImageData` source — the
|
|
38
40
|
* WebGL counterpart of Babylon's `ThinEngine.updateDynamicTexture`. The source
|
|
39
|
-
* is retained on the texture
|
|
41
|
+
* is retained on the texture for `webglcontextrestored` unless the engine is
|
|
42
|
+
* host-owned (`createHostOwnedGLEngine`), and
|
|
40
43
|
* `tex.width` / `tex.height` follow the source's size (`texImage2D` resizes
|
|
41
44
|
* the storage). No-op when the context is lost/disposed or the texture is
|
|
42
45
|
* disposed.
|
package/dynamic-texture.js
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* pixels are pushed on demand from a canvas / `OffscreenCanvas` / image / video
|
|
11
11
|
* / `ImageBitmap` / `ImageData` source. The most recent source is retained
|
|
12
12
|
* internally and replayed into the fresh handle on `webglcontextrestored` by the
|
|
13
|
-
* engine's standard context-restore protocol
|
|
13
|
+
* engine's standard context-restore protocol unless the engine is host-owned
|
|
14
|
+
* (`createHostOwnedGLEngine`); that mode drops the source reference after each upload.
|
|
14
15
|
*/
|
|
15
16
|
import { bindTextureForUpload, setTexImageSourceSize, setBoundTextureParams, setUnpackState, } from "./texture.js";
|
|
16
17
|
/** Create a texture backed by an empty (blank) `width × height` RGBA8
|
|
@@ -21,7 +22,8 @@ import { bindTextureForUpload, setTexImageSourceSize, setBoundTextureParams, set
|
|
|
21
22
|
* The texture is immediately sampleable (reads as transparent black until the
|
|
22
23
|
* first update). It is context-restore-safe: the most recent source pushed via
|
|
23
24
|
* {@link updateDynamicTexture} is replayed into the fresh handle on
|
|
24
|
-
* `webglcontextrestored` (and re-blanked if no update happened yet)
|
|
25
|
+
* `webglcontextrestored` (and re-blanked if no update happened yet), unless
|
|
26
|
+
* the engine is host-owned (`createHostOwnedGLEngine`).
|
|
25
27
|
*
|
|
26
28
|
* @param engine - The engine to create GL resources on.
|
|
27
29
|
* @param width - Texture width in texels (clamped to ≥ 1).
|
|
@@ -93,7 +95,8 @@ export function createDynamicTexture(engine, width, height, options) {
|
|
|
93
95
|
/** Push 2D pixels into a {@link createDynamicTexture} texture from a canvas /
|
|
94
96
|
* `OffscreenCanvas` / image / video / `ImageBitmap` / `ImageData` source — the
|
|
95
97
|
* WebGL counterpart of Babylon's `ThinEngine.updateDynamicTexture`. The source
|
|
96
|
-
* is retained on the texture
|
|
98
|
+
* is retained on the texture for `webglcontextrestored` unless the engine is
|
|
99
|
+
* host-owned (`createHostOwnedGLEngine`), and
|
|
97
100
|
* `tex.width` / `tex.height` follow the source's size (`texImage2D` resizes
|
|
98
101
|
* the storage). No-op when the context is lost/disposed or the texture is
|
|
99
102
|
* disposed.
|
|
@@ -111,7 +114,16 @@ export function updateDynamicTexture(tex, source, options) {
|
|
|
111
114
|
tex._dynSource = source;
|
|
112
115
|
tex._invertY = options?.invertY;
|
|
113
116
|
tex._premultiplyAlpha = options?.premultiplyAlpha;
|
|
114
|
-
|
|
117
|
+
try {
|
|
118
|
+
tex._upload(engine);
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
// Also on a throwing upload (e.g. a cross-origin source): a host-owned
|
|
122
|
+
// engine never replays, so it must not keep the source alive.
|
|
123
|
+
if (engine._noRestore) {
|
|
124
|
+
tex._dynSource = null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
115
127
|
}
|
|
116
128
|
/** Forget the source a dynamic texture retained for context-restore replay.
|
|
117
129
|
* The current GPU pixels are kept (no re-upload), but the source reference is
|