@babylonjs/lite-gl 1.15.0 → 1.17.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/mesh.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mesh.js","sourceRoot":"","sources":["../src/mesh.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAiB,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,oCAAoC;AACpC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,2BAA2B;AAC3B,MAAM,WAAW,GAAG,MAAM,CAAC;AAC3B,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,qBAAqB;AACrB,MAAM,KAAK,GAAG,MAAM,CAAC;AACrB,yBAAyB;AACzB,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB,8BAA8B;AAC9B,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAoE5B,iFAAiF;AAEjF;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAuB,EAAE,IAAkB,EAAE,OAAO,GAAG,KAAK;IAC3F,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IACrB,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC;IACjC,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC9E,CAAC;IACD,MAAM,EAAE,GAAmB;QACvB,MAAM;QACN,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,KAAK,EAAE,IAAI;QACX,QAAQ,E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CAAC,kBAAkB,GAAG,IAAI,CAAC;AAChC,CAAC;AAED,kFAAkF;AAElF;;;oDAGoD;AACpD,SAAS,cAAc,CAAC,MAAuB;IAC3C,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,MAAM,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC;QAClB,CAAC,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAChC,CAAC;AACL,CAAC;AAED;iEACiE;AACjE,SAAS,kBAAkB,CAAC,MAAuB,EAAE,MAAmB;IACpE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,CAAC,CAAC,gBAAgB,KAAK,MAAM,EAAE,CAAC;QAChC,OAAO;IACX,CAAC;IACD,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC,CAAC,gBAAgB,GAAG,MAAM,CAAC;AAChC,CAAC","sourcesContent":["/**\n * Indexed meshes, dynamic vertex/index buffers, and hardware instancing.\n *\n * Part of the public API via the `@babylonjs/lite-gl` barrel. The package is\n * `sideEffects: false`, so consumers that only render the fullscreen quad /\n * sprites tree-shake the mesh code out.\n *\n * This is the lite-gl equivalent of Babylon's `ThinEngine.createVertexBuffer` /\n * `createIndexBuffer` / `_releaseBuffer` / `bindIndexBuffer` /\n * `bindInstancesBuffer` / `unbindInstanceAttributes` / `drawElementsType`. The\n * attribute binder reproduces Babylon's instancing semantics EXACTLY, including\n * the `computeStride = false → stride 0` \"sliding window\" used by ShapeBuilder's\n * tape buffers (consecutive instances read overlapping vec4 windows) and the\n * `divisor === undefined → 1` default.\n *\n * The mesh path runs on the DEFAULT (null) VAO — every buffer/attribute op binds\n * `gl.bindVertexArray(null)` first, so it never corrupts the quad / sprite VAOs.\n * Vertex and index buffers retain their CPU data and re-upload automatically on\n * `webglcontextrestored`.\n */\nimport type { GLEngineContext } from \"./context.js\";\nimport { onContextRestored, offContextRestored } from \"./context.js\";\nimport { getEffectAttributeLocation, type GLEffect } from \"./effect.js\";\nimport { applyGLStates } from \"./apply-states.js\";\n\n/** GL `gl.ARRAY_BUFFER`. */\nconst ARRAY_BUFFER = 0x8892;\n/** GL `gl.ELEMENT_ARRAY_BUFFER`. */\nconst ELEMENT_ARRAY_BUFFER = 0x8893;\n/** GL `gl.STATIC_DRAW`. */\nconst STATIC_DRAW = 0x88e4;\n/** GL `gl.DYNAMIC_DRAW`. */\nconst DYNAMIC_DRAW = 0x88e8;\n/** GL `gl.FLOAT`. */\nconst FLOAT = 0x1406;\n/** GL `gl.TRIANGLES`. */\nconst TRIANGLES = 0x0004;\n/** GL `gl.UNSIGNED_SHORT`. */\nconst UNSIGNED_SHORT = 0x1403;\n/** GL `gl.UNSIGNED_INT`. */\nconst UNSIGNED_INT = 0x1405;\n\n/** A GPU vertex buffer holding interleaved float vertex data. The lite-gl\n * counterpart of Babylon's `DataBuffer` for vertex data. */\nexport interface GLVertexBuffer {\n /** The live `WebGLBuffer`. Swapped on `webglcontextrestored`. */\n handle: WebGLBuffer;\n /** Size of the GL buffer in bytes. */\n byteLength: number;\n /** @internal */\n _disposed: boolean;\n /** @internal Delete the underlying GL buffer. */\n _deleteGpu: (gl: WebGL2RenderingContext) => void;\n /** @internal Re-create + re-upload the retained CPU data into a fresh handle. */\n _restore: (engine: GLEngineContext) => void;\n /** @internal Retained CPU data for context-restore replay (the creation /\n * last full-buffer upload). */\n _data: Float32Array;\n /** @internal `true` for `DYNAMIC_DRAW` (updated via `updateVertexBuffer`). */\n _dynamic: boolean;\n}\n\n/** A GPU index buffer. The lite-gl counterpart of Babylon's `DataBuffer` for\n * index data. */\nexport interface GLIndexBuffer {\n /** The live `WebGLBuffer`. Swapped on `webglcontextrestored`. */\n handle: WebGLBuffer;\n /** Number of indices. */\n count: number;\n /** `true` for 32-bit (`Uint32Array`) indices, `false` for 16-bit. */\n is32Bits: boolean;\n /** @internal */\n _disposed: boolean;\n /** @internal Delete the underlying GL buffer. */\n _deleteGpu: (gl: WebGL2RenderingContext) => void;\n /** @internal Re-create + re-upload the retained CPU data into a fresh handle. */\n _restore: (engine: GLEngineContext) => void;\n /** @internal Retained CPU data for context-restore replay. */\n _data: Uint16Array | Uint32Array;\n}\n\n/**\n * Describes one vertex attribute fed from a buffer — the lite-gl equivalent of\n * Babylon's `InstancingAttributeInfo`. Pass an array of these to\n * {@link bindAttributes}.\n */\nexport interface GLAttributeDescriptor {\n /** Attribute name; resolved to a location via the effect when `index` is\n * omitted (`Effect.getAttributeLocationByName`). */\n name?: string;\n /** Explicit attribute location. When set, overrides the `name` lookup. */\n index?: number;\n /** Number of components, 1–4. */\n size: number;\n /** Byte offset of this attribute's first element within the buffer. Default 0. */\n offset?: number;\n /**\n * Per-instance vertex divisor. **Omitted/`undefined` → `1` (instanced)**,\n * matching Babylon's `bindInstancesBuffer`. Pass `0` explicitly for a\n * per-vertex attribute (e.g. the base mesh position).\n */\n divisor?: number;\n /** GL component type. Default `gl.FLOAT`. */\n type?: GLenum;\n /** Normalize fixed-point integer data to `[0,1]`/`[-1,1]`. Default `false`. */\n normalized?: boolean;\n}\n\n/* ──────────────────────────────── buffers ──────────────────────────────── */\n\n/**\n * Create a GPU vertex buffer from interleaved float data.\n *\n * @param engine - The engine.\n * @param data - The vertex data. Retained by reference for context-restore — do\n * not mutate it in place; use {@link updateVertexBuffer} to change contents.\n * @param dynamic - Hint that the buffer will be updated frequently\n * (`DYNAMIC_DRAW`). Default `false` (`STATIC_DRAW`).\n * @returns The new {@link GLVertexBuffer}.\n */\nexport function createVertexBuffer(engine: GLEngineContext, data: Float32Array, dynamic = false): GLVertexBuffer {\n const gl = engine.gl;\n const handle = gl.createBuffer();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (vertex buffer)\");\n }\n const vb: GLVertexBuffer = {\n handle,\n byteLength: data.byteLength,\n _data: data,\n _dynamic: dynamic,\n _disposed: false,\n _deleteGpu: () => {},\n _restore: () => {},\n };\n vb._deleteGpu = (g: WebGL2RenderingContext): void => {\n g.deleteBuffer(vb.handle);\n };\n vb._restore = (target: GLEngineContext): void => {\n const g = target.gl;\n const fresh = g.createBuffer();\n if (fresh === null) {\n return;\n }\n vb.handle = fresh;\n bindArrayBufferRaw(target, fresh);\n g.bufferData(ARRAY_BUFFER, vb._data, vb._dynamic ? DYNAMIC_DRAW : STATIC_DRAW);\n };\n bindArrayBufferRaw(engine, handle);\n gl.bufferData(ARRAY_BUFFER, data, dynamic ? DYNAMIC_DRAW : STATIC_DRAW);\n engine._buffers.push(vb);\n return vb;\n}\n\n/**\n * Upload new contents into (part of) a vertex buffer via `bufferSubData`. A\n * full-buffer update from offset 0 also refreshes the retained CPU data used\n * for context-restore.\n *\n * @param engine - The engine.\n * @param vb - The vertex buffer to update.\n * @param data - The new float data.\n * @param dstByteOffset - Destination byte offset within the buffer. Default 0.\n */\nexport function updateVertexBuffer(engine: GLEngineContext, vb: GLVertexBuffer, data: Float32Array, dstByteOffset = 0): void {\n if (engine._isLost || engine._disposed || vb._disposed) {\n return;\n }\n bindArrayBufferRaw(engine, vb.handle);\n engine.gl.bufferSubData(ARRAY_BUFFER, dstByteOffset, data);\n if (dstByteOffset === 0 && data.byteLength >= vb.byteLength) {\n vb._data = data;\n vb.byteLength = data.byteLength;\n }\n}\n\n/**\n * Create a GPU index buffer. `Uint16Array` → 16-bit indices, `Uint32Array` →\n * 32-bit. Binds the default VAO first so it never corrupts the quad / sprite\n * VAO element bindings.\n *\n * @param engine - The engine.\n * @param data - The index data. Retained by reference for context-restore.\n * @returns The new {@link GLIndexBuffer}.\n */\nexport function createIndexBuffer(engine: GLEngineContext, data: Uint16Array | Uint32Array): GLIndexBuffer {\n const gl = engine.gl;\n const handle = gl.createBuffer();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (index buffer)\");\n }\n const is32 = data instanceof Uint32Array;\n const ib: GLIndexBuffer = {\n handle,\n count: data.length,\n is32Bits: is32,\n _data: data,\n _disposed: false,\n _deleteGpu: () => {},\n _restore: () => {},\n };\n ib._deleteGpu = (g: WebGL2RenderingContext): void => {\n g.deleteBuffer(ib.handle);\n };\n ib._restore = (target: GLEngineContext): void => {\n const g = target.gl;\n const fresh = g.createBuffer();\n if (fresh === null) {\n return;\n }\n ib.handle = fresh;\n bindDefaultVao(target);\n g.bindBuffer(ELEMENT_ARRAY_BUFFER, fresh);\n target._state.boundElementBuffer = fresh;\n g.bufferData(ELEMENT_ARRAY_BUFFER, ib._data, STATIC_DRAW);\n };\n bindDefaultVao(engine);\n gl.bindBuffer(ELEMENT_ARRAY_BUFFER, handle);\n engine._state.boundElementBuffer = handle;\n gl.bufferData(ELEMENT_ARRAY_BUFFER, data, STATIC_DRAW);\n engine._buffers.push(ib);\n return ib;\n}\n\n/** Dispose a vertex or index buffer (delete the GL buffer + unregister). Clears\n * the array/element-buffer cache slot if it pointed at this buffer. Idempotent. */\nexport function disposeBuffer(engine: GLEngineContext, buffer: GLVertexBuffer | GLIndexBuffer): void {\n if (buffer._disposed) {\n return;\n }\n buffer._disposed = true;\n const i = engine._buffers.indexOf(buffer);\n if (i !== -1) {\n engine._buffers.splice(i, 1);\n }\n const s = engine._state;\n if (!engine._isLost && !engine._disposed) {\n engine.gl.deleteBuffer(buffer.handle);\n }\n if (s.boundArrayBuffer === buffer.handle) {\n s.boundArrayBuffer = null;\n }\n if (s.boundElementBuffer === buffer.handle) {\n s.boundElementBuffer = null;\n }\n}\n\n/* ────────────────────────────── binding + draw ──────────────────────────── */\n\n/**\n * Bind an index buffer as the current element-array buffer (on the default\n * VAO). Cached. The lite-gl equivalent of Babylon's `_bindIndexBufferWithCache`.\n *\n * @param engine - The engine.\n * @param ib - The index buffer to bind.\n */\nexport function bindIndexBuffer(engine: GLEngineContext, ib: GLIndexBuffer): void {\n if (engine._isLost || engine._disposed || ib._disposed) {\n return;\n }\n bindDefaultVao(engine);\n const s = engine._state;\n if (s.boundElementBuffer === ib.handle) {\n return;\n }\n engine.gl.bindBuffer(ELEMENT_ARRAY_BUFFER, ib.handle);\n s.boundElementBuffer = ib.handle;\n}\n\n/**\n * Configure vertex attributes from `vb`, reproducing Babylon's\n * `bindInstancesBuffer` exactly. For each descriptor: resolves the location\n * (explicit `index` or via the effect), enables the attribute array, issues\n * `vertexAttribPointer`, and sets the vertex divisor (`undefined → 1`). Every\n * touched location is tracked so {@link unbindInstanceAttributes} can reset its\n * divisor afterwards.\n *\n * `computeStride` controls the GL stride passed to `vertexAttribPointer`:\n * - `false` (default) → stride `0`: each attribute is independently tightly\n * packed. Combined with overlapping `offset`s this yields the \"sliding window\"\n * ShapeBuilder uses for distance-field tape buffers.\n * - `true` → stride = Σ(`size`·4 bytes): interleaved per-vertex/per-instance.\n *\n * Runs on the default (null) VAO — never corrupts the quad / sprite VAOs.\n * No-op on a lost/disposed context or before the effect is ready.\n *\n * @param engine - The engine.\n * @param vb - The buffer supplying the attribute data.\n * @param descriptors - The attribute layout.\n * @param effect - The effect whose attribute locations resolve unnamed indices.\n * @param computeStride - See above. Default `false`.\n */\nexport function bindAttributes(engine: GLEngineContext, vb: GLVertexBuffer, descriptors: readonly GLAttributeDescriptor[], effect: GLEffect, computeStride = false): void {\n if (engine._isLost || engine._disposed || vb._disposed || !effect.isReady) {\n return;\n }\n const gl = engine.gl;\n const s = engine._state;\n bindDefaultVao(engine);\n bindArrayBufferRaw(engine, vb.handle);\n\n let stride = 0;\n if (computeStride) {\n for (let i = 0; i < descriptors.length; i++) {\n stride += (descriptors[i] as GLAttributeDescriptor).size * 4;\n }\n }\n\n for (let i = 0; i < descriptors.length; i++) {\n const d = descriptors[i] as GLAttributeDescriptor;\n const loc = d.index !== undefined ? d.index : d.name !== undefined ? getEffectAttributeLocation(engine, effect, d.name) : -1;\n if (loc < 0) {\n continue;\n }\n if (!s.enabledAttribs[loc]) {\n gl.enableVertexAttribArray(loc);\n s.enabledAttribs[loc] = true;\n }\n gl.vertexAttribPointer(loc, d.size, d.type ?? FLOAT, d.normalized ?? false, stride, d.offset ?? 0);\n gl.vertexAttribDivisor(loc, d.divisor === undefined ? 1 : d.divisor);\n s.instanceLocations.push(loc);\n }\n}\n\n/**\n * Reset the vertex divisor of every attribute touched by {@link bindAttributes}\n * back to 0 — the lite-gl equivalent of Babylon's `unbindInstanceAttributes`.\n * Call after an instanced draw so a following non-instanced draw is not skewed.\n * No-op on a lost/disposed context.\n *\n * @param engine - The engine.\n */\nexport function unbindInstanceAttributes(engine: GLEngineContext): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n const locs = engine._state.instanceLocations;\n for (let i = 0; i < locs.length; i++) {\n gl.vertexAttribDivisor(locs[i] as number, 0);\n }\n locs.length = 0;\n}\n\n/**\n * Draw indexed triangles from `ib` — the lite-gl equivalent of Babylon's\n * `drawElementsType` (triangle fill mode). When `instanceCount > 0` issues\n * `drawElementsInstanced`, otherwise `drawElements`. No-op on a lost/disposed\n * context or when no program is current.\n *\n * @param engine - The engine.\n * @param ib - The index buffer (also bound as a side-effect, cached).\n * @param indexCount - Number of indices to draw.\n * @param indexStart - First index offset (in indices, not bytes). Default 0.\n * @param instanceCount - Instance count for instanced draws. Default 0\n * (non-instanced).\n */\nexport function drawIndexed(engine: GLEngineContext, ib: GLIndexBuffer, indexCount: number, indexStart = 0, instanceCount = 0): void {\n if (engine._isLost || engine._disposed || ib._disposed) {\n return;\n }\n if (engine._state.currentProgram === null) {\n return;\n }\n bindIndexBuffer(engine, ib);\n const gl = engine.gl;\n const type = ib.is32Bits ? UNSIGNED_INT : UNSIGNED_SHORT;\n const byteOffset = indexStart * (ib.is32Bits ? 4 : 2);\n applyGLStates(engine);\n if (instanceCount > 0) {\n gl.drawElementsInstanced(TRIANGLES, indexCount, type, byteOffset, instanceCount);\n } else {\n gl.drawElements(TRIANGLES, indexCount, type, byteOffset);\n }\n}\n\n/* ────────────────────────── static mesh VAO ─────────────────────────────\n * The VAO-cached counterpart of the manual `bindAttributes` path above — Babylon's\n * `recordVertexArrayObject` / `_cachedVertexArrayObject` for STATIC meshes. A\n * `GLMeshVao` records the whole attribute layout (enable + pointer + divisor for\n * every attribute, across one or more vertex buffers) AND the index binding into a\n * single VAO ONCE. The per-frame draw is then just `bindVertexArray` +\n * `drawElements[Instanced]` — zero per-draw `vertexAttribPointer`/`vertexAttribDivisor`,\n * and no `unbindInstanceAttributes` (the VAO isolates the divisors from the default\n * VAO). Use this for fixed-layout meshes; keep `bindAttributes` for dynamic layouts\n * (e.g. ShapeBuilder's per-draw sliding-window tape buffers). */\n\n/** One vertex buffer + its attribute layout, for {@link createMeshVao}. */\nexport interface GLMeshVertexBuffer {\n /** The buffer supplying this group's attributes. */\n buffer: GLVertexBuffer;\n /** The attributes read from `buffer` (same shape as {@link bindAttributes}). */\n attributes: readonly GLAttributeDescriptor[];\n /** Stride mode (see {@link bindAttributes}): `false` (default) → stride `0`\n * per attribute; `true` → interleaved stride = Σ(`size`·4). */\n computeStride?: boolean;\n}\n\n/** A recorded Vertex Array Object capturing a static mesh's attribute layout +\n * index binding. Bind + draw it with {@link drawMesh} each frame — the GPU\n * replays the entire attribute setup from one `bindVertexArray`. Re-recorded\n * automatically on `webglcontextrestored`. */\nexport interface GLMeshVao {\n /** The live `WebGLVertexArrayObject`. Swapped on `webglcontextrestored`. */\n handle: WebGLVertexArrayObject;\n /** @internal */\n _disposed: boolean;\n /** @internal The index buffer recorded into the VAO. */\n _indexBuffer: GLIndexBuffer;\n /** @internal Resolved attribute bindings, reused to re-record on restore. */\n _bindings: _ResolvedBinding[];\n /** @internal `webglcontextrestored` re-record hook. */\n _restore: () => void;\n}\n\n/** @internal A single attribute with its location resolved once at record time\n * (locations are stable across re-link via `bindAttribLocation`, so the VAO can\n * re-record on context-restore without the effect). */\ninterface _ResolvedAttr {\n loc: number;\n size: number;\n type: number;\n normalized: boolean;\n stride: number;\n offset: number;\n divisor: number;\n}\n\n/** @internal A vertex buffer + its resolved attributes. */\ninterface _ResolvedBinding {\n buffer: GLVertexBuffer;\n attrs: _ResolvedAttr[];\n}\n\n/**\n * Record a static mesh's attribute layout + index binding into a new VAO. The\n * effect MUST be ready (its attribute locations are resolved here, once). Returns\n * a {@link GLMeshVao} to draw with {@link drawMesh}.\n *\n * @param engine - The engine.\n * @param vertexBuffers - One or more buffers + their attribute layouts.\n * @param indexBuffer - The index buffer recorded into the VAO.\n * @param effect - The effect whose attribute locations resolve unnamed indices.\n * @returns The recorded {@link GLMeshVao}.\n */\nexport function createMeshVao(engine: GLEngineContext, vertexBuffers: readonly GLMeshVertexBuffer[], indexBuffer: GLIndexBuffer, effect: GLEffect): GLMeshVao {\n const gl = engine.gl;\n // The effect's attribute locations are resolved (once) below; an unready effect\n // would resolve every name to -1 → a silently-empty VAO. Fail fast — callers\n // must gate on isEffectReady (see scene10's first-ready-frame creation).\n if (!effect.isReady) {\n throw new Error(\"lite-gl: createMeshVao requires a ready effect (poll isEffectReady first)\");\n }\n const handle = gl.createVertexArray();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createVertexArray returned null (mesh VAO)\");\n }\n // Resolve every attribute location ONCE (stable across re-link), so a restore\n // re-record needs only the buffer handles, not the effect.\n const bindings: _ResolvedBinding[] = [];\n for (const vbb of vertexBuffers) {\n let stride = 0;\n if (vbb.computeStride) {\n for (let i = 0; i < vbb.attributes.length; i++) {\n stride += (vbb.attributes[i] as GLAttributeDescriptor).size * 4;\n }\n }\n const attrs: _ResolvedAttr[] = [];\n for (let i = 0; i < vbb.attributes.length; i++) {\n const d = vbb.attributes[i] as GLAttributeDescriptor;\n const loc = d.index !== undefined ? d.index : d.name !== undefined ? getEffectAttributeLocation(engine, effect, d.name) : -1;\n if (loc < 0) {\n continue;\n }\n attrs.push({\n loc,\n size: d.size,\n type: d.type ?? FLOAT,\n normalized: d.normalized ?? false,\n stride,\n offset: d.offset ?? 0,\n divisor: d.divisor === undefined ? 1 : d.divisor,\n });\n }\n bindings.push({ buffer: vbb.buffer, attrs });\n }\n const vao: GLMeshVao = { handle, _disposed: false, _indexBuffer: indexBuffer, _bindings: bindings, _restore: () => {} };\n vao._restore = (): void => {\n if (engine._isLost || engine._disposed || vao._disposed) {\n return;\n }\n const fresh = engine.gl.createVertexArray();\n if (fresh === null) {\n return;\n }\n vao.handle = fresh;\n recordMeshVao(engine, vao);\n };\n recordMeshVao(engine, vao);\n onContextRestored(engine, vao._restore);\n return vao;\n}\n\n/**\n * Bind a {@link GLMeshVao} (cached `gl.bindVertexArray`). Rarely called directly —\n * {@link drawMesh} binds it for you. Binding restores the VAO's recorded element\n * binding, so the element-buffer cache is updated in lock-step.\n *\n * @param engine - The engine.\n * @param vao - The mesh VAO to bind.\n */\nexport function bindMeshVao(engine: GLEngineContext, vao: GLMeshVao): void {\n if (engine._isLost || engine._disposed || vao._disposed) {\n return;\n }\n const s = engine._state;\n if (s.boundVao === vao.handle) {\n return;\n }\n engine.gl.bindVertexArray(vao.handle);\n s.boundVao = vao.handle;\n s.boundElementBuffer = vao._indexBuffer.handle;\n}\n\n/**\n * Draw a static mesh recorded with {@link createMeshVao}: binds its VAO (cached),\n * flushes deferred GL state, and issues ONE `drawElements` (or\n * `drawElementsInstanced` when `instanceCount > 0`) over the VAO's full index\n * buffer. No per-draw attribute (re)binding. No-op on a lost/disposed context, a\n * disposed VAO, or when no program is current.\n *\n * @param engine - The engine.\n * @param vao - The mesh VAO to draw.\n * @param instanceCount - Instance count for instanced draws. Default 0 (non-instanced).\n */\nexport function drawMesh(engine: GLEngineContext, vao: GLMeshVao, instanceCount = 0): void {\n if (engine._isLost || engine._disposed || vao._disposed) {\n return;\n }\n if (engine._state.currentProgram === null) {\n return;\n }\n bindMeshVao(engine, vao);\n applyGLStates(engine);\n const ib = vao._indexBuffer;\n const gl = engine.gl;\n const type = ib.is32Bits ? UNSIGNED_INT : UNSIGNED_SHORT;\n if (instanceCount > 0) {\n gl.drawElementsInstanced(TRIANGLES, ib.count, type, 0, instanceCount);\n } else {\n gl.drawElements(TRIANGLES, ib.count, type, 0);\n }\n}\n\n/** Dispose a {@link GLMeshVao}: delete the VAO and unregister its restore hook.\n * Does NOT dispose the vertex/index buffers (the caller owns those). Idempotent. */\nexport function disposeMeshVao(engine: GLEngineContext, vao: GLMeshVao): void {\n if (vao._disposed) {\n return;\n }\n vao._disposed = true;\n offContextRestored(engine, vao._restore);\n if (!engine._isLost && !engine._disposed) {\n const s = engine._state;\n engine.gl.deleteVertexArray(vao.handle);\n if (s.boundVao === vao.handle) {\n // Return to the default VAO so the cache stays coherent.\n engine.gl.bindVertexArray(null);\n s.boundVao = null;\n s.boundElementBuffer = null;\n }\n }\n}\n\n/** @internal Record `vao._bindings` + the index binding into `vao.handle`. Leaves\n * the default (null) VAO bound afterwards (so the mesh VAO is not left current),\n * forgetting the element-buffer cache. Touches neither `s.enabledAttribs` (those\n * track the DEFAULT VAO) nor the divisor reset — all of that lives in the VAO. */\nfunction recordMeshVao(engine: GLEngineContext, vao: GLMeshVao): void {\n const gl = engine.gl;\n const s = engine._state;\n gl.bindVertexArray(vao.handle);\n s.boundVao = vao.handle;\n for (const b of vao._bindings) {\n bindArrayBufferRaw(engine, b.buffer.handle);\n for (const a of b.attrs) {\n gl.enableVertexAttribArray(a.loc);\n gl.vertexAttribPointer(a.loc, a.size, a.type, a.normalized, a.stride, a.offset);\n gl.vertexAttribDivisor(a.loc, a.divisor);\n }\n }\n gl.bindBuffer(ELEMENT_ARRAY_BUFFER, vao._indexBuffer.handle);\n gl.bindVertexArray(null);\n s.boundVao = null;\n s.boundElementBuffer = null;\n}\n\n/* ──────────────────────────── internal helpers ──────────────────────────── */\n\n/** Bind the default (null) VAO if not already bound. The mesh path lives here so\n * it never disturbs the quad / sprite VAO state. Binding a VAO restores ITS\n * element-array binding, so the element-buffer cache is forgotten on the\n * switch (the next `bindIndexBuffer` re-binds). */\nfunction bindDefaultVao(engine: GLEngineContext): void {\n const s = engine._state;\n if (s.boundVao !== null) {\n engine.gl.bindVertexArray(null);\n s.boundVao = null;\n s.boundElementBuffer = null;\n }\n}\n\n/** Cached `gl.bindBuffer(ARRAY_BUFFER, …)`. ARRAY_BUFFER binding is global (not\n * VAO state), so this cache is coherent across VAO switches. */\nfunction bindArrayBufferRaw(engine: GLEngineContext, handle: WebGLBuffer): void {\n const s = engine._state;\n if (s.boundArrayBuffer === handle) {\n return;\n }\n engine.gl.bindBuffer(ARRAY_BUFFER, handle);\n s.boundArrayBuffer = handle;\n}\n"]}
1
+ {"version":3,"file":"mesh.js","sourceRoot":"","sources":["../src/mesh.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAiB,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,oCAAoC;AACpC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,2BAA2B;AAC3B,MAAM,WAAW,GAAG,MAAM,CAAC;AAC3B,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,qBAAqB;AACrB,MAAM,KAAK,GAAG,MAAM,CAAC;AACrB,yBAAyB;AACzB,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB,8BAA8B;AAC9B,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAoE5B,iFAAiF;AAEjF;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAuB,EAAE,IAAkB,EAAE,OAAO,GAAG,KAAK;IAC3F,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IACrB,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC;IACjC,IAAI,MAAM,KAAK,IA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,mBAAmB,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;IACL,CAAC;IACD,EAAE,CAAC,UAAU,CAAC,oBAAoB,EAAE,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC7D,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC;IAClB,CAAC,CAAC,kBAAkB,GAAG,IAAI,CAAC;AAChC,CAAC;AAED,kFAAkF;AAElF;;;oDAGoD;AACpD,SAAS,cAAc,CAAC,MAAuB;IAC3C,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,MAAM,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC;QAClB,CAAC,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAChC,CAAC;AACL,CAAC;AAED;iEACiE;AACjE,SAAS,kBAAkB,CAAC,MAAuB,EAAE,MAAmB;IACpE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,CAAC,CAAC,gBAAgB,KAAK,MAAM,EAAE,CAAC;QAChC,OAAO;IACX,CAAC;IACD,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC,CAAC,gBAAgB,GAAG,MAAM,CAAC;AAChC,CAAC","sourcesContent":["/**\n * Indexed meshes, dynamic vertex/index buffers, and hardware instancing.\n *\n * Part of the public API via the `@babylonjs/lite-gl` barrel. The package is\n * `sideEffects: false`, so consumers that only render the fullscreen quad /\n * sprites tree-shake the mesh code out.\n *\n * This is the lite-gl equivalent of Babylon's `ThinEngine.createVertexBuffer` /\n * `createIndexBuffer` / `_releaseBuffer` / `bindIndexBuffer` /\n * `bindInstancesBuffer` / `unbindInstanceAttributes` / `drawElementsType`. The\n * attribute binder reproduces Babylon's instancing semantics EXACTLY, including\n * the `computeStride = false → stride 0` \"sliding window\" used by ShapeBuilder's\n * tape buffers (consecutive instances read overlapping vec4 windows) and the\n * `divisor === undefined → 1` default.\n *\n * The mesh path runs on the DEFAULT (null) VAO — every buffer/attribute op binds\n * `gl.bindVertexArray(null)` first, so it never corrupts the quad / sprite VAOs.\n * Vertex and index buffers retain their CPU data and re-upload automatically on\n * `webglcontextrestored`.\n */\nimport type { GLEngineContext } from \"./context.js\";\nimport { onContextRestored, offContextRestored } from \"./context.js\";\nimport { getEffectAttributeLocation, type GLEffect } from \"./effect.js\";\nimport { applyGLStates } from \"./apply-states.js\";\n\n/** GL `gl.ARRAY_BUFFER`. */\nconst ARRAY_BUFFER = 0x8892;\n/** GL `gl.ELEMENT_ARRAY_BUFFER`. */\nconst ELEMENT_ARRAY_BUFFER = 0x8893;\n/** GL `gl.STATIC_DRAW`. */\nconst STATIC_DRAW = 0x88e4;\n/** GL `gl.DYNAMIC_DRAW`. */\nconst DYNAMIC_DRAW = 0x88e8;\n/** GL `gl.FLOAT`. */\nconst FLOAT = 0x1406;\n/** GL `gl.TRIANGLES`. */\nconst TRIANGLES = 0x0004;\n/** GL `gl.UNSIGNED_SHORT`. */\nconst UNSIGNED_SHORT = 0x1403;\n/** GL `gl.UNSIGNED_INT`. */\nconst UNSIGNED_INT = 0x1405;\n\n/** A GPU vertex buffer holding interleaved float vertex data. The lite-gl\n * counterpart of Babylon's `DataBuffer` for vertex data. */\nexport interface GLVertexBuffer {\n /** The live `WebGLBuffer`. Swapped on `webglcontextrestored`. */\n handle: WebGLBuffer;\n /** Size of the GL buffer in bytes. */\n byteLength: number;\n /** @internal */\n _disposed: boolean;\n /** @internal Delete the underlying GL buffer. */\n _deleteGpu: (gl: WebGL2RenderingContext) => void;\n /** @internal Re-create + re-upload the retained CPU data into a fresh handle. */\n _restore: (engine: GLEngineContext) => void;\n /** @internal Retained CPU data for context-restore replay (the creation /\n * last full-buffer upload). */\n _data: Float32Array;\n /** @internal `true` for `DYNAMIC_DRAW` (updated via `updateVertexBuffer`). */\n _dynamic: boolean;\n}\n\n/** A GPU index buffer. The lite-gl counterpart of Babylon's `DataBuffer` for\n * index data. */\nexport interface GLIndexBuffer {\n /** The live `WebGLBuffer`. Swapped on `webglcontextrestored`. */\n handle: WebGLBuffer;\n /** Number of indices. */\n count: number;\n /** `true` for 32-bit (`Uint32Array`) indices, `false` for 16-bit. */\n is32Bits: boolean;\n /** @internal */\n _disposed: boolean;\n /** @internal Delete the underlying GL buffer. */\n _deleteGpu: (gl: WebGL2RenderingContext) => void;\n /** @internal Re-create + re-upload the retained CPU data into a fresh handle. */\n _restore: (engine: GLEngineContext) => void;\n /** @internal Retained CPU data for context-restore replay. */\n _data: Uint16Array | Uint32Array;\n}\n\n/**\n * Describes one vertex attribute fed from a buffer — the lite-gl equivalent of\n * Babylon's `InstancingAttributeInfo`. Pass an array of these to\n * {@link bindAttributes}.\n */\nexport interface GLAttributeDescriptor {\n /** Attribute name; resolved to a location via the effect when `index` is\n * omitted (`Effect.getAttributeLocationByName`). */\n name?: string;\n /** Explicit attribute location. When set, overrides the `name` lookup. */\n index?: number;\n /** Number of components, 1–4. */\n size: number;\n /** Byte offset of this attribute's first element within the buffer. Default 0. */\n offset?: number;\n /**\n * Per-instance vertex divisor. **Omitted/`undefined` → `1` (instanced)**,\n * matching Babylon's `bindInstancesBuffer`. Pass `0` explicitly for a\n * per-vertex attribute (e.g. the base mesh position).\n */\n divisor?: number;\n /** GL component type. Default `gl.FLOAT`. */\n type?: GLenum;\n /** Normalize fixed-point integer data to `[0,1]`/`[-1,1]`. Default `false`. */\n normalized?: boolean;\n}\n\n/* ──────────────────────────────── buffers ──────────────────────────────── */\n\n/**\n * Create a GPU vertex buffer from interleaved float data.\n *\n * @param engine - The engine.\n * @param data - The vertex data. Retained by reference for context-restore — do\n * not mutate it in place; use {@link updateVertexBuffer} to change contents.\n * @param dynamic - Hint that the buffer will be updated frequently\n * (`DYNAMIC_DRAW`). Default `false` (`STATIC_DRAW`).\n * @returns The new {@link GLVertexBuffer}.\n */\nexport function createVertexBuffer(engine: GLEngineContext, data: Float32Array, dynamic = false): GLVertexBuffer {\n const gl = engine.gl;\n const handle = gl.createBuffer();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (vertex buffer)\");\n }\n const vb: GLVertexBuffer = {\n handle,\n byteLength: data.byteLength,\n _data: data,\n _dynamic: dynamic,\n _disposed: false,\n _deleteGpu: () => {},\n _restore: () => {},\n };\n vb._deleteGpu = (g: WebGL2RenderingContext): void => {\n g.deleteBuffer(vb.handle);\n };\n vb._restore = (target: GLEngineContext): void => {\n const g = target.gl;\n const fresh = g.createBuffer();\n if (fresh === null) {\n return;\n }\n vb.handle = fresh;\n bindArrayBufferRaw(target, fresh);\n g.bufferData(ARRAY_BUFFER, vb._data, vb._dynamic ? DYNAMIC_DRAW : STATIC_DRAW);\n };\n bindArrayBufferRaw(engine, handle);\n gl.bufferData(ARRAY_BUFFER, data, dynamic ? DYNAMIC_DRAW : STATIC_DRAW);\n engine._buffers.push(vb);\n return vb;\n}\n\n/**\n * Upload new contents into (part of) a vertex buffer via `bufferSubData`. A\n * full-buffer update from offset 0 also refreshes the retained CPU data used\n * for context-restore.\n *\n * @param engine - The engine.\n * @param vb - The vertex buffer to update.\n * @param data - The new float data.\n * @param dstByteOffset - Destination byte offset within the buffer. Default 0.\n */\nexport function updateVertexBuffer(engine: GLEngineContext, vb: GLVertexBuffer, data: Float32Array, dstByteOffset = 0): void {\n if (engine._isLost || engine._disposed || vb._disposed) {\n return;\n }\n bindArrayBufferRaw(engine, vb.handle);\n engine.gl.bufferSubData(ARRAY_BUFFER, dstByteOffset, data);\n if (dstByteOffset === 0 && data.byteLength >= vb.byteLength) {\n vb._data = data;\n vb.byteLength = data.byteLength;\n }\n}\n\n/**\n * Create a GPU index buffer. `Uint16Array` → 16-bit indices, `Uint32Array` →\n * 32-bit. Binds the default VAO first so it never corrupts the quad / sprite\n * VAO element bindings.\n *\n * @param engine - The engine.\n * @param data - The index data. Retained by reference for context-restore.\n * @returns The new {@link GLIndexBuffer}.\n */\nexport function createIndexBuffer(engine: GLEngineContext, data: Uint16Array | Uint32Array): GLIndexBuffer {\n const gl = engine.gl;\n const handle = gl.createBuffer();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (index buffer)\");\n }\n const is32 = data instanceof Uint32Array;\n const ib: GLIndexBuffer = {\n handle,\n count: data.length,\n is32Bits: is32,\n _data: data,\n _disposed: false,\n _deleteGpu: () => {},\n _restore: () => {},\n };\n ib._deleteGpu = (g: WebGL2RenderingContext): void => {\n g.deleteBuffer(ib.handle);\n };\n ib._restore = (target: GLEngineContext): void => {\n const g = target.gl;\n const fresh = g.createBuffer();\n if (fresh === null) {\n return;\n }\n ib.handle = fresh;\n bindDefaultVao(target);\n g.bindBuffer(ELEMENT_ARRAY_BUFFER, fresh);\n target._state.boundElementBuffer = fresh;\n g.bufferData(ELEMENT_ARRAY_BUFFER, ib._data, STATIC_DRAW);\n };\n bindDefaultVao(engine);\n gl.bindBuffer(ELEMENT_ARRAY_BUFFER, handle);\n engine._state.boundElementBuffer = handle;\n gl.bufferData(ELEMENT_ARRAY_BUFFER, data, STATIC_DRAW);\n engine._buffers.push(ib);\n return ib;\n}\n\n/** Dispose a vertex or index buffer (delete the GL buffer + unregister). Clears\n * the array/element-buffer cache slot if it pointed at this buffer. Idempotent. */\nexport function disposeBuffer(engine: GLEngineContext, buffer: GLVertexBuffer | GLIndexBuffer): void {\n if (buffer._disposed) {\n return;\n }\n buffer._disposed = true;\n const i = engine._buffers.indexOf(buffer);\n if (i !== -1) {\n engine._buffers.splice(i, 1);\n }\n const s = engine._state;\n if (!engine._isLost && !engine._disposed) {\n engine.gl.deleteBuffer(buffer.handle);\n }\n if (s.boundArrayBuffer === buffer.handle) {\n s.boundArrayBuffer = null;\n }\n if (s.boundElementBuffer === buffer.handle) {\n s.boundElementBuffer = null;\n }\n}\n\n/* ────────────────────────────── binding + draw ──────────────────────────── */\n\n/**\n * Bind an index buffer as the current element-array buffer (on the default\n * VAO). Cached. The lite-gl equivalent of Babylon's `_bindIndexBufferWithCache`.\n *\n * @param engine - The engine.\n * @param ib - The index buffer to bind.\n */\nexport function bindIndexBuffer(engine: GLEngineContext, ib: GLIndexBuffer): void {\n if (engine._isLost || engine._disposed || ib._disposed) {\n return;\n }\n bindDefaultVao(engine);\n const s = engine._state;\n if (s.boundElementBuffer === ib.handle) {\n return;\n }\n engine.gl.bindBuffer(ELEMENT_ARRAY_BUFFER, ib.handle);\n s.boundElementBuffer = ib.handle;\n}\n\n/**\n * Configure vertex attributes from `vb`, reproducing Babylon's\n * `bindInstancesBuffer` exactly. For each descriptor: resolves the location\n * (explicit `index` or via the effect), enables the attribute array, issues\n * `vertexAttribPointer`, and sets the vertex divisor (`undefined → 1`). Each\n * instanced location (divisor ≠ 0) is tracked once so {@link unbindInstanceAttributes}\n * can reset its divisor afterwards; per-vertex locations already have divisor 0 and are\n * not tracked, so callers that never instance can rebind every frame without growth.\n *\n * `computeStride` controls the GL stride passed to `vertexAttribPointer`:\n * - `false` (default) → stride `0`: each attribute is independently tightly\n * packed. Combined with overlapping `offset`s this yields the \"sliding window\"\n * ShapeBuilder uses for distance-field tape buffers.\n * - `true` → stride = Σ(`size`·4 bytes): interleaved per-vertex/per-instance.\n *\n * Runs on the default (null) VAO — never corrupts the quad / sprite VAOs.\n * No-op on a lost/disposed context or before the effect is ready.\n *\n * @param engine - The engine.\n * @param vb - The buffer supplying the attribute data.\n * @param descriptors - The attribute layout.\n * @param effect - The effect whose attribute locations resolve unnamed indices.\n * @param computeStride - See above. Default `false`.\n */\nexport function bindAttributes(engine: GLEngineContext, vb: GLVertexBuffer, descriptors: readonly GLAttributeDescriptor[], effect: GLEffect, computeStride = false): void {\n if (engine._isLost || engine._disposed || vb._disposed || !effect.isReady) {\n return;\n }\n const gl = engine.gl;\n const s = engine._state;\n bindDefaultVao(engine);\n bindArrayBufferRaw(engine, vb.handle);\n\n let stride = 0;\n if (computeStride) {\n for (let i = 0; i < descriptors.length; i++) {\n stride += (descriptors[i] as GLAttributeDescriptor).size * 4;\n }\n }\n\n for (let i = 0; i < descriptors.length; i++) {\n const d = descriptors[i] as GLAttributeDescriptor;\n const loc = d.index !== undefined ? d.index : d.name !== undefined ? getEffectAttributeLocation(engine, effect, d.name) : -1;\n if (loc < 0) {\n continue;\n }\n if (!s.enabledAttribs[loc]) {\n gl.enableVertexAttribArray(loc);\n s.enabledAttribs[loc] = true;\n }\n gl.vertexAttribPointer(loc, d.size, d.type ?? FLOAT, d.normalized ?? false, stride, d.offset ?? 0);\n const divisor = d.divisor ?? 1;\n gl.vertexAttribDivisor(loc, divisor);\n if (divisor !== 0 && !s.instanceLocations.includes(loc)) {\n s.instanceLocations.push(loc);\n }\n }\n}\n\n/**\n * Reset the vertex divisor of every attribute touched by {@link bindAttributes}\n * back to 0 — the lite-gl equivalent of Babylon's `unbindInstanceAttributes`.\n * Call after an instanced draw so a following non-instanced draw is not skewed.\n * No-op on a lost/disposed context.\n *\n * @param engine - The engine.\n */\nexport function unbindInstanceAttributes(engine: GLEngineContext): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n const locs = engine._state.instanceLocations;\n for (let i = 0; i < locs.length; i++) {\n gl.vertexAttribDivisor(locs[i] as number, 0);\n }\n locs.length = 0;\n}\n\n/**\n * Draw indexed triangles from `ib` — the lite-gl equivalent of Babylon's\n * `drawElementsType` (triangle fill mode). When `instanceCount > 0` issues\n * `drawElementsInstanced`, otherwise `drawElements`. No-op on a lost/disposed\n * context or when no program is current.\n *\n * @param engine - The engine.\n * @param ib - The index buffer (also bound as a side-effect, cached).\n * @param indexCount - Number of indices to draw.\n * @param indexStart - First index offset (in indices, not bytes). Default 0.\n * @param instanceCount - Instance count for instanced draws. Default 0\n * (non-instanced).\n */\nexport function drawIndexed(engine: GLEngineContext, ib: GLIndexBuffer, indexCount: number, indexStart = 0, instanceCount = 0): void {\n if (engine._isLost || engine._disposed || ib._disposed) {\n return;\n }\n if (engine._state.currentProgram === null) {\n return;\n }\n bindIndexBuffer(engine, ib);\n const gl = engine.gl;\n const type = ib.is32Bits ? UNSIGNED_INT : UNSIGNED_SHORT;\n const byteOffset = indexStart * (ib.is32Bits ? 4 : 2);\n applyGLStates(engine);\n if (instanceCount > 0) {\n gl.drawElementsInstanced(TRIANGLES, indexCount, type, byteOffset, instanceCount);\n } else {\n gl.drawElements(TRIANGLES, indexCount, type, byteOffset);\n }\n}\n\n/* ────────────────────────── static mesh VAO ─────────────────────────────\n * The VAO-cached counterpart of the manual `bindAttributes` path above — Babylon's\n * `recordVertexArrayObject` / `_cachedVertexArrayObject` for STATIC meshes. A\n * `GLMeshVao` records the whole attribute layout (enable + pointer + divisor for\n * every attribute, across one or more vertex buffers) AND the index binding into a\n * single VAO ONCE. The per-frame draw is then just `bindVertexArray` +\n * `drawElements[Instanced]` — zero per-draw `vertexAttribPointer`/`vertexAttribDivisor`,\n * and no `unbindInstanceAttributes` (the VAO isolates the divisors from the default\n * VAO). Use this for fixed-layout meshes; keep `bindAttributes` for dynamic layouts\n * (e.g. ShapeBuilder's per-draw sliding-window tape buffers). */\n\n/** One vertex buffer + its attribute layout, for {@link createMeshVao}. */\nexport interface GLMeshVertexBuffer {\n /** The buffer supplying this group's attributes. */\n buffer: GLVertexBuffer;\n /** The attributes read from `buffer` (same shape as {@link bindAttributes}). */\n attributes: readonly GLAttributeDescriptor[];\n /** Stride mode (see {@link bindAttributes}): `false` (default) → stride `0`\n * per attribute; `true` → interleaved stride = Σ(`size`·4). */\n computeStride?: boolean;\n}\n\n/** A recorded Vertex Array Object capturing a static mesh's attribute layout +\n * index binding. Bind + draw it with {@link drawMesh} each frame — the GPU\n * replays the entire attribute setup from one `bindVertexArray`. Re-recorded\n * automatically on `webglcontextrestored`. */\nexport interface GLMeshVao {\n /** The live `WebGLVertexArrayObject`. Swapped on `webglcontextrestored`. */\n handle: WebGLVertexArrayObject;\n /** @internal */\n _disposed: boolean;\n /** @internal The index buffer recorded into the VAO. */\n _indexBuffer: GLIndexBuffer;\n /** @internal Resolved attribute bindings, reused to re-record on restore. */\n _bindings: _ResolvedBinding[];\n /** @internal `webglcontextrestored` re-record hook. */\n _restore: () => void;\n}\n\n/** @internal A single attribute with its location resolved once at record time\n * (locations are stable across re-link via `bindAttribLocation`, so the VAO can\n * re-record on context-restore without the effect). */\ninterface _ResolvedAttr {\n loc: number;\n size: number;\n type: number;\n normalized: boolean;\n stride: number;\n offset: number;\n divisor: number;\n}\n\n/** @internal A vertex buffer + its resolved attributes. */\ninterface _ResolvedBinding {\n buffer: GLVertexBuffer;\n attrs: _ResolvedAttr[];\n}\n\n/**\n * Record a static mesh's attribute layout + index binding into a new VAO. The\n * effect MUST be ready (its attribute locations are resolved here, once). Returns\n * a {@link GLMeshVao} to draw with {@link drawMesh}.\n *\n * @param engine - The engine.\n * @param vertexBuffers - One or more buffers + their attribute layouts.\n * @param indexBuffer - The index buffer recorded into the VAO.\n * @param effect - The effect whose attribute locations resolve unnamed indices.\n * @returns The recorded {@link GLMeshVao}.\n */\nexport function createMeshVao(engine: GLEngineContext, vertexBuffers: readonly GLMeshVertexBuffer[], indexBuffer: GLIndexBuffer, effect: GLEffect): GLMeshVao {\n const gl = engine.gl;\n // The effect's attribute locations are resolved (once) below; an unready effect\n // would resolve every name to -1 → a silently-empty VAO. Fail fast — callers\n // must gate on isEffectReady (see scene10's first-ready-frame creation).\n if (!effect.isReady) {\n throw new Error(\"lite-gl: createMeshVao requires a ready effect (poll isEffectReady first)\");\n }\n const handle = gl.createVertexArray();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createVertexArray returned null (mesh VAO)\");\n }\n // Resolve every attribute location ONCE (stable across re-link), so a restore\n // re-record needs only the buffer handles, not the effect.\n const bindings: _ResolvedBinding[] = [];\n for (const vbb of vertexBuffers) {\n let stride = 0;\n if (vbb.computeStride) {\n for (let i = 0; i < vbb.attributes.length; i++) {\n stride += (vbb.attributes[i] as GLAttributeDescriptor).size * 4;\n }\n }\n const attrs: _ResolvedAttr[] = [];\n for (let i = 0; i < vbb.attributes.length; i++) {\n const d = vbb.attributes[i] as GLAttributeDescriptor;\n const loc = d.index !== undefined ? d.index : d.name !== undefined ? getEffectAttributeLocation(engine, effect, d.name) : -1;\n if (loc < 0) {\n continue;\n }\n attrs.push({\n loc,\n size: d.size,\n type: d.type ?? FLOAT,\n normalized: d.normalized ?? false,\n stride,\n offset: d.offset ?? 0,\n divisor: d.divisor === undefined ? 1 : d.divisor,\n });\n }\n bindings.push({ buffer: vbb.buffer, attrs });\n }\n const vao: GLMeshVao = { handle, _disposed: false, _indexBuffer: indexBuffer, _bindings: bindings, _restore: () => {} };\n vao._restore = (): void => {\n if (engine._isLost || engine._disposed || vao._disposed) {\n return;\n }\n const fresh = engine.gl.createVertexArray();\n if (fresh === null) {\n return;\n }\n vao.handle = fresh;\n recordMeshVao(engine, vao);\n };\n recordMeshVao(engine, vao);\n onContextRestored(engine, vao._restore);\n return vao;\n}\n\n/**\n * Bind a {@link GLMeshVao} (cached `gl.bindVertexArray`). Rarely called directly —\n * {@link drawMesh} binds it for you. Binding restores the VAO's recorded element\n * binding, so the element-buffer cache is updated in lock-step.\n *\n * @param engine - The engine.\n * @param vao - The mesh VAO to bind.\n */\nexport function bindMeshVao(engine: GLEngineContext, vao: GLMeshVao): void {\n if (engine._isLost || engine._disposed || vao._disposed) {\n return;\n }\n const s = engine._state;\n if (s.boundVao === vao.handle) {\n return;\n }\n engine.gl.bindVertexArray(vao.handle);\n s.boundVao = vao.handle;\n s.boundElementBuffer = vao._indexBuffer.handle;\n}\n\n/**\n * Draw a static mesh recorded with {@link createMeshVao}: binds its VAO (cached),\n * flushes deferred GL state, and issues ONE `drawElements` (or\n * `drawElementsInstanced` when `instanceCount > 0`) over the VAO's full index\n * buffer. No per-draw attribute (re)binding. No-op on a lost/disposed context, a\n * disposed VAO, or when no program is current.\n *\n * @param engine - The engine.\n * @param vao - The mesh VAO to draw.\n * @param instanceCount - Instance count for instanced draws. Default 0 (non-instanced).\n */\nexport function drawMesh(engine: GLEngineContext, vao: GLMeshVao, instanceCount = 0): void {\n if (engine._isLost || engine._disposed || vao._disposed) {\n return;\n }\n if (engine._state.currentProgram === null) {\n return;\n }\n bindMeshVao(engine, vao);\n applyGLStates(engine);\n const ib = vao._indexBuffer;\n const gl = engine.gl;\n const type = ib.is32Bits ? UNSIGNED_INT : UNSIGNED_SHORT;\n if (instanceCount > 0) {\n gl.drawElementsInstanced(TRIANGLES, ib.count, type, 0, instanceCount);\n } else {\n gl.drawElements(TRIANGLES, ib.count, type, 0);\n }\n}\n\n/** Dispose a {@link GLMeshVao}: delete the VAO and unregister its restore hook.\n * Does NOT dispose the vertex/index buffers (the caller owns those). Idempotent. */\nexport function disposeMeshVao(engine: GLEngineContext, vao: GLMeshVao): void {\n if (vao._disposed) {\n return;\n }\n vao._disposed = true;\n offContextRestored(engine, vao._restore);\n if (!engine._isLost && !engine._disposed) {\n const s = engine._state;\n engine.gl.deleteVertexArray(vao.handle);\n if (s.boundVao === vao.handle) {\n // Return to the default VAO so the cache stays coherent.\n engine.gl.bindVertexArray(null);\n s.boundVao = null;\n s.boundElementBuffer = null;\n }\n }\n}\n\n/** @internal Record `vao._bindings` + the index binding into `vao.handle`. Leaves\n * the default (null) VAO bound afterwards (so the mesh VAO is not left current),\n * forgetting the element-buffer cache. Touches neither `s.enabledAttribs` (those\n * track the DEFAULT VAO) nor the divisor reset — all of that lives in the VAO. */\nfunction recordMeshVao(engine: GLEngineContext, vao: GLMeshVao): void {\n const gl = engine.gl;\n const s = engine._state;\n gl.bindVertexArray(vao.handle);\n s.boundVao = vao.handle;\n for (const b of vao._bindings) {\n bindArrayBufferRaw(engine, b.buffer.handle);\n for (const a of b.attrs) {\n gl.enableVertexAttribArray(a.loc);\n gl.vertexAttribPointer(a.loc, a.size, a.type, a.normalized, a.stride, a.offset);\n gl.vertexAttribDivisor(a.loc, a.divisor);\n }\n }\n gl.bindBuffer(ELEMENT_ARRAY_BUFFER, vao._indexBuffer.handle);\n gl.bindVertexArray(null);\n s.boundVao = null;\n s.boundElementBuffer = null;\n}\n\n/* ──────────────────────────── internal helpers ──────────────────────────── */\n\n/** Bind the default (null) VAO if not already bound. The mesh path lives here so\n * it never disturbs the quad / sprite VAO state. Binding a VAO restores ITS\n * element-array binding, so the element-buffer cache is forgotten on the\n * switch (the next `bindIndexBuffer` re-binds). */\nfunction bindDefaultVao(engine: GLEngineContext): void {\n const s = engine._state;\n if (s.boundVao !== null) {\n engine.gl.bindVertexArray(null);\n s.boundVao = null;\n s.boundElementBuffer = null;\n }\n}\n\n/** Cached `gl.bindBuffer(ARRAY_BUFFER, …)`. ARRAY_BUFFER binding is global (not\n * VAO state), so this cache is coherent across VAO switches. */\nfunction bindArrayBufferRaw(engine: GLEngineContext, handle: WebGLBuffer): void {\n const s = engine._state;\n if (s.boundArrayBuffer === handle) {\n return;\n }\n engine.gl.bindBuffer(ARRAY_BUFFER, handle);\n s.boundArrayBuffer = handle;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/lite-gl",
3
- "version": "1.15.0",
3
+ "version": "1.17.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": "60390",
36
- "sourceVersion": "1d1a2c0de2fc845d57096b7abe0256c10e648ff3"
35
+ "azureBuildId": "60696",
36
+ "sourceVersion": "22bd82496ecbb38f7bbd4107ef5eca40c2897bd0"
37
37
  }
38
38
  }
package/shader.d.ts CHANGED
@@ -4,19 +4,21 @@
4
4
  * `effect.ts` during `createEffect` and during the context-restored
5
5
  * re-compile path.
6
6
  */
7
- /** Compile a single shader stage. Returns the shader handle; sets the
8
- * `errorOut` array's element 0 to a non-null string on failure. */
9
- export declare function compileShader(gl: WebGL2RenderingContext, source: string, stage: GLenum, errorOut: (string | null)[]): WebGLShader | null;
7
+ /** Submit a shader stage without querying compilation results. Returns null
8
+ * only on allocation failure; shader diagnostics are collected after a
9
+ * completed program link fails. */
10
+ export declare function compileShader(gl: WebGL2RenderingContext, source: string, stage: GLenum): WebGLShader | null;
10
11
  /** Attach + bind + link. Returns the program handle. Does NOT block on
11
- * link completion — callers use `pollLinkStatus` to drive the parallel-
12
+ * link completion — callers use `isLinkComplete` to drive the parallel-
12
13
  * shader-compile state machine. */
13
14
  export declare function linkProgram(gl: WebGL2RenderingContext, vs: WebGLShader, fs: WebGLShader, attributeNames: readonly string[]): WebGLProgram | null;
14
15
  /** Returns `true` when the program has finished linking and can be queried.
15
16
  * When the `KHR_parallel_shader_compile` extension is present, this is the
16
- * cheap async-friendly poll; without it, link is synchronous so the answer
17
- * is always `true`. */
17
+ * cheap async-friendly poll; without it, the subsequent LINK_STATUS query
18
+ * may block until linking completes. */
18
19
  export declare function isLinkComplete(gl: WebGL2RenderingContext, program: WebGLProgram, parallel: {
19
20
  COMPLETION_STATUS_KHR: number;
20
21
  } | null): boolean;
21
- /** Returns null on success, the info log on failure. */
22
- export declare function getLinkError(gl: WebGL2RenderingContext, program: WebGLProgram): string | null;
22
+ /** Query a completed link. Only on failure, collect the program log and any
23
+ * failed shader stages' logs; never query shader status on the success path. */
24
+ export declare function getLinkError(gl: WebGL2RenderingContext, program: WebGLProgram, vs: WebGLShader, fs: WebGLShader): string | null;
package/shader.js CHANGED
@@ -4,25 +4,20 @@
4
4
  * `effect.ts` during `createEffect` and during the context-restored
5
5
  * re-compile path.
6
6
  */
7
- /** Compile a single shader stage. Returns the shader handle; sets the
8
- * `errorOut` array's element 0 to a non-null string on failure. */
9
- export function compileShader(gl, source, stage, errorOut) {
7
+ /** Submit a shader stage without querying compilation results. Returns null
8
+ * only on allocation failure; shader diagnostics are collected after a
9
+ * completed program link fails. */
10
+ export function compileShader(gl, source, stage) {
10
11
  const shader = gl.createShader(stage);
11
12
  if (shader === null) {
12
- errorOut[0] = "gl.createShader returned null";
13
13
  return null;
14
14
  }
15
15
  gl.shaderSource(shader, source);
16
16
  gl.compileShader(shader);
17
- if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
18
- errorOut[0] = gl.getShaderInfoLog(shader) ?? "shader compile failed";
19
- gl.deleteShader(shader);
20
- return null;
21
- }
22
17
  return shader;
23
18
  }
24
19
  /** Attach + bind + link. Returns the program handle. Does NOT block on
25
- * link completion — callers use `pollLinkStatus` to drive the parallel-
20
+ * link completion — callers use `isLinkComplete` to drive the parallel-
26
21
  * shader-compile state machine. */
27
22
  export function linkProgram(gl, vs, fs, attributeNames) {
28
23
  const program = gl.createProgram();
@@ -47,19 +42,27 @@ export function linkProgram(gl, vs, fs, attributeNames) {
47
42
  }
48
43
  /** Returns `true` when the program has finished linking and can be queried.
49
44
  * When the `KHR_parallel_shader_compile` extension is present, this is the
50
- * cheap async-friendly poll; without it, link is synchronous so the answer
51
- * is always `true`. */
45
+ * cheap async-friendly poll; without it, the subsequent LINK_STATUS query
46
+ * may block until linking completes. */
52
47
  export function isLinkComplete(gl, program, parallel) {
53
48
  if (parallel === null) {
54
49
  return true;
55
50
  }
56
51
  return Boolean(gl.getProgramParameter(program, parallel.COMPLETION_STATUS_KHR));
57
52
  }
58
- /** Returns null on success, the info log on failure. */
59
- export function getLinkError(gl, program) {
53
+ /** Query a completed link. Only on failure, collect the program log and any
54
+ * failed shader stages' logs; never query shader status on the success path. */
55
+ export function getLinkError(gl, program, vs, fs) {
60
56
  if (gl.getProgramParameter(program, gl.LINK_STATUS)) {
61
57
  return null;
62
58
  }
63
- return gl.getProgramInfoLog(program) ?? "link failed";
59
+ let error = `link failed: ${gl.getProgramInfoLog(program) || "no program info log"}`;
60
+ if (!gl.getShaderParameter(vs, gl.COMPILE_STATUS)) {
61
+ error += `\nvertex compile failed: ${gl.getShaderInfoLog(vs) || "no shader info log"}`;
62
+ }
63
+ if (!gl.getShaderParameter(fs, gl.COMPILE_STATUS)) {
64
+ error += `\nfragment compile failed: ${gl.getShaderInfoLog(fs) || "no shader info log"}`;
65
+ }
66
+ return error;
64
67
  }
65
68
  //# sourceMappingURL=shader.js.map
package/shader.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"shader.js","sourceRoot":"","sources":["../src/shader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;oEACoE;AACpE,MAAM,UAAU,aAAa,CAAC,EAA0B,EAAE,MAAc,EAAE,KAAa,EAAE,QAA2B;IAChH,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAClB,QAAQ,CAAC,CAAC,CAAC,GAAG,+BAA+B,CAAC;QAC9C,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACzB,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC;QACpD,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,uBAAuB,CAAC;QACrE,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QACxB,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;oCAEoC;AACpC,MAAM,UAAU,WAAW,CAAC,EAA0B,EAAE,EAAe,EAAE,EAAe,EAAE,cAAiC;IACvH,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC;IACnC,IAAI,OAAO,KAAK,IA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ext` and never touch the cache layer. Used by\n * `effect.ts` during `createEffect` and during the context-restored\n * re-compile path.\n */\n\n/** Compile a single shader stage. Returns the shader handle; sets the\n * `errorOut` array's element 0 to a non-null string on failure. */\nexport function compileShader(gl: WebGL2RenderingContext, source: string, stage: GLenum, errorOut: (string | null)[]): WebGLShader | null {\n const shader = gl.createShader(stage);\n if (shader === null) {\n errorOut[0] = \"gl.createShader returned null\";\n return null;\n }\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n errorOut[0] = gl.getShaderInfoLog(shader) ?? \"shader compile failed\";\n gl.deleteShader(shader);\n return null;\n }\n return shader;\n}\n\n/** Attach + bind + link. Returns the program handle. Does NOT block on\n * link completion — callers use `pollLinkStatus` to drive the parallel-\n * shader-compile state machine. */\nexport function linkProgram(gl: WebGL2RenderingContext, vs: WebGLShader, fs: WebGLShader, attributeNames: readonly string[]): WebGLProgram | null {\n const program = gl.createProgram();\n if (program === null) {\n return null;\n }\n gl.attachShader(program, vs);\n gl.attachShader(program, fs);\n // Bind every declared attribute, but in particular guarantee that the FIRST\n // attribute (`position`) maps to location 0 — the shared fullscreen-quad VAO\n // depends on this so the same VAO works across every effect's program.\n // Must run BEFORE linkProgram. The GLSL conversion also emits\n // `layout(location = N)` as belt-and-suspenders.\n for (let i = 0; i < attributeNames.length; i++) {\n const name = attributeNames[i];\n if (name !== undefined) {\n gl.bindAttribLocation(program, i, name);\n }\n }\n gl.linkProgram(program);\n return program;\n}\n\n/** Returns `true` when the program has finished linking and can be queried.\n * When the `KHR_parallel_shader_compile` extension is present, this is the\n * cheap async-friendly poll; without it, link is synchronous so the answer\n * is always `true`. */\nexport function isLinkComplete(gl: WebGL2RenderingContext, program: WebGLProgram, parallel: { COMPLETION_STATUS_KHR: number } | null): boolean {\n if (parallel === null) {\n return true;\n }\n return Boolean(gl.getProgramParameter(program, parallel.COMPLETION_STATUS_KHR));\n}\n\n/** Returns null on success, the info log on failure. */\nexport function getLinkError(gl: WebGL2RenderingContext, program: WebGLProgram): string | null {\n if (gl.getProgramParameter(program, gl.LINK_STATUS)) {\n return null;\n }\n return gl.getProgramInfoLog(program) ?? \"link failed\";\n}\n"]}
1
+ {"version":3,"file":"shader.js","sourceRoot":"","sources":["../src/shader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;oCAEoC;AACpC,MAAM,UAAU,aAAa,CAAC,EAA0B,EAAE,MAAc,EAAE,KAAa;IACnF,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACzB,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;oCAEoC;AACpC,MAAM,UAAU,WAAW,CAAC,EAA0B,EAAE,EAAe,EAAE,EAAe,EAAE,cAAiC;IACvH,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC;IACnC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC7B,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC7B,4EAA4E;IAC5E,6EAA6E;IAC7E,uEAAuE;IACvE,8DAA8D;IAC9D,iDAAiD;IACjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7C,MAAM,IAAI,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,EAAE,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;QAC5C,CAAC;IACL,CAAC;IACD,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACxB,OAAO,OAAO,CAAC;AACnB,CAAC;AAED;;;yCAGyC;AACzC,MAAM,UAAU,cAAc,CAAC,EAA0B,EAAE,OAAqB,EAAE,QAAkD;IAChI,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,OAAO,CAAC,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC,CAAC;AACpF,CAAC;AAED;iFACiF;AACjF,MAAM,UAAU,YAAY,CAAC,EAA0B,EAAE,OAAqB,EAAE,EAAe,EAAE,EAAe;IAC5G,IAAI,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC;QAClD,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,IAAI,KAAK,GAAG,gBAAgB,EAAE,CAAC,iBAAiB,CAAC,OAAO,CAAC,IAAI,qBAAqB,EAAE,CAAC;IACrF,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,EAAE,EAAE,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC;QAChD,KAAK,IAAI,4BAA4B,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC,IAAI,oBAAoB,EAAE,CAAC;IAC3F,CAAC;IACD,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,EAAE,EAAE,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC;QAChD,KAAK,IAAI,8BAA8B,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC,IAAI,oBAAoB,EAAE,CAAC;IAC7F,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["/**\n * Shader / program compilation helpers. Pure functions — they take a raw\n * `WebGL2RenderingContext` and never touch the cache layer. Used by\n * `effect.ts` during `createEffect` and during the context-restored\n * re-compile path.\n */\n\n/** Submit a shader stage without querying compilation results. Returns null\n * only on allocation failure; shader diagnostics are collected after a\n * completed program link fails. */\nexport function compileShader(gl: WebGL2RenderingContext, source: string, stage: GLenum): WebGLShader | null {\n const shader = gl.createShader(stage);\n if (shader === null) {\n return null;\n }\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n return shader;\n}\n\n/** Attach + bind + link. Returns the program handle. Does NOT block on\n * link completion — callers use `isLinkComplete` to drive the parallel-\n * shader-compile state machine. */\nexport function linkProgram(gl: WebGL2RenderingContext, vs: WebGLShader, fs: WebGLShader, attributeNames: readonly string[]): WebGLProgram | null {\n const program = gl.createProgram();\n if (program === null) {\n return null;\n }\n gl.attachShader(program, vs);\n gl.attachShader(program, fs);\n // Bind every declared attribute, but in particular guarantee that the FIRST\n // attribute (`position`) maps to location 0 — the shared fullscreen-quad VAO\n // depends on this so the same VAO works across every effect's program.\n // Must run BEFORE linkProgram. The GLSL conversion also emits\n // `layout(location = N)` as belt-and-suspenders.\n for (let i = 0; i < attributeNames.length; i++) {\n const name = attributeNames[i];\n if (name !== undefined) {\n gl.bindAttribLocation(program, i, name);\n }\n }\n gl.linkProgram(program);\n return program;\n}\n\n/** Returns `true` when the program has finished linking and can be queried.\n * When the `KHR_parallel_shader_compile` extension is present, this is the\n * cheap async-friendly poll; without it, the subsequent LINK_STATUS query\n * may block until linking completes. */\nexport function isLinkComplete(gl: WebGL2RenderingContext, program: WebGLProgram, parallel: { COMPLETION_STATUS_KHR: number } | null): boolean {\n if (parallel === null) {\n return true;\n }\n return Boolean(gl.getProgramParameter(program, parallel.COMPLETION_STATUS_KHR));\n}\n\n/** Query a completed link. Only on failure, collect the program log and any\n * failed shader stages' logs; never query shader status on the success path. */\nexport function getLinkError(gl: WebGL2RenderingContext, program: WebGLProgram, vs: WebGLShader, fs: WebGLShader): string | null {\n if (gl.getProgramParameter(program, gl.LINK_STATUS)) {\n return null;\n }\n let error = `link failed: ${gl.getProgramInfoLog(program) || \"no program info log\"}`;\n if (!gl.getShaderParameter(vs, gl.COMPILE_STATUS)) {\n error += `\\nvertex compile failed: ${gl.getShaderInfoLog(vs) || \"no shader info log\"}`;\n }\n if (!gl.getShaderParameter(fs, gl.COMPILE_STATUS)) {\n error += `\\nfragment compile failed: ${gl.getShaderInfoLog(fs) || \"no shader info log\"}`;\n }\n return error;\n}\n"]}
package/state.d.ts CHANGED
@@ -103,6 +103,7 @@ export interface GLState {
103
103
  /**
104
104
  * Attribute locations currently configured with a non-default vertex divisor
105
105
  * (instanced attributes), mirroring Babylon's `_currentInstanceLocations`.
106
+ * Each location is recorded once, so repeated binds without an unbind stay bounded.
106
107
  * `unbindInstanceAttributes` resets each back to divisor 0 and clears this.
107
108
  */
108
109
  instanceLocations: number[];
package/state.js.map CHANGED
@@ -1 +1 @@
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,C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C,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 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"]}
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,MA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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 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 * Each location is recorded once, so repeated binds without an unbind stay bounded.\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 CHANGED
@@ -45,5 +45,7 @@ export declare function generateTexture3DMipMaps(engine: GLEngineContext, tex: G
45
45
  export declare function updateTexture3DSamplingMode(engine: GLEngineContext, tex: GLTexture3D, minFilter: GLenum, magFilter: GLenum): void;
46
46
  /** Update changed S/T/R wrapping and retain it across context restoration. Unchanged values are elided. */
47
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. */
48
+ /** Dispose a 3D texture and invalidate any units that still reference its handle.
49
+ * Deregistration is expected O(1); shared references retain their registry entry
50
+ * until the final release, and repeated disposal is a no-op. */
49
51
  export declare function disposeTexture3D(engine: GLEngineContext, tex: GLTexture3D): void;
package/texture-3d.js CHANGED
@@ -140,7 +140,7 @@ export function createTexture3DFromPixels(engine, data, width, height, depth, op
140
140
  };
141
141
  upload(engine);
142
142
  initializeParameters(engine);
143
- engine._textures.push(tex);
143
+ engine._textures.add(tex);
144
144
  return tex;
145
145
  }
146
146
  /** Generate a full 3D mip chain for an existing volume and replay it on context restoration. No-op after loss or disposal. */
@@ -205,7 +205,9 @@ export function updateTexture3DWrapMode(engine, tex, wrapS, wrapT, wrapR) {
205
205
  tex._wrapR = wrapR;
206
206
  }
207
207
  }
208
- /** Dispose a 3D texture and invalidate any units that still reference its handle. */
208
+ /** Dispose a 3D texture and invalidate any units that still reference its handle.
209
+ * Deregistration is expected O(1); shared references retain their registry entry
210
+ * until the final release, and repeated disposal is a no-op. */
209
211
  export function disposeTexture3D(engine, tex) {
210
212
  if (tex._disposed) {
211
213
  return;
@@ -215,10 +217,7 @@ export function disposeTexture3D(engine, tex) {
215
217
  return;
216
218
  }
217
219
  tex._disposed = true;
218
- const index = engine._textures.indexOf(tex);
219
- if (index !== -1) {
220
- engine._textures.splice(index, 1);
221
- }
220
+ engine._textures.delete(tex);
222
221
  if (!engine._isLost && !engine._disposed) {
223
222
  engine.gl.deleteTexture(tex.handle);
224
223
  }
package/texture-3d.js.map CHANGED
@@ -1 +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,eAAe,CAAC,MAAuB;IAC5C,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5B,IAAI,KAAK,CAAC,gBAAgB,KAAK,SAAS,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC,gBAAgB,CAAC;IAClC,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAkC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrG,KAAK,CAAC,gBAAgB,GAAG,KAAK,CAAC;IAC/B,MAAM,UAAU,GAAG,GAAS,EAAE;QAC1B,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtB,KAAK,CAAC,oBAAoB,GAAG,KAAK,CAAC;IACvC,CAAC,CAAC;IACF,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAClC,CAAC,MAAM,CAAC,uBAAuB,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAuB,EAAE,IAAY,EAAE,MAA2B,EAAE,SAAkB;IAC5G,MAAM,KAAK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C;AAED,qFAAqF;AACrF,MAAM,UAAU,gBAAgB,CAAC,MAAuB,EAAE,GAAgB;IACtE,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;QAChB,OAAO;IACX,CAAC;IACD,IAAI,GAAG,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC;QACpB,GAAG,CAAC,SAAS,EAAE,CAAC;QAChB,OAAO;IACX,CAAC;IACD,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;IACrB,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QACf,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACtC,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"]}
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,eAAe,CAAC,MAAuB;IAC5C,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5B,IAAI,KAAK,CAAC,gBAAgB,KAAK,SAAS,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC,gBAAgB,CAAC;IAClC,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAkC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrG,KAAK,CAAC,gBAAgB,GAAG,KAAK,CAAC;IAC/B,MAAM,UAAU,GAAG,GAAS,EAAE;QAC1B,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtB,KAAK,CAAC,oBAAoB,GAAG,KAAK,CAAC;IACvC,CAAC,CAAC;IACF,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAClC,CAAC,MAAM,CAAC,uBAAuB,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAuB,EAAE,IAAY,EAAE,MAA2B,EAAE,SAAkB;IAC5G,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5B,MAAM,KAAK,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACtC,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACvC,OAAO;IACX,CAAC;IACD,MAAM,EAAE,GAAG,MAA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AE,CAAC;QAChB,OAAO;IACX,CAAC;IACD,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;IACrB,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7B,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.add(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.\n * Deregistration is expected O(1); shared references retain their registry entry\n * until the final release, and repeated disposal is a no-op. */\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 engine._textures.delete(tex);\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"]}