@babylonjs/lite-gl 1.13.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/context.js.map +1 -1
- package/index.d.ts +2 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/state.d.ts +1 -1
- package/state.js.map +1 -1
- package/texture-3d.d.ts +49 -0
- package/texture-3d.js +234 -0
- package/texture-3d.js.map +1 -0
- package/texture.d.ts +1 -1
- package/texture.js.map +1 -1
package/README.md
CHANGED
|
@@ -81,6 +81,8 @@ use.
|
|
|
81
81
|
- **Fullscreen renderer** — `createEffectWrapper`, `applyEffectWrapper`,
|
|
82
82
|
`drawEffect`, `setViewport`, `disposeEffectWrapper`.
|
|
83
83
|
- **Textures** — `createRawTexture` (typed-array upload, LDR byte formats),
|
|
84
|
+
`createTexture3DFromPixels` + `setEffectTexture3D` (optional native RGBA8
|
|
85
|
+
LUT volumes with trilinear sampling and zero 2D-only bundle cost),
|
|
84
86
|
`createFloatTexture` (float / half-float HDR opt-in), `generateTextureMipMaps`,
|
|
85
87
|
`loadTexture2D` (async URL upload with a 1×1 placeholder), `bindTexture`,
|
|
86
88
|
`disposeTexture`, plus `updateRawTexture`, `updateTextureSamplingMode`,
|
|
@@ -104,7 +106,9 @@ use.
|
|
|
104
106
|
|
|
105
107
|
Runnable scenes for every feature live in the repo's GL **lab**
|
|
106
108
|
(`lab/gl/`) — fullscreen effects, textures, sprites, blend modes,
|
|
107
|
-
HTML-element textures and render-to-texture round-trips.
|
|
109
|
+
HTML-element textures and render-to-texture round-trips. The standalone
|
|
110
|
+
`/gl/texture-3d-test.html` source test (`lab/gl/src/texture-3d-test.ts`) checks
|
|
111
|
+
native 3D texel addressing and trilinear filtering without a gallery demo.
|
|
108
112
|
|
|
109
113
|
## License
|
|
110
114
|
|
package/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.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,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 { GLRenderTarget } from \"./render-target.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/** 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 texture registry — populated by `createRawTexture` /\n * `loadTexture2D` / `createHtmlElementTexture`. Used by the\n * context-restored protocol to replay uploads.\n * @internal\n */\n _textures: GLTexture[];\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 (`bindRenderTarget(engine, null)` 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}\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: [],\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.canvas.removeEventListener(\"webglcontextlost\", engine._lostHandler as EventListener, false);\n engine.canvas.removeEventListener(\"webglcontextrestored\", engine._restoredHandler, false);\n\n const gl = engine.gl;\n // Iterate snapshots — the dispose paths splice into the 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 const textures = engine._textures.slice();\n for (const tex of textures) {\n if (!tex._disposed) {\n tex._disposed = true;\n gl.deleteTexture(tex.handle);\n }\n }\n engine._textures.length = 0;\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":"AAIA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAgB,MAAM,YAAY,CAAC;AAyM1F;;;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,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,KAAK;KACxE,CAAC;IACF,MAAM,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAkC,CAAC;IAC/E,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,IAAI,GAAG,SAAS,CAA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zE,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 { 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/** 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 texture registry — populated by `createRawTexture` /\n * `loadTexture2D` / `createHtmlElementTexture`. Used by the\n * context-restored protocol to replay uploads.\n * @internal\n */\n _textures: (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 (`bindRenderTarget(engine, null)` 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}\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: [],\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.canvas.removeEventListener(\"webglcontextlost\", engine._lostHandler as EventListener, false);\n engine.canvas.removeEventListener(\"webglcontextrestored\", engine._restoredHandler, false);\n\n const gl = engine.gl;\n // Iterate snapshots — the dispose paths splice into the 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 const textures = engine._textures.slice();\n for (const tex of textures) {\n if (!tex._disposed) {\n tex._disposed = true;\n gl.deleteTexture(tex.handle);\n }\n }\n engine._textures.length = 0;\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"]}
|
package/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export { createEffectWrapper, applyEffectWrapper, drawEffect, setViewport, dispo
|
|
|
8
8
|
export type { GLEffectWrapperOptions, GLEffectWrapper, GLViewport } from "./effect-renderer.js";
|
|
9
9
|
export { createRawTexture, createFloatTexture, generateTextureMipMaps, loadTexture2D, bindTexture, disposeTexture, updateRawTexture, updateTextureSamplingMode, updateTextureWrapMode, createTextureFromHandle, } from "./texture.js";
|
|
10
10
|
export type { GLTextureOptions, GLFloatTextureOptions, GLTexture } from "./texture.js";
|
|
11
|
+
export { createTexture3DFromPixels, bindTexture3D, setEffectTexture3D, generateTexture3DMipMaps, updateTexture3DSamplingMode, updateTexture3DWrapMode, disposeTexture3D, } from "./texture-3d.js";
|
|
12
|
+
export type { GLPixelsTexture3DOptions, GLTexture3D } from "./texture-3d.js";
|
|
11
13
|
export { createDynamicTexture, updateDynamicTexture, clearDynamicTextureSource } from "./dynamic-texture.js";
|
|
12
14
|
export { createRenderTarget, createFloatRenderTarget, bindRenderTarget, generateRenderTargetMipMaps, resizeRenderTarget, readRenderTargetPixels, disposeRenderTarget, } from "./render-target.js";
|
|
13
15
|
export type { GLRenderTarget, GLRenderTargetOptions, GLFloatRenderTargetOptions } from "./render-target.js";
|
package/index.js
CHANGED
|
@@ -22,6 +22,7 @@ export { createEffect, useEffect, isEffectReady, executeWhenCompiled, disposeEff
|
|
|
22
22
|
export { createEffectWrapper, applyEffectWrapper, drawEffect, setViewport, disposeEffectWrapper } from "./effect-renderer.js";
|
|
23
23
|
// ─── Textures ────────────────────────────────────────────────────────
|
|
24
24
|
export { createRawTexture, createFloatTexture, generateTextureMipMaps, loadTexture2D, bindTexture, disposeTexture, updateRawTexture, updateTextureSamplingMode, updateTextureWrapMode, createTextureFromHandle, } from "./texture.js";
|
|
25
|
+
export { createTexture3DFromPixels, bindTexture3D, setEffectTexture3D, generateTexture3DMipMaps, updateTexture3DSamplingMode, updateTexture3DWrapMode, disposeTexture3D, } from "./texture-3d.js";
|
|
25
26
|
// ─── Dynamic textures ────────────────────────────────────────────────
|
|
26
27
|
export { createDynamicTexture, updateDynamicTexture, clearDynamicTextureSource } from "./dynamic-texture.js";
|
|
27
28
|
// ─── Render targets ──────────────────────────────────────────────────
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,gFAAgF;AAChF,EAAE;AACF,iFAAiF;AACjF,4EAA4E;AAC5E,2EAA2E;AAC3E,yEAAyE;AACzE,+DAA+D;AAC/D,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,wCAAwC;AAExC,wEAAwE;AACxE,OAAO,EACH,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,kBAAkB,GACrB,MAAM,cAAc,CAAC;AAGtB,uEAAuE;AACvE,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEvG,wEAAwE;AACxE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEjE,wEAAwE;AACxE,OAAO,EACH,YAAY,EACZ,SAAS,EACT,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,GACpB,MAAM,aAAa,CAAC;AAGrB,wEAAwE;AACxE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAG9H,wEAAwE;AACxE,OAAO,EACH,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,aAAa,EACb,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,yBAAyB,EACzB,qBAAqB,EACrB,uBAAuB,GAC1B,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,gFAAgF;AAChF,EAAE;AACF,iFAAiF;AACjF,4EAA4E;AAC5E,2EAA2E;AAC3E,yEAAyE;AACzE,+DAA+D;AAC/D,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,wCAAwC;AAExC,wEAAwE;AACxE,OAAO,EACH,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,E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AA2B,EAC3B,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,GACtB,MAAM,oBAAoB,CAAC;AAG5B,wEAAwE;AACxE,OAAO,EACH,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,cAAc,EACd,wBAAwB,EACxB,WAAW,EACX,aAAa,EACb,WAAW,EACX,QAAQ,EACR,cAAc,GACjB,MAAM,WAAW,CAAC;AAGnB,wEAAwE;AACxE,sEAAsE;AACtE,0BAA0B;AAC1B,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGrG,wEAAwE;AACxE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,YAAY,EAAE,WAAW,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAGhK,wEAAwE;AACxE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE1D,wEAAwE;AACxE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAGpH,wEAAwE;AACxE,gFAAgF;AAChF,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["// @babylonjs/lite-gl — Public API\n// Function-based, tree-shakeable WebGL2 micro-engine. Import only what you use.\n//\n// Convention (mirrors @babylonjs/lite): the public API is re-exported EXPLICITLY\n// by name — never `export *`. This keeps the public surface intentional and\n// reviewable, lets `export type` mark type-only re-exports (required under\n// `isolatedModules`), and keeps internal helpers (e.g. `bindTextureRaw`,\n// `bindTextureForUpload`) out of consumers' bundles + `.d.ts`.\n//\n// The package is `sideEffects: false` and no module has top-level side effects,\n// so a consumer that imports only the symbols it needs tree-shakes everything\n// else (sprites, html-texture, …) away.\n\n// ─── Engine / context ────────────────────────────────────────────────\nexport {\n createGLEngine,\n disposeGLEngine,\n resizeGLEngine,\n setGLEngineSize,\n wipeGLStateCache,\n getRenderWidth,\n getRenderHeight,\n getHardwareScalingLevel,\n setHardwareScalingLevel,\n getRenderingCanvas,\n onContextLost,\n offContextLost,\n onContextRestored,\n offContextRestored,\n} from \"./context.js\";\nexport type { GLEngineOptions, GLEngineCaps, GLEngineContext } from \"./context.js\";\n\n// ─── Alpha-to-coverage (optional) ───────────────────────────────────\nexport { getAlphaToCoverage, getCurrentSampleCount, setAlphaToCoverage } from \"./alpha-to-coverage.js\";\n\n// ─── Render loop ─────────────────────────────────────────────────────\nexport { runRenderLoop, stopRenderLoop } from \"./render-loop.js\";\n\n// ─── Effects ─────────────────────────────────────────────────────────\nexport {\n createEffect,\n useEffect,\n isEffectReady,\n executeWhenCompiled,\n disposeEffect,\n setEffectFloat,\n setEffectFloat2,\n setEffectFloat3,\n setEffectFloat4,\n setEffectColor3,\n setEffectColor4,\n setEffectVector2,\n setEffectDirectColor4,\n setEffectInt,\n setEffectTexture,\n setEffectMatrix,\n setEffectMatrix3x3,\n setEffectFloatArray,\n setEffectFloatArray4,\n setEffectIntArray,\n} from \"./effect.js\";\nexport type { GLEffectOptions, GLEffect } from \"./effect.js\";\n\n// ─── Effect renderer (fullscreen quad) ───────────────────────────────\nexport { createEffectWrapper, applyEffectWrapper, drawEffect, setViewport, disposeEffectWrapper } from \"./effect-renderer.js\";\nexport type { GLEffectWrapperOptions, GLEffectWrapper, GLViewport } from \"./effect-renderer.js\";\n\n// ─── Textures ────────────────────────────────────────────────────────\nexport {\n createRawTexture,\n createFloatTexture,\n generateTextureMipMaps,\n loadTexture2D,\n bindTexture,\n disposeTexture,\n updateRawTexture,\n updateTextureSamplingMode,\n updateTextureWrapMode,\n createTextureFromHandle,\n} from \"./texture.js\";\nexport type { GLTextureOptions, GLFloatTextureOptions, GLTexture } from \"./texture.js\";\nexport {\n createTexture3DFromPixels,\n bindTexture3D,\n setEffectTexture3D,\n generateTexture3DMipMaps,\n updateTexture3DSamplingMode,\n updateTexture3DWrapMode,\n disposeTexture3D,\n} from \"./texture-3d.js\";\nexport type { GLPixelsTexture3DOptions, GLTexture3D } from \"./texture-3d.js\";\n\n// ─── Dynamic textures ────────────────────────────────────────────────\nexport { createDynamicTexture, updateDynamicTexture, clearDynamicTextureSource } from \"./dynamic-texture.js\";\n\n// ─── Render targets ──────────────────────────────────────────────────\nexport {\n createRenderTarget,\n createFloatRenderTarget,\n bindRenderTarget,\n generateRenderTargetMipMaps,\n resizeRenderTarget,\n readRenderTargetPixels,\n disposeRenderTarget,\n} from \"./render-target.js\";\nexport type { GLRenderTarget, GLRenderTargetOptions, GLFloatRenderTargetOptions } from \"./render-target.js\";\n\n// ─── Meshes / buffers / instancing ───────────────────────────────────\nexport {\n createVertexBuffer,\n updateVertexBuffer,\n createIndexBuffer,\n disposeBuffer,\n bindIndexBuffer,\n bindAttributes,\n unbindInstanceAttributes,\n drawIndexed,\n createMeshVao,\n bindMeshVao,\n drawMesh,\n disposeMeshVao,\n} from \"./mesh.js\";\nexport type { GLVertexBuffer, GLIndexBuffer, GLAttributeDescriptor, GLMeshVertexBuffer, GLMeshVao } from \"./mesh.js\";\n\n// ─── Blend modes ─────────────────────────────────────────────────────\n// GLBlendMode / GLBlendEquation are const + same-name type; one value\n// re-export carries both.\nexport { GLBlendMode, GLBlendEquation, setBlendMode, setBlendState, disableBlend } from \"./blend.js\";\nexport type { GLBlendState } from \"./blend.js\";\n\n// ─── Depth / stencil / color-mask / clear ────────────────────────────\nexport { setDepthState, setCullState, setStencilState, setStencilOpSeparate, setColorMask, clearEngine, generateRenderTargetStencil } from \"./depth-stencil.js\";\nexport type { GLDepthState, GLStencilState, GLStencilOpState, GLClearOptions } from \"./depth-stencil.js\";\n\n// ─── Scissor ─────────────────────────────────────────────────────────\nexport { setScissor, disableScissor } from \"./scissor.js\";\n\n// ─── Sprites ─────────────────────────────────────────────────────────\nexport { createSpriteRenderer, renderSprites, setSpriteRendererTexture, disposeSpriteRenderer } from \"./sprites.js\";\nexport type { GLSprite, GLSpriteColor, GLSpriteRendererOptions, GLSpriteRenderer } from \"./sprites.js\";\n\n// ─── HTML-element textures ───────────────────────────────────────────\n// GLSamplingMode is a const + same-name type; one value re-export carries both.\nexport { createHtmlElementTexture, updateHtmlElementTexture, GLSamplingMode } from \"./html-texture.js\";\nexport type { GLHtmlElementTextureOptions } from \"./html-texture.js\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babylonjs/lite-gl",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Function-based, tree-shakeable WebGL2 micro-engine for fullscreen effects, sprites and dynamic textures — the WebGL counterpart of @babylonjs/lite.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"babylon",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"babylonLiteRelease": {
|
|
35
|
-
"azureBuildId": "
|
|
36
|
-
"sourceVersion": "
|
|
35
|
+
"azureBuildId": "60331",
|
|
36
|
+
"sourceVersion": "28e91edfe24a7ca3bd080b976612e674f03c8b41"
|
|
37
37
|
}
|
|
38
38
|
}
|
package/state.d.ts
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
export interface GLState {
|
|
30
30
|
currentProgram: WebGLProgram | null;
|
|
31
31
|
activeTextureUnit: number;
|
|
32
|
-
/** Per-unit binding; length === caps.maxTextureUnits. */
|
|
32
|
+
/** Per-unit TEXTURE_2D binding; length === caps.maxTextureUnits. */
|
|
33
33
|
boundTextures: (WebGLTexture | null)[];
|
|
34
34
|
boundArrayBuffer: WebGLBuffer | null;
|
|
35
35
|
boundElementBuffer: WebGLBuffer | null;
|
package/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"A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,CAAC;IACtB,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC;IACpB,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC;IACpB,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC;IACpB,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC;IACpB,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAC9B,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAChC,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC;IAC1B,KAAK,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC;IAC1B,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;IACnB,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;IACnB,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;IACnB,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;IACnB,KAAK,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC;IAC3B,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;IACvB,KAAK,CAAC,sBAAsB,GAAG,CAAC,CAAC,CAAC;IAClC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC;IAChC,KAAK,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC;AACvC,CAAC;AAED;;;wDAGwD;AACxD,MAAM,UAAU,YAAY,CAAC,KAAc;IACvC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACzB,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;IACrB,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;IACrB,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;AACzB,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\n\n/* ─── Deferred render-state index-array layout ────────────────────────────────\n * The deferred render-state (blend / depth / cull / stencil / color-mask) lives\n * in a flat `Float64Array(46)` on `GLState.rs`: slots `0..20` hold the ACTUAL\n * applied GL state, slots `21..41` (`RS_X + RS_DESIRED`) the DESIRED twin, and\n * slots `42..45` the standalone (no-desired-twin) cached `gl.clearColor` RGBA.\n * `setStencilOpSeparate` lazily expands it to 52 slots for back-face operations.\n *\n * These `@internal` index consts are imported by blend.ts / depth-stencil.ts /\n * apply-states.ts. Because they are plain `const` integers, esbuild inlines each\n * to a 1–2 char literal (`rs[RS_BLEND_SRC_RGB + RS_DESIRED]` → `rs[22]`) when\n * bundling a scene — far smaller than the old cross-module `.dBlendSrcRGB` named\n * props, which could not be mangled and shipped verbatim in every bundle.\n *\n * Float64Array (NOT Int32Array) is required: `RS_STENCIL_MASK` /\n * `RS_STENCIL_FUNC_MASK` can be `0xFFFFFFFF`, which Int32 would store as `-1` and\n * collide with the `-1` \"unset\" sentinel; Float64 keeps `4294967295` distinct. */\n/** @internal */ export const RS_BLEND_ENABLED = 0;\n/** @internal */ export const RS_BLEND_SRC_RGB = 1;\n/** @internal */ export const RS_BLEND_DST_RGB = 2;\n/** @internal */ export const RS_BLEND_SRC_A = 3;\n/** @internal */ export const RS_BLEND_DST_A = 4;\n/** @internal */ export const RS_BLEND_EQ_RGB = 5;\n/** @internal */ export const RS_BLEND_EQ_A = 6;\n/** @internal */ export const RS_DEPTH_TEST = 7;\n/** @internal */ export const RS_DEPTH_MASK = 8;\n/** @internal */ export const RS_DEPTH_FUNC = 9;\n/** @internal */ export const RS_CULL_ENABLED = 10;\n/** @internal */ export const RS_CULL_FACE = 11;\n/** @internal */ export const RS_STENCIL_TEST = 12;\n/** @internal */ export const RS_STENCIL_MASK = 13;\n/** @internal */ export const RS_STENCIL_FUNC_FUNC = 14;\n/** @internal */ export const RS_STENCIL_FUNC_REF = 15;\n/** @internal */ export const RS_STENCIL_FUNC_MASK = 16;\n/** @internal */ export const RS_STENCIL_OP_FAIL = 17;\n/** @internal */ export const RS_STENCIL_OP_ZFAIL = 18;\n/** @internal */ export const RS_STENCIL_OP_ZPASS = 19;\n/** @internal */ export const RS_COLOR_MASK = 20;\n/** @internal Offset from an ACTUAL slot (`0..20`) to its DESIRED twin (`21..41`). */\nexport const RS_DESIRED = 21;\n/* Standalone cached gl.clearColor RGBA slots (`42..45`) — NO desired twin; a\n * simple apply-on-clear cache like viewport/scissor, stored in `rs` (not as named\n * GLState fields) so the index access mangles small instead of shipping\n * `.clearColorR` verbatim in every bundle. */\n/** @internal */ export const RS_CLEAR_R = 42;\n/** @internal */ export const RS_CLEAR_G = 43;\n/** @internal */ export const RS_CLEAR_B = 44;\n/** @internal */ export const RS_CLEAR_A = 45;\n\n/**\n * GL-state cache type. Owned by `GLEngineContext._state`.\n *\n * Two flavours of cached state coexist here:\n *\n * - **Eager bindings** (program / buffers / textures / VAO / framebuffer /\n * viewport / scissor / unpack). Each binding setter issues its `gl.*` call\n * immediately and updates the matching field in lock-step, eliding the call\n * when the cache already matches.\n * - **Deferred render-state** (blend / depth / cull / stencil / color-mask),\n * stored in the {@link GLState.rs} index-array. These follow Babylon's\n * `applyStates()` model: each setter records only the DESIRED slot\n * (`rs[RS_X + RS_DESIRED]`) and sets `statesDirty`; the real `gl.*` calls are\n * flushed by {@link applyGLStates} (apply-states.ts) immediately before each\n * draw / clear, reconciling DESIRED → ACTUAL and writing the actual slots\n * (`rs[RS_X]`) in lock-step. Both halves keep their `-1`/`0` unset sentinels.\n *\n * See `00-lite-gl.md` §4 for the full table of cached operations and the\n * deferred-state flush sites.\n *\n * INVARIANTS:\n * - The cache is the source of truth. If consumers poke `engine.gl.*` directly\n * they will silently corrupt this state.\n * - On `webglcontextlost` the whole `rs` array (both the actual and desired\n * halves) is reset to its initial sentinels (handles are dead anyway;\n * subsequent setters bail out on `engine._isLost`, and a post-restore setter\n * re-marks `statesDirty`).\n */\nexport interface GLState {\n currentProgram: WebGLProgram | null;\n activeTextureUnit: number;\n /** Per-unit binding; length === caps.maxTextureUnits. */\n boundTextures: (WebGLTexture | null)[];\n boundArrayBuffer: WebGLBuffer | null;\n boundElementBuffer: WebGLBuffer | null;\n boundVao: WebGLVertexArrayObject | null;\n viewportX: number;\n viewportY: number;\n viewportW: number;\n viewportH: number;\n /**\n * Currently-bound draw framebuffer, or `null` for the default (canvas)\n * framebuffer. Owned by the render-target module's `bindRenderTarget`\n * (binding `null` returns to the canvas). Reset to `null` on context-lost.\n */\n boundFramebuffer: WebGLFramebuffer | null;\n /**\n * Deferred render-state (blend / depth / cull / stencil / color-mask) packed\n * into a flat `Float64Array(46)`. Slots `0..20` (indexed by the `RS_*`\n * consts) are the ACTUAL applied GL state — what {@link applyGLStates} last\n * wrote to the context; slots `21..41` (`rs[RS_X + RS_DESIRED]`) are the\n * DESIRED twin the setters record. The setters write ONLY the desired half\n * (never `gl.*`, never the actual half) and raise `statesDirty`;\n * `applyGLStates` reconciles each desired → its actual twin right before a\n * draw / clear, issuing only the GL calls that changed and updating the\n * actual half in lock-step. Both preset and arbitrary blend paths feed the\n * same desired slots, so they can never desync.\n *\n * Sentinels (identical for both halves): `-1` for the tri-state enables\n * (`RS_BLEND_ENABLED` / `RS_DEPTH_TEST` / `RS_DEPTH_MASK` / `RS_CULL_ENABLED`\n * / `RS_STENCIL_TEST`) and the mask caches (`RS_STENCIL_MASK` /\n * `RS_COLOR_MASK`), plus the leading stencil-op slot\n * (`RS_STENCIL_OP_FAIL`); `0` for every other func / equation / op / ref\n * slot. The leading op sentinel lets the first op\n * setter seed omitted fields to WebGL's `KEEP` defaults before merging. An\n * unset desired equals its unset actual and is never flushed; the `-1`\n * blend/test sentinels guarantee the first applied state is never elided.\n * The blend func/equation slots are only trusted while `RS_BLEND_ENABLED` is\n * `1` — the disabled→enabled transition re-issues both (matching Babylon's\n * `AlphaState`, which does not track them while blending is off).\n *\n * `setStencilOpSeparate` lazily replaces this array with a 52-slot copy; the\n * six appended slots cache actual and desired back-face operations without\n * moving any base index.\n *\n * Float64 (not Int32): `RS_STENCIL_MASK` / `RS_STENCIL_FUNC_MASK` can be\n * `0xFFFFFFFF`, which Int32 stores as `-1` — colliding with the `-1` unset\n * sentinel. Reset on context-lost. */\n rs: Float64Array;\n /** `true` when at least one deferred-state setter ran since the last\n * {@link applyGLStates}. Gates the flush so an unchanged frame issues no\n * reconciliation work. */\n statesDirty: boolean;\n /* ─── Deferred render-state appliers (per-category, lazily installed) ──────\n * Each category's reconciler (blend / depth+cull / stencil / color-mask) is\n * installed onto its slot the first time the matching setter runs — a runtime\n * assignment, NOT a module-level side effect. `applyGLStates` dispatches ONLY\n * through these slots, so the reconcilers (and their GL reconciliation code)\n * are reachable only when their setter is in the bundle: a scene that never\n * touches a category tree-shakes its reconciler out entirely (e.g. a clear-\n * only scene drops all four). Left undefined until installed; never cleared on\n * context-lost (a post-restore setter re-installs idempotently). */\n /** @internal Blend reconciler (Babylon's `_alphaState`). */\n _flushBlend?: (engine: GLEngineContext) => void;\n /** @internal Depth + cull reconciler (Babylon's `_depthCullingState`). */\n _flushDepthCull?: (engine: GLEngineContext) => void;\n /** @internal Stencil reconciler (Babylon's `_stencilState`). */\n _flushStencil?: (engine: GLEngineContext) => void;\n /** @internal Lazy hook that mirrors shared stencil operations to the back face. */\n _setStencilBack?: (cache: GLState, state: { opFail?: GLenum; opZFail?: GLenum; opZPass?: GLenum }) => void;\n /** @internal Color-write-mask reconciler (Babylon's `setColorWrite`). */\n _flushColorMask?: (engine: GLEngineContext) => void;\n /** Scissor-test enable tri-state (`-1` unset, `0` off, `1` on). */\n scissorEnabled: number;\n scissorX: number;\n scissorY: number;\n scissorW: number;\n scissorH: number;\n /** Cached `gl.pixelStorei(UNPACK_ALIGNMENT)`, or `-1` when unset. */\n unpackAlignment: number;\n /** Cached `gl.pixelStorei(UNPACK_FLIP_Y_WEBGL)`, or `-1` when unset. */\n unpackFlipY: number;\n /** Cached `gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL)`, or `-1` unset. */\n unpackPremultiplyAlpha: number;\n /**\n * Per-location vertex-attribute enable flags for the DEFAULT (null) VAO —\n * the mesh / instancing path (mirrors Babylon's `_vertexAttribArraysEnabled`).\n * Index is the attribute location. lite-gl's quad / sprite paths use their\n * own VAOs and do not touch this. Cleared on context-lost.\n */\n enabledAttribs: boolean[];\n /**\n * Attribute locations currently configured with a non-default vertex divisor\n * (instanced attributes), mirroring Babylon's `_currentInstanceLocations`.\n * `unbindInstanceAttributes` resets each back to divisor 0 and clears this.\n */\n instanceLocations: number[];\n /** Shared fullscreen quad — lazily created on first `applyEffectWrapper`. */\n quadVbo: WebGLBuffer | null;\n quadIbo: WebGLBuffer | null;\n quadVao: WebGLVertexArrayObject | null;\n}\n\n/** Indices in `rs` whose unset sentinel is `-1` (the tri-state enables, the\n * `stencilMask` / `colorMask` caches, and the leading shared stencil-op slot).\n * Every other slot defaults to `0`. The sentinel is written to BOTH\n * the actual (`i`) and desired (`i + RS_DESIRED`) halves. Kept as a\n * function-local literal so it stays a runtime value (no module-level\n * allocation / side effect). */\nfunction applyRenderStateSentinels(rs: Float64Array): void {\n for (const i of [RS_BLEND_ENABLED, RS_DEPTH_TEST, RS_DEPTH_MASK, RS_CULL_ENABLED, RS_STENCIL_TEST, RS_STENCIL_MASK, RS_STENCIL_OP_FAIL, RS_COLOR_MASK]) {\n rs[i] = -1;\n rs[i + RS_DESIRED] = -1;\n }\n // clearColor RGBA (standalone, no DESIRED twin) — `-1` forces the first clear\n // to issue gl.clearColor (valid components are 0..1).\n rs[RS_CLEAR_R] = rs[RS_CLEAR_G] = rs[RS_CLEAR_B] = rs[RS_CLEAR_A] = -1;\n}\n\n/** Allocate the 46-slot deferred render-state array (21 actual + 21 desired + 4\n * standalone clearColor) initialised to its unset sentinels — a fresh\n * `Float64Array` is already all `0`, so only the `-1` slots need writing. */\nfunction createRenderStateArray(): Float64Array {\n const rs = new Float64Array(46);\n applyRenderStateSentinels(rs);\n return rs;\n}\n\n/** Re-initialise a live render-state array in place: zero every slot, then\n * restore the `-1` sentinels. */\nfunction resetRenderStateArray(rs: Float64Array): void {\n rs.fill(0);\n applyRenderStateSentinels(rs);\n}\n\n/** Allocate a fresh, fully-null GLState sized for `maxTextureUnits`. */\nexport function createGLState(maxTextureUnits: number): GLState {\n return {\n currentProgram: null,\n activeTextureUnit: 0,\n boundTextures: new Array<WebGLTexture | null>(maxTextureUnits).fill(null),\n boundArrayBuffer: null,\n boundElementBuffer: null,\n boundVao: null,\n viewportX: 0,\n viewportY: 0,\n viewportW: 0,\n viewportH: 0,\n boundFramebuffer: null,\n rs: createRenderStateArray(),\n statesDirty: false,\n scissorEnabled: -1,\n scissorX: 0,\n scissorY: 0,\n scissorW: 0,\n scissorH: 0,\n unpackAlignment: -1,\n unpackFlipY: -1,\n unpackPremultiplyAlpha: -1,\n enabledAttribs: [],\n instanceLocations: [],\n quadVbo: null,\n quadIbo: null,\n quadVao: null,\n };\n}\n\n/** Reset only the cached \"current GL state\" — every binding (program / buffers /\n * textures / VAO / framebuffer) and render-state (blend / depth / stencil /\n * scissor / color-mask / viewport / unpack) field, including the whole `rs`\n * deferred render-state array (BOTH the actual applied values and the DESIRED\n * twins) plus `statesDirty` — to its unset sentinel, WITHOUT discarding owned\n * GPU resources (the shared quad). After this, the next setter in each category\n * is re-issued rather than elided.\n *\n * Used by `resetGLState` (context-lost) and by `wipeGLStateCache` (a host that\n * shares the GL context calling in after mutating raw `gl.*` state). The shared\n * quad's GL objects are still alive in the latter case, so they are preserved\n * here to avoid leaking + needlessly rebuilding them every render scope. */\nexport function resetGLStateCache(state: GLState): void {\n state.currentProgram = null;\n state.activeTextureUnit = 0;\n state.boundTextures.fill(null);\n state.boundArrayBuffer = null;\n state.boundElementBuffer = null;\n state.boundVao = null;\n state.viewportX = 0;\n state.viewportY = 0;\n state.viewportW = 0;\n state.viewportH = 0;\n state.boundFramebuffer = null;\n resetRenderStateArray(state.rs);\n state.statesDirty = false;\n state.scissorEnabled = -1;\n state.scissorX = 0;\n state.scissorY = 0;\n state.scissorW = 0;\n state.scissorH = 0;\n state.unpackAlignment = -1;\n state.unpackFlipY = -1;\n state.unpackPremultiplyAlpha = -1;\n state.enabledAttribs.length = 0;\n state.instanceLocations.length = 0;\n}\n\n/** Zero the cache in-place. Used by the context-lost handler — GL handles are\n * already dead per WebGL spec; we forget what we knew about them (including the\n * shared quad, whose GL objects are gone and must be rebuilt) so the next\n * bind/use after restore is NOT incorrectly elided. */\nexport function resetGLState(state: GLState): void {\n resetGLStateCache(state);\n state.quadVbo = null;\n state.quadIbo = null;\n state.quadVao = null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;kFAekF;AAClF,gBAAgB,CAAC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AACnD,gBAAgB,CAAC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AACnD,gBAAgB,CAAC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AACnD,gBAAgB,CAAC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AACjD,gBAAgB,CAAC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AACjD,gBAAgB,CAAC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AAClD,gBAAgB,CAAC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAChD,gBAAgB,CAAC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAChD,gBAAgB,CAAC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAChD,gBAAgB,CAAC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAChD,gBAAgB,CAAC,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AACnD,gBAAgB,CAAC,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;AAChD,gBAAgB,CAAC,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AACnD,gBAAgB,CAAC,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AACnD,gBAAgB,CAAC,MAA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AAC;IACrB,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;IACrB,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;AACzB,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\n\n/* ─── Deferred render-state index-array layout ────────────────────────────────\n * The deferred render-state (blend / depth / cull / stencil / color-mask) lives\n * in a flat `Float64Array(46)` on `GLState.rs`: slots `0..20` hold the ACTUAL\n * applied GL state, slots `21..41` (`RS_X + RS_DESIRED`) the DESIRED twin, and\n * slots `42..45` the standalone (no-desired-twin) cached `gl.clearColor` RGBA.\n * `setStencilOpSeparate` lazily expands it to 52 slots for back-face operations.\n *\n * These `@internal` index consts are imported by blend.ts / depth-stencil.ts /\n * apply-states.ts. Because they are plain `const` integers, esbuild inlines each\n * to a 1–2 char literal (`rs[RS_BLEND_SRC_RGB + RS_DESIRED]` → `rs[22]`) when\n * bundling a scene — far smaller than the old cross-module `.dBlendSrcRGB` named\n * props, which could not be mangled and shipped verbatim in every bundle.\n *\n * Float64Array (NOT Int32Array) is required: `RS_STENCIL_MASK` /\n * `RS_STENCIL_FUNC_MASK` can be `0xFFFFFFFF`, which Int32 would store as `-1` and\n * collide with the `-1` \"unset\" sentinel; Float64 keeps `4294967295` distinct. */\n/** @internal */ export const RS_BLEND_ENABLED = 0;\n/** @internal */ export const RS_BLEND_SRC_RGB = 1;\n/** @internal */ export const RS_BLEND_DST_RGB = 2;\n/** @internal */ export const RS_BLEND_SRC_A = 3;\n/** @internal */ export const RS_BLEND_DST_A = 4;\n/** @internal */ export const RS_BLEND_EQ_RGB = 5;\n/** @internal */ export const RS_BLEND_EQ_A = 6;\n/** @internal */ export const RS_DEPTH_TEST = 7;\n/** @internal */ export const RS_DEPTH_MASK = 8;\n/** @internal */ export const RS_DEPTH_FUNC = 9;\n/** @internal */ export const RS_CULL_ENABLED = 10;\n/** @internal */ export const RS_CULL_FACE = 11;\n/** @internal */ export const RS_STENCIL_TEST = 12;\n/** @internal */ export const RS_STENCIL_MASK = 13;\n/** @internal */ export const RS_STENCIL_FUNC_FUNC = 14;\n/** @internal */ export const RS_STENCIL_FUNC_REF = 15;\n/** @internal */ export const RS_STENCIL_FUNC_MASK = 16;\n/** @internal */ export const RS_STENCIL_OP_FAIL = 17;\n/** @internal */ export const RS_STENCIL_OP_ZFAIL = 18;\n/** @internal */ export const RS_STENCIL_OP_ZPASS = 19;\n/** @internal */ export const RS_COLOR_MASK = 20;\n/** @internal Offset from an ACTUAL slot (`0..20`) to its DESIRED twin (`21..41`). */\nexport const RS_DESIRED = 21;\n/* Standalone cached gl.clearColor RGBA slots (`42..45`) — NO desired twin; a\n * simple apply-on-clear cache like viewport/scissor, stored in `rs` (not as named\n * GLState fields) so the index access mangles small instead of shipping\n * `.clearColorR` verbatim in every bundle. */\n/** @internal */ export const RS_CLEAR_R = 42;\n/** @internal */ export const RS_CLEAR_G = 43;\n/** @internal */ export const RS_CLEAR_B = 44;\n/** @internal */ export const RS_CLEAR_A = 45;\n\n/**\n * GL-state cache type. Owned by `GLEngineContext._state`.\n *\n * Two flavours of cached state coexist here:\n *\n * - **Eager bindings** (program / buffers / textures / VAO / framebuffer /\n * viewport / scissor / unpack). Each binding setter issues its `gl.*` call\n * immediately and updates the matching field in lock-step, eliding the call\n * when the cache already matches.\n * - **Deferred render-state** (blend / depth / cull / stencil / color-mask),\n * stored in the {@link GLState.rs} index-array. These follow Babylon's\n * `applyStates()` model: each setter records only the DESIRED slot\n * (`rs[RS_X + RS_DESIRED]`) and sets `statesDirty`; the real `gl.*` calls are\n * flushed by {@link applyGLStates} (apply-states.ts) immediately before each\n * draw / clear, reconciling DESIRED → ACTUAL and writing the actual slots\n * (`rs[RS_X]`) in lock-step. Both halves keep their `-1`/`0` unset sentinels.\n *\n * See `00-lite-gl.md` §4 for the full table of cached operations and the\n * deferred-state flush sites.\n *\n * INVARIANTS:\n * - The cache is the source of truth. If consumers poke `engine.gl.*` directly\n * they will silently corrupt this state.\n * - On `webglcontextlost` the whole `rs` array (both the actual and desired\n * halves) is reset to its initial sentinels (handles are dead anyway;\n * subsequent setters bail out on `engine._isLost`, and a post-restore setter\n * re-marks `statesDirty`).\n */\nexport interface GLState {\n currentProgram: WebGLProgram | null;\n activeTextureUnit: number;\n /** Per-unit TEXTURE_2D binding; length === caps.maxTextureUnits. */\n boundTextures: (WebGLTexture | null)[];\n /** Per-unit TEXTURE_3D binding, allocated only when first used. @internal */\n _boundTextures3D?: (WebGLTexture | null | undefined)[];\n /** Cached zero WebGL2 unpack row/image/skip layout for 3D uploads. @internal */\n _unpack3DLayoutKnown?: boolean;\n boundArrayBuffer: WebGLBuffer | null;\n boundElementBuffer: WebGLBuffer | null;\n boundVao: WebGLVertexArrayObject | null;\n viewportX: number;\n viewportY: number;\n viewportW: number;\n viewportH: number;\n /**\n * Currently-bound draw framebuffer, or `null` for the default (canvas)\n * framebuffer. Owned by the render-target module's `bindRenderTarget`\n * (binding `null` returns to the canvas). Reset to `null` on context-lost.\n */\n boundFramebuffer: WebGLFramebuffer | null;\n /**\n * Deferred render-state (blend / depth / cull / stencil / color-mask) packed\n * into a flat `Float64Array(46)`. Slots `0..20` (indexed by the `RS_*`\n * consts) are the ACTUAL applied GL state — what {@link applyGLStates} last\n * wrote to the context; slots `21..41` (`rs[RS_X + RS_DESIRED]`) are the\n * DESIRED twin the setters record. The setters write ONLY the desired half\n * (never `gl.*`, never the actual half) and raise `statesDirty`;\n * `applyGLStates` reconciles each desired → its actual twin right before a\n * draw / clear, issuing only the GL calls that changed and updating the\n * actual half in lock-step. Both preset and arbitrary blend paths feed the\n * same desired slots, so they can never desync.\n *\n * Sentinels (identical for both halves): `-1` for the tri-state enables\n * (`RS_BLEND_ENABLED` / `RS_DEPTH_TEST` / `RS_DEPTH_MASK` / `RS_CULL_ENABLED`\n * / `RS_STENCIL_TEST`) and the mask caches (`RS_STENCIL_MASK` /\n * `RS_COLOR_MASK`), plus the leading stencil-op slot\n * (`RS_STENCIL_OP_FAIL`); `0` for every other func / equation / op / ref\n * slot. The leading op sentinel lets the first op\n * setter seed omitted fields to WebGL's `KEEP` defaults before merging. An\n * unset desired equals its unset actual and is never flushed; the `-1`\n * blend/test sentinels guarantee the first applied state is never elided.\n * The blend func/equation slots are only trusted while `RS_BLEND_ENABLED` is\n * `1` — the disabled→enabled transition re-issues both (matching Babylon's\n * `AlphaState`, which does not track them while blending is off).\n *\n * `setStencilOpSeparate` lazily replaces this array with a 52-slot copy; the\n * six appended slots cache actual and desired back-face operations without\n * moving any base index.\n *\n * Float64 (not Int32): `RS_STENCIL_MASK` / `RS_STENCIL_FUNC_MASK` can be\n * `0xFFFFFFFF`, which Int32 stores as `-1` — colliding with the `-1` unset\n * sentinel. Reset on context-lost. */\n rs: Float64Array;\n /** `true` when at least one deferred-state setter ran since the last\n * {@link applyGLStates}. Gates the flush so an unchanged frame issues no\n * reconciliation work. */\n statesDirty: boolean;\n /* ─── Deferred render-state appliers (per-category, lazily installed) ──────\n * Each category's reconciler (blend / depth+cull / stencil / color-mask) is\n * installed onto its slot the first time the matching setter runs — a runtime\n * assignment, NOT a module-level side effect. `applyGLStates` dispatches ONLY\n * through these slots, so the reconcilers (and their GL reconciliation code)\n * are reachable only when their setter is in the bundle: a scene that never\n * touches a category tree-shakes its reconciler out entirely (e.g. a clear-\n * only scene drops all four). Left undefined until installed; never cleared on\n * context-lost (a post-restore setter re-installs idempotently). */\n /** @internal Blend reconciler (Babylon's `_alphaState`). */\n _flushBlend?: (engine: GLEngineContext) => void;\n /** @internal Depth + cull reconciler (Babylon's `_depthCullingState`). */\n _flushDepthCull?: (engine: GLEngineContext) => void;\n /** @internal Stencil reconciler (Babylon's `_stencilState`). */\n _flushStencil?: (engine: GLEngineContext) => void;\n /** @internal Lazy hook that mirrors shared stencil operations to the back face. */\n _setStencilBack?: (cache: GLState, state: { opFail?: GLenum; opZFail?: GLenum; opZPass?: GLenum }) => void;\n /** @internal Color-write-mask reconciler (Babylon's `setColorWrite`). */\n _flushColorMask?: (engine: GLEngineContext) => void;\n /** Scissor-test enable tri-state (`-1` unset, `0` off, `1` on). */\n scissorEnabled: number;\n scissorX: number;\n scissorY: number;\n scissorW: number;\n scissorH: number;\n /** Cached `gl.pixelStorei(UNPACK_ALIGNMENT)`, or `-1` when unset. */\n unpackAlignment: number;\n /** Cached `gl.pixelStorei(UNPACK_FLIP_Y_WEBGL)`, or `-1` when unset. */\n unpackFlipY: number;\n /** Cached `gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL)`, or `-1` unset. */\n unpackPremultiplyAlpha: number;\n /**\n * Per-location vertex-attribute enable flags for the DEFAULT (null) VAO —\n * the mesh / instancing path (mirrors Babylon's `_vertexAttribArraysEnabled`).\n * Index is the attribute location. lite-gl's quad / sprite paths use their\n * own VAOs and do not touch this. Cleared on context-lost.\n */\n enabledAttribs: boolean[];\n /**\n * Attribute locations currently configured with a non-default vertex divisor\n * (instanced attributes), mirroring Babylon's `_currentInstanceLocations`.\n * `unbindInstanceAttributes` resets each back to divisor 0 and clears this.\n */\n instanceLocations: number[];\n /** Shared fullscreen quad — lazily created on first `applyEffectWrapper`. */\n quadVbo: WebGLBuffer | null;\n quadIbo: WebGLBuffer | null;\n quadVao: WebGLVertexArrayObject | null;\n}\n\n/** Indices in `rs` whose unset sentinel is `-1` (the tri-state enables, the\n * `stencilMask` / `colorMask` caches, and the leading shared stencil-op slot).\n * Every other slot defaults to `0`. The sentinel is written to BOTH\n * the actual (`i`) and desired (`i + RS_DESIRED`) halves. Kept as a\n * function-local literal so it stays a runtime value (no module-level\n * allocation / side effect). */\nfunction applyRenderStateSentinels(rs: Float64Array): void {\n for (const i of [RS_BLEND_ENABLED, RS_DEPTH_TEST, RS_DEPTH_MASK, RS_CULL_ENABLED, RS_STENCIL_TEST, RS_STENCIL_MASK, RS_STENCIL_OP_FAIL, RS_COLOR_MASK]) {\n rs[i] = -1;\n rs[i + RS_DESIRED] = -1;\n }\n // clearColor RGBA (standalone, no DESIRED twin) — `-1` forces the first clear\n // to issue gl.clearColor (valid components are 0..1).\n rs[RS_CLEAR_R] = rs[RS_CLEAR_G] = rs[RS_CLEAR_B] = rs[RS_CLEAR_A] = -1;\n}\n\n/** Allocate the 46-slot deferred render-state array (21 actual + 21 desired + 4\n * standalone clearColor) initialised to its unset sentinels — a fresh\n * `Float64Array` is already all `0`, so only the `-1` slots need writing. */\nfunction createRenderStateArray(): Float64Array {\n const rs = new Float64Array(46);\n applyRenderStateSentinels(rs);\n return rs;\n}\n\n/** Re-initialise a live render-state array in place: zero every slot, then\n * restore the `-1` sentinels. */\nfunction resetRenderStateArray(rs: Float64Array): void {\n rs.fill(0);\n applyRenderStateSentinels(rs);\n}\n\n/** Allocate a fresh, fully-null GLState sized for `maxTextureUnits`. */\nexport function createGLState(maxTextureUnits: number): GLState {\n return {\n currentProgram: null,\n activeTextureUnit: 0,\n boundTextures: new Array<WebGLTexture | null>(maxTextureUnits).fill(null),\n boundArrayBuffer: null,\n boundElementBuffer: null,\n boundVao: null,\n viewportX: 0,\n viewportY: 0,\n viewportW: 0,\n viewportH: 0,\n boundFramebuffer: null,\n rs: createRenderStateArray(),\n statesDirty: false,\n scissorEnabled: -1,\n scissorX: 0,\n scissorY: 0,\n scissorW: 0,\n scissorH: 0,\n unpackAlignment: -1,\n unpackFlipY: -1,\n unpackPremultiplyAlpha: -1,\n enabledAttribs: [],\n instanceLocations: [],\n quadVbo: null,\n quadIbo: null,\n quadVao: null,\n };\n}\n\n/** Reset only the cached \"current GL state\" — every binding (program / buffers /\n * textures / VAO / framebuffer) and render-state (blend / depth / stencil /\n * scissor / color-mask / viewport / unpack) field, including the whole `rs`\n * deferred render-state array (BOTH the actual applied values and the DESIRED\n * twins) plus `statesDirty` — to its unset sentinel, WITHOUT discarding owned\n * GPU resources (the shared quad). After this, the next setter in each category\n * is re-issued rather than elided.\n *\n * Used by `resetGLState` (context-lost) and by `wipeGLStateCache` (a host that\n * shares the GL context calling in after mutating raw `gl.*` state). The shared\n * quad's GL objects are still alive in the latter case, so they are preserved\n * here to avoid leaking + needlessly rebuilding them every render scope. */\nexport function resetGLStateCache(state: GLState): void {\n state.currentProgram = null;\n state.activeTextureUnit = 0;\n state.boundTextures.fill(null);\n state.boundArrayBuffer = null;\n state.boundElementBuffer = null;\n state.boundVao = null;\n state.viewportX = 0;\n state.viewportY = 0;\n state.viewportW = 0;\n state.viewportH = 0;\n state.boundFramebuffer = null;\n resetRenderStateArray(state.rs);\n state.statesDirty = false;\n state.scissorEnabled = -1;\n state.scissorX = 0;\n state.scissorY = 0;\n state.scissorW = 0;\n state.scissorH = 0;\n state.unpackAlignment = -1;\n state.unpackFlipY = -1;\n state.unpackPremultiplyAlpha = -1;\n state.enabledAttribs.length = 0;\n state.instanceLocations.length = 0;\n}\n\n/** Zero the cache in-place. Used by the context-lost handler — GL handles are\n * already dead per WebGL spec; we forget what we knew about them (including the\n * shared quad, whose GL objects are gone and must be rebuilt) so the next\n * bind/use after restore is NOT incorrectly elided. */\nexport function resetGLState(state: GLState): void {\n resetGLStateCache(state);\n state.quadVbo = null;\n state.quadIbo = null;\n state.quadVao = null;\n}\n"]}
|
package/texture-3d.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type GLEngineContext } from "./context.js";
|
|
2
|
+
import type { GLEffect } from "./effect.js";
|
|
3
|
+
import { type GLTexture } from "./texture.js";
|
|
4
|
+
/** Sampling and format overrides for {@link createTexture3DFromPixels}. */
|
|
5
|
+
export interface GLPixelsTexture3DOptions {
|
|
6
|
+
/** Wrap mode on all three axes. Defaults to `gl.CLAMP_TO_EDGE`. */
|
|
7
|
+
addressMode?: GLenum;
|
|
8
|
+
/** Minification and magnification filter. Defaults to `gl.LINEAR` (trilinear sampling without mipmaps). */
|
|
9
|
+
filter?: GLenum;
|
|
10
|
+
/** Decode sRGB texels on sampling. Defaults to false (`gl.RGBA8`). */
|
|
11
|
+
srgb?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** A managed `gl.TEXTURE_3D` handle, usable with `setEffectTexture3D` and `sampler3D`. */
|
|
14
|
+
export interface GLTexture3D extends Omit<GLTexture, "target"> {
|
|
15
|
+
/** This target distinguishes 3D volumes from textures accepted by the 2D APIs. */
|
|
16
|
+
readonly target: WebGL2RenderingContext["TEXTURE_3D"];
|
|
17
|
+
/** Number of slices in the volume. */
|
|
18
|
+
depth: number;
|
|
19
|
+
}
|
|
20
|
+
/** Bind a 3D texture to one sampler unit. `null` unbinds only `TEXTURE_3D`; repeated binds are elided. */
|
|
21
|
+
export declare function bindTexture3D(engine: GLEngineContext, unit: number, tex: GLTexture3D | null): void;
|
|
22
|
+
/**
|
|
23
|
+
* Bind a volume to an effect's pre-assigned `sampler3D` unit without reissuing
|
|
24
|
+
* `uniform1i`. Pass `null` to unbind only the 3D target on that unit.
|
|
25
|
+
*/
|
|
26
|
+
export declare function setEffectTexture3D(engine: GLEngineContext, effect: GLEffect, samplerName: string, tex: GLTexture3D | null): void;
|
|
27
|
+
/**
|
|
28
|
+
* Upload a tightly packed RGBA8 volume to a native WebGL2 3D texture. Useful
|
|
29
|
+
* for color-grading LUTs without flattening the cube into a 2D atlas. The
|
|
30
|
+
* default linear, clamp-to-edge sampling interpolates all three axes in
|
|
31
|
+
* hardware. The source must remain unchanged for context-restore replay;
|
|
32
|
+
* release the texture with `disposeTexture3D` when done.
|
|
33
|
+
*
|
|
34
|
+
* @param engine - WebGL2 engine.
|
|
35
|
+
* @param data - `width * height * depth * 4` RGBA bytes; x fastest, then y, then z.
|
|
36
|
+
* @param width - X dimension, a positive integer at most `MAX_3D_TEXTURE_SIZE`.
|
|
37
|
+
* @param height - Y dimension, subject to the same limit.
|
|
38
|
+
* @param depth - Z dimension, subject to the same limit.
|
|
39
|
+
* @param options - Filter, wrap, and sRGB overrides.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createTexture3DFromPixels(engine: GLEngineContext, data: Uint8Array, width: number, height: number, depth: number, options?: GLPixelsTexture3DOptions): GLTexture3D;
|
|
42
|
+
/** Generate a full 3D mip chain for an existing volume and replay it on context restoration. No-op after loss or disposal. */
|
|
43
|
+
export declare function generateTexture3DMipMaps(engine: GLEngineContext, tex: GLTexture3D): void;
|
|
44
|
+
/** Update changed 3D min/mag filters and retain them across context restoration. Unchanged values are elided. */
|
|
45
|
+
export declare function updateTexture3DSamplingMode(engine: GLEngineContext, tex: GLTexture3D, minFilter: GLenum, magFilter: GLenum): void;
|
|
46
|
+
/** Update changed S/T/R wrapping and retain it across context restoration. Unchanged values are elided. */
|
|
47
|
+
export declare function updateTexture3DWrapMode(engine: GLEngineContext, tex: GLTexture3D, wrapS: GLenum, wrapT: GLenum, wrapR: GLenum): void;
|
|
48
|
+
/** Dispose a 3D texture and invalidate any units that still reference its handle. */
|
|
49
|
+
export declare function disposeTexture3D(engine: GLEngineContext, tex: GLTexture3D): void;
|
package/texture-3d.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { onContextLost } from "./context.js";
|
|
2
|
+
import { setUnpackState } from "./texture.js";
|
|
3
|
+
function boundTextures3D(engine) {
|
|
4
|
+
const state = engine._state;
|
|
5
|
+
if (state._boundTextures3D !== undefined) {
|
|
6
|
+
return state._boundTextures3D;
|
|
7
|
+
}
|
|
8
|
+
const bound = new Array(state.boundTextures.length).fill(undefined);
|
|
9
|
+
state._boundTextures3D = bound;
|
|
10
|
+
const invalidate = () => {
|
|
11
|
+
bound.fill(undefined);
|
|
12
|
+
state._unpack3DLayoutKnown = false;
|
|
13
|
+
};
|
|
14
|
+
onContextLost(engine, invalidate);
|
|
15
|
+
(engine._stateCacheInvalidators ??= []).push(invalidate);
|
|
16
|
+
return bound;
|
|
17
|
+
}
|
|
18
|
+
function bindTexture3DRaw(engine, unit, handle, forUpload) {
|
|
19
|
+
const state = engine._state;
|
|
20
|
+
const bound = boundTextures3D(engine);
|
|
21
|
+
if (bound[unit] === handle && !forUpload) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const gl = engine.gl;
|
|
25
|
+
if (state.activeTextureUnit !== unit || bound[unit] === undefined) {
|
|
26
|
+
gl.activeTexture(gl.TEXTURE0 + unit);
|
|
27
|
+
state.activeTextureUnit = unit;
|
|
28
|
+
}
|
|
29
|
+
if (bound[unit] !== handle) {
|
|
30
|
+
gl.bindTexture(gl.TEXTURE_3D, handle);
|
|
31
|
+
bound[unit] = handle;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function setUnpack3DLayout(engine) {
|
|
35
|
+
if (engine._state._unpack3DLayoutKnown) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const gl = engine.gl;
|
|
39
|
+
gl.pixelStorei(gl.UNPACK_ROW_LENGTH, 0);
|
|
40
|
+
gl.pixelStorei(gl.UNPACK_IMAGE_HEIGHT, 0);
|
|
41
|
+
gl.pixelStorei(gl.UNPACK_SKIP_PIXELS, 0);
|
|
42
|
+
gl.pixelStorei(gl.UNPACK_SKIP_ROWS, 0);
|
|
43
|
+
gl.pixelStorei(gl.UNPACK_SKIP_IMAGES, 0);
|
|
44
|
+
engine._state._unpack3DLayoutKnown = true;
|
|
45
|
+
}
|
|
46
|
+
/** Bind a 3D texture to one sampler unit. `null` unbinds only `TEXTURE_3D`; repeated binds are elided. */
|
|
47
|
+
export function bindTexture3D(engine, unit, tex) {
|
|
48
|
+
if (engine._isLost || engine._disposed || tex?._disposed) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
bindTexture3DRaw(engine, unit, tex?.handle ?? null, false);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Bind a volume to an effect's pre-assigned `sampler3D` unit without reissuing
|
|
55
|
+
* `uniform1i`. Pass `null` to unbind only the 3D target on that unit.
|
|
56
|
+
*/
|
|
57
|
+
export function setEffectTexture3D(engine, effect, samplerName, tex) {
|
|
58
|
+
if (engine._isLost || !effect.isReady) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const unit = effect.samplerUnits[samplerName];
|
|
62
|
+
if (unit === undefined) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
bindTexture3D(engine, unit, tex);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Upload a tightly packed RGBA8 volume to a native WebGL2 3D texture. Useful
|
|
69
|
+
* for color-grading LUTs without flattening the cube into a 2D atlas. The
|
|
70
|
+
* default linear, clamp-to-edge sampling interpolates all three axes in
|
|
71
|
+
* hardware. The source must remain unchanged for context-restore replay;
|
|
72
|
+
* release the texture with `disposeTexture3D` when done.
|
|
73
|
+
*
|
|
74
|
+
* @param engine - WebGL2 engine.
|
|
75
|
+
* @param data - `width * height * depth * 4` RGBA bytes; x fastest, then y, then z.
|
|
76
|
+
* @param width - X dimension, a positive integer at most `MAX_3D_TEXTURE_SIZE`.
|
|
77
|
+
* @param height - Y dimension, subject to the same limit.
|
|
78
|
+
* @param depth - Z dimension, subject to the same limit.
|
|
79
|
+
* @param options - Filter, wrap, and sRGB overrides.
|
|
80
|
+
*/
|
|
81
|
+
export function createTexture3DFromPixels(engine, data, width, height, depth, options = {}) {
|
|
82
|
+
const gl = engine.gl;
|
|
83
|
+
const maxSize = gl.getParameter(gl.MAX_3D_TEXTURE_SIZE);
|
|
84
|
+
if (![width, height, depth].every((size) => Number.isSafeInteger(size) && size >= 1 && size <= maxSize)) {
|
|
85
|
+
throw new Error(`lite-gl: 3D texture dimensions must be positive integers <= ${maxSize} (got ${width}x${height}x${depth})`);
|
|
86
|
+
}
|
|
87
|
+
const expected = width * height * depth * 4;
|
|
88
|
+
if (data.length < expected) {
|
|
89
|
+
throw new Error(`lite-gl: 3D texture data too short: need ${expected} RGBA bytes, got ${data.length}`);
|
|
90
|
+
}
|
|
91
|
+
const format = options.srgb ? gl.SRGB8_ALPHA8 : gl.RGBA8;
|
|
92
|
+
const filter = options.filter ?? gl.LINEAR;
|
|
93
|
+
const address = options.addressMode ?? gl.CLAMP_TO_EDGE;
|
|
94
|
+
if (filter !== gl.NEAREST && filter !== gl.LINEAR) {
|
|
95
|
+
throw new Error("lite-gl: 3D texture filter must be gl.NEAREST or gl.LINEAR");
|
|
96
|
+
}
|
|
97
|
+
if (address !== gl.CLAMP_TO_EDGE && address !== gl.REPEAT && address !== gl.MIRRORED_REPEAT) {
|
|
98
|
+
throw new Error("lite-gl: 3D texture addressMode must be gl.CLAMP_TO_EDGE, gl.REPEAT or gl.MIRRORED_REPEAT");
|
|
99
|
+
}
|
|
100
|
+
const handle = gl.createTexture();
|
|
101
|
+
if (handle === null) {
|
|
102
|
+
throw new Error("lite-gl: gl.createTexture returned null");
|
|
103
|
+
}
|
|
104
|
+
const upload = (target) => {
|
|
105
|
+
const g = target.gl;
|
|
106
|
+
setUnpackState(target, false, false, 4);
|
|
107
|
+
setUnpack3DLayout(target);
|
|
108
|
+
bindTexture3DRaw(target, 0, tex.handle, true);
|
|
109
|
+
g.texImage3D(g.TEXTURE_3D, 0, format, width, height, depth, 0, g.RGBA, g.UNSIGNED_BYTE, data);
|
|
110
|
+
if (tex._hasMipMaps) {
|
|
111
|
+
g.generateMipmap(g.TEXTURE_3D);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const initializeParameters = (target) => {
|
|
115
|
+
const g = target.gl;
|
|
116
|
+
g.texParameteri(g.TEXTURE_3D, g.TEXTURE_MIN_FILTER, tex._minFilter);
|
|
117
|
+
g.texParameteri(g.TEXTURE_3D, g.TEXTURE_MAG_FILTER, tex._magFilter);
|
|
118
|
+
g.texParameteri(g.TEXTURE_3D, g.TEXTURE_WRAP_S, tex._wrapS);
|
|
119
|
+
g.texParameteri(g.TEXTURE_3D, g.TEXTURE_WRAP_T, tex._wrapT);
|
|
120
|
+
g.texParameteri(g.TEXTURE_3D, g.TEXTURE_WRAP_R, tex._wrapR);
|
|
121
|
+
};
|
|
122
|
+
const tex = {
|
|
123
|
+
handle,
|
|
124
|
+
target: gl.TEXTURE_3D,
|
|
125
|
+
width,
|
|
126
|
+
height,
|
|
127
|
+
depth,
|
|
128
|
+
isReady: true,
|
|
129
|
+
_minFilter: filter,
|
|
130
|
+
_magFilter: filter,
|
|
131
|
+
_wrapS: address,
|
|
132
|
+
_wrapT: address,
|
|
133
|
+
_wrapR: address,
|
|
134
|
+
_hasMipMaps: false,
|
|
135
|
+
_disposed: false,
|
|
136
|
+
_refCount: 1,
|
|
137
|
+
_upload: upload,
|
|
138
|
+
_initializeParameters: initializeParameters,
|
|
139
|
+
_wasReady: true,
|
|
140
|
+
};
|
|
141
|
+
upload(engine);
|
|
142
|
+
initializeParameters(engine);
|
|
143
|
+
engine._textures.push(tex);
|
|
144
|
+
return tex;
|
|
145
|
+
}
|
|
146
|
+
/** Generate a full 3D mip chain for an existing volume and replay it on context restoration. No-op after loss or disposal. */
|
|
147
|
+
export function generateTexture3DMipMaps(engine, tex) {
|
|
148
|
+
if (engine._isLost || engine._disposed || tex._disposed) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
bindTexture3DRaw(engine, 0, tex.handle, true);
|
|
152
|
+
engine.gl.generateMipmap(engine.gl.TEXTURE_3D);
|
|
153
|
+
tex._hasMipMaps = true;
|
|
154
|
+
}
|
|
155
|
+
/** Update changed 3D min/mag filters and retain them across context restoration. Unchanged values are elided. */
|
|
156
|
+
export function updateTexture3DSamplingMode(engine, tex, minFilter, magFilter) {
|
|
157
|
+
if (engine._isLost || engine._disposed || tex._disposed || (tex._minFilter === minFilter && tex._magFilter === magFilter)) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const gl = engine.gl;
|
|
161
|
+
if (minFilter !== gl.NEAREST &&
|
|
162
|
+
minFilter !== gl.LINEAR &&
|
|
163
|
+
minFilter !== gl.NEAREST_MIPMAP_NEAREST &&
|
|
164
|
+
minFilter !== gl.LINEAR_MIPMAP_NEAREST &&
|
|
165
|
+
minFilter !== gl.NEAREST_MIPMAP_LINEAR &&
|
|
166
|
+
minFilter !== gl.LINEAR_MIPMAP_LINEAR) {
|
|
167
|
+
throw new Error("lite-gl: invalid 3D texture minification filter");
|
|
168
|
+
}
|
|
169
|
+
if (magFilter !== gl.NEAREST && magFilter !== gl.LINEAR) {
|
|
170
|
+
throw new Error("lite-gl: 3D texture magnification filter must be gl.NEAREST or gl.LINEAR");
|
|
171
|
+
}
|
|
172
|
+
bindTexture3DRaw(engine, 0, tex.handle, true);
|
|
173
|
+
if (tex._minFilter !== minFilter) {
|
|
174
|
+
gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MIN_FILTER, minFilter);
|
|
175
|
+
tex._minFilter = minFilter;
|
|
176
|
+
}
|
|
177
|
+
if (tex._magFilter !== magFilter) {
|
|
178
|
+
gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MAG_FILTER, magFilter);
|
|
179
|
+
tex._magFilter = magFilter;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function validTexture3DWrap(gl, mode) {
|
|
183
|
+
return mode === gl.CLAMP_TO_EDGE || mode === gl.REPEAT || mode === gl.MIRRORED_REPEAT;
|
|
184
|
+
}
|
|
185
|
+
/** Update changed S/T/R wrapping and retain it across context restoration. Unchanged values are elided. */
|
|
186
|
+
export function updateTexture3DWrapMode(engine, tex, wrapS, wrapT, wrapR) {
|
|
187
|
+
if (engine._isLost || engine._disposed || tex._disposed || (tex._wrapS === wrapS && tex._wrapT === wrapT && tex._wrapR === wrapR)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const gl = engine.gl;
|
|
191
|
+
if (!validTexture3DWrap(gl, wrapS) || !validTexture3DWrap(gl, wrapT) || !validTexture3DWrap(gl, wrapR)) {
|
|
192
|
+
throw new Error("lite-gl: 3D texture wrap mode must be gl.CLAMP_TO_EDGE, gl.REPEAT or gl.MIRRORED_REPEAT");
|
|
193
|
+
}
|
|
194
|
+
bindTexture3DRaw(engine, 0, tex.handle, true);
|
|
195
|
+
if (tex._wrapS !== wrapS) {
|
|
196
|
+
gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_S, wrapS);
|
|
197
|
+
tex._wrapS = wrapS;
|
|
198
|
+
}
|
|
199
|
+
if (tex._wrapT !== wrapT) {
|
|
200
|
+
gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_T, wrapT);
|
|
201
|
+
tex._wrapT = wrapT;
|
|
202
|
+
}
|
|
203
|
+
if (tex._wrapR !== wrapR) {
|
|
204
|
+
gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_R, wrapR);
|
|
205
|
+
tex._wrapR = wrapR;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/** Dispose a 3D texture and invalidate any units that still reference its handle. */
|
|
209
|
+
export function disposeTexture3D(engine, tex) {
|
|
210
|
+
if (tex._disposed) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (tex._refCount > 1) {
|
|
214
|
+
tex._refCount--;
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
tex._disposed = true;
|
|
218
|
+
const index = engine._textures.indexOf(tex);
|
|
219
|
+
if (index !== -1) {
|
|
220
|
+
engine._textures.splice(index, 1);
|
|
221
|
+
}
|
|
222
|
+
if (!engine._isLost && !engine._disposed) {
|
|
223
|
+
engine.gl.deleteTexture(tex.handle);
|
|
224
|
+
}
|
|
225
|
+
const bound = engine._state._boundTextures3D;
|
|
226
|
+
if (bound !== undefined) {
|
|
227
|
+
for (let unit = 0; unit < bound.length; unit++) {
|
|
228
|
+
if (bound[unit] === tex.handle) {
|
|
229
|
+
bound[unit] = null;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=texture-3d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"texture-3d.js","sourceRoot":"","sources":["../src/texture-3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAwB,MAAM,cAAc,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAkB,MAAM,cAAc,CAAC;AAgC9D,SAAS,eA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CAAC;IACD,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACvC,MAAM,CAAC,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC;IAC7C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACtB,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;YAC7C,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,MAAM,EAAE,CAAC;gBAC7B,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;YACvB,CAAC;QACL,CAAC;IACL,CAAC;AACL,CAAC","sourcesContent":["import { onContextLost, type GLEngineContext } from \"./context.js\";\nimport type { GLEffect } from \"./effect.js\";\nimport { setUnpackState, type GLTexture } from \"./texture.js\";\n\n/** Sampling and format overrides for {@link createTexture3DFromPixels}. */\nexport interface GLPixelsTexture3DOptions {\n /** Wrap mode on all three axes. Defaults to `gl.CLAMP_TO_EDGE`. */\n addressMode?: GLenum;\n /** Minification and magnification filter. Defaults to `gl.LINEAR` (trilinear sampling without mipmaps). */\n filter?: GLenum;\n /** Decode sRGB texels on sampling. Defaults to false (`gl.RGBA8`). */\n srgb?: boolean;\n}\n\n/** A managed `gl.TEXTURE_3D` handle, usable with `setEffectTexture3D` and `sampler3D`. */\nexport interface GLTexture3D extends Omit<GLTexture, \"target\"> {\n /** This target distinguishes 3D volumes from textures accepted by the 2D APIs. */\n readonly target: WebGL2RenderingContext[\"TEXTURE_3D\"];\n /** Number of slices in the volume. */\n depth: number;\n /** @internal */\n _minFilter: GLenum;\n /** @internal */\n _magFilter: GLenum;\n /** @internal */\n _wrapS: GLenum;\n /** @internal */\n _wrapT: GLenum;\n /** @internal */\n _wrapR: GLenum;\n /** @internal */\n _hasMipMaps: boolean;\n}\n\nfunction boundTextures3D(engine: GLEngineContext): (WebGLTexture | null | undefined)[] {\n const state = engine._state;\n if (state._boundTextures3D !== undefined) {\n return state._boundTextures3D;\n }\n const bound = new Array<WebGLTexture | null | undefined>(state.boundTextures.length).fill(undefined);\n state._boundTextures3D = bound;\n const invalidate = (): void => {\n bound.fill(undefined);\n state._unpack3DLayoutKnown = false;\n };\n onContextLost(engine, invalidate);\n (engine._stateCacheInvalidators ??= []).push(invalidate);\n return bound;\n}\n\nfunction bindTexture3DRaw(engine: GLEngineContext, unit: number, handle: WebGLTexture | null, forUpload: boolean): void {\n const state = engine._state;\n const bound = boundTextures3D(engine);\n if (bound[unit] === handle && !forUpload) {\n return;\n }\n const gl = engine.gl;\n if (state.activeTextureUnit !== unit || bound[unit] === undefined) {\n gl.activeTexture(gl.TEXTURE0 + unit);\n state.activeTextureUnit = unit;\n }\n if (bound[unit] !== handle) {\n gl.bindTexture(gl.TEXTURE_3D, handle);\n bound[unit] = handle;\n }\n}\n\nfunction setUnpack3DLayout(engine: GLEngineContext): void {\n if (engine._state._unpack3DLayoutKnown) {\n return;\n }\n const gl = engine.gl;\n gl.pixelStorei(gl.UNPACK_ROW_LENGTH, 0);\n gl.pixelStorei(gl.UNPACK_IMAGE_HEIGHT, 0);\n gl.pixelStorei(gl.UNPACK_SKIP_PIXELS, 0);\n gl.pixelStorei(gl.UNPACK_SKIP_ROWS, 0);\n gl.pixelStorei(gl.UNPACK_SKIP_IMAGES, 0);\n engine._state._unpack3DLayoutKnown = true;\n}\n\n/** Bind a 3D texture to one sampler unit. `null` unbinds only `TEXTURE_3D`; repeated binds are elided. */\nexport function bindTexture3D(engine: GLEngineContext, unit: number, tex: GLTexture3D | null): void {\n if (engine._isLost || engine._disposed || tex?._disposed) {\n return;\n }\n bindTexture3DRaw(engine, unit, tex?.handle ?? null, false);\n}\n\n/**\n * Bind a volume to an effect's pre-assigned `sampler3D` unit without reissuing\n * `uniform1i`. Pass `null` to unbind only the 3D target on that unit.\n */\nexport function setEffectTexture3D(engine: GLEngineContext, effect: GLEffect, samplerName: string, tex: GLTexture3D | null): void {\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const unit = effect.samplerUnits[samplerName];\n if (unit === undefined) {\n return;\n }\n bindTexture3D(engine, unit, tex);\n}\n\n/**\n * Upload a tightly packed RGBA8 volume to a native WebGL2 3D texture. Useful\n * for color-grading LUTs without flattening the cube into a 2D atlas. The\n * default linear, clamp-to-edge sampling interpolates all three axes in\n * hardware. The source must remain unchanged for context-restore replay;\n * release the texture with `disposeTexture3D` when done.\n *\n * @param engine - WebGL2 engine.\n * @param data - `width * height * depth * 4` RGBA bytes; x fastest, then y, then z.\n * @param width - X dimension, a positive integer at most `MAX_3D_TEXTURE_SIZE`.\n * @param height - Y dimension, subject to the same limit.\n * @param depth - Z dimension, subject to the same limit.\n * @param options - Filter, wrap, and sRGB overrides.\n */\nexport function createTexture3DFromPixels(\n engine: GLEngineContext,\n data: Uint8Array,\n width: number,\n height: number,\n depth: number,\n options: GLPixelsTexture3DOptions = {}\n): GLTexture3D {\n const gl = engine.gl;\n const maxSize = gl.getParameter(gl.MAX_3D_TEXTURE_SIZE) as number;\n if (![width, height, depth].every((size) => Number.isSafeInteger(size) && size >= 1 && size <= maxSize)) {\n throw new Error(`lite-gl: 3D texture dimensions must be positive integers <= ${maxSize} (got ${width}x${height}x${depth})`);\n }\n const expected = width * height * depth * 4;\n if (data.length < expected) {\n throw new Error(`lite-gl: 3D texture data too short: need ${expected} RGBA bytes, got ${data.length}`);\n }\n const format = options.srgb ? gl.SRGB8_ALPHA8 : gl.RGBA8;\n const filter = options.filter ?? gl.LINEAR;\n const address = options.addressMode ?? gl.CLAMP_TO_EDGE;\n if (filter !== gl.NEAREST && filter !== gl.LINEAR) {\n throw new Error(\"lite-gl: 3D texture filter must be gl.NEAREST or gl.LINEAR\");\n }\n if (address !== gl.CLAMP_TO_EDGE && address !== gl.REPEAT && address !== gl.MIRRORED_REPEAT) {\n throw new Error(\"lite-gl: 3D texture addressMode must be gl.CLAMP_TO_EDGE, gl.REPEAT or gl.MIRRORED_REPEAT\");\n }\n const handle = gl.createTexture();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createTexture returned null\");\n }\n\n const upload = (target: GLEngineContext): void => {\n const g = target.gl;\n setUnpackState(target, false, false, 4);\n setUnpack3DLayout(target);\n bindTexture3DRaw(target, 0, tex.handle, true);\n g.texImage3D(g.TEXTURE_3D, 0, format, width, height, depth, 0, g.RGBA, g.UNSIGNED_BYTE, data);\n if (tex._hasMipMaps) {\n g.generateMipmap(g.TEXTURE_3D);\n }\n };\n const initializeParameters = (target: GLEngineContext): void => {\n const g = target.gl;\n g.texParameteri(g.TEXTURE_3D, g.TEXTURE_MIN_FILTER, tex._minFilter);\n g.texParameteri(g.TEXTURE_3D, g.TEXTURE_MAG_FILTER, tex._magFilter);\n g.texParameteri(g.TEXTURE_3D, g.TEXTURE_WRAP_S, tex._wrapS);\n g.texParameteri(g.TEXTURE_3D, g.TEXTURE_WRAP_T, tex._wrapT);\n g.texParameteri(g.TEXTURE_3D, g.TEXTURE_WRAP_R, tex._wrapR);\n };\n const tex: GLTexture3D = {\n handle,\n target: gl.TEXTURE_3D,\n width,\n height,\n depth,\n isReady: true,\n _minFilter: filter,\n _magFilter: filter,\n _wrapS: address,\n _wrapT: address,\n _wrapR: address,\n _hasMipMaps: false,\n _disposed: false,\n _refCount: 1,\n _upload: upload,\n _initializeParameters: initializeParameters,\n _wasReady: true,\n };\n upload(engine);\n initializeParameters(engine);\n engine._textures.push(tex);\n return tex;\n}\n\n/** Generate a full 3D mip chain for an existing volume and replay it on context restoration. No-op after loss or disposal. */\nexport function generateTexture3DMipMaps(engine: GLEngineContext, tex: GLTexture3D): void {\n if (engine._isLost || engine._disposed || tex._disposed) {\n return;\n }\n bindTexture3DRaw(engine, 0, tex.handle, true);\n engine.gl.generateMipmap(engine.gl.TEXTURE_3D);\n tex._hasMipMaps = true;\n}\n\n/** Update changed 3D min/mag filters and retain them across context restoration. Unchanged values are elided. */\nexport function updateTexture3DSamplingMode(engine: GLEngineContext, tex: GLTexture3D, minFilter: GLenum, magFilter: GLenum): void {\n if (engine._isLost || engine._disposed || tex._disposed || (tex._minFilter === minFilter && tex._magFilter === magFilter)) {\n return;\n }\n const gl = engine.gl;\n if (\n minFilter !== gl.NEAREST &&\n minFilter !== gl.LINEAR &&\n minFilter !== gl.NEAREST_MIPMAP_NEAREST &&\n minFilter !== gl.LINEAR_MIPMAP_NEAREST &&\n minFilter !== gl.NEAREST_MIPMAP_LINEAR &&\n minFilter !== gl.LINEAR_MIPMAP_LINEAR\n ) {\n throw new Error(\"lite-gl: invalid 3D texture minification filter\");\n }\n if (magFilter !== gl.NEAREST && magFilter !== gl.LINEAR) {\n throw new Error(\"lite-gl: 3D texture magnification filter must be gl.NEAREST or gl.LINEAR\");\n }\n bindTexture3DRaw(engine, 0, tex.handle, true);\n if (tex._minFilter !== minFilter) {\n gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MIN_FILTER, minFilter);\n tex._minFilter = minFilter;\n }\n if (tex._magFilter !== magFilter) {\n gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MAG_FILTER, magFilter);\n tex._magFilter = magFilter;\n }\n}\n\nfunction validTexture3DWrap(gl: WebGL2RenderingContext, mode: GLenum): boolean {\n return mode === gl.CLAMP_TO_EDGE || mode === gl.REPEAT || mode === gl.MIRRORED_REPEAT;\n}\n\n/** Update changed S/T/R wrapping and retain it across context restoration. Unchanged values are elided. */\nexport function updateTexture3DWrapMode(engine: GLEngineContext, tex: GLTexture3D, wrapS: GLenum, wrapT: GLenum, wrapR: GLenum): void {\n if (engine._isLost || engine._disposed || tex._disposed || (tex._wrapS === wrapS && tex._wrapT === wrapT && tex._wrapR === wrapR)) {\n return;\n }\n const gl = engine.gl;\n if (!validTexture3DWrap(gl, wrapS) || !validTexture3DWrap(gl, wrapT) || !validTexture3DWrap(gl, wrapR)) {\n throw new Error(\"lite-gl: 3D texture wrap mode must be gl.CLAMP_TO_EDGE, gl.REPEAT or gl.MIRRORED_REPEAT\");\n }\n bindTexture3DRaw(engine, 0, tex.handle, true);\n if (tex._wrapS !== wrapS) {\n gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_S, wrapS);\n tex._wrapS = wrapS;\n }\n if (tex._wrapT !== wrapT) {\n gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_T, wrapT);\n tex._wrapT = wrapT;\n }\n if (tex._wrapR !== wrapR) {\n gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_WRAP_R, wrapR);\n tex._wrapR = wrapR;\n }\n}\n\n/** Dispose a 3D texture and invalidate any units that still reference its handle. */\nexport function disposeTexture3D(engine: GLEngineContext, tex: GLTexture3D): void {\n if (tex._disposed) {\n return;\n }\n if (tex._refCount > 1) {\n tex._refCount--;\n return;\n }\n tex._disposed = true;\n const index = engine._textures.indexOf(tex);\n if (index !== -1) {\n engine._textures.splice(index, 1);\n }\n if (!engine._isLost && !engine._disposed) {\n engine.gl.deleteTexture(tex.handle);\n }\n const bound = engine._state._boundTextures3D;\n if (bound !== undefined) {\n for (let unit = 0; unit < bound.length; unit++) {\n if (bound[unit] === tex.handle) {\n bound[unit] = null;\n }\n }\n }\n}\n"]}
|
package/texture.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export interface GLTexture {
|
|
|
40
40
|
/** The live `WebGLTexture`. MUTABLE — swapped for a fresh handle on
|
|
41
41
|
* `webglcontextrestored` while consumers keep the same `GLTexture` reference. */
|
|
42
42
|
handle: WebGLTexture;
|
|
43
|
-
/** GL texture target (
|
|
43
|
+
/** GL texture target (normally `gl.TEXTURE_2D`); 3D textures use their own API. */
|
|
44
44
|
readonly target: GLenum;
|
|
45
45
|
/** Texture width in texels. Updated once an async upload resolves. */
|
|
46
46
|
width: number;
|
package/texture.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{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,SAAS,CAAC;QACxB,CAAC;IACL,CAAC;IACD,IAAI,IAAI,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,MAAM,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;YACrB,OAAO,EAAE,CAAC,OAAO,CAAC;QACtB,CAAC;QACD,IAAI,MAAM,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC,MAAM,CAAC;QACrB,CAAC;IACL,CAAC;IACD,IAAI,IAAI,KAAK,EAAE,CAAC,UAAU,EAAE,CAAC;QACzB,IAAI,MAAM,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;YACrB,OAAO,EAAE,CAAC,OAAO,CAAC;QACtB,CAAC;QACD,IAAI,MAAM,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC,MAAM,CAAC;QACrB,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\n\n/** Texture sampling / wrap options. All have GL-spec defaults. Mipmaps are NOT\n * a create option — generate the chain explicitly via {@link generateTextureMipMaps}. */\nexport interface GLTextureOptions {\n /** Default: false (matches Babylon's default raw-texture behaviour). */\n invertY?: boolean;\n /** Default: gl.LINEAR. */\n minFilter?: GLenum;\n /** Default: gl.LINEAR. */\n magFilter?: GLenum;\n /** Default: gl.CLAMP_TO_EDGE. May be `gl.REPEAT` / `gl.MIRRORED_REPEAT`\n * (NPOT-safe in WebGL2). */\n wrapS?: GLenum;\n /** Default: gl.CLAMP_TO_EDGE. May be `gl.REPEAT` / `gl.MIRRORED_REPEAT`. */\n wrapT?: GLenum;\n /** `gl.pixelStorei(UNPACK_ALIGNMENT)` for the upload (1/2/4/8). Default 4.\n * Use 1 for tightly-packed non-RGBA rows. */\n unpackAlignment?: number;\n /** Premultiply alpha at upload (`UNPACK_PREMULTIPLY_ALPHA_WEBGL`). Default\n * false. */\n premultiplyAlpha?: boolean;\n /** Explicit sized internalFormat for `texImage2D`. When provided it is used\n * verbatim and the inline LDR resolver is bypassed — this is how\n * {@link createFloatTexture} injects its `RGBA16F` / `RGBA32F` choice\n * without the byte path ever referencing the float-format table (keeping it\n * tree-shakeable out of RGBA8-only bundles). Default: derived from\n * `format`/`type` via the LDR resolver. */\n internalFormat?: GLenum;\n}\n\n/**\n * Pure-state texture handle. The `handle` field is MUTABLE so the same logical\n * texture survives a `webglcontextrestored` event — every consumer keeps the\n * same `GLTexture` reference; only the internal `WebGLTexture` is swapped.\n *\n * `loadTexture2D` also uses the same handle for the 1×1 placeholder upload AND\n * the final image upload — so a `bindTexture(engine, unit, tex)` made before the\n * image has decoded remains valid once the image arrives.\n */\nexport interface GLTexture {\n /** The live `WebGLTexture`. MUTABLE — swapped for a fresh handle on\n * `webglcontextrestored` while consumers keep the same `GLTexture` reference. */\n handle: WebGLTexture;\n /** GL texture target (always `gl.TEXTURE_2D` for this package). */\n readonly target: GLenum;\n /** Texture width in texels. Updated once an async upload resolves. */\n width: number;\n /** Texture height in texels. Updated once an async upload resolves. */\n height: number;\n /** True when the texture is safe to sample with final content (placeholders\n * read as not-ready until their image/upload completes). */\n isReady: boolean;\n /** @internal */\n _disposed: boolean;\n /** @internal */\n _refCount: number;\n /** Replays the latest pixel content into the currently bound texture handle. @internal */\n _upload: (engine: GLEngineContext) => void;\n /** Initializes creation-time sampling state on the bound texture handle. @internal */\n _initializeParameters?: (engine: GLEngineContext) => void;\n /**\n * Snapshot of `isReady` captured on `webglcontextlost` so the restore\n * handler knows whether to flip it back on after `_upload`. Textures\n * that were still mid-load (e.g. `loadTexture2D` whose bitmap hadn't\n * arrived) stay not-ready; the async path will set `isReady=true` once\n * the bitmap finishes decoding into the new handle.\n * @internal\n */\n _wasReady: boolean;\n /**\n * Live re-upload hook installed by `createRawTexture` — lets\n * `updateRawTexture` replace the pixel data (and optionally the size)\n * through the same closure that the context-restore replay uses, keeping\n * restore correct. Absent on image / HTML-element / external textures.\n * @internal\n */\n _updateRaw?: (engine: GLEngineContext, data: ArrayBufferView | null, width: number, height: number, unpackAlignment: number) => void;\n /**\n * Dynamic-texture source captured by `updateDynamicTexture`\n * (`@babylonjs/lite-gl`) and replayed into the fresh handle\n * on `webglcontextrestored`. Null/absent on non-dynamic textures.\n * @internal\n */\n _dynSource?: TexImageSource | null;\n /** UNPACK_FLIP_Y applied when replaying {@link GLTexture._dynSource}. @internal */\n _dynInvertY?: boolean;\n /** UNPACK_PREMULTIPLY_ALPHA applied when replaying {@link GLTexture._dynSource}. @internal */\n _dynPremultiplyAlpha?: boolean;\n /**\n * The `handle` the dynamic texture's `texParameteri` filter/wrap state was\n * last applied to. `texParameteri` is per-texture GL state that survives pixel\n * re-uploads, so the dynamic-texture `_upload` re-applies it ONLY when this no\n * longer matches `handle` — i.e. at creation and after `webglcontextrestored`\n * installs a fresh handle — not on every per-frame `updateDynamicTexture`.\n * @internal\n */\n _dynParamsHandle?: WebGLTexture | null;\n}\n\n/**\n * Apply the three `UNPACK_*` pixel-store flags through the GL-state cache,\n * eliding redundant `pixelStorei` calls. Centralising this guarantees EVERY\n * upload path sets all three explicitly, so a premultiplying / flipping upload\n * never leaks its flag into a later upload that forgot to set it.\n * @internal\n */\nexport function setUnpackState(engine: GLEngineContext, flipY: boolean, premultiplyAlpha: boolean, alignment = 4): void {\n const gl = engine.gl;\n const s = engine._state;\n const fy = flipY ? 1 : 0;\n if (s.unpackFlipY !== fy) {\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, fy);\n s.unpackFlipY = fy;\n }\n const pm = premultiplyAlpha ? 1 : 0;\n if (s.unpackPremultiplyAlpha !== pm) {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, pm);\n s.unpackPremultiplyAlpha = pm;\n }\n if (s.unpackAlignment !== alignment) {\n gl.pixelStorei(gl.UNPACK_ALIGNMENT, alignment);\n s.unpackAlignment = alignment;\n }\n}\n\n/** Apply sampling and wrap state to the texture currently bound for upload. @internal */\nexport function setBoundTextureParams(gl: WebGL2RenderingContext, minFilter: GLenum, magFilter: GLenum, wrapS: GLenum, wrapT: GLenum): void {\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT);\n}\n\n/** Uint8 / float raw texture upload. The pixel data can be replaced later via\n * {@link updateRawTexture}; the sampling and wrap can be changed via\n * {@link updateTextureSamplingMode} / {@link updateTextureWrapMode}. */\nexport function createRawTexture(\n engine: GLEngineContext,\n data: ArrayBufferView | null,\n width: number,\n height: number,\n format: GLenum,\n type: GLenum,\n options?: GLTextureOptions\n): GLTexture {\n const gl = engine.gl;\n const handle = gl.createTexture();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createTexture returned null\");\n }\n const opts = options ?? {};\n const minFilter = opts.minFilter ?? gl.LINEAR;\n const magFilter = opts.magFilter ?? gl.LINEAR;\n const wrapS = opts.wrapS ?? gl.CLAMP_TO_EDGE;\n const wrapT = opts.wrapT ?? gl.CLAMP_TO_EDGE;\n const invertY = opts.invertY ?? false;\n const premultiply = opts.premultiplyAlpha ?? false;\n // LDR byte formats are resolved INLINE here; the float-format table in\n // `pickSizedInternalFormat` is deliberately NOT referenced from this path so\n // it tree-shakes out of byte-only bundles. `createFloatTexture` injects its\n // sized float format via `opts.internalFormat`.\n const internalFormat = opts.internalFormat ?? resolveLdrInternalFormat(gl, format, type);\n\n // Mutable upload state — `updateRawTexture` mutates these and re-runs\n // `upload`, so the context-restore replay (which calls the same `upload`)\n // always reproduces the latest contents.\n let curData = data;\n let curWidth = width;\n let curHeight = height;\n let curAlign = opts.unpackAlignment ?? 4;\n\n const upload = (target: GLEngineContext): void => {\n const g = target.gl;\n setUnpackState(target, invertY, premultiply, curAlign);\n bindTextureForUpload(target, tex.handle);\n g.texImage2D(g.TEXTURE_2D, 0, internalFormat, curWidth, curHeight, 0, format, type, curData);\n };\n\n const initializeParameters = (target: GLEngineContext): void => {\n setBoundTextureParams(target.gl, minFilter, magFilter, wrapS, wrapT);\n };\n\n const tex: GLTexture = {\n handle,\n target: gl.TEXTURE_2D,\n width,\n height,\n isReady: true,\n _disposed: false,\n _refCount: 1,\n _upload: upload,\n _initializeParameters: initializeParameters,\n _wasReady: true,\n };\n tex._updateRaw = (target: GLEngineContext, newData: ArrayBufferView | null, newWidth: number, newHeight: number, unpackAlignment: number): void => {\n curData = newData;\n curWidth = newWidth;\n curHeight = newHeight;\n curAlign = unpackAlignment;\n tex.width = newWidth;\n tex.height = newHeight;\n upload(target);\n };\n upload(engine);\n initializeParameters(engine);\n engine._textures.push(tex);\n return tex;\n}\n\n/** Options for {@link createFloatTexture} — the shared {@link GLTextureOptions}\n * plus the float-specific `type` / `format`. */\nexport interface GLFloatTextureOptions extends GLTextureOptions {\n /** Float texel type — `gl.HALF_FLOAT` (default) or `gl.FLOAT`. */\n type?: GLenum;\n /** Color format. Default `gl.RGBA`. */\n format?: GLenum;\n}\n\n/**\n * Create a float / half-float raw texture — the HDR counterpart of\n * {@link createRawTexture}. This is the ONLY texture factory that carries the\n * `RGBA16F` / `RGBA32F` sized-format knowledge (via {@link pickSizedInternalFormat}),\n * so byte-only consumers calling {@link createRawTexture} ship none of it.\n * Defaults to `gl.HALF_FLOAT`; pass `options.type = gl.FLOAT` for full 32-bit.\n * The caller is responsible for the matching engine cap (e.g.\n * `caps.textureFloatLinearFiltering`) when sampling these with `LINEAR`.\n *\n * @param engine - The engine.\n * @param data - Initial pixels (`Float32Array` for FLOAT, `Uint16Array` for\n * HALF_FLOAT), or `null` for an uninitialised allocation.\n * @param width - Texture width in texels (≥ 1).\n * @param height - Texture height in texels (≥ 1).\n * @param options - See {@link GLFloatTextureOptions}.\n * @returns The new {@link GLTexture}.\n */\nexport function createFloatTexture(engine: GLEngineContext, data: ArrayBufferView | null, width: number, height: number, options?: GLFloatTextureOptions): GLTexture {\n const gl = engine.gl;\n const o = options ?? {};\n const format = o.format ?? gl.RGBA;\n const type = o.type ?? gl.HALF_FLOAT;\n // Precompute the sized float internalFormat HERE and pass it through, so\n // `createRawTexture`'s inline LDR resolver is bypassed and the float table\n // stays out of byte-only bundles.\n const internalFormat = pickSizedInternalFormat(gl, format, type);\n return createRawTexture(engine, data, width, height, format, type, { ...o, internalFormat });\n}\n\n/** Generate the mip chain for a texture from its level-0 contents — mipmaps as\n * an explicit opt-in function rather than baked into the create path. Binds for\n * upload (unit 0). No-op on a lost/disposed context or a handle-less texture. */\nexport function generateTextureMipMaps(engine: GLEngineContext, tex: GLTexture): void {\n if (engine._isLost || engine._disposed || tex._disposed || tex.handle === null) {\n return;\n }\n bindTextureForUpload(engine, tex.handle);\n engine.gl.generateMipmap(engine.gl.TEXTURE_2D);\n}\n\n/**\n * Re-upload the pixel data (and optionally resize) of a texture created by\n * {@link createRawTexture} — the lite-gl equivalent of Babylon's\n * `updateRawTexture` / `_uploadDataToTextureDirectly`. Goes through the same\n * upload closure used by context-restore, so the new contents survive a context\n * loss. No-op on a lost/disposed/non-raw texture.\n *\n * @param engine - The engine.\n * @param tex - The raw texture to update.\n * @param data - New pixel data (must match the original `format`/`type`).\n * @param options - Optional new `width`/`height` (default: unchanged) and\n * `unpackAlignment` (default 4).\n */\nexport function updateRawTexture(\n engine: GLEngineContext,\n tex: GLTexture,\n data: ArrayBufferView | null,\n options?: { width?: number; height?: number; unpackAlignment?: number }\n): void {\n if (engine._isLost || engine._disposed || tex._disposed || tex._updateRaw === undefined) {\n return;\n }\n const o = options ?? {};\n tex._updateRaw(engine, data, o.width ?? tex.width, o.height ?? tex.height, o.unpackAlignment ?? 4);\n}\n\n/** Update a texture's min/mag sampling filters — the lite-gl equivalent of\n * Babylon's `updateTextureSamplingMode`. Binds for upload (unit 0) so the\n * `texParameteri` lands on this texture. No-op on a lost/disposed context. */\nexport function updateTextureSamplingMode(engine: GLEngineContext, tex: GLTexture, minFilter: GLenum, magFilter: GLenum): void {\n if (engine._isLost || engine._disposed || tex._disposed) {\n return;\n }\n const gl = engine.gl;\n bindTextureForUpload(engine, tex.handle);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);\n}\n\n/** Update a texture's S/T wrap modes (`gl.CLAMP_TO_EDGE` / `gl.REPEAT` /\n * `gl.MIRRORED_REPEAT`) — the lite-gl equivalent of Babylon's\n * `updateTextureWrappingMode`. No-op on a lost/disposed context. */\nexport function updateTextureWrapMode(engine: GLEngineContext, tex: GLTexture, wrapS: GLenum, wrapT: GLenum): void {\n if (engine._isLost || engine._disposed || tex._disposed) {\n return;\n }\n const gl = engine.gl;\n bindTextureForUpload(engine, tex.handle);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT);\n}\n\n/**\n * Wrap an existing raw `WebGLTexture` (e.g. one created by a host renderer or a\n * previous engine) as a {@link GLTexture} — the lite-gl equivalent of\n * ShapeBuilder's `createTextureGraphicsResourceFromExternalWebGLTexture`.\n *\n * The wrapper does NOT own the underlying handle's upload — it is NOT registered\n * for context-restore replay (the external owner is responsible for that) and is\n * marked ready immediately. `disposeTexture` will still `gl.deleteTexture` it, so\n * only wrap a handle whose deletion you intend lite-gl to manage.\n *\n * @param engine - The engine.\n * @param handle - The external `WebGLTexture`.\n * @param width - Texture width in texels.\n * @param height - Texture height in texels.\n * @param options - Optional sampling/wrap to apply once (min/mag/wrapS/wrapT).\n * @returns A {@link GLTexture} wrapping the handle.\n */\nexport function createTextureFromHandle(engine: GLEngineContext, handle: WebGLTexture, width: number, height: number, options?: GLTextureOptions): GLTexture {\n const tex: GLTexture = {\n handle,\n target: engine.gl.TEXTURE_2D,\n width,\n height,\n isReady: true,\n _disposed: false,\n _refCount: 1,\n // External handle — restore replay is the external owner's job.\n _upload: () => {},\n _wasReady: true,\n };\n if (options !== undefined) {\n const gl = engine.gl;\n bindTextureForUpload(engine, handle);\n setBoundTextureParams(gl, options.minFilter ?? gl.LINEAR, options.magFilter ?? gl.LINEAR, options.wrapS ?? gl.CLAMP_TO_EDGE, options.wrapT ?? gl.CLAMP_TO_EDGE);\n }\n return tex;\n}\n\n/** Asynchronous image upload.The returned texture is immediately usable (1×1\n * transparent placeholder); `isReady` flips true once the image has been\n * decoded and uploaded. The decoded `ImageBitmap` is retained on the texture\n * for offline-safe `webglcontextrestored` replay. */\nexport function loadTexture2D(engine: GLEngineContext, url: string, options?: GLTextureOptions, onLoad?: (tex: GLTexture) => void, onError?: (err: Error) => void): GLTexture {\n const gl = engine.gl;\n const handle = gl.createTexture();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createTexture returned null\");\n }\n const opts = options ?? {};\n const minFilter = opts.minFilter ?? gl.LINEAR;\n const magFilter = opts.magFilter ?? gl.LINEAR;\n const wrapS = opts.wrapS ?? gl.CLAMP_TO_EDGE;\n const wrapT = opts.wrapT ?? gl.CLAMP_TO_EDGE;\n const invertY = opts.invertY ?? false;\n\n let bitmap: ImageBitmap | null = null;\n const placeholderPixels = new Uint8Array([0, 0, 0, 0]);\n\n const upload = (target: GLEngineContext): void => {\n const g = target.gl;\n // invertY is applied at decode time via createImageBitmap({ imageOrientation })\n // because UNPACK_FLIP_Y_WEBGL is IGNORED for ImageBitmap sources (and the 1×1\n // placeholder is flip-invariant), so keep flip + premultiply off here.\n setUnpackState(target, false, false);\n bindTextureForUpload(target, tex.handle);\n if (bitmap !== null) {\n g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, g.RGBA, g.UNSIGNED_BYTE, bitmap);\n tex.width = bitmap.width;\n tex.height = bitmap.height;\n } else {\n g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, 1, 1, 0, g.RGBA, g.UNSIGNED_BYTE, placeholderPixels);\n }\n };\n\n const initializeParameters = (target: GLEngineContext): void => {\n setBoundTextureParams(target.gl, minFilter, magFilter, wrapS, wrapT);\n };\n\n const tex: GLTexture = {\n handle,\n target: gl.TEXTURE_2D,\n width: 1,\n height: 1,\n isReady: false,\n _disposed: false,\n _refCount: 1,\n _upload: upload,\n _initializeParameters: initializeParameters,\n _wasReady: false,\n };\n // Placeholder upload — makes the texture sampleable before the real image arrives.\n upload(engine);\n initializeParameters(engine);\n engine._textures.push(tex);\n\n // Fetch + decode the real image. Re-uploads via the same closure once the\n // bitmap is in hand (so context-restore replay sees the real image too).\n fetch(url)\n .then((r) => {\n if (!r.ok) {\n throw new Error(`lite-gl: fetch ${url} -> HTTP ${r.status}`);\n }\n return r.blob();\n })\n .then((blob) => createImageBitmap(blob, { premultiplyAlpha: \"none\", imageOrientation: invertY ? \"flipY\" : \"none\" }))\n .then((bm) => {\n if (tex._disposed) {\n bm.close();\n return;\n }\n bitmap = bm;\n // If the context is lost mid-flight, defer the upload — the restore\n // handler will call _upload again, which will then see `bitmap !== null`\n // and replay the real image.\n if (!engine._isLost) {\n upload(engine);\n tex.isReady = true;\n }\n tex._wasReady = true;\n if (onLoad !== undefined) {\n onLoad(tex);\n }\n })\n .catch((err: unknown) => {\n const e = err instanceof Error ? err : new Error(String(err));\n if (onError !== undefined) {\n onError(e);\n } else {\n console.error(\"lite-gl: loadTexture2D failed\", e);\n }\n });\n\n return tex;\n}\n\n/** Cached bind. Skips `gl.activeTexture` and/or `gl.bindTexture` when nothing\n * changes. No-op when `tex._disposed` or `engine._isLost`. */\nexport function bindTexture(engine: GLEngineContext, unit: number, tex: GLTexture | null): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n if (tex !== null && tex._disposed) {\n return;\n }\n bindTextureRaw(engine, unit, tex === null ? null : tex.handle);\n}\n\n/** @internal — for callers that already hold a raw `WebGLTexture`. Not part of\n * the public API: `bindTexture` (public) and the texture `_upload` closures bind\n * through the cache, so consumers never call this directly. */\nexport function bindTextureRaw(engine: GLEngineContext, unit: number, handle: WebGLTexture | null): void {\n const s = engine._state;\n const gl = engine.gl;\n if (s.boundTextures[unit] === handle) {\n return;\n }\n if (s.activeTextureUnit !== unit) {\n gl.activeTexture(gl.TEXTURE0 + unit);\n s.activeTextureUnit = unit;\n }\n gl.bindTexture(gl.TEXTURE_2D, handle);\n s.boundTextures[unit] = handle;\n}\n\n/** @internal Bind `handle` on texture unit 0 **for an upload** (`texImage2D`).\n * Unlike {@link bindTextureRaw} — which elides the entire bind when the handle is\n * already bound on the unit (correct for *sampling*, where the active unit is\n * irrelevant) — an upload writes into the texture on the ACTIVE unit. A prior\n * multi-sampler draw may have left a non-zero unit active while this handle is\n * still bound on unit 0, so we must force unit 0 active even on a bind cache-hit,\n * keeping the `_state` cache coherent. */\nexport function bindTextureForUpload(engine: GLEngineContext, handle: WebGLTexture): void {\n const s = engine._state;\n const gl = engine.gl;\n if (s.activeTextureUnit !== 0) {\n gl.activeTexture(gl.TEXTURE0);\n s.activeTextureUnit = 0;\n }\n if (s.boundTextures[0] !== handle) {\n gl.bindTexture(gl.TEXTURE_2D, handle);\n s.boundTextures[0] = handle;\n }\n}\n\n/** Disposes the texture. Walks `_state.boundTextures` and clears every slot\n * that still references the handle — otherwise a later `bindTexture(unit, B)`\n * to the same unit would be wrongly elided when slot still showed handle A. */\nexport function disposeTexture(engine: GLEngineContext, tex: GLTexture): void {\n if (tex._disposed) {\n return;\n }\n if (tex._refCount > 1) {\n tex._refCount--;\n return;\n }\n tex._disposed = true;\n const i = engine._textures.indexOf(tex);\n if (i !== -1) {\n engine._textures.splice(i, 1);\n }\n if (!engine._isLost && !engine._disposed) {\n engine.gl.deleteTexture(tex.handle);\n }\n const bound = engine._state.boundTextures;\n for (let u = 0; u < bound.length; u++) {\n if (bound[u] === tex.handle) {\n bound[u] = null;\n }\n }\n}\n\n/** Internal — resolve the sized internalFormat for the LDR (byte) `texImage2D`\n * paths ONLY: RGBA→RGBA8, RGB→RGB8, RG→RG8, RED→R8, LUMINANCE passthrough.\n * Deliberately knows nothing about FLOAT / HALF_FLOAT so the float-format table\n * in {@link pickSizedInternalFormat} tree-shakes out of byte-only bundles.\n * @internal */\nfunction resolveLdrInternalFormat(gl: WebGL2RenderingContext, format: GLenum, type: GLenum): GLenum {\n if (type === gl.UNSIGNED_BYTE) {\n if (format === gl.RGBA) {\n return gl.RGBA8;\n }\n if (format === gl.RGB) {\n return gl.RGB8;\n }\n if (format === gl.RG) {\n return gl.RG8;\n }\n if (format === gl.RED) {\n return gl.R8;\n }\n if (format === gl.LUMINANCE) {\n return gl.LUMINANCE;\n }\n }\n return format;\n}\n\n/** Internal — pick a sized internalFormat for `texImage2D`. WebGL2 prefers\n * sized formats for non-color-renderable / non-readback paths; for the\n * NeonBrush use cases (sample-only) the unsized format works too, but sized\n * is more portable. Shared with the render-target module.\n * @internal */\nexport function pickSizedInternalFormat(gl: WebGL2RenderingContext, format: GLenum, type: GLenum): GLenum {\n if (type === gl.UNSIGNED_BYTE) {\n if (format === gl.RGBA) {\n return gl.RGBA8;\n }\n if (format === gl.RGB) {\n return gl.RGB8;\n }\n if (format === gl.LUMINANCE) {\n return gl.LUMINANCE;\n }\n }\n if (type === gl.FLOAT) {\n if (format === gl.RGBA) {\n return gl.RGBA32F;\n }\n if (format === gl.RGB) {\n return gl.RGB32F;\n }\n }\n if (type === gl.HALF_FLOAT) {\n if (format === gl.RGBA) {\n return gl.RGBA16F;\n }\n if (format === gl.RGB) {\n return gl.RGB16F;\n }\n }\n return format;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"texture.js","sourceRoot":"","sources":["../src/texture.ts"],"names":[],"mappings":"AAoGA;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,MAAuB,EAAE,KAAc,EAAE,gBAAyB,EAAE,SAAS,GAAG,CAAC;IAC5G,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IACrB,MAAM,CA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AAG,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC,MAAM,CAAC;QACrB,CAAC;IACL,CAAC;IACD,IAAI,IAAI,KAAK,EAAE,CAAC,UAAU,EAAE,CAAC;QACzB,IAAI,MAAM,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;YACrB,OAAO,EAAE,CAAC,OAAO,CAAC;QACtB,CAAC;QACD,IAAI,MAAM,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC,MAAM,CAAC;QACrB,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\n\n/** Texture sampling / wrap options. All have GL-spec defaults. Mipmaps are NOT\n * a create option — generate the chain explicitly via {@link generateTextureMipMaps}. */\nexport interface GLTextureOptions {\n /** Default: false (matches Babylon's default raw-texture behaviour). */\n invertY?: boolean;\n /** Default: gl.LINEAR. */\n minFilter?: GLenum;\n /** Default: gl.LINEAR. */\n magFilter?: GLenum;\n /** Default: gl.CLAMP_TO_EDGE. May be `gl.REPEAT` / `gl.MIRRORED_REPEAT`\n * (NPOT-safe in WebGL2). */\n wrapS?: GLenum;\n /** Default: gl.CLAMP_TO_EDGE. May be `gl.REPEAT` / `gl.MIRRORED_REPEAT`. */\n wrapT?: GLenum;\n /** `gl.pixelStorei(UNPACK_ALIGNMENT)` for the upload (1/2/4/8). Default 4.\n * Use 1 for tightly-packed non-RGBA rows. */\n unpackAlignment?: number;\n /** Premultiply alpha at upload (`UNPACK_PREMULTIPLY_ALPHA_WEBGL`). Default\n * false. */\n premultiplyAlpha?: boolean;\n /** Explicit sized internalFormat for `texImage2D`. When provided it is used\n * verbatim and the inline LDR resolver is bypassed — this is how\n * {@link createFloatTexture} injects its `RGBA16F` / `RGBA32F` choice\n * without the byte path ever referencing the float-format table (keeping it\n * tree-shakeable out of RGBA8-only bundles). Default: derived from\n * `format`/`type` via the LDR resolver. */\n internalFormat?: GLenum;\n}\n\n/**\n * Pure-state texture handle. The `handle` field is MUTABLE so the same logical\n * texture survives a `webglcontextrestored` event — every consumer keeps the\n * same `GLTexture` reference; only the internal `WebGLTexture` is swapped.\n *\n * `loadTexture2D` also uses the same handle for the 1×1 placeholder upload AND\n * the final image upload — so a `bindTexture(engine, unit, tex)` made before the\n * image has decoded remains valid once the image arrives.\n */\nexport interface GLTexture {\n /** The live `WebGLTexture`. MUTABLE — swapped for a fresh handle on\n * `webglcontextrestored` while consumers keep the same `GLTexture` reference. */\n handle: WebGLTexture;\n /** GL texture target (normally `gl.TEXTURE_2D`); 3D textures use their own API. */\n readonly target: GLenum;\n /** Texture width in texels. Updated once an async upload resolves. */\n width: number;\n /** Texture height in texels. Updated once an async upload resolves. */\n height: number;\n /** True when the texture is safe to sample with final content (placeholders\n * read as not-ready until their image/upload completes). */\n isReady: boolean;\n /** @internal */\n _disposed: boolean;\n /** @internal */\n _refCount: number;\n /** Replays the latest pixel content into the currently bound texture handle. @internal */\n _upload: (engine: GLEngineContext) => void;\n /** Initializes creation-time sampling state on the bound texture handle. @internal */\n _initializeParameters?: (engine: GLEngineContext) => void;\n /**\n * Snapshot of `isReady` captured on `webglcontextlost` so the restore\n * handler knows whether to flip it back on after `_upload`. Textures\n * that were still mid-load (e.g. `loadTexture2D` whose bitmap hadn't\n * arrived) stay not-ready; the async path will set `isReady=true` once\n * the bitmap finishes decoding into the new handle.\n * @internal\n */\n _wasReady: boolean;\n /**\n * Live re-upload hook installed by `createRawTexture` — lets\n * `updateRawTexture` replace the pixel data (and optionally the size)\n * through the same closure that the context-restore replay uses, keeping\n * restore correct. Absent on image / HTML-element / external textures.\n * @internal\n */\n _updateRaw?: (engine: GLEngineContext, data: ArrayBufferView | null, width: number, height: number, unpackAlignment: number) => void;\n /**\n * Dynamic-texture source captured by `updateDynamicTexture`\n * (`@babylonjs/lite-gl`) and replayed into the fresh handle\n * on `webglcontextrestored`. Null/absent on non-dynamic textures.\n * @internal\n */\n _dynSource?: TexImageSource | null;\n /** UNPACK_FLIP_Y applied when replaying {@link GLTexture._dynSource}. @internal */\n _dynInvertY?: boolean;\n /** UNPACK_PREMULTIPLY_ALPHA applied when replaying {@link GLTexture._dynSource}. @internal */\n _dynPremultiplyAlpha?: boolean;\n /**\n * The `handle` the dynamic texture's `texParameteri` filter/wrap state was\n * last applied to. `texParameteri` is per-texture GL state that survives pixel\n * re-uploads, so the dynamic-texture `_upload` re-applies it ONLY when this no\n * longer matches `handle` — i.e. at creation and after `webglcontextrestored`\n * installs a fresh handle — not on every per-frame `updateDynamicTexture`.\n * @internal\n */\n _dynParamsHandle?: WebGLTexture | null;\n}\n\n/**\n * Apply the three `UNPACK_*` pixel-store flags through the GL-state cache,\n * eliding redundant `pixelStorei` calls. Centralising this guarantees EVERY\n * upload path sets all three explicitly, so a premultiplying / flipping upload\n * never leaks its flag into a later upload that forgot to set it.\n * @internal\n */\nexport function setUnpackState(engine: GLEngineContext, flipY: boolean, premultiplyAlpha: boolean, alignment = 4): void {\n const gl = engine.gl;\n const s = engine._state;\n const fy = flipY ? 1 : 0;\n if (s.unpackFlipY !== fy) {\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, fy);\n s.unpackFlipY = fy;\n }\n const pm = premultiplyAlpha ? 1 : 0;\n if (s.unpackPremultiplyAlpha !== pm) {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, pm);\n s.unpackPremultiplyAlpha = pm;\n }\n if (s.unpackAlignment !== alignment) {\n gl.pixelStorei(gl.UNPACK_ALIGNMENT, alignment);\n s.unpackAlignment = alignment;\n }\n}\n\n/** Apply sampling and wrap state to the texture currently bound for upload. @internal */\nexport function setBoundTextureParams(gl: WebGL2RenderingContext, minFilter: GLenum, magFilter: GLenum, wrapS: GLenum, wrapT: GLenum): void {\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT);\n}\n\n/** Uint8 / float raw texture upload. The pixel data can be replaced later via\n * {@link updateRawTexture}; the sampling and wrap can be changed via\n * {@link updateTextureSamplingMode} / {@link updateTextureWrapMode}. */\nexport function createRawTexture(\n engine: GLEngineContext,\n data: ArrayBufferView | null,\n width: number,\n height: number,\n format: GLenum,\n type: GLenum,\n options?: GLTextureOptions\n): GLTexture {\n const gl = engine.gl;\n const handle = gl.createTexture();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createTexture returned null\");\n }\n const opts = options ?? {};\n const minFilter = opts.minFilter ?? gl.LINEAR;\n const magFilter = opts.magFilter ?? gl.LINEAR;\n const wrapS = opts.wrapS ?? gl.CLAMP_TO_EDGE;\n const wrapT = opts.wrapT ?? gl.CLAMP_TO_EDGE;\n const invertY = opts.invertY ?? false;\n const premultiply = opts.premultiplyAlpha ?? false;\n // LDR byte formats are resolved INLINE here; the float-format table in\n // `pickSizedInternalFormat` is deliberately NOT referenced from this path so\n // it tree-shakes out of byte-only bundles. `createFloatTexture` injects its\n // sized float format via `opts.internalFormat`.\n const internalFormat = opts.internalFormat ?? resolveLdrInternalFormat(gl, format, type);\n\n // Mutable upload state — `updateRawTexture` mutates these and re-runs\n // `upload`, so the context-restore replay (which calls the same `upload`)\n // always reproduces the latest contents.\n let curData = data;\n let curWidth = width;\n let curHeight = height;\n let curAlign = opts.unpackAlignment ?? 4;\n\n const upload = (target: GLEngineContext): void => {\n const g = target.gl;\n setUnpackState(target, invertY, premultiply, curAlign);\n bindTextureForUpload(target, tex.handle);\n g.texImage2D(g.TEXTURE_2D, 0, internalFormat, curWidth, curHeight, 0, format, type, curData);\n };\n\n const initializeParameters = (target: GLEngineContext): void => {\n setBoundTextureParams(target.gl, minFilter, magFilter, wrapS, wrapT);\n };\n\n const tex: GLTexture = {\n handle,\n target: gl.TEXTURE_2D,\n width,\n height,\n isReady: true,\n _disposed: false,\n _refCount: 1,\n _upload: upload,\n _initializeParameters: initializeParameters,\n _wasReady: true,\n };\n tex._updateRaw = (target: GLEngineContext, newData: ArrayBufferView | null, newWidth: number, newHeight: number, unpackAlignment: number): void => {\n curData = newData;\n curWidth = newWidth;\n curHeight = newHeight;\n curAlign = unpackAlignment;\n tex.width = newWidth;\n tex.height = newHeight;\n upload(target);\n };\n upload(engine);\n initializeParameters(engine);\n engine._textures.push(tex);\n return tex;\n}\n\n/** Options for {@link createFloatTexture} — the shared {@link GLTextureOptions}\n * plus the float-specific `type` / `format`. */\nexport interface GLFloatTextureOptions extends GLTextureOptions {\n /** Float texel type — `gl.HALF_FLOAT` (default) or `gl.FLOAT`. */\n type?: GLenum;\n /** Color format. Default `gl.RGBA`. */\n format?: GLenum;\n}\n\n/**\n * Create a float / half-float raw texture — the HDR counterpart of\n * {@link createRawTexture}. This is the ONLY texture factory that carries the\n * `RGBA16F` / `RGBA32F` sized-format knowledge (via {@link pickSizedInternalFormat}),\n * so byte-only consumers calling {@link createRawTexture} ship none of it.\n * Defaults to `gl.HALF_FLOAT`; pass `options.type = gl.FLOAT` for full 32-bit.\n * The caller is responsible for the matching engine cap (e.g.\n * `caps.textureFloatLinearFiltering`) when sampling these with `LINEAR`.\n *\n * @param engine - The engine.\n * @param data - Initial pixels (`Float32Array` for FLOAT, `Uint16Array` for\n * HALF_FLOAT), or `null` for an uninitialised allocation.\n * @param width - Texture width in texels (≥ 1).\n * @param height - Texture height in texels (≥ 1).\n * @param options - See {@link GLFloatTextureOptions}.\n * @returns The new {@link GLTexture}.\n */\nexport function createFloatTexture(engine: GLEngineContext, data: ArrayBufferView | null, width: number, height: number, options?: GLFloatTextureOptions): GLTexture {\n const gl = engine.gl;\n const o = options ?? {};\n const format = o.format ?? gl.RGBA;\n const type = o.type ?? gl.HALF_FLOAT;\n // Precompute the sized float internalFormat HERE and pass it through, so\n // `createRawTexture`'s inline LDR resolver is bypassed and the float table\n // stays out of byte-only bundles.\n const internalFormat = pickSizedInternalFormat(gl, format, type);\n return createRawTexture(engine, data, width, height, format, type, { ...o, internalFormat });\n}\n\n/** Generate the mip chain for a texture from its level-0 contents — mipmaps as\n * an explicit opt-in function rather than baked into the create path. Binds for\n * upload (unit 0). No-op on a lost/disposed context or a handle-less texture. */\nexport function generateTextureMipMaps(engine: GLEngineContext, tex: GLTexture): void {\n if (engine._isLost || engine._disposed || tex._disposed || tex.handle === null) {\n return;\n }\n bindTextureForUpload(engine, tex.handle);\n engine.gl.generateMipmap(engine.gl.TEXTURE_2D);\n}\n\n/**\n * Re-upload the pixel data (and optionally resize) of a texture created by\n * {@link createRawTexture} — the lite-gl equivalent of Babylon's\n * `updateRawTexture` / `_uploadDataToTextureDirectly`. Goes through the same\n * upload closure used by context-restore, so the new contents survive a context\n * loss. No-op on a lost/disposed/non-raw texture.\n *\n * @param engine - The engine.\n * @param tex - The raw texture to update.\n * @param data - New pixel data (must match the original `format`/`type`).\n * @param options - Optional new `width`/`height` (default: unchanged) and\n * `unpackAlignment` (default 4).\n */\nexport function updateRawTexture(\n engine: GLEngineContext,\n tex: GLTexture,\n data: ArrayBufferView | null,\n options?: { width?: number; height?: number; unpackAlignment?: number }\n): void {\n if (engine._isLost || engine._disposed || tex._disposed || tex._updateRaw === undefined) {\n return;\n }\n const o = options ?? {};\n tex._updateRaw(engine, data, o.width ?? tex.width, o.height ?? tex.height, o.unpackAlignment ?? 4);\n}\n\n/** Update a texture's min/mag sampling filters — the lite-gl equivalent of\n * Babylon's `updateTextureSamplingMode`. Binds for upload (unit 0) so the\n * `texParameteri` lands on this texture. No-op on a lost/disposed context. */\nexport function updateTextureSamplingMode(engine: GLEngineContext, tex: GLTexture, minFilter: GLenum, magFilter: GLenum): void {\n if (engine._isLost || engine._disposed || tex._disposed) {\n return;\n }\n const gl = engine.gl;\n bindTextureForUpload(engine, tex.handle);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);\n}\n\n/** Update a texture's S/T wrap modes (`gl.CLAMP_TO_EDGE` / `gl.REPEAT` /\n * `gl.MIRRORED_REPEAT`) — the lite-gl equivalent of Babylon's\n * `updateTextureWrappingMode`. No-op on a lost/disposed context. */\nexport function updateTextureWrapMode(engine: GLEngineContext, tex: GLTexture, wrapS: GLenum, wrapT: GLenum): void {\n if (engine._isLost || engine._disposed || tex._disposed) {\n return;\n }\n const gl = engine.gl;\n bindTextureForUpload(engine, tex.handle);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT);\n}\n\n/**\n * Wrap an existing raw `WebGLTexture` (e.g. one created by a host renderer or a\n * previous engine) as a {@link GLTexture} — the lite-gl equivalent of\n * ShapeBuilder's `createTextureGraphicsResourceFromExternalWebGLTexture`.\n *\n * The wrapper does NOT own the underlying handle's upload — it is NOT registered\n * for context-restore replay (the external owner is responsible for that) and is\n * marked ready immediately. `disposeTexture` will still `gl.deleteTexture` it, so\n * only wrap a handle whose deletion you intend lite-gl to manage.\n *\n * @param engine - The engine.\n * @param handle - The external `WebGLTexture`.\n * @param width - Texture width in texels.\n * @param height - Texture height in texels.\n * @param options - Optional sampling/wrap to apply once (min/mag/wrapS/wrapT).\n * @returns A {@link GLTexture} wrapping the handle.\n */\nexport function createTextureFromHandle(engine: GLEngineContext, handle: WebGLTexture, width: number, height: number, options?: GLTextureOptions): GLTexture {\n const tex: GLTexture = {\n handle,\n target: engine.gl.TEXTURE_2D,\n width,\n height,\n isReady: true,\n _disposed: false,\n _refCount: 1,\n // External handle — restore replay is the external owner's job.\n _upload: () => {},\n _wasReady: true,\n };\n if (options !== undefined) {\n const gl = engine.gl;\n bindTextureForUpload(engine, handle);\n setBoundTextureParams(gl, options.minFilter ?? gl.LINEAR, options.magFilter ?? gl.LINEAR, options.wrapS ?? gl.CLAMP_TO_EDGE, options.wrapT ?? gl.CLAMP_TO_EDGE);\n }\n return tex;\n}\n\n/** Asynchronous image upload.The returned texture is immediately usable (1×1\n * transparent placeholder); `isReady` flips true once the image has been\n * decoded and uploaded. The decoded `ImageBitmap` is retained on the texture\n * for offline-safe `webglcontextrestored` replay. */\nexport function loadTexture2D(engine: GLEngineContext, url: string, options?: GLTextureOptions, onLoad?: (tex: GLTexture) => void, onError?: (err: Error) => void): GLTexture {\n const gl = engine.gl;\n const handle = gl.createTexture();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createTexture returned null\");\n }\n const opts = options ?? {};\n const minFilter = opts.minFilter ?? gl.LINEAR;\n const magFilter = opts.magFilter ?? gl.LINEAR;\n const wrapS = opts.wrapS ?? gl.CLAMP_TO_EDGE;\n const wrapT = opts.wrapT ?? gl.CLAMP_TO_EDGE;\n const invertY = opts.invertY ?? false;\n\n let bitmap: ImageBitmap | null = null;\n const placeholderPixels = new Uint8Array([0, 0, 0, 0]);\n\n const upload = (target: GLEngineContext): void => {\n const g = target.gl;\n // invertY is applied at decode time via createImageBitmap({ imageOrientation })\n // because UNPACK_FLIP_Y_WEBGL is IGNORED for ImageBitmap sources (and the 1×1\n // placeholder is flip-invariant), so keep flip + premultiply off here.\n setUnpackState(target, false, false);\n bindTextureForUpload(target, tex.handle);\n if (bitmap !== null) {\n g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, g.RGBA, g.UNSIGNED_BYTE, bitmap);\n tex.width = bitmap.width;\n tex.height = bitmap.height;\n } else {\n g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, 1, 1, 0, g.RGBA, g.UNSIGNED_BYTE, placeholderPixels);\n }\n };\n\n const initializeParameters = (target: GLEngineContext): void => {\n setBoundTextureParams(target.gl, minFilter, magFilter, wrapS, wrapT);\n };\n\n const tex: GLTexture = {\n handle,\n target: gl.TEXTURE_2D,\n width: 1,\n height: 1,\n isReady: false,\n _disposed: false,\n _refCount: 1,\n _upload: upload,\n _initializeParameters: initializeParameters,\n _wasReady: false,\n };\n // Placeholder upload — makes the texture sampleable before the real image arrives.\n upload(engine);\n initializeParameters(engine);\n engine._textures.push(tex);\n\n // Fetch + decode the real image. Re-uploads via the same closure once the\n // bitmap is in hand (so context-restore replay sees the real image too).\n fetch(url)\n .then((r) => {\n if (!r.ok) {\n throw new Error(`lite-gl: fetch ${url} -> HTTP ${r.status}`);\n }\n return r.blob();\n })\n .then((blob) => createImageBitmap(blob, { premultiplyAlpha: \"none\", imageOrientation: invertY ? \"flipY\" : \"none\" }))\n .then((bm) => {\n if (tex._disposed) {\n bm.close();\n return;\n }\n bitmap = bm;\n // If the context is lost mid-flight, defer the upload — the restore\n // handler will call _upload again, which will then see `bitmap !== null`\n // and replay the real image.\n if (!engine._isLost) {\n upload(engine);\n tex.isReady = true;\n }\n tex._wasReady = true;\n if (onLoad !== undefined) {\n onLoad(tex);\n }\n })\n .catch((err: unknown) => {\n const e = err instanceof Error ? err : new Error(String(err));\n if (onError !== undefined) {\n onError(e);\n } else {\n console.error(\"lite-gl: loadTexture2D failed\", e);\n }\n });\n\n return tex;\n}\n\n/** Cached bind. Skips `gl.activeTexture` and/or `gl.bindTexture` when nothing\n * changes. No-op when `tex._disposed` or `engine._isLost`. */\nexport function bindTexture(engine: GLEngineContext, unit: number, tex: GLTexture | null): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n if (tex !== null && tex._disposed) {\n return;\n }\n bindTextureRaw(engine, unit, tex === null ? null : tex.handle);\n}\n\n/** @internal — for callers that already hold a raw `WebGLTexture`. Not part of\n * the public API: `bindTexture` (public) and the texture `_upload` closures bind\n * through the cache, so consumers never call this directly. */\nexport function bindTextureRaw(engine: GLEngineContext, unit: number, handle: WebGLTexture | null): void {\n const s = engine._state;\n const gl = engine.gl;\n if (s.boundTextures[unit] === handle) {\n return;\n }\n if (s.activeTextureUnit !== unit) {\n gl.activeTexture(gl.TEXTURE0 + unit);\n s.activeTextureUnit = unit;\n }\n gl.bindTexture(gl.TEXTURE_2D, handle);\n s.boundTextures[unit] = handle;\n}\n\n/** @internal Bind `handle` on texture unit 0 **for an upload** (`texImage2D`).\n * Unlike {@link bindTextureRaw} — which elides the entire bind when the handle is\n * already bound on the unit (correct for *sampling*, where the active unit is\n * irrelevant) — an upload writes into the texture on the ACTIVE unit. A prior\n * multi-sampler draw may have left a non-zero unit active while this handle is\n * still bound on unit 0, so we must force unit 0 active even on a bind cache-hit,\n * keeping the `_state` cache coherent. */\nexport function bindTextureForUpload(engine: GLEngineContext, handle: WebGLTexture): void {\n const s = engine._state;\n const gl = engine.gl;\n if (s.activeTextureUnit !== 0) {\n gl.activeTexture(gl.TEXTURE0);\n s.activeTextureUnit = 0;\n }\n if (s.boundTextures[0] !== handle) {\n gl.bindTexture(gl.TEXTURE_2D, handle);\n s.boundTextures[0] = handle;\n }\n}\n\n/** Disposes the texture. Walks `_state.boundTextures` and clears every slot\n * that still references the handle — otherwise a later `bindTexture(unit, B)`\n * to the same unit would be wrongly elided when slot still showed handle A. */\nexport function disposeTexture(engine: GLEngineContext, tex: GLTexture): void {\n if (tex._disposed) {\n return;\n }\n if (tex._refCount > 1) {\n tex._refCount--;\n return;\n }\n tex._disposed = true;\n const i = engine._textures.indexOf(tex);\n if (i !== -1) {\n engine._textures.splice(i, 1);\n }\n if (!engine._isLost && !engine._disposed) {\n engine.gl.deleteTexture(tex.handle);\n }\n const bound = engine._state.boundTextures;\n for (let u = 0; u < bound.length; u++) {\n if (bound[u] === tex.handle) {\n bound[u] = null;\n }\n }\n}\n\n/** Internal — resolve the sized internalFormat for the LDR (byte) `texImage2D`\n * paths ONLY: RGBA→RGBA8, RGB→RGB8, RG→RG8, RED→R8, LUMINANCE passthrough.\n * Deliberately knows nothing about FLOAT / HALF_FLOAT so the float-format table\n * in {@link pickSizedInternalFormat} tree-shakes out of byte-only bundles.\n * @internal */\nfunction resolveLdrInternalFormat(gl: WebGL2RenderingContext, format: GLenum, type: GLenum): GLenum {\n if (type === gl.UNSIGNED_BYTE) {\n if (format === gl.RGBA) {\n return gl.RGBA8;\n }\n if (format === gl.RGB) {\n return gl.RGB8;\n }\n if (format === gl.RG) {\n return gl.RG8;\n }\n if (format === gl.RED) {\n return gl.R8;\n }\n if (format === gl.LUMINANCE) {\n return gl.LUMINANCE;\n }\n }\n return format;\n}\n\n/** Internal — pick a sized internalFormat for `texImage2D`. WebGL2 prefers\n * sized formats for non-color-renderable / non-readback paths; for the\n * NeonBrush use cases (sample-only) the unsized format works too, but sized\n * is more portable. Shared with the render-target module.\n * @internal */\nexport function pickSizedInternalFormat(gl: WebGL2RenderingContext, format: GLenum, type: GLenum): GLenum {\n if (type === gl.UNSIGNED_BYTE) {\n if (format === gl.RGBA) {\n return gl.RGBA8;\n }\n if (format === gl.RGB) {\n return gl.RGB8;\n }\n if (format === gl.LUMINANCE) {\n return gl.LUMINANCE;\n }\n }\n if (type === gl.FLOAT) {\n if (format === gl.RGBA) {\n return gl.RGBA32F;\n }\n if (format === gl.RGB) {\n return gl.RGB32F;\n }\n }\n if (type === gl.HALF_FLOAT) {\n if (format === gl.RGBA) {\n return gl.RGBA16F;\n }\n if (format === gl.RGB) {\n return gl.RGB16F;\n }\n }\n return format;\n}\n"]}
|