@babylonjs/lite-gl 1.24.0 → 1.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +5 -4
- package/blend.d.ts +1 -1
- package/blend.js +1 -1
- package/blend.js.map +1 -1
- package/context.d.ts +47 -4
- package/context.js +100 -11
- package/context.js.map +1 -1
- package/depth-stencil.d.ts +3 -2
- package/depth-stencil.js +10 -11
- package/depth-stencil.js.map +1 -1
- package/dynamic-texture.d.ts +6 -3
- package/dynamic-texture.js +16 -4
- package/dynamic-texture.js.map +1 -1
- package/effect.d.ts +12 -3
- package/effect.js +35 -24
- package/effect.js.map +1 -1
- package/family.d.ts +5 -1
- package/family.js.map +1 -1
- package/framebuffer-validation.d.ts +20 -0
- package/framebuffer-validation.js +37 -0
- package/framebuffer-validation.js.map +1 -0
- package/html-texture.d.ts +2 -2
- package/html-texture.js.map +1 -1
- package/index.d.ts +3 -2
- package/index.js +3 -2
- package/index.js.map +1 -1
- package/mesh.d.ts +68 -14
- package/mesh.js +211 -61
- package/mesh.js.map +1 -1
- package/package.json +3 -3
- package/render-target.d.ts +11 -9
- package/render-target.js +50 -35
- package/render-target.js.map +1 -1
- package/scissor.d.ts +1 -1
- package/scissor.js.map +1 -1
- package/sprites.d.ts +5 -3
- package/sprites.js +24 -23
- package/sprites.js.map +1 -1
- package/state.d.ts +25 -13
- package/state.js +13 -10
- package/state.js.map +1 -1
- package/text/_gpu/text-instances.js +1 -1
- package/text/_gpu/text-instances.js.map +1 -1
- package/texture-3d.d.ts +2 -1
- package/texture-3d.js +7 -2
- package/texture-3d.js.map +1 -1
- package/texture-source.d.ts +4 -2
- package/texture-source.js +3 -2
- package/texture-source.js.map +1 -1
- package/texture.d.ts +18 -8
- package/texture.js +61 -35
- package/texture.js.map +1 -1
- package/web-family.d.ts +2 -1
- package/web-family.js.map +1 -1
package/render-target.js.map
CHANGED
|
@@ -1 +1 @@
|
|
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AS,GAAG,CAAC,CAAC;IAChB,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACnC,CAAC","sourcesContent":["/**\n * Render-to-texture (offscreen framebuffer) support.\n *\n * Part of the public API via the `@babylonjs/lite-gl` barrel. The package is\n * `sideEffects: false`, so consumers that only render fullscreen effects to the\n * canvas tree-shake the FBO code out.\n *\n * This is the lite-gl equivalent of Babylon's `RenderTargetWrapper` +\n * `ThinEngine.createRenderTargetTexture` / `bindFramebuffer` /\n * `restoreDefaultFramebuffer` / `_readTexturePixelsSync`. A render target owns a\n * color {@link GLTexture} (or attaches a caller-supplied one) plus an optional\n * depth and/or stencil renderbuffer, all wrapped in a single\n * `WebGLFramebuffer`.\n *\n * The default {@link createRenderTarget} makes an 8-bit **RGBA8** (or, via\n * `format`, `R8` / `RG8`) color target and ships none of the HDR sized-format\n * knowledge; {@link createFloatRenderTarget}\n * is the separate opt-in for float / half-float color attachments (it alone\n * carries the `RGBA16F` / `RGBA32F` table, so RGBA8 consumers tree-shake it\n * away).\n *\n * The full color/depth/stencil GPU set is rebuilt automatically on\n * `webglcontextrestored` — the render target registers itself with the engine's\n * `_renderTargets` registry, and the context-restore protocol calls its\n * `_restore` closure AFTER the standalone texture replay. A caller-supplied\n * (BYO) color texture lives in the engine's `_textures` registry and is restored\n * there first; the RT then re-attaches its freshly-swapped handle.\n */\nimport { bindTextureForUpload, pickSizedInternalFormat, resolveLdrInternalFormat, setBoundTextureParams, type GLTexture } from \"./texture.js\";\nimport type { GLEngineContext } from \"./context.js\";\n\n/**\n * Presents a retained composition target to the whole canvas without disturbing\n * its contents; an active scissor rectangle does not clip the presentation.\n * Presentation copies framebuffers, which WebGL2 forbids into a multisampled\n * canvas, so it throws for an engine created with `antialias: true`.\n */\nexport function presentRenderTarget(target: GLRenderTarget): void {\n const engine = target._engine;\n if (engine._isLost || engine._disposed || target._disposed || !target.isReady) {\n return;\n }\n const gl = engine.gl;\n const s = engine._state;\n // A wiped cache records the canvas binding whatever is actually bound, so that binding is reissued.\n if (s.boundFramebuffer === null) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n }\n restoreDefaultFramebuffer(engine);\n // Queried with the canvas framebuffer bound; its sample count is fixed when the context is created.\n engine._canvasSamples ??= Number(gl.getParameter(gl.SAMPLES));\n if (engine._canvasSamples > 0) {\n throw new Error(\"lite-gl: presentRenderTarget cannot copy into a multisampled canvas; create the engine without antialias\");\n }\n let scissorEnabled = s.scissorEnabled;\n if (scissorEnabled === -1) {\n scissorEnabled = gl.isEnabled(gl.SCISSOR_TEST) ? 1 : 0;\n }\n if (scissorEnabled === 1) {\n gl.disable(gl.SCISSOR_TEST);\n }\n gl.bindFramebuffer(gl.READ_FRAMEBUFFER, target._framebuffer);\n gl.blitFramebuffer(0, 0, target.width, target.height, 0, 0, engine.canvas.width, engine.canvas.height, gl.COLOR_BUFFER_BIT, gl.NEAREST);\n gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null);\n if (scissorEnabled === 1) {\n gl.enable(gl.SCISSOR_TEST);\n }\n s.scissorEnabled = scissorEnabled;\n}\n\n/** GL `gl.UNSIGNED_BYTE` — the default (RGBA8) color attachment type. */\nconst UNSIGNED_BYTE = 0x1401;\n/** GL `gl.HALF_FLOAT`. */\nconst HALF_FLOAT = 0x140b;\n/** GL `gl.FLOAT`. */\nconst FLOAT = 0x1406;\n/** GL `gl.RGBA`. */\nconst RGBA = 0x1908;\n/** GL `gl.RED`. */\nconst RED = 0x1903;\n/** GL `gl.RG`. */\nconst RG = 0x8227;\n/** GL `gl.LINEAR`. */\nconst LINEAR = 0x2601;\n/** GL `gl.CLAMP_TO_EDGE`. */\nconst CLAMP_TO_EDGE = 0x812f;\n\n/** Options for {@link createRenderTarget}. Every field has a Babylon-matching\n * default: the bare `createRenderTarget(engine, width, height)` makes an RGBA8\n * color-only target with linear filtering and clamp wrapping. */\nexport interface GLRenderTargetOptions {\n /** Allocate a depth renderbuffer (`DEPTH_COMPONENT16`). Default `false`.\n * Stencil is NOT a create option — opt in (packed depth+stencil, or\n * stencil-only) via `generateRenderTargetStencil`\n * (`@babylonjs/lite-gl`), which keeps the stencil/packed\n * renderbuffer code out of the render-target core bundle. */\n generateDepthBuffer?: boolean;\n /** 8-bit color attachment format: `gl.RGBA` (default, `RGBA8`), `gl.RG`\n * (`RG8`) or `gl.RED` (`R8`) — ≙ Babylon's `RenderTargetCreationOptions.format`.\n * Ignored when {@link colorTexture} is supplied. Read single/two-channel\n * targets tightly via `readRenderTargetPixels(rt, { format })`. */\n format?: GLenum;\n /** Color texture minification filter. Default `gl.LINEAR`. */\n minFilter?: GLenum;\n /** Color texture magnification filter. Default `gl.LINEAR`. */\n magFilter?: GLenum;\n /** Color texture S wrap. Default `gl.CLAMP_TO_EDGE`. */\n wrapS?: GLenum;\n /** Color texture T wrap. Default `gl.CLAMP_TO_EDGE`. */\n wrapT?: GLenum;\n /** Attach a caller-supplied (BYO) color {@link GLTexture} instead of creating\n * one. When supplied the render target does NOT own or restore it — the\n * texture is engine-managed (restored by the standard texture-restore path\n * first) and the RT re-attaches its swapped handle afterwards. The caller is\n * responsible for sizing it to `width`×`height` and for disposing it.\n * Readbacks use the creator's texel type, so a float / half-float texture\n * must be attached via `createFloatRenderTarget` with a matching `type`\n * (`createRenderTarget` reads as `UNSIGNED_BYTE`). */\n colorTexture?: GLTexture;\n}\n\n/** Options for {@link createFloatRenderTarget} — {@link GLRenderTargetOptions}\n * (always RGBA, so without `format`) plus the float color `type`. */\nexport interface GLFloatRenderTargetOptions extends Omit<GLRenderTargetOptions, \"format\"> {\n /** Float color attachment type. Default `gl.HALF_FLOAT`. Pass `gl.FLOAT` for\n * full 32-bit. Downgraded to the best renderable type the engine supports\n * (`caps.textureFloatRender` / `caps.textureHalfFloatRender`), mirroring\n * Babylon's `getTextureType`. */\n type?: GLenum;\n}\n\n/** Read rectangle and channel layout shared by {@link readRenderTargetPixels}\n * and {@link readRenderTargetPixelsToBuffer}. Every field is optional: the\n * defaults read the whole target as RGBA. */\nexport interface GLReadPixelsRegionOptions {\n /** Lower-left X of the read rectangle, in texels. Default `0`. */\n x?: number;\n /** Lower-left Y of the read rectangle, in texels. Default `0`. */\n y?: number;\n /** Read rectangle width in texels. Default: the target's width. */\n width?: number;\n /** Read rectangle height in texels. Default: the target's height. */\n height?: number;\n /** Read format: `gl.RGBA` (default, 4 channels), `gl.RG` (2) or `gl.RED` (1). */\n format?: GLenum;\n}\n\n/** Options for {@link readRenderTargetPixels}. Every field is optional: the bare\n * `readRenderTargetPixels(rt)` reads the whole target as RGBA into a fresh\n * buffer. */\nexport interface GLReadPixelsOptions extends GLReadPixelsRegionOptions {\n /** Preallocated buffer (`width*height*channels` elements of the matching\n * type), reused to avoid per-call allocation. Default: a fresh buffer. */\n into?: ArrayBufferView;\n}\n\n/** Options for {@link readRenderTargetPixelsToBuffer}. */\nexport interface GLReadPixelsToBufferOptions extends GLReadPixelsRegionOptions {\n /** Byte offset into the destination `WebGLBuffer` where the first texel is\n * written. Must be a multiple of the read type's size. Default `0`. */\n offset?: number;\n}\n\n/** Resolved (defaults-applied) attachment description, retained on the render\n * target so `webglcontextrestored` can rebuild the exact same GPU set. */\ninterface ResolvedRTConfig {\n internalFormat: GLenum;\n format: GLenum;\n type: GLenum;\n hasDepth: boolean;\n minFilter: GLenum;\n magFilter: GLenum;\n wrapS: GLenum;\n wrapT: GLenum;\n /** True when the RT created (and therefore owns/restores/deletes) its color\n * texture; false for a BYO {@link GLRenderTargetOptions.colorTexture}. */\n ownsColorTexture: boolean;\n}\n\n/**\n * An offscreen render target — a `WebGLFramebuffer` wrapping a color\n * {@link GLTexture} and an optional depth / stencil renderbuffer. The lite-gl\n * counterpart of Babylon's `RenderTargetWrapper`.\n */\nexport interface GLRenderTarget {\n /** The color attachment, sampleable like any other {@link GLTexture}\n * (`setEffectTexture` / `bindTexture`). For an owned attachment its handle\n * is swapped on `webglcontextrestored` while consumers keep this same\n * reference. */\n texture: GLTexture;\n /** Color attachment width in texels. */\n width: number;\n /** Color attachment height in texels. */\n height: number;\n /** True once the color attachment + framebuffer are allocated. */\n isReady: boolean;\n /** @internal The framebuffer object. Swapped on context-restore. */\n _framebuffer: WebGLFramebuffer | null;\n /** @internal Depth-only (`DEPTH_COMPONENT16`) renderbuffer built by the core,\n * OR the packed/stencil renderbuffer installed by `generateRenderTargetStencil`\n * — a single field either way. Null when neither depth nor stencil is used. */\n _depthStencil: WebGLRenderbuffer | null;\n /**\n * @internal Optional stencil rebuild hook installed by\n * `generateRenderTargetStencil` (`@babylonjs/lite-gl`). When\n * present it OWNS the depth/stencil renderbuffer (replacing the core\n * depth-only buffer) and is re-invoked after every FBO rebuild\n * (create-via-helper, resize, context-restore) so the attachment survives.\n */\n _rebuildDepthStencil?: (engine: GLEngineContext) => void;\n /** @internal Resolved attachment config, for context-restore rebuild. */\n _config: ResolvedRTConfig;\n /** The engine that created (and owns) this render target. Operations on it derive\n * their engine from here, so they take the render target alone. @internal */\n _engine: GLEngineContext;\n /** @internal */\n _disposed: boolean;\n /** @internal Delete every GPU object the target owns (FBO, renderbuffer, and\n * the color texture iff owned). Resets the bound-framebuffer cache if it\n * pointed at this target. Called by `disposeRenderTarget`, `resizeRenderTarget`\n * and engine dispose. */\n _deleteGpu: (gl: WebGL2RenderingContext) => void;\n /** @internal Rebuild the FBO + renderbuffer (+ owned color texture) into\n * fresh handles after `webglcontextrestored`. */\n _restore: (engine: GLEngineContext) => void;\n}\n\n/**\n * Create an offscreen 8-bit render target — **RGBA8** by default, or `R8` /\n * `RG8` via {@link GLRenderTargetOptions.format}.\n *\n * The color attachment is an owned {@link GLTexture} (rebuilt by this target's\n * own restore hook), unless {@link GLRenderTargetOptions.colorTexture} supplies a\n * caller-managed (BYO) one. Mirrors Babylon's `createRenderTargetTexture`.\n *\n * @param engine - The engine to allocate GL resources on.\n * @param width - Color attachment width in texels. Must be a positive integer.\n * @param height - Color attachment height in texels. Must be a positive integer.\n * @param options - See {@link GLRenderTargetOptions}.\n * @returns The new {@link GLRenderTarget}.\n * @throws If `format` is not `RGBA` / `RG` / `RED`, `width`/`height` are not\n * positive integers, a GL handle could not be allocated, or the resulting\n * framebuffer is not complete. On failure every partial GPU object (including\n * an owned color texture) is released first.\n */\nexport function createRenderTarget(engine: GLEngineContext, width: number, height: number, options?: GLRenderTargetOptions): GLRenderTarget {\n const opts = options ?? {};\n const format = opts.format ?? RGBA;\n if (format !== RGBA && format !== RG && format !== RED) {\n throw new Error(`lite-gl: unsupported render target format 0x${format.toString(16)}`);\n }\n return buildRT(engine, width, height, opts, resolveLdrInternalFormat(engine.gl, format, UNSIGNED_BYTE), format, UNSIGNED_BYTE);\n}\n\n/**\n * Create an offscreen **float / half-float** render target — the HDR opt-in\n * counterpart of {@link createRenderTarget}. This is the only render-target\n * factory that references the `RGBA16F` / `RGBA32F` sized-format table, so RGBA8\n * consumers ship none of it.\n *\n * Defaults to `gl.HALF_FLOAT`; pass `options.type = gl.FLOAT` for full 32-bit.\n * The requested type is downgraded to the best renderable type the engine\n * supports (mirroring Babylon's `getTextureType`).\n *\n * @param engine - The engine to allocate GL resources on.\n * @param width - Color attachment width in texels. Must be a positive integer.\n * @param height - Color attachment height in texels. Must be a positive integer.\n * @param options - See {@link GLFloatRenderTargetOptions}.\n * @returns The new {@link GLRenderTarget}.\n * @throws As {@link createRenderTarget}.\n */\nexport function createFloatRenderTarget(engine: GLEngineContext, width: number, height: number, options?: GLFloatRenderTargetOptions): GLRenderTarget {\n const opts = options ?? {};\n const type = resolveColorType(engine, opts.type ?? HALF_FLOAT);\n const internalFormat = pickSizedInternalFormat(engine.gl, RGBA, type);\n return buildRT(engine, width, height, opts, internalFormat, RGBA, type);\n}\n\n/**\n * Bind the render target's framebuffer as the draw target and set the viewport\n * to cover it. Use {@link restoreDefaultFramebuffer} to return to the canvas.\n * Subsequent `drawEffect` / `drawIndexed` / `clearEngine` calls write into the\n * bound target.\n *\n * Cached. No-op on a lost/disposed context or a disposed `rt`. Mipmaps are NOT\n * regenerated here — refresh a target's mip chain explicitly via\n * {@link generateRenderTargetMipMaps} after rendering into it.\n *\n * @param rt - The render target to draw into.\n */\nexport function bindRenderTarget(rt: GLRenderTarget): void {\n const engine = rt._engine;\n if (engine._isLost || engine._disposed || rt._disposed) {\n return;\n }\n bindFramebufferAndViewport(engine, rt, rt._framebuffer, rt.width, rt.height);\n}\n\n/**\n * Bind the default (canvas) framebuffer and reset the viewport to the full\n * canvas — the counterpart of Babylon's `restoreDefaultFramebuffer`. Cached;\n * no-op on a lost/disposed context.\n *\n * @param engine - The engine.\n */\nexport function restoreDefaultFramebuffer(engine: GLEngineContext): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n bindFramebufferAndViewport(engine, null, null, engine.canvas.width, engine.canvas.height);\n}\n\nfunction bindFramebufferAndViewport(engine: GLEngineContext, rt: GLRenderTarget | null, fb: WebGLFramebuffer | null, width: number, height: number): void {\n const s = engine._state;\n if (s.boundFramebuffer !== fb) {\n engine.gl.bindFramebuffer(engine.gl.FRAMEBUFFER, fb);\n s.boundFramebuffer = fb;\n }\n engine._currentRenderTarget = rt;\n setViewportCached(engine, 0, 0, width, height);\n}\n\n/** Regenerate a render target's color-attachment mip chain from its (freshly\n * rendered) level-0 — mipmaps for render targets are a pure manual opt-in\n * (call this after rendering into the target). No-op for a disposed target, a\n * handle-less color attachment, or a lost/disposed context. */\nexport function generateRenderTargetMipMaps(rt: GLRenderTarget): void {\n const engine = rt._engine;\n if (engine._isLost || engine._disposed || rt._disposed || rt.texture.handle === null) {\n return;\n }\n bindTextureForUpload(engine, rt.texture.handle);\n engine.gl.generateMipmap(engine.gl.TEXTURE_2D);\n}\n\n/**\n * Resize the render target's color attachment (and depth/stencil renderbuffer).\n * Reallocates storage at the new size; the contents are discarded. The\n * `GLRenderTarget` / `GLTexture` identity is preserved, so consumers and\n * effect-sampler bindings holding the reference stay valid. If this target was\n * the live draw target, it is rebound (with the new-size viewport) afterwards.\n *\n * No-op when the size is unchanged or `rt` is disposed. While the context is\n * lost the new size is recorded but the GL reallocation is deferred to the\n * restore hook.\n *\n * @param rt - The render target to resize.\n * @param width - New width in texels (≥ 1).\n * @param height - New height in texels (≥ 1).\n */\nexport function resizeRenderTarget(rt: GLRenderTarget, width: number, height: number): void {\n const engine = rt._engine;\n if (rt._disposed) {\n return;\n }\n validateSize(width, height);\n if (rt.width === width && rt.height === height) {\n return;\n }\n rt.width = width;\n rt.height = height;\n rt.texture.width = width;\n rt.texture.height = height;\n if (engine._isLost || engine._disposed) {\n return;\n }\n // Capture the live binding BEFORE we delete the old FBO so we can restore it.\n const wasBound = engine._state.boundFramebuffer === rt._framebuffer && rt._framebuffer !== null;\n // For a BYO color texture, re-specify the caller's storage at the new size\n // (contents discarded, like the owned path). `_updateRaw` updates the\n // texture's tracked dims AND re-runs its upload closure — `_upload` alone\n // would re-upload at the stale ORIGINAL size, leaving the attachment a\n // different size than the FBO. An external handle without `_updateRaw` must\n // be resized by its owner; we then just rebuild the FBO around it. An owned\n // texture is recreated wholesale by allocateRenderTargetGpu.\n if (!rt._config.ownsColorTexture) {\n rt.texture._updateRaw?.(engine, null, width, height, 4);\n }\n rt._deleteGpu(engine.gl);\n allocateRenderTargetGpu(engine, rt);\n if (wasBound) {\n bindRenderTarget(rt);\n }\n}\n\n/**\n * Synchronously read back a rectangle of the render target's color attachment\n * via `gl.readPixels` — the lite-gl equivalent of Babylon's\n * `_readTexturePixelsSync`. Binds the target's framebuffer (leaving it bound,\n * matching Babylon).\n *\n * The returned array element type follows the color attachment type:\n * `Uint8Array` for `UNSIGNED_BYTE`, `Float32Array` for `FLOAT`, `Uint16Array`\n * for `HALF_FLOAT`. Origin is GL bottom-left.\n *\n * Reads `RGBA` by default (like Babylon; always readable, a `RED` target reads\n * back as `R,0,0,1`). Pass `format` `gl.RED` / `gl.RG` to read 1 / 2 channels\n * per texel into a tightly packed buffer (`PACK_ALIGNMENT` is set to 1 and left\n * there — lite-gl does not otherwise use it). WebGL only guarantees non-RGBA\n * reads when they match the implementation-chosen\n * `gl.IMPLEMENTATION_COLOR_READ_FORMAT` (`RED` for `R8`, `RG` for `RG8` in all\n * major browsers).\n *\n * @param rt - The render target to read from.\n * @param options - See {@link GLReadPixelsOptions}. Default: the whole target,\n * as RGBA, into a fresh buffer.\n * @returns The pixel buffer (the provided `into`, or a freshly allocated one).\n * Empty buffer on a lost/disposed context.\n */\nexport function readRenderTargetPixels(rt: GLRenderTarget, options?: GLReadPixelsOptions): ArrayBufferView {\n const opts = options ?? {};\n const width = opts.width ?? rt.width;\n const height = opts.height ?? rt.height;\n const format = opts.format ?? RGBA;\n const into = opts.into;\n const gl = bindForRead(rt, format);\n if (gl === null) {\n return into ?? new Uint8Array(0);\n }\n const type = rt._config.type;\n let buffer = into;\n if (buffer === undefined) {\n const elements = width * height * (format === RED ? 1 : format === RG ? 2 : 4);\n buffer = type === gl.FLOAT ? new Float32Array(elements) : type === gl.HALF_FLOAT ? new Uint16Array(elements) : new Uint8Array(elements);\n }\n gl.readPixels(opts.x ?? 0, opts.y ?? 0, width, height, format, type, buffer);\n return buffer;\n}\n\n/**\n * Read a rectangle of the render target's color attachment into a GPU\n * `WebGLBuffer` (`PIXEL_PACK_BUFFER` readback): `gl.readPixels` with a byte\n * offset instead of a CPU array, so the copy stays on the GPU and can be\n * consumed later without a sync stall (e.g. `gl.fenceSync` +\n * `gl.getBufferSubData`, or as vertex data).\n *\n * Same rectangle / `format` rules as {@link readRenderTargetPixels}: whole\n * target as RGBA by default, `gl.RED` / `gl.RG` read 1 / 2 channels per texel\n * tightly packed (`PACK_ALIGNMENT` 1). The texel type follows the color\n * attachment type. `buffer` must already be allocated (`gl.bufferData`) large\n * enough for `offset + width*height*channels*bytesPerChannel` bytes, and (per\n * WebGL2) must never have been bound to `ELEMENT_ARRAY_BUFFER`.\n *\n * Binds the target's framebuffer (left bound, like\n * {@link readRenderTargetPixels}), binds `buffer` to `PIXEL_PACK_BUFFER` for\n * the read and then unbinds it (`null`), so later CPU readbacks keep working.\n * No-op on a lost/disposed context or a disposed target.\n *\n * @param rt - The render target to read from.\n * @param buffer - Destination `WebGLBuffer`, created on `rt`'s context.\n * @param options - See {@link GLReadPixelsToBufferOptions}.\n */\nexport function readRenderTargetPixelsToBuffer(rt: GLRenderTarget, buffer: WebGLBuffer, options?: GLReadPixelsToBufferOptions): void {\n const opts = options ?? {};\n const format = opts.format ?? RGBA;\n const gl = bindForRead(rt, format);\n if (gl === null) {\n return;\n }\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, buffer);\n gl.readPixels(opts.x ?? 0, opts.y ?? 0, opts.width ?? rt.width, opts.height ?? rt.height, format, rt._config.type, opts.offset ?? 0);\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);\n}\n\n/** Shared readback prologue: bail on a lost/disposed context or target, bind\n * `rt`'s framebuffer (cached), and set `PACK_ALIGNMENT` 1 for the tightly\n * packed `RED` / `RG` reads. Returns the context, or `null` to skip the read. */\nfunction bindForRead(rt: GLRenderTarget, format: GLenum): WebGL2RenderingContext | null {\n const engine = rt._engine;\n if (engine._isLost || engine._disposed || rt._disposed) {\n return null;\n }\n const gl = engine.gl;\n const s = engine._state;\n if (s.boundFramebuffer !== rt._framebuffer) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, rt._framebuffer);\n s.boundFramebuffer = rt._framebuffer;\n }\n if (format !== RGBA) {\n // Not cached: a sync readback dwarfs it, and callers may change it directly.\n gl.pixelStorei(gl.PACK_ALIGNMENT, 1);\n }\n return gl;\n}\n\n/**\n * Release the render target's framebuffer, depth/stencil renderbuffer and (iff\n * owned) color texture, and unregister it from the engine. Idempotent, and a\n * no-op for `null`/`undefined` (so an optional target can be released\n * unconditionally). Clears the bound-framebuffer cache if it pointed at this\n * target, and any sampler slot that held the color texture handle.\n *\n * A BYO {@link GLRenderTargetOptions.colorTexture} is NOT disposed here — it is\n * engine-managed and the caller owns its lifetime.\n *\n * @param rt - The render target to dispose, or `null`/`undefined` for a no-op.\n */\nexport function disposeRenderTarget(rt: GLRenderTarget | null | undefined): void {\n if (rt === null || rt === undefined || rt._disposed) {\n return;\n }\n const engine = rt._engine;\n rt._disposed = true;\n // Only the owned color texture is marked disposed here; a BYO texture stays\n // live for its caller-owner.\n if (rt._config.ownsColorTexture) {\n rt.texture._disposed = true;\n }\n if (engine._currentRenderTarget === rt) {\n engine._currentRenderTarget = null;\n }\n const i = engine._renderTargets.indexOf(rt);\n if (i !== -1) {\n engine._renderTargets.splice(i, 1);\n }\n // Capture the handle before _deleteGpu nulls it (owned case).\n const handle = rt.texture.handle;\n if (!engine._isLost && !engine._disposed) {\n rt._deleteGpu(engine.gl);\n } else {\n rt._framebuffer = null;\n rt._depthStencil = null;\n }\n if (handle !== null) {\n const bound = engine._state.boundTextures;\n for (let u = 0; u < bound.length; u++) {\n if (bound[u] === handle) {\n bound[u] = null;\n }\n }\n }\n}\n\n/* ──────────────────────────── internal helpers ──────────────────────────── */\n\n/** Shared private constructor. Validates size, resolves the config (given the\n * exact sized `internalFormat` by the caller — NO format-table lookup), wires\n * the owned-or-BYO color texture, allocates the GPU set atomically, and\n * registers the target. */\nfunction buildRT(engine: GLEngineContext, width: number, height: number, options: GLRenderTargetOptions, internalFormat: GLenum, format: GLenum, type: GLenum): GLRenderTarget {\n validateSize(width, height);\n const gl = engine.gl;\n const byo = options.colorTexture;\n const config: ResolvedRTConfig = {\n internalFormat,\n format,\n type,\n hasDepth: options.generateDepthBuffer ?? false,\n minFilter: options.minFilter ?? LINEAR,\n magFilter: options.magFilter ?? LINEAR,\n wrapS: options.wrapS ?? CLAMP_TO_EDGE,\n wrapT: options.wrapT ?? CLAMP_TO_EDGE,\n ownsColorTexture: byo === undefined,\n };\n\n const texture: GLTexture = byo ?? {\n handle: null as unknown as WebGLTexture,\n target: gl.TEXTURE_2D,\n width,\n height,\n isReady: false,\n _engine: engine,\n _disposed: false,\n _refCount: 1,\n // Owned-by-RT: its storage is (re)allocated by allocateRenderTargetGpu,\n // never via the engine `_textures` replay (it is NOT registered there).\n _upload: () => {},\n _wasReady: false,\n };\n\n const rt: GLRenderTarget = {\n texture,\n width,\n height,\n isReady: false,\n _framebuffer: null,\n _depthStencil: null,\n _rebuildDepthStencil: undefined,\n _config: config,\n _engine: engine,\n _disposed: false,\n _deleteGpu: () => {},\n _restore: () => {},\n };\n\n rt._deleteGpu = (glc: WebGL2RenderingContext): void => {\n const s = engine._state;\n if (rt._framebuffer !== null) {\n // Deleting the bound FBO reverts GL to framebuffer 0 (spec) — just\n // reset the cache, no explicit rebind needed.\n if (s.boundFramebuffer === rt._framebuffer) {\n s.boundFramebuffer = null;\n }\n glc.deleteFramebuffer(rt._framebuffer);\n rt._framebuffer = null;\n }\n if (rt._depthStencil !== null) {\n glc.deleteRenderbuffer(rt._depthStencil);\n rt._depthStencil = null;\n }\n // Never delete a BYO color texture — the caller-owner manages it.\n if (config.ownsColorTexture && rt.texture.handle !== null) {\n glc.deleteTexture(rt.texture.handle);\n rt.texture.handle = null as unknown as WebGLTexture;\n }\n rt.texture.isReady = false;\n rt.isReady = false;\n };\n\n rt._restore = (target: GLEngineContext): void => {\n // Resilient: a restore failure must not break the engine's restore loop.\n try {\n allocateRenderTargetGpu(target, rt);\n } catch (err) {\n console.error(\"lite-gl: render target restore failed\", err);\n }\n };\n\n allocateRenderTargetGpu(engine, rt);\n engine._renderTargets.push(rt);\n return rt;\n}\n\n/** Downgrade a requested float/half-float color type to the best renderable\n * type the engine supports, mirroring Babylon's `getTextureType`. */\nfunction resolveColorType(engine: GLEngineContext, type: GLenum): GLenum {\n const gl = engine.gl;\n if (type === FLOAT && !engine.caps.textureFloatRender) {\n return engine.caps.textureHalfFloatRender ? gl.HALF_FLOAT : gl.UNSIGNED_BYTE;\n }\n if (type === HALF_FLOAT && !engine.caps.textureHalfFloatRender) {\n return gl.UNSIGNED_BYTE;\n }\n return type;\n}\n\n/** Validate a render-target size is a pair of positive integers. */\nfunction validateSize(width: number, height: number): void {\n if (!Number.isInteger(width) || !Number.isInteger(height) || width < 1 || height < 1) {\n throw new Error(`lite-gl: render target size must be positive integers, got ${width}x${height}`);\n }\n}\n\n/**\n * (Re)allocate the color texture (iff owned), framebuffer and depth/stencil\n * renderbuffer into fresh handles, attach them, and validate completeness.\n * Shared by create / resize / context-restore. No-op on a lost/disposed context.\n *\n * ATOMIC: captures the previously-bound framebuffer and restores it in a\n * `finally`; on any failure deletes the partial FBO / renderbuffer (and the\n * owned color texture it created), nulls the fields, and rethrows — so a failed\n * build never leaks a GPU handle nor leaves a half-attached framebuffer bound.\n */\nfunction allocateRenderTargetGpu(engine: GLEngineContext, rt: GLRenderTarget): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n const s = engine._state;\n const c = rt._config;\n const prevFb = s.boundFramebuffer;\n let createdTexture: WebGLTexture | null = null;\n let fb: WebGLFramebuffer | null = null;\n let rb: WebGLRenderbuffer | null = null;\n try {\n // ── Color texture (owned only) ───────────────────────────────────────\n if (c.ownsColorTexture) {\n const texHandle = gl.createTexture();\n if (texHandle === null) {\n throw new Error(\"lite-gl: gl.createTexture returned null (render target color)\");\n }\n createdTexture = texHandle;\n rt.texture.handle = texHandle;\n bindTextureForUpload(engine, texHandle);\n gl.texImage2D(gl.TEXTURE_2D, 0, c.internalFormat, rt.width, rt.height, 0, c.format, c.type, null);\n setBoundTextureParams(gl, c.minFilter, c.magFilter, c.wrapS, c.wrapT);\n rt.texture.isReady = true;\n rt.texture._wasReady = true;\n }\n\n // ── Framebuffer + attachments ────────────────────────────────────────\n fb = gl.createFramebuffer();\n if (fb === null) {\n throw new Error(\"lite-gl: gl.createFramebuffer returned null\");\n }\n rt._framebuffer = fb;\n gl.bindFramebuffer(gl.FRAMEBUFFER, fb);\n s.boundFramebuffer = fb;\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, rt.texture.handle, 0);\n\n // ── Depth (core, DEPTH-ONLY) ─────────────────────────────────────────\n // The core only ever builds a DEPTH_COMPONENT16 depth buffer. Stencil /\n // packed depth-stencil is an opt-in installed by\n // `generateRenderTargetStencil` (`@babylonjs/lite-gl`),\n // which sets `_rebuildDepthStencil` to a closure that REPLACES the\n // depth-only buffer below with its own packed/stencil renderbuffer. That\n // hook is re-run here on every rebuild (create / resize / context-restore)\n // so a helper-added stencil attachment survives at the new size.\n rt._depthStencil = null;\n if (c.hasDepth) {\n rb = gl.createRenderbuffer();\n if (rb === null) {\n throw new Error(\"lite-gl: gl.createRenderbuffer returned null\");\n }\n gl.bindRenderbuffer(gl.RENDERBUFFER, rb);\n gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, rt.width, rt.height);\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, rb);\n gl.bindRenderbuffer(gl.RENDERBUFFER, null);\n rt._depthStencil = rb;\n }\n // A helper-attached stencil replaces/augments the depth-only buffer.\n rt._rebuildDepthStencil?.(engine);\n\n const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);\n if (status !== gl.FRAMEBUFFER_COMPLETE) {\n throw new Error(`lite-gl: render target framebuffer incomplete (status 0x${status.toString(16)})`);\n }\n rt.isReady = true;\n } catch (e) {\n // Free whatever depth/stencil renderbuffer is currently attached. After a\n // `_rebuildDepthStencil` hook ran, `rt._depthStencil` may be a packed buffer\n // the hook swapped in (it deletes the core `rb` itself on success), so free\n // the live `rt._depthStencil` rather than the stale local `rb`.\n if (rt._depthStencil !== null) {\n gl.deleteRenderbuffer(rt._depthStencil);\n }\n rt._depthStencil = null;\n if (fb !== null) {\n gl.deleteFramebuffer(fb);\n }\n rt._framebuffer = null;\n // Delete ONLY a texture we created here (owned). Never a BYO texture.\n if (createdTexture !== null) {\n gl.deleteTexture(createdTexture);\n rt.texture.handle = null as unknown as WebGLTexture;\n rt.texture.isReady = false;\n }\n rt.isReady = false;\n throw e;\n } finally {\n // Restore the previously-bound draw target — creation/restore must not\n // silently redirect subsequent draws.\n if (s.boundFramebuffer !== prevFb) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, prevFb);\n s.boundFramebuffer = prevFb;\n }\n }\n}\n\n/** Inline cached `gl.viewport` — kept local so the render-target module has\n * no runtime dependency on the effect-renderer module. */\nfunction setViewportCached(engine: GLEngineContext, x: number, y: number, w: number, h: number): void {\n const s = engine._state;\n if (s.viewportX === x && s.viewportY === y && s.viewportW === w && s.viewportH === h) {\n return;\n }\n s.viewportX = x;\n s.viewportY = y;\n s.viewportW = w;\n s.viewportH = h;\n engine.gl.viewport(x, y, w, h);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"render-target.js","sourceRoot":"","sources":["../src/render-target.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,qBAAqB,EAAkB,MAAM,cAAc,CAAC;AAE9I,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAsB;IACtD,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;IAC9B,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAC5E,OAAO;IACX,CAAC;IACD,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IACrB,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,yBAAyB,CAAC,MAAM,CAAC,CAAC;IAClC,oGAAoG;IACpG,MAAM,CAAC,cAAc,KAAK,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9D,IAAI,MAAM,CAAC,cAAc,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,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AAG,IAA+B,CAAC;YACpD,EAAE,CAAC,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;QAC/B,CAAC;QACD,EAAE,CAAC,OAAO,GAAG,KAAK,CAAC;QACnB,MAAM,CAAC,CAAC;IACZ,CAAC;YAAS,CAAC;QACP,uEAAuE;QACvE,sCAAsC;QACtC,IAAI,CAAC,CAAC,gBAAgB,KAAK,MAAM,EAAE,CAAC;YAChC,EAAE,CAAC,eAAe,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;YAC3C,CAAC,CAAC,gBAAgB,GAAG,MAAM,CAAC;QAChC,CAAC;IACL,CAAC;AACL,CAAC;AAED;2DAC2D;AAC3D,SAAS,iBAAiB,CAAC,MAAuB,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS;IAC1F,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,CAAC,CAAC,SAAS,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,KAAK,CAAC,EAAE,CAAC;QACnF,OAAO;IACX,CAAC;IACD,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC;IAChB,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC;IAChB,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC;IAChB,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC;IAChB,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACnC,CAAC","sourcesContent":["/**\n * Render-to-texture (offscreen framebuffer) support.\n *\n * Part of the public API via the `@babylonjs/lite-gl` barrel. The package is\n * `sideEffects: false`, so consumers that only render fullscreen effects to the\n * canvas tree-shake the FBO code out.\n *\n * This is the lite-gl equivalent of Babylon's `RenderTargetWrapper` +\n * `ThinEngine.createRenderTargetTexture` / `bindFramebuffer` /\n * `restoreDefaultFramebuffer` / `_readTexturePixelsSync`. A render target owns a\n * color {@link GLTexture} (or attaches a caller-supplied one) plus an optional\n * depth and/or stencil renderbuffer, all wrapped in a single\n * `WebGLFramebuffer`.\n *\n * The default {@link createRenderTarget} makes an 8-bit **RGBA8** (or, via\n * `format`, `R8` / `RG8`) color target and ships none of the HDR sized-format\n * knowledge; {@link createFloatRenderTarget}\n * is the separate opt-in for float / half-float color attachments (it alone\n * carries the `RGBA16F` / `RGBA32F` table, so RGBA8 consumers tree-shake it\n * away).\n *\n * Unless the engine is host-owned (`createHostOwnedGLEngine`), the full color/depth/stencil GPU set is rebuilt automatically on\n * `webglcontextrestored` — the render target registers itself with the engine's\n * `_renderTargets` registry, and the context-restore protocol calls its\n * `_restore` closure AFTER the standalone texture replay. A caller-supplied\n * (BYO) color texture lives in the engine's `_textures` registry and is restored\n * there first; the RT then re-attaches its freshly-swapped handle.\n */\nimport { bindTextureForUpload, pickSizedInternalFormat, resolveLdrInternalFormat, setBoundTextureParams, type GLTexture } from \"./texture.js\";\nimport type { GLEngineContext } from \"./context.js\";\nimport { validateFramebuffer } from \"./framebuffer-validation.js\";\n\n/**\n * Presents a retained composition target to the whole canvas without disturbing\n * its contents; an active scissor rectangle does not clip the presentation.\n * Presentation copies framebuffers, which WebGL2 forbids into a multisampled\n * canvas, so it throws for an engine created with `antialias: true`.\n */\nexport function presentRenderTarget(target: GLRenderTarget): void {\n const engine = target._engine;\n if (engine._isLost || engine._disposed || target._disposed || !target.isReady) {\n return;\n }\n const gl = engine.gl;\n const s = engine._state;\n restoreDefaultFramebuffer(engine);\n // Queried with the canvas framebuffer bound; its sample count is fixed when the context is created.\n engine._canvasSamples ??= Number(gl.getParameter(gl.SAMPLES));\n if (engine._canvasSamples > 0) {\n throw new Error(\"lite-gl: presentRenderTarget cannot copy into a multisampled canvas; create the engine without antialias\");\n }\n let scissorEnabled = s.scissorEnabled;\n if (scissorEnabled === -1) {\n scissorEnabled = gl.isEnabled(gl.SCISSOR_TEST) ? 1 : 0;\n }\n if (scissorEnabled === 1) {\n gl.disable(gl.SCISSOR_TEST);\n }\n gl.bindFramebuffer(gl.READ_FRAMEBUFFER, target._framebuffer);\n gl.blitFramebuffer(0, 0, target.width, target.height, 0, 0, engine.canvas.width, engine.canvas.height, gl.COLOR_BUFFER_BIT, gl.NEAREST);\n gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null);\n if (scissorEnabled === 1) {\n gl.enable(gl.SCISSOR_TEST);\n }\n s.scissorEnabled = scissorEnabled;\n}\n\n/** GL `gl.UNSIGNED_BYTE` — the default (RGBA8) color attachment type. */\nconst UNSIGNED_BYTE = 0x1401;\n/** GL `gl.HALF_FLOAT`. */\nconst HALF_FLOAT = 0x140b;\n/** GL `gl.FLOAT`. */\nconst FLOAT = 0x1406;\n/** GL `gl.RGBA`. */\nconst RGBA = 0x1908;\n/** GL `gl.RED`. */\nconst RED = 0x1903;\n/** GL `gl.RG`. */\nconst RG = 0x8227;\n/** GL `gl.LINEAR`. */\nconst LINEAR = 0x2601;\n/** GL `gl.CLAMP_TO_EDGE`. */\nconst CLAMP_TO_EDGE = 0x812f;\n\n/** Options for {@link createRenderTarget}. Every field has a Babylon-matching\n * default: the bare `createRenderTarget(engine, width, height)` makes an RGBA8\n * color-only target with linear filtering and clamp wrapping. */\nexport interface GLRenderTargetOptions {\n /** Allocate a depth renderbuffer (`DEPTH_COMPONENT16`). Default `false`.\n * Stencil is NOT a create option — opt in (packed depth+stencil, or\n * stencil-only) via `generateRenderTargetStencil`\n * (`@babylonjs/lite-gl`), which keeps the stencil/packed\n * renderbuffer code out of the render-target core bundle. */\n generateDepthBuffer?: boolean;\n /** 8-bit color attachment format: `gl.RGBA` (default, `RGBA8`), `gl.RG`\n * (`RG8`) or `gl.RED` (`R8`) — ≙ Babylon's `RenderTargetCreationOptions.format`.\n * Ignored when {@link colorTexture} is supplied. Read single/two-channel\n * targets tightly via `readRenderTargetPixels(rt, { format })`. */\n format?: GLenum;\n /** Color texture minification filter. Default `gl.LINEAR`. */\n minFilter?: GLenum;\n /** Color texture magnification filter. Default `gl.LINEAR`. */\n magFilter?: GLenum;\n /** Color texture S wrap. Default `gl.CLAMP_TO_EDGE`. */\n wrapS?: GLenum;\n /** Color texture T wrap. Default `gl.CLAMP_TO_EDGE`. */\n wrapT?: GLenum;\n /** Attach a caller-supplied (BYO) color {@link GLTexture} instead of creating\n * one. When supplied the render target does NOT own or restore it — the\n * texture is engine-managed (restored by the standard texture-restore path\n * first) and the RT re-attaches its swapped handle afterwards. The caller is\n * responsible for sizing it to `width`×`height` and for disposing it.\n * Readbacks use the creator's texel type, so a float / half-float texture\n * must be attached via `createFloatRenderTarget` with a matching `type`\n * (`createRenderTarget` reads as `UNSIGNED_BYTE`). */\n colorTexture?: GLTexture;\n}\n\n/** Options for {@link createFloatRenderTarget} — {@link GLRenderTargetOptions}\n * (always RGBA, so without `format`) plus the float color `type`. */\nexport interface GLFloatRenderTargetOptions extends Omit<GLRenderTargetOptions, \"format\"> {\n /** Float color attachment type. Default `gl.HALF_FLOAT`. Pass `gl.FLOAT` for\n * full 32-bit. Downgraded to the best renderable type the engine supports\n * (`caps.textureFloatRender` / `caps.textureHalfFloatRender`), mirroring\n * Babylon's `getTextureType`. */\n type?: GLenum;\n}\n\n/** Read rectangle and channel layout shared by {@link readRenderTargetPixels}\n * and {@link readRenderTargetPixelsToBuffer}. Every field is optional: the\n * defaults read the whole target as RGBA. */\nexport interface GLReadPixelsRegionOptions {\n /** Lower-left X of the read rectangle, in texels. Default `0`. */\n x?: number;\n /** Lower-left Y of the read rectangle, in texels. Default `0`. */\n y?: number;\n /** Read rectangle width in texels. Default: the target's width. */\n width?: number;\n /** Read rectangle height in texels. Default: the target's height. */\n height?: number;\n /** Read format: `gl.RGBA` (default, 4 channels), `gl.RG` (2) or `gl.RED` (1). */\n format?: GLenum;\n}\n\n/** Options for {@link readRenderTargetPixels}. Every field is optional: the bare\n * `readRenderTargetPixels(rt)` reads the whole target as RGBA into a fresh\n * buffer. */\nexport interface GLReadPixelsOptions extends GLReadPixelsRegionOptions {\n /** Preallocated buffer (`width*height*channels` elements of the matching\n * type), reused to avoid per-call allocation. Default: a fresh buffer. */\n into?: ArrayBufferView;\n}\n\n/** Options for {@link readRenderTargetPixelsToBuffer}. */\nexport interface GLReadPixelsToBufferOptions extends GLReadPixelsRegionOptions {\n /** Byte offset into the destination `WebGLBuffer` where the first texel is\n * written. Must be a multiple of the read type's size. Default `0`. */\n offset?: number;\n}\n\n/** Resolved (defaults-applied) attachment description, retained on the render\n * target so `webglcontextrestored` can rebuild the exact same GPU set. */\ninterface ResolvedRTConfig {\n internalFormat: GLenum;\n format: GLenum;\n type: GLenum;\n hasDepth: boolean;\n minFilter: GLenum;\n magFilter: GLenum;\n wrapS: GLenum;\n wrapT: GLenum;\n /** True when the RT created (and therefore owns/restores/deletes) its color\n * texture; false for a BYO {@link GLRenderTargetOptions.colorTexture}. */\n ownsColorTexture: boolean;\n}\n\n/**\n * An offscreen render target — a `WebGLFramebuffer` wrapping a color\n * {@link GLTexture} and an optional depth / stencil renderbuffer. The lite-gl\n * counterpart of Babylon's `RenderTargetWrapper`.\n */\nexport interface GLRenderTarget {\n /** The color attachment, sampleable like any other {@link GLTexture}\n * (`setEffectTexture` / `bindTexture`). For an owned attachment its handle\n * is swapped on `webglcontextrestored` while consumers keep this same\n * reference. */\n texture: GLTexture;\n /** Color attachment width in texels. */\n width: number;\n /** Color attachment height in texels. */\n height: number;\n /** True once the color attachment + framebuffer are allocated. */\n isReady: boolean;\n /** @internal The framebuffer object. Swapped on context-restore. */\n _framebuffer: WebGLFramebuffer | null;\n /** @internal Depth-only (`DEPTH_COMPONENT16`) renderbuffer built by the core,\n * OR the packed/stencil renderbuffer installed by `generateRenderTargetStencil`\n * — a single field either way. Null when neither depth nor stencil is used. */\n _depthStencil: WebGLRenderbuffer | null;\n /**\n * @internal Optional stencil rebuild hook installed by\n * `generateRenderTargetStencil` (`@babylonjs/lite-gl`). When\n * present it OWNS the depth/stencil renderbuffer (replacing the core\n * depth-only buffer) and is re-invoked after every FBO rebuild\n * (create-via-helper, resize, context-restore) so the attachment survives.\n */\n _rebuildDepthStencil?: (engine: GLEngineContext) => void;\n /** @internal Resolved attachment config, for context-restore rebuild. */\n _config: ResolvedRTConfig;\n /** The engine that created (and owns) this render target. Operations on it derive\n * their engine from here, so they take the render target alone. @internal */\n _engine: GLEngineContext;\n /** @internal */\n _disposed: boolean;\n /** @internal Delete every GPU object the target owns (FBO, renderbuffer, and\n * the color texture iff owned). Resets the bound-framebuffer cache if it\n * pointed at this target. Called by `disposeRenderTarget`, `resizeRenderTarget`\n * and engine dispose. */\n _deleteGpu: (gl: WebGL2RenderingContext) => void;\n /** @internal Rebuild the FBO + renderbuffer (+ owned color texture) into\n * fresh handles after `webglcontextrestored`. */\n _restore?: (engine: GLEngineContext) => void;\n}\n\n/**\n * Create an offscreen 8-bit render target — **RGBA8** by default, or `R8` /\n * `RG8` via {@link GLRenderTargetOptions.format}.\n *\n * The color attachment is an owned {@link GLTexture} (rebuilt by this target's\n * own restore hook), unless {@link GLRenderTargetOptions.colorTexture} supplies a\n * caller-managed (BYO) one. Mirrors Babylon's `createRenderTargetTexture`.\n *\n * @param engine - The engine to allocate GL resources on.\n * @param width - Color attachment width in texels. Must be a positive integer up to `caps.maxTextureSize`.\n * @param height - Color attachment height in texels. Must be a positive integer up to `caps.maxTextureSize`.\n * @param options - See {@link GLRenderTargetOptions}.\n * @returns The new {@link GLRenderTarget}.\n * @throws If `format` is not `RGBA` / `RG` / `RED`, `width`/`height` are not\n * positive integers up to `caps.maxTextureSize`, a GL handle could not be allocated, or the resulting\n * framebuffer is not complete (unless `setFramebufferValidation(engine, false)`\n * opted out of completeness checks). On failure every partial GPU object (including\n * an owned color texture) is released first.\n */\nexport function createRenderTarget(engine: GLEngineContext, width: number, height: number, options?: GLRenderTargetOptions): GLRenderTarget {\n const opts = options ?? {};\n const format = opts.format ?? RGBA;\n if (format !== RGBA && format !== RG && format !== RED) {\n throw new Error(`lite-gl: unsupported render target format 0x${format.toString(16)}`);\n }\n return buildRT(engine, width, height, opts, resolveLdrInternalFormat(engine.gl, format, UNSIGNED_BYTE), format, UNSIGNED_BYTE);\n}\n\n/**\n * Create an offscreen **float / half-float** render target — the HDR opt-in\n * counterpart of {@link createRenderTarget}. This is the only render-target\n * factory that references the `RGBA16F` / `RGBA32F` sized-format table, so RGBA8\n * consumers ship none of it.\n *\n * Defaults to `gl.HALF_FLOAT`; pass `options.type = gl.FLOAT` for full 32-bit.\n * The requested type is downgraded to the best renderable type the engine\n * supports (mirroring Babylon's `getTextureType`).\n *\n * @param engine - The engine to allocate GL resources on.\n * @param width - Color attachment width in texels. Must be a positive integer up to `caps.maxTextureSize`.\n * @param height - Color attachment height in texels. Must be a positive integer up to `caps.maxTextureSize`.\n * @param options - See {@link GLFloatRenderTargetOptions}.\n * @returns The new {@link GLRenderTarget}.\n * @throws As {@link createRenderTarget}.\n */\nexport function createFloatRenderTarget(engine: GLEngineContext, width: number, height: number, options?: GLFloatRenderTargetOptions): GLRenderTarget {\n const opts = options ?? {};\n const type = resolveColorType(engine, opts.type ?? HALF_FLOAT);\n const internalFormat = pickSizedInternalFormat(engine.gl, RGBA, type);\n return buildRT(engine, width, height, opts, internalFormat, RGBA, type);\n}\n\n/**\n * Bind the render target's framebuffer as the draw target and set the viewport\n * to cover it. Use {@link restoreDefaultFramebuffer} to return to the canvas.\n * Subsequent `drawEffect` / `drawIndexed` / `clearEngine` calls write into the\n * bound target.\n *\n * Cached. No-op on a lost/disposed context or a disposed `rt`. Mipmaps are NOT\n * regenerated here — refresh a target's mip chain explicitly via\n * {@link generateRenderTargetMipMaps} after rendering into it.\n *\n * @param rt - The render target to draw into.\n */\nexport function bindRenderTarget(rt: GLRenderTarget): void {\n const engine = rt._engine;\n if (engine._isLost || engine._disposed || rt._disposed) {\n return;\n }\n bindFramebufferAndViewport(engine, rt, rt._framebuffer, rt.width, rt.height);\n}\n\n/**\n * Bind the default (canvas) framebuffer and reset the viewport to the full\n * canvas — the counterpart of Babylon's `restoreDefaultFramebuffer`. Cached;\n * no-op on a lost/disposed context.\n *\n * @param engine - The engine.\n */\nexport function restoreDefaultFramebuffer(engine: GLEngineContext): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n bindFramebufferAndViewport(engine, null, null, engine.canvas.width, engine.canvas.height);\n}\n\nfunction bindFramebufferAndViewport(engine: GLEngineContext, rt: GLRenderTarget | null, fb: WebGLFramebuffer | null, width: number, height: number): void {\n const s = engine._state;\n if (s.boundFramebuffer !== fb) {\n engine.gl.bindFramebuffer(engine.gl.FRAMEBUFFER, fb);\n s.boundFramebuffer = fb;\n }\n engine._currentRenderTarget = rt;\n setViewportCached(engine, 0, 0, width, height);\n}\n\n/** Regenerate a render target's color-attachment mip chain from its (freshly\n * rendered) level-0 — mipmaps for render targets are a pure manual opt-in\n * (call this after rendering into the target). No-op for a disposed target, a\n * handle-less color attachment, or a lost/disposed context. */\nexport function generateRenderTargetMipMaps(rt: GLRenderTarget): void {\n const engine = rt._engine;\n if (engine._isLost || engine._disposed || rt._disposed || rt.texture.handle === null) {\n return;\n }\n bindTextureForUpload(engine, rt.texture.handle);\n engine.gl.generateMipmap(engine.gl.TEXTURE_2D);\n}\n\n/**\n * Resize the render target's color attachment (and depth/stencil renderbuffer).\n * Reallocates storage at the new size; the contents are discarded. The\n * `GLRenderTarget` / `GLTexture` identity is preserved, so consumers and\n * effect-sampler bindings holding the reference stay valid. If this target was\n * the live draw target, it is rebound (with the new-size viewport) afterwards.\n *\n * No-op when the size is unchanged or `rt` is disposed. While the context is\n * lost the new size is recorded but the GL reallocation is deferred to the\n * restore hook.\n *\n * @param rt - The render target to resize.\n * @param width - New width in texels (1 to `caps.maxTextureSize`).\n * @param height - New height in texels (1 to `caps.maxTextureSize`).\n * @throws If the size is invalid; the target keeps its current size.\n */\nexport function resizeRenderTarget(rt: GLRenderTarget, width: number, height: number): void {\n const engine = rt._engine;\n if (rt._disposed) {\n return;\n }\n validateSize(engine, width, height);\n if (rt.width === width && rt.height === height) {\n return;\n }\n rt.width = width;\n rt.height = height;\n rt.texture.width = width;\n rt.texture.height = height;\n if (engine._isLost || engine._disposed) {\n return;\n }\n // Capture the live binding BEFORE we delete the old FBO so we can restore it.\n const wasBound = engine._state.boundFramebuffer === rt._framebuffer && rt._framebuffer !== null;\n // For a BYO color texture, re-specify the caller's storage at the new size\n // (contents discarded, like the owned path). `_updateRaw` updates the\n // texture's tracked dims AND re-runs its upload closure — `_upload` alone\n // would re-upload at the stale ORIGINAL size, leaving the attachment a\n // different size than the FBO. An external handle without `_updateRaw` must\n // be resized by its owner; we then just rebuild the FBO around it. An owned\n // texture is recreated wholesale by allocateRenderTargetGpu.\n if (!rt._config.ownsColorTexture) {\n rt.texture._updateRaw?.(engine, null, width, height, 4);\n }\n rt._deleteGpu(engine.gl);\n allocateRenderTargetGpu(engine, rt);\n if (wasBound) {\n bindRenderTarget(rt);\n }\n}\n\n/**\n * Synchronously read back a rectangle of the render target's color attachment\n * via `gl.readPixels` — the lite-gl equivalent of Babylon's\n * `_readTexturePixelsSync`. Binds the target's framebuffer (leaving it bound,\n * matching Babylon).\n *\n * The returned array element type follows the color attachment type:\n * `Uint8Array` for `UNSIGNED_BYTE`, `Float32Array` for `FLOAT`, `Uint16Array`\n * for `HALF_FLOAT`. Origin is GL bottom-left.\n *\n * Reads `RGBA` by default (like Babylon; always readable, a `RED` target reads\n * back as `R,0,0,1`). Pass `format` `gl.RED` / `gl.RG` to read 1 / 2 channels\n * per texel into a tightly packed buffer (`PACK_ALIGNMENT` is set to 1 and left\n * there — lite-gl does not otherwise use it). WebGL only guarantees non-RGBA\n * reads when they match the implementation-chosen\n * `gl.IMPLEMENTATION_COLOR_READ_FORMAT` (`RED` for `R8`, `RG` for `RG8` in all\n * major browsers).\n *\n * @param rt - The render target to read from.\n * @param options - See {@link GLReadPixelsOptions}. Default: the whole target,\n * as RGBA, into a fresh buffer.\n * @returns The pixel buffer (the provided `into`, or a freshly allocated one).\n * Empty buffer on a lost/disposed context.\n */\nexport function readRenderTargetPixels(rt: GLRenderTarget, options?: GLReadPixelsOptions): ArrayBufferView {\n const opts = options ?? {};\n const width = opts.width ?? rt.width;\n const height = opts.height ?? rt.height;\n const format = opts.format ?? RGBA;\n const into = opts.into;\n const gl = bindForRead(rt, format);\n if (gl === null) {\n return into ?? new Uint8Array(0);\n }\n const type = rt._config.type;\n let buffer = into;\n if (buffer === undefined) {\n const elements = width * height * (format === RED ? 1 : format === RG ? 2 : 4);\n buffer = type === gl.FLOAT ? new Float32Array(elements) : type === gl.HALF_FLOAT ? new Uint16Array(elements) : new Uint8Array(elements);\n }\n gl.readPixels(opts.x ?? 0, opts.y ?? 0, width, height, format, type, buffer);\n return buffer;\n}\n\n/**\n * Read a rectangle of the render target's color attachment into a GPU\n * `WebGLBuffer` (`PIXEL_PACK_BUFFER` readback): `gl.readPixels` with a byte\n * offset instead of a CPU array, so the copy stays on the GPU and can be\n * consumed later without a sync stall (e.g. `gl.fenceSync` +\n * `gl.getBufferSubData`, or as vertex data).\n *\n * Same rectangle / `format` rules as {@link readRenderTargetPixels}: whole\n * target as RGBA by default, `gl.RED` / `gl.RG` read 1 / 2 channels per texel\n * tightly packed (`PACK_ALIGNMENT` 1). The texel type follows the color\n * attachment type. `buffer` must already be allocated (`gl.bufferData`) large\n * enough for `offset + width*height*channels*bytesPerChannel` bytes, and (per\n * WebGL2) must never have been bound to `ELEMENT_ARRAY_BUFFER`.\n *\n * Binds the target's framebuffer (left bound, like\n * {@link readRenderTargetPixels}), binds `buffer` to `PIXEL_PACK_BUFFER` for\n * the read and then unbinds it (`null`), so later CPU readbacks keep working.\n * No-op on a lost/disposed context or a disposed target.\n *\n * @param rt - The render target to read from.\n * @param buffer - Destination `WebGLBuffer`, created on `rt`'s context.\n * @param options - See {@link GLReadPixelsToBufferOptions}.\n */\nexport function readRenderTargetPixelsToBuffer(rt: GLRenderTarget, buffer: WebGLBuffer, options?: GLReadPixelsToBufferOptions): void {\n const opts = options ?? {};\n const format = opts.format ?? RGBA;\n const gl = bindForRead(rt, format);\n if (gl === null) {\n return;\n }\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, buffer);\n gl.readPixels(opts.x ?? 0, opts.y ?? 0, opts.width ?? rt.width, opts.height ?? rt.height, format, rt._config.type, opts.offset ?? 0);\n gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);\n}\n\n/** Shared readback prologue: bail on a lost/disposed context or target, bind\n * `rt`'s framebuffer (cached), and set `PACK_ALIGNMENT` 1 for the tightly\n * packed `RED` / `RG` reads. Returns the context, or `null` to skip the read. */\nfunction bindForRead(rt: GLRenderTarget, format: GLenum): WebGL2RenderingContext | null {\n const engine = rt._engine;\n if (engine._isLost || engine._disposed || rt._disposed) {\n return null;\n }\n const gl = engine.gl;\n const s = engine._state;\n if (s.boundFramebuffer !== rt._framebuffer) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, rt._framebuffer);\n s.boundFramebuffer = rt._framebuffer;\n }\n if (format !== RGBA) {\n // Not cached: a sync readback dwarfs it, and callers may change it directly.\n gl.pixelStorei(gl.PACK_ALIGNMENT, 1);\n }\n return gl;\n}\n\n/**\n * Release the render target's framebuffer, depth/stencil renderbuffer and (iff\n * owned) color texture, and unregister it from the engine. Idempotent, and a\n * no-op for `null`/`undefined` (so an optional target can be released\n * unconditionally). Clears the bound-framebuffer cache if it pointed at this\n * target, and any sampler slot that held the color texture handle.\n *\n * A BYO {@link GLRenderTargetOptions.colorTexture} is NOT disposed here — it is\n * engine-managed and the caller owns its lifetime.\n *\n * @param rt - The render target to dispose, or `null`/`undefined` for a no-op.\n */\nexport function disposeRenderTarget(rt: GLRenderTarget | null | undefined): void {\n if (rt === null || rt === undefined || rt._disposed) {\n return;\n }\n const engine = rt._engine;\n rt._disposed = true;\n // Only the owned color texture is marked disposed here; a BYO texture stays\n // live for its caller-owner.\n if (rt._config.ownsColorTexture) {\n rt.texture._disposed = true;\n }\n if (engine._currentRenderTarget === rt) {\n engine._currentRenderTarget = null;\n }\n const i = engine._renderTargets.indexOf(rt);\n if (i !== -1) {\n engine._renderTargets.splice(i, 1);\n }\n // Capture the handle before _deleteGpu nulls it (owned case).\n const handle = rt.texture.handle;\n if (!engine._isLost && !engine._disposed) {\n rt._deleteGpu(engine.gl);\n } else {\n rt._framebuffer = null;\n rt._depthStencil = null;\n }\n if (handle !== null) {\n const bound = engine._state.boundTextures;\n for (let u = 0; u < bound.length; u++) {\n if (bound[u] === handle) {\n bound[u] = null;\n }\n }\n }\n}\n\n/* ──────────────────────────── internal helpers ──────────────────────────── */\n\n/** Shared private constructor. Validates size, resolves the config (given the\n * exact sized `internalFormat` by the caller — NO format-table lookup), wires\n * the owned-or-BYO color texture, allocates the GPU set atomically, and\n * registers the target. */\nfunction buildRT(engine: GLEngineContext, width: number, height: number, options: GLRenderTargetOptions, internalFormat: GLenum, format: GLenum, type: GLenum): GLRenderTarget {\n validateSize(engine, width, height);\n const gl = engine.gl;\n const byo = options.colorTexture;\n const config: ResolvedRTConfig = {\n internalFormat,\n format,\n type,\n hasDepth: options.generateDepthBuffer ?? false,\n minFilter: options.minFilter ?? LINEAR,\n magFilter: options.magFilter ?? LINEAR,\n wrapS: options.wrapS ?? CLAMP_TO_EDGE,\n wrapT: options.wrapT ?? CLAMP_TO_EDGE,\n ownsColorTexture: byo === undefined,\n };\n\n const texture: GLTexture = byo ?? {\n handle: null as unknown as WebGLTexture,\n target: gl.TEXTURE_2D,\n width,\n height,\n isReady: false,\n _engine: engine,\n _disposed: false,\n _refCount: 1,\n // Owned-by-RT: its storage is (re)allocated by allocateRenderTargetGpu,\n // never via the engine `_textures` replay (it is NOT registered there).\n _upload: () => {},\n _wasReady: false,\n };\n\n const rt: GLRenderTarget = {\n texture,\n width,\n height,\n isReady: false,\n _framebuffer: null,\n _depthStencil: null,\n _rebuildDepthStencil: undefined,\n _config: config,\n _engine: engine,\n _disposed: false,\n _deleteGpu: () => {},\n };\n\n rt._deleteGpu = (glc: WebGL2RenderingContext): void => {\n const s = engine._state;\n if (rt._framebuffer !== null) {\n // Deleting the bound FBO reverts GL to framebuffer 0 (spec) — just\n // reset the cache, no explicit rebind needed.\n if (s.boundFramebuffer === rt._framebuffer) {\n s.boundFramebuffer = null;\n }\n glc.deleteFramebuffer(rt._framebuffer);\n rt._framebuffer = null;\n }\n if (rt._depthStencil !== null) {\n glc.deleteRenderbuffer(rt._depthStencil);\n rt._depthStencil = null;\n }\n // Never delete a BYO color texture — the caller-owner manages it.\n if (config.ownsColorTexture && rt.texture.handle !== null) {\n glc.deleteTexture(rt.texture.handle);\n rt.texture.handle = null as unknown as WebGLTexture;\n }\n rt.texture.isReady = false;\n rt.isReady = false;\n };\n\n if (!engine._noRestore) {\n rt._restore = (target: GLEngineContext): void => {\n // Resilient: a restore failure must not break the engine's restore loop.\n try {\n // The restored context may support a smaller size; fail before\n // re-specifying storage and leave the target not ready.\n validateSize(target, rt.width, rt.height);\n const tex = rt.texture;\n // A BYO raw texture replays its last upload; apply a resize made\n // during loss before reattaching it (contents discarded, as in resize).\n if (!config.ownsColorTexture && (tex.width !== rt.width || tex.height !== rt.height)) {\n tex._updateRaw?.(target, null, rt.width, rt.height, 4);\n }\n allocateRenderTargetGpu(target, rt);\n } catch (err) {\n // Loss leaves the flag set; a target whose rebuild failed must not\n // report ready over its dead framebuffer.\n rt.isReady = false;\n console.error(\"lite-gl: render target restore failed\", err);\n }\n };\n }\n\n allocateRenderTargetGpu(engine, rt);\n engine._renderTargets.push(rt);\n return rt;\n}\n\n/** Downgrade a requested float/half-float color type to the best renderable\n * type the engine supports, mirroring Babylon's `getTextureType`. */\nfunction resolveColorType(engine: GLEngineContext, type: GLenum): GLenum {\n const gl = engine.gl;\n if (type === FLOAT && !engine.caps.textureFloatRender) {\n return engine.caps.textureHalfFloatRender ? gl.HALF_FLOAT : gl.UNSIGNED_BYTE;\n }\n if (type === HALF_FLOAT && !engine.caps.textureHalfFloatRender) {\n return gl.UNSIGNED_BYTE;\n }\n return type;\n}\n\n/** Validate a render-target size is a pair of positive integers within the\n * engine's `MAX_TEXTURE_SIZE`. Checked before any storage is (re)specified:\n * WebGL rejects an oversized `texImage2D` without throwing, and a caller-owned\n * color texture would keep its old storage, completing the framebuffer at the\n * wrong size. */\nfunction validateSize(engine: GLEngineContext, width: number, height: number): void {\n const max = engine.caps.maxTextureSize;\n if (!Number.isInteger(width) || !Number.isInteger(height) || width < 1 || height < 1 || width > max || height > max) {\n throw new Error(`lite-gl: render target size must be positive integers up to ${max}, got ${width}x${height}`);\n }\n}\n\n/**\n * (Re)allocate the color texture (iff owned), framebuffer and depth/stencil\n * renderbuffer into fresh handles, attach them, and validate completeness (unless opted out).\n * Shared by create / resize / context-restore. No-op on a lost/disposed context.\n *\n * ATOMIC: captures the previously-bound framebuffer and restores it in a\n * `finally`; on any failure deletes the partial FBO / renderbuffer (and the\n * owned color texture it created), nulls the fields, and rethrows — so a failed\n * build never leaks a GPU handle nor leaves a half-attached framebuffer bound.\n */\nfunction allocateRenderTargetGpu(engine: GLEngineContext, rt: GLRenderTarget): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n const s = engine._state;\n const c = rt._config;\n // An unknown (wiped) binding is restored as the canvas.\n const prevFb = s.boundFramebuffer ?? null;\n let createdTexture: WebGLTexture | null = null;\n let fb: WebGLFramebuffer | null = null;\n let rb: WebGLRenderbuffer | null = null;\n try {\n // ── Color texture (owned only) ───────────────────────────────────────\n if (c.ownsColorTexture) {\n const texHandle = gl.createTexture();\n if (texHandle === null) {\n throw new Error(\"lite-gl: gl.createTexture returned null (render target color)\");\n }\n createdTexture = texHandle;\n rt.texture.handle = texHandle;\n bindTextureForUpload(engine, texHandle);\n gl.texImage2D(gl.TEXTURE_2D, 0, c.internalFormat, rt.width, rt.height, 0, c.format, c.type, null);\n setBoundTextureParams(gl, c.minFilter, c.magFilter, c.wrapS, c.wrapT);\n rt.texture.isReady = true;\n rt.texture._wasReady = true;\n }\n\n // ── Framebuffer + attachments ────────────────────────────────────────\n fb = gl.createFramebuffer();\n if (fb === null) {\n throw new Error(\"lite-gl: gl.createFramebuffer returned null\");\n }\n rt._framebuffer = fb;\n gl.bindFramebuffer(gl.FRAMEBUFFER, fb);\n s.boundFramebuffer = fb;\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, rt.texture.handle, 0);\n\n // ── Depth (core, DEPTH-ONLY) ─────────────────────────────────────────\n // The core only ever builds a DEPTH_COMPONENT16 depth buffer. Stencil /\n // packed depth-stencil is an opt-in installed by\n // `generateRenderTargetStencil` (`@babylonjs/lite-gl`),\n // which sets `_rebuildDepthStencil` to a closure that REPLACES the\n // depth-only buffer below with its own packed/stencil renderbuffer. That\n // hook is re-run here on every rebuild (create / resize / context-restore)\n // so a helper-added stencil attachment survives at the new size.\n rt._depthStencil = null;\n if (c.hasDepth) {\n rb = gl.createRenderbuffer();\n if (rb === null) {\n throw new Error(\"lite-gl: gl.createRenderbuffer returned null\");\n }\n gl.bindRenderbuffer(gl.RENDERBUFFER, rb);\n gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, rt.width, rt.height);\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, rb);\n gl.bindRenderbuffer(gl.RENDERBUFFER, null);\n rt._depthStencil = rb;\n }\n // A helper-attached stencil replaces/augments the depth-only buffer.\n rt._rebuildDepthStencil?.(engine);\n\n validateFramebuffer(engine, false);\n rt.isReady = true;\n } catch (e) {\n // Free whatever depth/stencil renderbuffer is currently attached. After a\n // `_rebuildDepthStencil` hook ran, `rt._depthStencil` may be a packed buffer\n // the hook swapped in (it deletes the core `rb` itself on success), so free\n // the live `rt._depthStencil` rather than the stale local `rb`.\n if (rt._depthStencil !== null) {\n gl.deleteRenderbuffer(rt._depthStencil);\n }\n rt._depthStencil = null;\n if (fb !== null) {\n gl.deleteFramebuffer(fb);\n }\n rt._framebuffer = null;\n // Delete ONLY a texture we created here (owned). Never a BYO texture.\n if (createdTexture !== null) {\n gl.deleteTexture(createdTexture);\n rt.texture.handle = null as unknown as WebGLTexture;\n rt.texture.isReady = false;\n }\n rt.isReady = false;\n throw e;\n } finally {\n // Restore the previously-bound draw target — creation/restore must not\n // silently redirect subsequent draws.\n if (s.boundFramebuffer !== prevFb) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, prevFb);\n s.boundFramebuffer = prevFb;\n }\n }\n}\n\n/** Inline cached `gl.viewport` — kept local so the render-target module has\n * no runtime dependency on the effect-renderer module. */\nfunction setViewportCached(engine: GLEngineContext, x: number, y: number, w: number, h: number): void {\n const s = engine._state;\n if (s.viewportX === x && s.viewportY === y && s.viewportW === w && s.viewportH === h) {\n return;\n }\n s.viewportX = x;\n s.viewportY = y;\n s.viewportW = w;\n s.viewportH = h;\n engine.gl.viewport(x, y, w, h);\n}\n"]}
|
package/scissor.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* issues for clip rects). Cached in `GLState`.
|
|
5
5
|
*
|
|
6
6
|
* Coordinates are raw WebGL (lower-left origin). A consumer using a top-left
|
|
7
|
-
* coordinate convention
|
|
7
|
+
* coordinate convention flips Y itself
|
|
8
8
|
* (`viewportHeight - rect.bottom`) before calling, exactly as it did against
|
|
9
9
|
* Babylon's `ThinEngine`.
|
|
10
10
|
*/
|
package/scissor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scissor.js","sourceRoot":"","sources":["../src/scissor.ts"],"names":[],"mappings":"AAYA,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAE5B;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CAAC,MAAuB,EAAE,CAAS,EAAE,CAAS,EAAE,KAAa,EAAE,MAAc;IACnG,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACrC,OAAO;IACX,CAAC;IACD,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IACrB,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,CAAC,CAAC,cAAc,KAAK,CAAC,EAAE,CAAC;QACzB,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC;QACrB,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAC5B,CAAC;IACD,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,KAAK,IAAI,CAAC,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;QACxF,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;QACf,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;QACf,CAAC,CAAC,QAAQ,GAAG,KAAK,CAAC;QACnB,CAAC,CAAC,QAAQ,GAAG,MAAM,CAAC;QACpB,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,MAAuB;IAClD,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACrC,OAAO;IACX,CAAC;IACD,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,CAAC,CAAC,cAAc,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO;IACX,CAAC;IACD,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC;IACrB,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AACpC,CAAC","sourcesContent":["/**\n * Scissor-test state — the lite-gl counterpart of Babylon's\n * `engine.enableScissor` / `disableScissor` (and the raw `gl.scissor` Babylon\n * issues for clip rects). Cached in `GLState`.\n *\n * Coordinates are raw WebGL (lower-left origin). A consumer using a top-left\n * coordinate convention
|
|
1
|
+
{"version":3,"file":"scissor.js","sourceRoot":"","sources":["../src/scissor.ts"],"names":[],"mappings":"AAYA,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAE5B;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CAAC,MAAuB,EAAE,CAAS,EAAE,CAAS,EAAE,KAAa,EAAE,MAAc;IACnG,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACrC,OAAO;IACX,CAAC;IACD,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IACrB,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,CAAC,CAAC,cAAc,KAAK,CAAC,EAAE,CAAC;QACzB,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC;QACrB,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAC5B,CAAC;IACD,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,KAAK,IAAI,CAAC,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;QACxF,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;QACf,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;QACf,CAAC,CAAC,QAAQ,GAAG,KAAK,CAAC;QACnB,CAAC,CAAC,QAAQ,GAAG,MAAM,CAAC;QACpB,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,MAAuB;IAClD,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACrC,OAAO;IACX,CAAC;IACD,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,CAAC,CAAC,cAAc,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO;IACX,CAAC;IACD,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC;IACrB,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AACpC,CAAC","sourcesContent":["/**\n * Scissor-test state — the lite-gl counterpart of Babylon's\n * `engine.enableScissor` / `disableScissor` (and the raw `gl.scissor` Babylon\n * issues for clip rects). Cached in `GLState`.\n *\n * Coordinates are raw WebGL (lower-left origin). A consumer using a top-left\n * coordinate convention flips Y itself\n * (`viewportHeight - rect.bottom`) before calling, exactly as it did against\n * Babylon's `ThinEngine`.\n */\nimport type { GLEngineContext } from \"./context.js\";\n\n/** GL `gl.SCISSOR_TEST`. */\nconst SCISSOR_TEST = 0x0c11;\n\n/**\n * Enable the scissor test and set the clip rectangle (lower-left origin),\n * cached. Re-issues `gl.scissor` only when the rectangle changes, and\n * `gl.enable(SCISSOR_TEST)` only on the disabled→enabled transition.\n *\n * @param engine - The engine.\n * @param x - Lower-left X of the scissor rectangle, in pixels.\n * @param y - Lower-left Y of the scissor rectangle, in pixels.\n * @param width - Rectangle width in pixels; a nonnegative integer.\n * @param height - Rectangle height in pixels; a nonnegative integer.\n */\nexport function setScissor(engine: GLEngineContext, x: number, y: number, width: number, height: number): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n const s = engine._state;\n if (s.scissorEnabled !== 1) {\n s.scissorEnabled = 1;\n gl.enable(SCISSOR_TEST);\n }\n if (s.scissorX !== x || s.scissorY !== y || s.scissorW !== width || s.scissorH !== height) {\n s.scissorX = x;\n s.scissorY = y;\n s.scissorW = width;\n s.scissorH = height;\n gl.scissor(x, y, width, height);\n }\n}\n\n/**\n * Disable the scissor test (`gl.disable(SCISSOR_TEST)`), cached. Repeated calls\n * after the first are elided.\n *\n * @param engine - The engine.\n */\nexport function disableScissor(engine: GLEngineContext): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const s = engine._state;\n if (s.scissorEnabled === 0) {\n return;\n }\n s.scissorEnabled = 0;\n engine.gl.disable(SCISSOR_TEST);\n}\n"]}
|
package/sprites.d.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* This is the lite-gl equivalent of Babylon's `SpriteRenderer` + `ThinSprite`
|
|
8
8
|
* (`Sprites/spriteRenderer.js`, `Sprites/thinSprite.js`). The vertex layout,
|
|
9
9
|
* per-cell UV math and corner/rotation transform are copied verbatim from the
|
|
10
|
-
* non-instanced path of Babylon's `SpriteRenderer` so a
|
|
11
|
-
* renders identically. The shaders are the GLSL ES 3.00 translation of
|
|
10
|
+
* non-instanced path of Babylon's `SpriteRenderer` so a ported `ThinEngine`
|
|
11
|
+
* consumer renders identically. The shaders are the GLSL ES 3.00 translation of
|
|
12
12
|
* Babylon's `Shaders/sprites.vertex.js` / `sprites.fragment.js`, with the
|
|
13
13
|
* fog / log-depth / pixel-perfect / alpha-test branches removed (lite-gl has
|
|
14
14
|
* no depth attachment by default — see notes on `disableDepthWrite` below).
|
|
@@ -142,7 +142,9 @@ export interface GLSpriteRenderer {
|
|
|
142
142
|
* Preallocates the CPU vertex scratch and the index buffer at `capacity`, so
|
|
143
143
|
* {@link renderSprites} performs no allocations. The sprite GPU buffers are
|
|
144
144
|
* rebuilt automatically on `webglcontextrestored` (the owned effect is rebuilt
|
|
145
|
-
* by the engine's context-restore protocol)
|
|
145
|
+
* by the engine's context-restore protocol), unless the engine is host-owned
|
|
146
|
+
* (`createHostOwnedGLEngine`). Static index data is regenerated on rebuild, not
|
|
147
|
+
* retained.
|
|
146
148
|
*
|
|
147
149
|
* @param engine - The engine to create GL resources on.
|
|
148
150
|
* @param options - See {@link GLSpriteRendererOptions}.
|
package/sprites.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* This is the lite-gl equivalent of Babylon's `SpriteRenderer` + `ThinSprite`
|
|
8
8
|
* (`Sprites/spriteRenderer.js`, `Sprites/thinSprite.js`). The vertex layout,
|
|
9
9
|
* per-cell UV math and corner/rotation transform are copied verbatim from the
|
|
10
|
-
* non-instanced path of Babylon's `SpriteRenderer` so a
|
|
11
|
-
* renders identically. The shaders are the GLSL ES 3.00 translation of
|
|
10
|
+
* non-instanced path of Babylon's `SpriteRenderer` so a ported `ThinEngine`
|
|
11
|
+
* consumer renders identically. The shaders are the GLSL ES 3.00 translation of
|
|
12
12
|
* Babylon's `Shaders/sprites.vertex.js` / `sprites.fragment.js`, with the
|
|
13
13
|
* fog / log-depth / pixel-perfect / alpha-test branches removed (lite-gl has
|
|
14
14
|
* no depth attachment by default — see notes on `disableDepthWrite` below).
|
|
@@ -100,7 +100,9 @@ const SPRITE_ATTRIBUTES = ["position", "options", "offsets", "inverts", "cellInf
|
|
|
100
100
|
* Preallocates the CPU vertex scratch and the index buffer at `capacity`, so
|
|
101
101
|
* {@link renderSprites} performs no allocations. The sprite GPU buffers are
|
|
102
102
|
* rebuilt automatically on `webglcontextrestored` (the owned effect is rebuilt
|
|
103
|
-
* by the engine's context-restore protocol)
|
|
103
|
+
* by the engine's context-restore protocol), unless the engine is host-owned
|
|
104
|
+
* (`createHostOwnedGLEngine`). Static index data is regenerated on rebuild, not
|
|
105
|
+
* retained.
|
|
104
106
|
*
|
|
105
107
|
* @param engine - The engine to create GL resources on.
|
|
106
108
|
* @param options - See {@link GLSpriteRendererOptions}.
|
|
@@ -128,18 +130,6 @@ export function createSpriteRenderer(engine, options) {
|
|
|
128
130
|
samplerNames: ["diffuseSampler"],
|
|
129
131
|
attributeNames: SPRITE_ATTRIBUTES,
|
|
130
132
|
});
|
|
131
|
-
// Build the static index buffer data once: [0,1,2, 0,2,3] per sprite.
|
|
132
|
-
const indices = new Uint16Array(capacity * INDICES_PER_SPRITE);
|
|
133
|
-
for (let i = 0; i < capacity; i++) {
|
|
134
|
-
const v = i * VERTS_PER_SPRITE;
|
|
135
|
-
const o = i * INDICES_PER_SPRITE;
|
|
136
|
-
indices[o] = v;
|
|
137
|
-
indices[o + 1] = v + 1;
|
|
138
|
-
indices[o + 2] = v + 2;
|
|
139
|
-
indices[o + 3] = v;
|
|
140
|
-
indices[o + 4] = v + 2;
|
|
141
|
-
indices[o + 5] = v + 3;
|
|
142
|
-
}
|
|
143
133
|
const renderer = {
|
|
144
134
|
texture: options.texture,
|
|
145
135
|
cellWidth,
|
|
@@ -154,15 +144,15 @@ export function createSpriteRenderer(engine, options) {
|
|
|
154
144
|
_vbo: null,
|
|
155
145
|
_ibo: null,
|
|
156
146
|
_vertexData: new Float32Array(capacity * VERTS_PER_SPRITE * FLOATS_PER_VERTEX),
|
|
157
|
-
_indices: indices,
|
|
158
|
-
_restore: () => { },
|
|
159
147
|
_disposed: false,
|
|
160
148
|
};
|
|
161
|
-
renderer._restore = () => {
|
|
162
|
-
buildSpriteBuffers(engine, renderer);
|
|
163
|
-
};
|
|
164
|
-
onContextRestored(engine, renderer._restore);
|
|
165
149
|
buildSpriteBuffers(engine, renderer);
|
|
150
|
+
if (!engine._noRestore) {
|
|
151
|
+
renderer._restore = () => {
|
|
152
|
+
buildSpriteBuffers(engine, renderer);
|
|
153
|
+
};
|
|
154
|
+
onContextRestored(engine, renderer._restore);
|
|
155
|
+
}
|
|
166
156
|
return renderer;
|
|
167
157
|
}
|
|
168
158
|
/**
|
|
@@ -350,7 +340,9 @@ export function disposeSpriteRenderer(renderer) {
|
|
|
350
340
|
return;
|
|
351
341
|
}
|
|
352
342
|
renderer._disposed = true;
|
|
353
|
-
|
|
343
|
+
if (renderer._restore) {
|
|
344
|
+
offContextRestored(engine, renderer._restore);
|
|
345
|
+
}
|
|
354
346
|
disposeEffect(renderer._effect);
|
|
355
347
|
if (!engine._isLost && !engine._disposed) {
|
|
356
348
|
const gl = engine.gl;
|
|
@@ -425,6 +417,15 @@ function buildSpriteBuffers(engine, renderer) {
|
|
|
425
417
|
renderer._ibo = ibo;
|
|
426
418
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);
|
|
427
419
|
s.boundElementBuffer = ibo;
|
|
428
|
-
|
|
420
|
+
// Regenerate the static [0,1,2, 0,2,3] pattern instead of retaining it:
|
|
421
|
+
// creation and the rare restore pay one transient array, nothing per frame.
|
|
422
|
+
const indices = new Uint16Array(renderer.capacity * INDICES_PER_SPRITE);
|
|
423
|
+
for (let i = 0, v = 0; i < indices.length; i += INDICES_PER_SPRITE, v += VERTS_PER_SPRITE) {
|
|
424
|
+
indices[i] = indices[i + 3] = v;
|
|
425
|
+
indices[i + 1] = v + 1;
|
|
426
|
+
indices[i + 2] = indices[i + 4] = v + 2;
|
|
427
|
+
indices[i + 5] = v + 3;
|
|
428
|
+
}
|
|
429
|
+
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
|
|
429
430
|
}
|
|
430
431
|
//# sourceMappingURL=sprites.js.map
|
package/sprites.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sprites.js","sourceRoot":"","sources":["../src/sprites.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAwB,MAAM,cAAc,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,aAAa,EAAiB,aAAa,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACrH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,kFAAkF;AAElF;;kFAEkF;AAClF,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8B3B,CAAC;AAEH;;uEAEuE;AACvE,MAAM,sBAAsB,GAAG;;;;;;;;;;EAU7B,CAAC;AAEH,kFAAkF;AAElF;;2BAE2B;AAC3B,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,0E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F,EAAE,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;IAC9B,EAAE,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,mBAAmB,EAAE,EAAE,GAAG,eAAe,CAAC,CAAC;IACzF,EAAE,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;IAC9B,EAAE,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,mBAAmB,EAAE,EAAE,GAAG,eAAe,CAAC,CAAC;IAEzF,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC;IAC9B,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IAC3E,CAAC;IACD,QAAQ,CAAC,IAAI,GAAG,GAAG,CAAC;IACpB,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;IAC5C,CAAC,CAAC,kBAAkB,GAAG,GAAG,CAAC;IAC3B,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,oBAAoB,EAAE,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["/**\n * Sprite / instanced-quad renderer.\n *\n * Part of the public API via the `@babylonjs/lite-gl` barrel. The package is\n * `sideEffects: false`, so consumers that don't render sprites tree-shake it out.\n *\n * This is the lite-gl equivalent of Babylon's `SpriteRenderer` + `ThinSprite`\n * (`Sprites/spriteRenderer.js`, `Sprites/thinSprite.js`). The vertex layout,\n * per-cell UV math and corner/rotation transform are copied verbatim from the\n * non-instanced path of Babylon's `SpriteRenderer` so a future NeonBrush port\n * renders identically. The shaders are the GLSL ES 3.00 translation of\n * Babylon's `Shaders/sprites.vertex.js` / `sprites.fragment.js`, with the\n * fog / log-depth / pixel-perfect / alpha-test branches removed (lite-gl has\n * no depth attachment by default — see notes on `disableDepthWrite` below).\n */\nimport { offContextRestored, onContextRestored, type GLEngineContext } from \"./context.js\";\nimport { createEffect, disposeEffect, type GLEffect, isEffectReady, setEffectTexture, useEffect } from \"./effect.js\";\nimport { GLBlendMode, setBlendMode } from \"./blend.js\";\nimport { applyGLStates } from \"./apply-states.js\";\nimport { type GLTexture } from \"./texture.js\";\n\n/* ───────────────────────────── shaders (GLSL ES 3.00) ───────────────────── */\n\n/** Vertex shader — GLSL ES 3.00 translation of Babylon's `spritesVertexShader`\n * core path. Attribute locations 0..5 match `createSpriteRenderer`'s\n * `attributeNames` order so the renderer's VAO feeds every program correctly. */\nconst SPRITE_VERTEX_SOURCE = `#version 300 es\nprecision highp float;\nlayout(location = 0) in vec4 position;\nlayout(location = 1) in vec2 options;\nlayout(location = 2) in vec2 offsets;\nlayout(location = 3) in vec2 inverts;\nlayout(location = 4) in vec4 cellInfo;\nlayout(location = 5) in vec4 color;\nuniform mat4 view;\nuniform mat4 projection;\nout vec2 vUV;\nout vec4 vColor;\nvoid main(void) {\n vec3 viewPos = (view * vec4(position.xyz, 1.0)).xyz;\n float angle = position.w;\n vec2 size = vec2(options.x, options.y);\n vec2 offset = offsets.xy;\n vec2 cornerPos = vec2(offset.x - 0.5, offset.y - 0.5) * size;\n vec3 rotatedCorner;\n rotatedCorner.x = cornerPos.x * cos(angle) - cornerPos.y * sin(angle);\n rotatedCorner.y = cornerPos.x * sin(angle) + cornerPos.y * cos(angle);\n rotatedCorner.z = 0.0;\n viewPos += rotatedCorner;\n gl_Position = projection * vec4(viewPos, 1.0);\n vColor = color;\n vec2 uvOffset = vec2(abs(offset.x - inverts.x), abs(1.0 - offset.y - inverts.y));\n vec2 uvPlace = cellInfo.xy;\n vec2 uvSize = cellInfo.zw;\n vUV.x = uvPlace.x + uvSize.x * uvOffset.x;\n vUV.y = uvPlace.y + uvSize.y * uvOffset.y;\n}`;\n\n/** Fragment shader — GLSL ES 3.00 translation of Babylon's `spritesPixelShader`\n * color pass: `texture(diffuseSampler, vUV) * vColor`. The alpha-test/discard\n * branch is dropped because lite-gl never runs the depth pre-pass. */\nconst SPRITE_FRAGMENT_SOURCE = `#version 300 es\nprecision highp float;\nin vec2 vUV;\nin vec4 vColor;\nuniform sampler2D diffuseSampler;\nout vec4 glFragColor;\nvoid main(void) {\n vec4 color = texture(diffuseSampler, vUV);\n color *= vColor;\n glFragColor = color;\n}`;\n\n/* ───────────────────────────── layout constants ─────────────────────────── */\n\n/** Floats per vertex: position.xyz + angle (4), size (2), corner offset (2),\n * inverts (2), cellInfo (4), color (4) = 18. Matches Babylon's non-instanced\n * `_vertexBufferSize`. */\nconst FLOATS_PER_VERTEX = 18;\n/** Four corner vertices per sprite quad (non-instanced, like Babylon). */\nconst VERTS_PER_SPRITE = 4;\n/** Six indices per sprite (two triangles). */\nconst INDICES_PER_SPRITE = 6;\n/** Bytes per float — `Float32Array.BYTES_PER_ELEMENT`. */\nconst BYTES_PER_FLOAT = 4;\n/** Stride between consecutive vertices, in bytes. */\nconst VERTEX_STRIDE_BYTES = FLOATS_PER_VERTEX * BYTES_PER_FLOAT;\n/** UV inset applied to each quad corner, matching Babylon's default\n * `SpriteRenderer` epsilon (0.01) so cell sampling never bleeds neighbours. */\nconst SPRITE_EPSILON = 0.01;\n/** Max sprites: 4 verts/sprite must keep every index within `Uint16` range\n * (`capacity * 4 - 1 <= 65535`). */\nconst MAX_CAPACITY = 16384;\n\n/** Per-corner U offset (pre-epsilon), one entry per quad vertex. Module-scoped\n * literal — pure per bundler convention, allocated once (never per frame). */\nconst CORNER_OFFSET_X = [0, 1, 1, 0];\n/** Per-corner V offset (pre-epsilon), one entry per quad vertex. */\nconst CORNER_OFFSET_Y = [0, 0, 1, 1];\n\n/** Attribute names in location order — index `i` is bound to `location = i` by\n * `createEffect`/`linkProgram`, matching the shader's `layout(location = i)`. */\nconst SPRITE_ATTRIBUTES = [\"position\", \"options\", \"offsets\", \"inverts\", \"cellInfo\", \"color\"] as const;\n\n/* ─────────────────────────────── public types ──────────────────────────── */\n\n/** An RGBA color with each channel in `[0, 1]`, used for per-sprite tint. */\nexport interface GLSpriteColor {\n /** Red, 0..1. */\n r: number;\n /** Green, 0..1. */\n g: number;\n /** Blue, 0..1. */\n b: number;\n /** Alpha, 0..1. */\n a: number;\n}\n\n/** A single sprite — a plain data object mirroring the fields of Babylon's\n * `ThinSprite` that the renderer reads. No animation state: `cellIndex` is set\n * directly by the consumer (lite-gl does not port `ThinSprite.playAnimation`). */\nexport interface GLSprite {\n /** World-space position of the sprite center. */\n position: { x: number; y: number; z: number };\n /** Width in world units. */\n width: number;\n /** Height in world units. */\n height: number;\n /** Rotation angle, in radians. */\n angle: number;\n /** Sprite-sheet cell index (0-based, row-major). Out-of-range / negative\n * values are clamped to 0, matching Babylon's `if (!cellIndex) = 0`. Ignored\n * when a manual UV rect (`uSize`) is set. Optional — defaults to `0`. */\n cellIndex?: number;\n /** Optional tint; defaults to opaque white `{ r: 1, g: 1, b: 1, a: 1 }`. */\n color?: GLSpriteColor;\n /** Flip the cell horizontally. Defaults to `false`. */\n invertU?: boolean;\n /** Flip the cell vertically. Defaults to `false`. */\n invertV?: boolean;\n /** Manual UV rect — normalized left (U) origin in `[0, 1]`, mirroring\n * Babylon's `ThinSprite._xOffset`. Set together with {@link GLSprite.uSize}\n * to address an arbitrary sub-rectangle of the sheet instead of the fixed\n * `cellIndex` grid (used by the lottie atlas, whose cells vary in size). */\n uOffset?: number;\n /** Manual UV rect — normalized top (V) origin in `[0, 1]` (≙ Babylon\n * `ThinSprite._yOffset`). See {@link GLSprite.uSize}. */\n vOffset?: number;\n /** Manual UV rect — cell width in **texels** (≙ Babylon `ThinSprite._xSize`;\n * divided by the texture width when building vertices). Presence of `uSize`\n * switches the sprite into manual-UV mode (the `cellIndex` grid is ignored).\n * `0` samples a single column — the \"solid color\" trick. */\n uSize?: number;\n /** Manual UV rect — cell height in **texels** (≙ Babylon `ThinSprite._ySize`).\n * See {@link GLSprite.uSize}. Defaults to `0` when `uSize` is set but `vSize`\n * is omitted. */\n vSize?: number;\n /** When `false`, the sprite is skipped. Defaults to `true`. */\n isVisible?: boolean;\n}\n\n/** Options for {@link createSpriteRenderer}. */\nexport interface GLSpriteRendererOptions {\n /** Maximum number of sprites drawable in one `renderSprites` call. Must be\n * an integer in `[1, 16384]` (the `Uint16` index-buffer limit). */\n capacity: number;\n /** Cell width in texels within the sprite sheet, for the fixed-grid\n * `cellIndex` path. Optional — defaults to `1`; irrelevant when every\n * sprite supplies a manual UV rect (`uSize`), as the lottie atlas does. */\n cellWidth?: number;\n /** Cell height in texels within the sprite sheet. Optional — defaults to\n * `1`. See {@link GLSpriteRendererOptions.cellWidth}. */\n cellHeight?: number;\n /** Per-corner UV/position inset applied to each quad vertex, in the `[0, 0.5)`\n * range — the `epsilon` constructor argument of Babylon's `SpriteRenderer`.\n * It both insets cell UV sampling (so a cell never bleeds its neighbours) and\n * shrinks the quad by `epsilon * size` per side. Defaults to `0.01` (Babylon's\n * `SpriteRenderer` default). Pass `0` to disable insetting — the lottie atlas\n * does this (it relies on edge-extruded cells + center sampling instead, so a\n * non-zero inset would shrink every sprite by ~`0.01·size` per edge). */\n epsilon?: number;\n /** The sprite-sheet texture. May be swapped later via\n * {@link setSpriteRendererTexture}. */\n texture: GLTexture;\n /** Blend mode for the draw. Defaults to {@link GLBlendMode.ALPHA} (2),\n * matching Babylon's `SpriteRenderer.blendMode` default. */\n blendMode?: GLBlendMode;\n /** When `true` (default), `renderSprites` resets the blend mode to\n * {@link GLBlendMode.DISABLE} after drawing — mirroring Babylon's\n * `SpriteRenderer.autoResetAlpha = true`. Set `false` to leave the\n * renderer's `blendMode` applied after the draw (the lottie player relies\n * on this so its premultiplied alpha mode persists across passes). */\n autoResetAlpha?: boolean;\n /** Accepted for Babylon API parity. lite-gl's default engine has no depth\n * attachment (`depth: false`), so there is no depth pre-pass and this flag\n * has no observable effect; it is stored verbatim for a future depth-aware\n * consumer. Defaults to `false`. */\n disableDepthWrite?: boolean;\n}\n\n/**\n * A sprite renderer owning its own VBO/IBO/VAO and `GLEffect`. Created by\n * {@link createSpriteRenderer}; drive it with {@link renderSprites} and release\n * it with {@link disposeSpriteRenderer}.\n */\nexport interface GLSpriteRenderer {\n /** The sprite-sheet texture sampled by the shader. Swap via\n * {@link setSpriteRendererTexture}. */\n texture: GLTexture;\n /** Cell width in texels (selects the sub-rectangle for `cellIndex`). */\n cellWidth: number;\n /** Cell height in texels. */\n cellHeight: number;\n /** Per-corner UV/position inset (Babylon `SpriteRenderer` `epsilon`). */\n epsilon: number;\n /** Active blend mode applied by `renderSprites` before drawing. */\n blendMode: GLBlendMode;\n /** When `true`, `renderSprites` resets blend to {@link GLBlendMode.DISABLE}\n * after drawing (Babylon `autoResetAlpha`). */\n autoResetAlpha: boolean;\n /** Babylon-parity flag (no effect without a depth attachment). */\n disableDepthWrite: boolean;\n /** Maximum sprites per draw, fixed at creation. */\n readonly capacity: number;\n /** @internal The compiled sprite effect this renderer owns. */\n _effect: GLEffect;\n /** @internal Sprite VAO (attribute pointers + element binding). Null until\n * built and after disposal; rebuilt on `webglcontextrestored`. */\n _vao: WebGLVertexArrayObject | null;\n /** @internal Dynamic vertex buffer, sized for `capacity` at creation. */\n _vbo: WebGLBuffer | null;\n /** @internal Static index buffer (`capacity * 6` `Uint16` indices). */\n _ibo: WebGLBuffer | null;\n /** @internal Preallocated CPU-side vertex scratch — reused every frame\n * (`renderSprites` performs zero allocations). */\n _vertexData: Float32Array;\n /** @internal Preallocated index data, uploaded once. */\n _indices: Uint16Array;\n /** @internal Context-restored handler — rebuilds the GPU buffers. */\n _restore: () => void;\n /** @internal True once disposed; subsequent calls are no-ops. */\n _disposed: boolean;\n}\n\n/* ──────────────────────────────── public API ───────────────────────────── */\n\n/**\n * Create a sprite renderer with its own GPU buffers and compiled effect.\n *\n * Preallocates the CPU vertex scratch and the index buffer at `capacity`, so\n * {@link renderSprites} performs no allocations. The sprite GPU buffers are\n * rebuilt automatically on `webglcontextrestored` (the owned effect is rebuilt\n * by the engine's context-restore protocol).\n *\n * @param engine - The engine to create GL resources on.\n * @param options - See {@link GLSpriteRendererOptions}.\n * @returns The new {@link GLSpriteRenderer}.\n * @throws If `capacity` is not an integer in `[1, 16384]`, or if a provided\n * `cellWidth`/`cellHeight` is not positive.\n */\nexport function createSpriteRenderer(engine: GLEngineContext, options: GLSpriteRendererOptions): GLSpriteRenderer {\n const capacity = options.capacity;\n if (!Number.isInteger(capacity) || capacity < 1 || capacity > MAX_CAPACITY) {\n throw new Error(`lite-gl: sprite renderer capacity must be an integer in [1, ${MAX_CAPACITY}], got ${capacity}`);\n }\n // cellWidth/cellHeight drive only the fixed-grid `cellIndex` path; manual-UV\n // consumers (the lottie atlas) omit them. Default to 1; reject explicit ≤ 0.\n const cellWidth = options.cellWidth ?? 1;\n const cellHeight = options.cellHeight ?? 1;\n if (!(cellWidth > 0) || !(cellHeight > 0)) {\n throw new Error(\"lite-gl: sprite renderer cellWidth/cellHeight must be > 0\");\n }\n\n const effect = createEffect(engine, {\n name: \"sprites\",\n vertexSource: SPRITE_VERTEX_SOURCE,\n fragmentSource: SPRITE_FRAGMENT_SOURCE,\n uniformNames: [\"view\", \"projection\"],\n samplerNames: [\"diffuseSampler\"],\n attributeNames: SPRITE_ATTRIBUTES,\n });\n\n // Build the static index buffer data once: [0,1,2, 0,2,3] per sprite.\n const indices = new Uint16Array(capacity * INDICES_PER_SPRITE);\n for (let i = 0; i < capacity; i++) {\n const v = i * VERTS_PER_SPRITE;\n const o = i * INDICES_PER_SPRITE;\n indices[o] = v;\n indices[o + 1] = v + 1;\n indices[o + 2] = v + 2;\n indices[o + 3] = v;\n indices[o + 4] = v + 2;\n indices[o + 5] = v + 3;\n }\n\n const renderer: GLSpriteRenderer = {\n texture: options.texture,\n cellWidth,\n cellHeight,\n epsilon: options.epsilon ?? SPRITE_EPSILON,\n blendMode: options.blendMode ?? GLBlendMode.ALPHA,\n autoResetAlpha: options.autoResetAlpha ?? true,\n disableDepthWrite: options.disableDepthWrite ?? false,\n capacity,\n _effect: effect,\n _vao: null,\n _vbo: null,\n _ibo: null,\n _vertexData: new Float32Array(capacity * VERTS_PER_SPRITE * FLOATS_PER_VERTEX),\n _indices: indices,\n _restore: () => {},\n _disposed: false,\n };\n\n renderer._restore = (): void => {\n buildSpriteBuffers(engine, renderer);\n };\n onContextRestored(engine, renderer._restore);\n buildSpriteBuffers(engine, renderer);\n return renderer;\n}\n\n/**\n * Build the per-sprite vertex data and draw all visible sprites in one\n * `drawElements` call. Performs no allocations — the vertex scratch is reused\n * and uploaded with `bufferSubData`.\n *\n * No-op when the context is lost/disposed, the renderer is disposed, the\n * texture is not ready, the effect is not ready, or there are no visible\n * sprites. Sets the renderer's blend mode before drawing and resets to\n * {@link GLBlendMode.DISABLE} afterwards (matching Babylon's\n * `autoResetAlpha = true`), so a subsequent `drawEffect` is unaffected.\n *\n * @param renderer - The renderer to draw with.\n * @param sprites - The sprites to draw (only `isVisible !== false` are drawn;\n * excess beyond `capacity` is ignored, matching Babylon).\n * @param deltaTime - Accepted for Babylon API parity; unused (lite-gl `GLSprite`\n * holds no animation state, so `cellIndex` is consumer-driven).\n * @param viewMatrix - Column-major 4x4 view matrix.\n * @param projectionMatrix - Column-major 4x4 projection matrix.\n */\nexport function renderSprites(\n renderer: GLSpriteRenderer,\n sprites: readonly GLSprite[],\n deltaTime: number,\n viewMatrix: Float32Array | number[],\n projectionMatrix: Float32Array | number[]\n): void {\n const engine = renderer._effect._engine;\n if (engine._isLost || engine._disposed || renderer._disposed) {\n return;\n }\n // `deltaTime` is accepted for Babylon `SpriteRenderer.render` parity but\n // unused: `GLSprite` carries no animation state, so `cellIndex` is driven\n // entirely by the consumer. Referenced here to keep the parameter name in\n // the public signature without tripping `noUnusedParameters`.\n void deltaTime;\n const tex = renderer.texture;\n if (!tex.isReady || sprites.length === 0) {\n return;\n }\n const effect = renderer._effect;\n if (!isEffectReady(effect)) {\n return;\n }\n if (renderer._vao === null || renderer._vbo === null) {\n return;\n }\n\n // ── Build vertex data (allocation-free) ──────────────────────────────────\n const vd = renderer._vertexData;\n const eps = renderer.epsilon;\n const texW = tex.width;\n const texH = tex.height;\n const cellW = renderer.cellWidth;\n const cellH = renderer.cellHeight;\n const rowSize = texW / cellW; // cells per sheet row\n const cellWidthN = cellW / texW;\n const cellHeightN = cellH / texH;\n const cap = renderer.capacity;\n const count = sprites.length;\n let visible = 0;\n for (let i = 0; i < count && visible < cap; i++) {\n const sprite = sprites[i];\n if (sprite === undefined || sprite.isVisible === false) {\n continue;\n }\n // UV rect — manual per-sprite rect (Babylon `ThinSprite._xOffset/_xSize`\n // path, selected when `uSize` is set) or the fixed `cellIndex` grid.\n // Both resolve to a normalized `(left, top, widthN, heightN)` rectangle,\n // matching Babylon's `_appendSpriteVertex` vertex layout exactly.\n let cellLeft: number;\n let cellTop: number;\n let cellWN: number;\n let cellHN: number;\n if (sprite.uSize !== undefined) {\n cellLeft = sprite.uOffset ?? 0;\n cellTop = sprite.vOffset ?? 0;\n cellWN = sprite.uSize / texW;\n cellHN = (sprite.vSize ?? 0) / texH;\n } else {\n const cellIndex = (sprite.cellIndex ?? 0) > 0 ? (sprite.cellIndex as number) : 0;\n const row = (cellIndex / rowSize) >> 0;\n cellLeft = ((cellIndex - row * rowSize) * cellW) / texW;\n cellTop = (row * cellH) / texH;\n cellWN = cellWidthN;\n cellHN = cellHeightN;\n }\n\n const px = sprite.position.x;\n const py = sprite.position.y;\n const pz = sprite.position.z;\n const angle = sprite.angle;\n const w = sprite.width;\n const h = sprite.height;\n const invU = sprite.invertU === true ? 1 : 0;\n const invV = sprite.invertV === true ? 1 : 0;\n const color = sprite.color;\n const cr = color !== undefined ? color.r : 1;\n const cg = color !== undefined ? color.g : 1;\n const cb = color !== undefined ? color.b : 1;\n const ca = color !== undefined ? color.a : 1;\n\n let off = visible * VERTS_PER_SPRITE * FLOATS_PER_VERTEX;\n for (let c = 0; c < VERTS_PER_SPRITE; c++) {\n const ox = CORNER_OFFSET_X[c] === 0 ? eps : 1 - eps;\n const oy = CORNER_OFFSET_Y[c] === 0 ? eps : 1 - eps;\n vd[off] = px;\n vd[off + 1] = py;\n vd[off + 2] = pz;\n vd[off + 3] = angle;\n vd[off + 4] = w;\n vd[off + 5] = h;\n vd[off + 6] = ox;\n vd[off + 7] = oy;\n vd[off + 8] = invU;\n vd[off + 9] = invV;\n vd[off + 10] = cellLeft;\n vd[off + 11] = cellTop;\n vd[off + 12] = cellWN;\n vd[off + 13] = cellHN;\n vd[off + 14] = cr;\n vd[off + 15] = cg;\n vd[off + 16] = cb;\n vd[off + 17] = ca;\n off += FLOATS_PER_VERTEX;\n }\n visible++;\n }\n if (visible === 0) {\n return;\n }\n\n // ── Upload + draw ────────────────────────────────────────────────────────\n const gl = engine.gl;\n const s = engine._state;\n const vao = renderer._vao;\n if (s.boundVao !== vao) {\n gl.bindVertexArray(vao);\n s.boundVao = vao;\n // Binding the VAO restores its element-array binding (VAO state).\n s.boundElementBuffer = renderer._ibo;\n }\n const vbo = renderer._vbo;\n if (s.boundArrayBuffer !== vbo) {\n gl.bindBuffer(gl.ARRAY_BUFFER, vbo);\n s.boundArrayBuffer = vbo;\n }\n const floatCount = visible * VERTS_PER_SPRITE * FLOATS_PER_VERTEX;\n gl.bufferSubData(gl.ARRAY_BUFFER, 0, vd, 0, floatCount);\n\n useEffect(effect);\n const viewLoc = effect.uniformLocations[\"view\"];\n if (viewLoc !== null && viewLoc !== undefined) {\n gl.uniformMatrix4fv(viewLoc, false, viewMatrix);\n }\n const projLoc = effect.uniformLocations[\"projection\"];\n if (projLoc !== null && projLoc !== undefined) {\n gl.uniformMatrix4fv(projLoc, false, projectionMatrix);\n }\n setEffectTexture(effect, \"diffuseSampler\", tex);\n\n setBlendMode(engine, renderer.blendMode);\n applyGLStates(engine);\n gl.drawElements(gl.TRIANGLES, visible * INDICES_PER_SPRITE, gl.UNSIGNED_SHORT, 0);\n // Auto-reset (Babylon `autoResetAlpha = true`): leave blend disabled so a\n // subsequent fullscreen `drawEffect` renders with the same state as before.\n // When `autoResetAlpha` is false (lottie), keep `renderer.blendMode` applied\n // so a premultiplied-alpha mode persists across multiple atlas-page passes.\n if (renderer.autoResetAlpha) {\n setBlendMode(engine, GLBlendMode.DISABLE);\n }\n}\n\n/** Swap the sprite-sheet texture (≙ Babylon assigning `SpriteRenderer.texture`\n * after an async load). The cell size is unchanged — adjust `cellWidth` /\n * `cellHeight` on the renderer directly if the new sheet differs. No-op when\n * the renderer is disposed.\n * No GL call is made — the texture is bound at draw time.\n *\n * @param renderer - The renderer to update.\n * @param texture - The new sprite-sheet texture. */\nexport function setSpriteRendererTexture(renderer: GLSpriteRenderer, texture: GLTexture): void {\n if (renderer._disposed) {\n return;\n }\n renderer.texture = texture;\n}\n\n/** Release the renderer's VAO/VBO/IBO and the effect it owns, and unregister\n * its context-restore handler. Idempotent. Does NOT dispose the texture — the\n * consumer that supplied it owns its lifetime.\n *\n * @param renderer - The renderer to dispose. */\nexport function disposeSpriteRenderer(renderer: GLSpriteRenderer): void {\n const engine = renderer._effect._engine;\n if (renderer._disposed) {\n return;\n }\n renderer._disposed = true;\n offContextRestored(engine, renderer._restore);\n disposeEffect(renderer._effect);\n if (!engine._isLost && !engine._disposed) {\n const gl = engine.gl;\n const s = engine._state;\n if (renderer._vao !== null) {\n gl.deleteVertexArray(renderer._vao);\n if (s.boundVao === renderer._vao) {\n s.boundVao = null;\n }\n }\n if (renderer._vbo !== null) {\n gl.deleteBuffer(renderer._vbo);\n if (s.boundArrayBuffer === renderer._vbo) {\n s.boundArrayBuffer = null;\n }\n }\n if (renderer._ibo !== null) {\n gl.deleteBuffer(renderer._ibo);\n if (s.boundElementBuffer === renderer._ibo) {\n s.boundElementBuffer = null;\n }\n }\n }\n renderer._vao = null;\n renderer._vbo = null;\n renderer._ibo = null;\n}\n\n/* ──────────────────────────── internal helpers ──────────────────────────── */\n\n/** (Re)create the VAO + VBO + IBO and configure the six vertex attributes.\n * Called from `createSpriteRenderer` and from the `webglcontextrestored`\n * handler (the prior handles are dead per the WebGL spec — not deleted here).\n * No-op when the context is lost/disposed. */\nfunction buildSpriteBuffers(engine: GLEngineContext, renderer: GLSpriteRenderer): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n const s = engine._state;\n\n const vao = gl.createVertexArray();\n if (vao === null) {\n throw new Error(\"lite-gl: gl.createVertexArray returned null (sprite VAO)\");\n }\n renderer._vao = vao;\n gl.bindVertexArray(vao);\n s.boundVao = vao;\n\n const vbo = gl.createBuffer();\n if (vbo === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (sprite VBO)\");\n }\n renderer._vbo = vbo;\n gl.bindBuffer(gl.ARRAY_BUFFER, vbo);\n s.boundArrayBuffer = vbo;\n // Allocate the dynamic vertex storage at full capacity; filled per frame.\n gl.bufferData(gl.ARRAY_BUFFER, renderer._vertexData.byteLength, gl.DYNAMIC_DRAW);\n\n // Attribute pointers — locations match SPRITE_ATTRIBUTES / shader layout.\n gl.enableVertexAttribArray(0);\n gl.vertexAttribPointer(0, 4, gl.FLOAT, false, VERTEX_STRIDE_BYTES, 0);\n gl.enableVertexAttribArray(1);\n gl.vertexAttribPointer(1, 2, gl.FLOAT, false, VERTEX_STRIDE_BYTES, 4 * BYTES_PER_FLOAT);\n gl.enableVertexAttribArray(2);\n gl.vertexAttribPointer(2, 2, gl.FLOAT, false, VERTEX_STRIDE_BYTES, 6 * BYTES_PER_FLOAT);\n gl.enableVertexAttribArray(3);\n gl.vertexAttribPointer(3, 2, gl.FLOAT, false, VERTEX_STRIDE_BYTES, 8 * BYTES_PER_FLOAT);\n gl.enableVertexAttribArray(4);\n gl.vertexAttribPointer(4, 4, gl.FLOAT, false, VERTEX_STRIDE_BYTES, 10 * BYTES_PER_FLOAT);\n gl.enableVertexAttribArray(5);\n gl.vertexAttribPointer(5, 4, gl.FLOAT, false, VERTEX_STRIDE_BYTES, 14 * BYTES_PER_FLOAT);\n\n const ibo = gl.createBuffer();\n if (ibo === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (sprite IBO)\");\n }\n renderer._ibo = ibo;\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);\n s.boundElementBuffer = ibo;\n gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, renderer._indices, gl.STATIC_DRAW);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sprites.js","sourceRoot":"","sources":["../src/sprites.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAwB,MAAM,cAAc,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,aAAa,EAAiB,aAAa,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACrH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,kFAAkF;AAElF;;kFAEkF;AAClF,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8B3B,CAAC;AAEH;;uEAEuE;AACvE,MAAM,sBAAsB,GAAG;;;;;;;;;;EAU7B,CAAC;AAEH,kFAAkF;AAElF;;2BAE2B;AAC3B,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,0EAA0E;AAC1E,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,8CAA8C;AAC9C,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,0DAA0D;AAC1D,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,qDAAqD;AACrD,MAAM,mBAAmB,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAChE;gFACgF;AAChF,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B;qCACqC;AACrC,MAAM,YAAY,GAAG,KAAK,CAAC;AAE3B;+EAC+E;AAC/E,MAAM,eAAe,GAAG,CAAC,CAAC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CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QAChC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACvB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACxC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IACD,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,oBAAoB,EAAE,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC;AACpE,CAAC","sourcesContent":["/**\n * Sprite / instanced-quad renderer.\n *\n * Part of the public API via the `@babylonjs/lite-gl` barrel. The package is\n * `sideEffects: false`, so consumers that don't render sprites tree-shake it out.\n *\n * This is the lite-gl equivalent of Babylon's `SpriteRenderer` + `ThinSprite`\n * (`Sprites/spriteRenderer.js`, `Sprites/thinSprite.js`). The vertex layout,\n * per-cell UV math and corner/rotation transform are copied verbatim from the\n * non-instanced path of Babylon's `SpriteRenderer` so a ported `ThinEngine`\n * consumer renders identically. The shaders are the GLSL ES 3.00 translation of\n * Babylon's `Shaders/sprites.vertex.js` / `sprites.fragment.js`, with the\n * fog / log-depth / pixel-perfect / alpha-test branches removed (lite-gl has\n * no depth attachment by default — see notes on `disableDepthWrite` below).\n */\nimport { offContextRestored, onContextRestored, type GLEngineContext } from \"./context.js\";\nimport { createEffect, disposeEffect, type GLEffect, isEffectReady, setEffectTexture, useEffect } from \"./effect.js\";\nimport { GLBlendMode, setBlendMode } from \"./blend.js\";\nimport { applyGLStates } from \"./apply-states.js\";\nimport { type GLTexture } from \"./texture.js\";\n\n/* ───────────────────────────── shaders (GLSL ES 3.00) ───────────────────── */\n\n/** Vertex shader — GLSL ES 3.00 translation of Babylon's `spritesVertexShader`\n * core path. Attribute locations 0..5 match `createSpriteRenderer`'s\n * `attributeNames` order so the renderer's VAO feeds every program correctly. */\nconst SPRITE_VERTEX_SOURCE = `#version 300 es\nprecision highp float;\nlayout(location = 0) in vec4 position;\nlayout(location = 1) in vec2 options;\nlayout(location = 2) in vec2 offsets;\nlayout(location = 3) in vec2 inverts;\nlayout(location = 4) in vec4 cellInfo;\nlayout(location = 5) in vec4 color;\nuniform mat4 view;\nuniform mat4 projection;\nout vec2 vUV;\nout vec4 vColor;\nvoid main(void) {\n vec3 viewPos = (view * vec4(position.xyz, 1.0)).xyz;\n float angle = position.w;\n vec2 size = vec2(options.x, options.y);\n vec2 offset = offsets.xy;\n vec2 cornerPos = vec2(offset.x - 0.5, offset.y - 0.5) * size;\n vec3 rotatedCorner;\n rotatedCorner.x = cornerPos.x * cos(angle) - cornerPos.y * sin(angle);\n rotatedCorner.y = cornerPos.x * sin(angle) + cornerPos.y * cos(angle);\n rotatedCorner.z = 0.0;\n viewPos += rotatedCorner;\n gl_Position = projection * vec4(viewPos, 1.0);\n vColor = color;\n vec2 uvOffset = vec2(abs(offset.x - inverts.x), abs(1.0 - offset.y - inverts.y));\n vec2 uvPlace = cellInfo.xy;\n vec2 uvSize = cellInfo.zw;\n vUV.x = uvPlace.x + uvSize.x * uvOffset.x;\n vUV.y = uvPlace.y + uvSize.y * uvOffset.y;\n}`;\n\n/** Fragment shader — GLSL ES 3.00 translation of Babylon's `spritesPixelShader`\n * color pass: `texture(diffuseSampler, vUV) * vColor`. The alpha-test/discard\n * branch is dropped because lite-gl never runs the depth pre-pass. */\nconst SPRITE_FRAGMENT_SOURCE = `#version 300 es\nprecision highp float;\nin vec2 vUV;\nin vec4 vColor;\nuniform sampler2D diffuseSampler;\nout vec4 glFragColor;\nvoid main(void) {\n vec4 color = texture(diffuseSampler, vUV);\n color *= vColor;\n glFragColor = color;\n}`;\n\n/* ───────────────────────────── layout constants ─────────────────────────── */\n\n/** Floats per vertex: position.xyz + angle (4), size (2), corner offset (2),\n * inverts (2), cellInfo (4), color (4) = 18. Matches Babylon's non-instanced\n * `_vertexBufferSize`. */\nconst FLOATS_PER_VERTEX = 18;\n/** Four corner vertices per sprite quad (non-instanced, like Babylon). */\nconst VERTS_PER_SPRITE = 4;\n/** Six indices per sprite (two triangles). */\nconst INDICES_PER_SPRITE = 6;\n/** Bytes per float — `Float32Array.BYTES_PER_ELEMENT`. */\nconst BYTES_PER_FLOAT = 4;\n/** Stride between consecutive vertices, in bytes. */\nconst VERTEX_STRIDE_BYTES = FLOATS_PER_VERTEX * BYTES_PER_FLOAT;\n/** UV inset applied to each quad corner, matching Babylon's default\n * `SpriteRenderer` epsilon (0.01) so cell sampling never bleeds neighbours. */\nconst SPRITE_EPSILON = 0.01;\n/** Max sprites: 4 verts/sprite must keep every index within `Uint16` range\n * (`capacity * 4 - 1 <= 65535`). */\nconst MAX_CAPACITY = 16384;\n\n/** Per-corner U offset (pre-epsilon), one entry per quad vertex. Module-scoped\n * literal — pure per bundler convention, allocated once (never per frame). */\nconst CORNER_OFFSET_X = [0, 1, 1, 0];\n/** Per-corner V offset (pre-epsilon), one entry per quad vertex. */\nconst CORNER_OFFSET_Y = [0, 0, 1, 1];\n\n/** Attribute names in location order — index `i` is bound to `location = i` by\n * `createEffect`/`linkProgram`, matching the shader's `layout(location = i)`. */\nconst SPRITE_ATTRIBUTES = [\"position\", \"options\", \"offsets\", \"inverts\", \"cellInfo\", \"color\"] as const;\n\n/* ─────────────────────────────── public types ──────────────────────────── */\n\n/** An RGBA color with each channel in `[0, 1]`, used for per-sprite tint. */\nexport interface GLSpriteColor {\n /** Red, 0..1. */\n r: number;\n /** Green, 0..1. */\n g: number;\n /** Blue, 0..1. */\n b: number;\n /** Alpha, 0..1. */\n a: number;\n}\n\n/** A single sprite — a plain data object mirroring the fields of Babylon's\n * `ThinSprite` that the renderer reads. No animation state: `cellIndex` is set\n * directly by the consumer (lite-gl does not port `ThinSprite.playAnimation`). */\nexport interface GLSprite {\n /** World-space position of the sprite center. */\n position: { x: number; y: number; z: number };\n /** Width in world units. */\n width: number;\n /** Height in world units. */\n height: number;\n /** Rotation angle, in radians. */\n angle: number;\n /** Sprite-sheet cell index (0-based, row-major). Out-of-range / negative\n * values are clamped to 0, matching Babylon's `if (!cellIndex) = 0`. Ignored\n * when a manual UV rect (`uSize`) is set. Optional — defaults to `0`. */\n cellIndex?: number;\n /** Optional tint; defaults to opaque white `{ r: 1, g: 1, b: 1, a: 1 }`. */\n color?: GLSpriteColor;\n /** Flip the cell horizontally. Defaults to `false`. */\n invertU?: boolean;\n /** Flip the cell vertically. Defaults to `false`. */\n invertV?: boolean;\n /** Manual UV rect — normalized left (U) origin in `[0, 1]`, mirroring\n * Babylon's `ThinSprite._xOffset`. Set together with {@link GLSprite.uSize}\n * to address an arbitrary sub-rectangle of the sheet instead of the fixed\n * `cellIndex` grid (used by the lottie atlas, whose cells vary in size). */\n uOffset?: number;\n /** Manual UV rect — normalized top (V) origin in `[0, 1]` (≙ Babylon\n * `ThinSprite._yOffset`). See {@link GLSprite.uSize}. */\n vOffset?: number;\n /** Manual UV rect — cell width in **texels** (≙ Babylon `ThinSprite._xSize`;\n * divided by the texture width when building vertices). Presence of `uSize`\n * switches the sprite into manual-UV mode (the `cellIndex` grid is ignored).\n * `0` samples a single column — the \"solid color\" trick. */\n uSize?: number;\n /** Manual UV rect — cell height in **texels** (≙ Babylon `ThinSprite._ySize`).\n * See {@link GLSprite.uSize}. Defaults to `0` when `uSize` is set but `vSize`\n * is omitted. */\n vSize?: number;\n /** When `false`, the sprite is skipped. Defaults to `true`. */\n isVisible?: boolean;\n}\n\n/** Options for {@link createSpriteRenderer}. */\nexport interface GLSpriteRendererOptions {\n /** Maximum number of sprites drawable in one `renderSprites` call. Must be\n * an integer in `[1, 16384]` (the `Uint16` index-buffer limit). */\n capacity: number;\n /** Cell width in texels within the sprite sheet, for the fixed-grid\n * `cellIndex` path. Optional — defaults to `1`; irrelevant when every\n * sprite supplies a manual UV rect (`uSize`), as the lottie atlas does. */\n cellWidth?: number;\n /** Cell height in texels within the sprite sheet. Optional — defaults to\n * `1`. See {@link GLSpriteRendererOptions.cellWidth}. */\n cellHeight?: number;\n /** Per-corner UV/position inset applied to each quad vertex, in the `[0, 0.5)`\n * range — the `epsilon` constructor argument of Babylon's `SpriteRenderer`.\n * It both insets cell UV sampling (so a cell never bleeds its neighbours) and\n * shrinks the quad by `epsilon * size` per side. Defaults to `0.01` (Babylon's\n * `SpriteRenderer` default). Pass `0` to disable insetting — the lottie atlas\n * does this (it relies on edge-extruded cells + center sampling instead, so a\n * non-zero inset would shrink every sprite by ~`0.01·size` per edge). */\n epsilon?: number;\n /** The sprite-sheet texture. May be swapped later via\n * {@link setSpriteRendererTexture}. */\n texture: GLTexture;\n /** Blend mode for the draw. Defaults to {@link GLBlendMode.ALPHA} (2),\n * matching Babylon's `SpriteRenderer.blendMode` default. */\n blendMode?: GLBlendMode;\n /** When `true` (default), `renderSprites` resets the blend mode to\n * {@link GLBlendMode.DISABLE} after drawing — mirroring Babylon's\n * `SpriteRenderer.autoResetAlpha = true`. Set `false` to leave the\n * renderer's `blendMode` applied after the draw (the lottie player relies\n * on this so its premultiplied alpha mode persists across passes). */\n autoResetAlpha?: boolean;\n /** Accepted for Babylon API parity. lite-gl's default engine has no depth\n * attachment (`depth: false`), so there is no depth pre-pass and this flag\n * has no observable effect; it is stored verbatim for a future depth-aware\n * consumer. Defaults to `false`. */\n disableDepthWrite?: boolean;\n}\n\n/**\n * A sprite renderer owning its own VBO/IBO/VAO and `GLEffect`. Created by\n * {@link createSpriteRenderer}; drive it with {@link renderSprites} and release\n * it with {@link disposeSpriteRenderer}.\n */\nexport interface GLSpriteRenderer {\n /** The sprite-sheet texture sampled by the shader. Swap via\n * {@link setSpriteRendererTexture}. */\n texture: GLTexture;\n /** Cell width in texels (selects the sub-rectangle for `cellIndex`). */\n cellWidth: number;\n /** Cell height in texels. */\n cellHeight: number;\n /** Per-corner UV/position inset (Babylon `SpriteRenderer` `epsilon`). */\n epsilon: number;\n /** Active blend mode applied by `renderSprites` before drawing. */\n blendMode: GLBlendMode;\n /** When `true`, `renderSprites` resets blend to {@link GLBlendMode.DISABLE}\n * after drawing (Babylon `autoResetAlpha`). */\n autoResetAlpha: boolean;\n /** Babylon-parity flag (no effect without a depth attachment). */\n disableDepthWrite: boolean;\n /** Maximum sprites per draw, fixed at creation. */\n readonly capacity: number;\n /** @internal The compiled sprite effect this renderer owns. */\n _effect: GLEffect;\n /** @internal Sprite VAO (attribute pointers + element binding). Null until\n * built and after disposal; rebuilt on `webglcontextrestored`. */\n _vao: WebGLVertexArrayObject | null;\n /** @internal Dynamic vertex buffer, sized for `capacity` at creation. */\n _vbo: WebGLBuffer | null;\n /** @internal Static index buffer (`capacity * 6` `Uint16` indices). */\n _ibo: WebGLBuffer | null;\n /** @internal Preallocated CPU-side vertex scratch — reused every frame\n * (`renderSprites` performs zero allocations). */\n _vertexData: Float32Array;\n /** @internal Context-restored handler — rebuilds the GPU buffers. */\n _restore?: () => void;\n /** @internal True once disposed; subsequent calls are no-ops. */\n _disposed: boolean;\n}\n\n/* ──────────────────────────────── public API ───────────────────────────── */\n\n/**\n * Create a sprite renderer with its own GPU buffers and compiled effect.\n *\n * Preallocates the CPU vertex scratch and the index buffer at `capacity`, so\n * {@link renderSprites} performs no allocations. The sprite GPU buffers are\n * rebuilt automatically on `webglcontextrestored` (the owned effect is rebuilt\n * by the engine's context-restore protocol), unless the engine is host-owned\n * (`createHostOwnedGLEngine`). Static index data is regenerated on rebuild, not\n * retained.\n *\n * @param engine - The engine to create GL resources on.\n * @param options - See {@link GLSpriteRendererOptions}.\n * @returns The new {@link GLSpriteRenderer}.\n * @throws If `capacity` is not an integer in `[1, 16384]`, or if a provided\n * `cellWidth`/`cellHeight` is not positive.\n */\nexport function createSpriteRenderer(engine: GLEngineContext, options: GLSpriteRendererOptions): GLSpriteRenderer {\n const capacity = options.capacity;\n if (!Number.isInteger(capacity) || capacity < 1 || capacity > MAX_CAPACITY) {\n throw new Error(`lite-gl: sprite renderer capacity must be an integer in [1, ${MAX_CAPACITY}], got ${capacity}`);\n }\n // cellWidth/cellHeight drive only the fixed-grid `cellIndex` path; manual-UV\n // consumers (the lottie atlas) omit them. Default to 1; reject explicit ≤ 0.\n const cellWidth = options.cellWidth ?? 1;\n const cellHeight = options.cellHeight ?? 1;\n if (!(cellWidth > 0) || !(cellHeight > 0)) {\n throw new Error(\"lite-gl: sprite renderer cellWidth/cellHeight must be > 0\");\n }\n\n const effect = createEffect(engine, {\n name: \"sprites\",\n vertexSource: SPRITE_VERTEX_SOURCE,\n fragmentSource: SPRITE_FRAGMENT_SOURCE,\n uniformNames: [\"view\", \"projection\"],\n samplerNames: [\"diffuseSampler\"],\n attributeNames: SPRITE_ATTRIBUTES,\n });\n\n const renderer: GLSpriteRenderer = {\n texture: options.texture,\n cellWidth,\n cellHeight,\n epsilon: options.epsilon ?? SPRITE_EPSILON,\n blendMode: options.blendMode ?? GLBlendMode.ALPHA,\n autoResetAlpha: options.autoResetAlpha ?? true,\n disableDepthWrite: options.disableDepthWrite ?? false,\n capacity,\n _effect: effect,\n _vao: null,\n _vbo: null,\n _ibo: null,\n _vertexData: new Float32Array(capacity * VERTS_PER_SPRITE * FLOATS_PER_VERTEX),\n _disposed: false,\n };\n\n buildSpriteBuffers(engine, renderer);\n if (!engine._noRestore) {\n renderer._restore = (): void => {\n buildSpriteBuffers(engine, renderer);\n };\n onContextRestored(engine, renderer._restore);\n }\n return renderer;\n}\n\n/**\n * Build the per-sprite vertex data and draw all visible sprites in one\n * `drawElements` call. Performs no allocations — the vertex scratch is reused\n * and uploaded with `bufferSubData`.\n *\n * No-op when the context is lost/disposed, the renderer is disposed, the\n * texture is not ready, the effect is not ready, or there are no visible\n * sprites. Sets the renderer's blend mode before drawing and resets to\n * {@link GLBlendMode.DISABLE} afterwards (matching Babylon's\n * `autoResetAlpha = true`), so a subsequent `drawEffect` is unaffected.\n *\n * @param renderer - The renderer to draw with.\n * @param sprites - The sprites to draw (only `isVisible !== false` are drawn;\n * excess beyond `capacity` is ignored, matching Babylon).\n * @param deltaTime - Accepted for Babylon API parity; unused (lite-gl `GLSprite`\n * holds no animation state, so `cellIndex` is consumer-driven).\n * @param viewMatrix - Column-major 4x4 view matrix.\n * @param projectionMatrix - Column-major 4x4 projection matrix.\n */\nexport function renderSprites(\n renderer: GLSpriteRenderer,\n sprites: readonly GLSprite[],\n deltaTime: number,\n viewMatrix: Float32Array | number[],\n projectionMatrix: Float32Array | number[]\n): void {\n const engine = renderer._effect._engine;\n if (engine._isLost || engine._disposed || renderer._disposed) {\n return;\n }\n // `deltaTime` is accepted for Babylon `SpriteRenderer.render` parity but\n // unused: `GLSprite` carries no animation state, so `cellIndex` is driven\n // entirely by the consumer. Referenced here to keep the parameter name in\n // the public signature without tripping `noUnusedParameters`.\n void deltaTime;\n const tex = renderer.texture;\n if (!tex.isReady || sprites.length === 0) {\n return;\n }\n const effect = renderer._effect;\n if (!isEffectReady(effect)) {\n return;\n }\n if (renderer._vao === null || renderer._vbo === null) {\n return;\n }\n\n // ── Build vertex data (allocation-free) ──────────────────────────────────\n const vd = renderer._vertexData;\n const eps = renderer.epsilon;\n const texW = tex.width;\n const texH = tex.height;\n const cellW = renderer.cellWidth;\n const cellH = renderer.cellHeight;\n const rowSize = texW / cellW; // cells per sheet row\n const cellWidthN = cellW / texW;\n const cellHeightN = cellH / texH;\n const cap = renderer.capacity;\n const count = sprites.length;\n let visible = 0;\n for (let i = 0; i < count && visible < cap; i++) {\n const sprite = sprites[i];\n if (sprite === undefined || sprite.isVisible === false) {\n continue;\n }\n // UV rect — manual per-sprite rect (Babylon `ThinSprite._xOffset/_xSize`\n // path, selected when `uSize` is set) or the fixed `cellIndex` grid.\n // Both resolve to a normalized `(left, top, widthN, heightN)` rectangle,\n // matching Babylon's `_appendSpriteVertex` vertex layout exactly.\n let cellLeft: number;\n let cellTop: number;\n let cellWN: number;\n let cellHN: number;\n if (sprite.uSize !== undefined) {\n cellLeft = sprite.uOffset ?? 0;\n cellTop = sprite.vOffset ?? 0;\n cellWN = sprite.uSize / texW;\n cellHN = (sprite.vSize ?? 0) / texH;\n } else {\n const cellIndex = (sprite.cellIndex ?? 0) > 0 ? (sprite.cellIndex as number) : 0;\n const row = (cellIndex / rowSize) >> 0;\n cellLeft = ((cellIndex - row * rowSize) * cellW) / texW;\n cellTop = (row * cellH) / texH;\n cellWN = cellWidthN;\n cellHN = cellHeightN;\n }\n\n const px = sprite.position.x;\n const py = sprite.position.y;\n const pz = sprite.position.z;\n const angle = sprite.angle;\n const w = sprite.width;\n const h = sprite.height;\n const invU = sprite.invertU === true ? 1 : 0;\n const invV = sprite.invertV === true ? 1 : 0;\n const color = sprite.color;\n const cr = color !== undefined ? color.r : 1;\n const cg = color !== undefined ? color.g : 1;\n const cb = color !== undefined ? color.b : 1;\n const ca = color !== undefined ? color.a : 1;\n\n let off = visible * VERTS_PER_SPRITE * FLOATS_PER_VERTEX;\n for (let c = 0; c < VERTS_PER_SPRITE; c++) {\n const ox = CORNER_OFFSET_X[c] === 0 ? eps : 1 - eps;\n const oy = CORNER_OFFSET_Y[c] === 0 ? eps : 1 - eps;\n vd[off] = px;\n vd[off + 1] = py;\n vd[off + 2] = pz;\n vd[off + 3] = angle;\n vd[off + 4] = w;\n vd[off + 5] = h;\n vd[off + 6] = ox;\n vd[off + 7] = oy;\n vd[off + 8] = invU;\n vd[off + 9] = invV;\n vd[off + 10] = cellLeft;\n vd[off + 11] = cellTop;\n vd[off + 12] = cellWN;\n vd[off + 13] = cellHN;\n vd[off + 14] = cr;\n vd[off + 15] = cg;\n vd[off + 16] = cb;\n vd[off + 17] = ca;\n off += FLOATS_PER_VERTEX;\n }\n visible++;\n }\n if (visible === 0) {\n return;\n }\n\n // ── Upload + draw ────────────────────────────────────────────────────────\n const gl = engine.gl;\n const s = engine._state;\n const vao = renderer._vao;\n if (s.boundVao !== vao) {\n gl.bindVertexArray(vao);\n s.boundVao = vao;\n // Binding the VAO restores its element-array binding (VAO state).\n s.boundElementBuffer = renderer._ibo;\n }\n const vbo = renderer._vbo;\n if (s.boundArrayBuffer !== vbo) {\n gl.bindBuffer(gl.ARRAY_BUFFER, vbo);\n s.boundArrayBuffer = vbo;\n }\n const floatCount = visible * VERTS_PER_SPRITE * FLOATS_PER_VERTEX;\n gl.bufferSubData(gl.ARRAY_BUFFER, 0, vd, 0, floatCount);\n\n useEffect(effect);\n const viewLoc = effect.uniformLocations[\"view\"];\n if (viewLoc !== null && viewLoc !== undefined) {\n gl.uniformMatrix4fv(viewLoc, false, viewMatrix);\n }\n const projLoc = effect.uniformLocations[\"projection\"];\n if (projLoc !== null && projLoc !== undefined) {\n gl.uniformMatrix4fv(projLoc, false, projectionMatrix);\n }\n setEffectTexture(effect, \"diffuseSampler\", tex);\n\n setBlendMode(engine, renderer.blendMode);\n applyGLStates(engine);\n gl.drawElements(gl.TRIANGLES, visible * INDICES_PER_SPRITE, gl.UNSIGNED_SHORT, 0);\n // Auto-reset (Babylon `autoResetAlpha = true`): leave blend disabled so a\n // subsequent fullscreen `drawEffect` renders with the same state as before.\n // When `autoResetAlpha` is false (lottie), keep `renderer.blendMode` applied\n // so a premultiplied-alpha mode persists across multiple atlas-page passes.\n if (renderer.autoResetAlpha) {\n setBlendMode(engine, GLBlendMode.DISABLE);\n }\n}\n\n/** Swap the sprite-sheet texture (≙ Babylon assigning `SpriteRenderer.texture`\n * after an async load). The cell size is unchanged — adjust `cellWidth` /\n * `cellHeight` on the renderer directly if the new sheet differs. No-op when\n * the renderer is disposed.\n * No GL call is made — the texture is bound at draw time.\n *\n * @param renderer - The renderer to update.\n * @param texture - The new sprite-sheet texture. */\nexport function setSpriteRendererTexture(renderer: GLSpriteRenderer, texture: GLTexture): void {\n if (renderer._disposed) {\n return;\n }\n renderer.texture = texture;\n}\n\n/** Release the renderer's VAO/VBO/IBO and the effect it owns, and unregister\n * its context-restore handler. Idempotent. Does NOT dispose the texture — the\n * consumer that supplied it owns its lifetime.\n *\n * @param renderer - The renderer to dispose. */\nexport function disposeSpriteRenderer(renderer: GLSpriteRenderer): void {\n const engine = renderer._effect._engine;\n if (renderer._disposed) {\n return;\n }\n renderer._disposed = true;\n if (renderer._restore) {\n offContextRestored(engine, renderer._restore);\n }\n disposeEffect(renderer._effect);\n if (!engine._isLost && !engine._disposed) {\n const gl = engine.gl;\n const s = engine._state;\n if (renderer._vao !== null) {\n gl.deleteVertexArray(renderer._vao);\n if (s.boundVao === renderer._vao) {\n s.boundVao = null;\n }\n }\n if (renderer._vbo !== null) {\n gl.deleteBuffer(renderer._vbo);\n if (s.boundArrayBuffer === renderer._vbo) {\n s.boundArrayBuffer = null;\n }\n }\n if (renderer._ibo !== null) {\n gl.deleteBuffer(renderer._ibo);\n if (s.boundElementBuffer === renderer._ibo) {\n s.boundElementBuffer = null;\n }\n }\n }\n renderer._vao = null;\n renderer._vbo = null;\n renderer._ibo = null;\n}\n\n/* ──────────────────────────── internal helpers ──────────────────────────── */\n\n/** (Re)create the VAO + VBO + IBO and configure the six vertex attributes.\n * Called from `createSpriteRenderer` and from the `webglcontextrestored`\n * handler (the prior handles are dead per the WebGL spec — not deleted here).\n * No-op when the context is lost/disposed. */\nfunction buildSpriteBuffers(engine: GLEngineContext, renderer: GLSpriteRenderer): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n const s = engine._state;\n\n const vao = gl.createVertexArray();\n if (vao === null) {\n throw new Error(\"lite-gl: gl.createVertexArray returned null (sprite VAO)\");\n }\n renderer._vao = vao;\n gl.bindVertexArray(vao);\n s.boundVao = vao;\n\n const vbo = gl.createBuffer();\n if (vbo === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (sprite VBO)\");\n }\n renderer._vbo = vbo;\n gl.bindBuffer(gl.ARRAY_BUFFER, vbo);\n s.boundArrayBuffer = vbo;\n // Allocate the dynamic vertex storage at full capacity; filled per frame.\n gl.bufferData(gl.ARRAY_BUFFER, renderer._vertexData.byteLength, gl.DYNAMIC_DRAW);\n\n // Attribute pointers — locations match SPRITE_ATTRIBUTES / shader layout.\n gl.enableVertexAttribArray(0);\n gl.vertexAttribPointer(0, 4, gl.FLOAT, false, VERTEX_STRIDE_BYTES, 0);\n gl.enableVertexAttribArray(1);\n gl.vertexAttribPointer(1, 2, gl.FLOAT, false, VERTEX_STRIDE_BYTES, 4 * BYTES_PER_FLOAT);\n gl.enableVertexAttribArray(2);\n gl.vertexAttribPointer(2, 2, gl.FLOAT, false, VERTEX_STRIDE_BYTES, 6 * BYTES_PER_FLOAT);\n gl.enableVertexAttribArray(3);\n gl.vertexAttribPointer(3, 2, gl.FLOAT, false, VERTEX_STRIDE_BYTES, 8 * BYTES_PER_FLOAT);\n gl.enableVertexAttribArray(4);\n gl.vertexAttribPointer(4, 4, gl.FLOAT, false, VERTEX_STRIDE_BYTES, 10 * BYTES_PER_FLOAT);\n gl.enableVertexAttribArray(5);\n gl.vertexAttribPointer(5, 4, gl.FLOAT, false, VERTEX_STRIDE_BYTES, 14 * BYTES_PER_FLOAT);\n\n const ibo = gl.createBuffer();\n if (ibo === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (sprite IBO)\");\n }\n renderer._ibo = ibo;\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);\n s.boundElementBuffer = ibo;\n // Regenerate the static [0,1,2, 0,2,3] pattern instead of retaining it:\n // creation and the rare restore pay one transient array, nothing per frame.\n const indices = new Uint16Array(renderer.capacity * INDICES_PER_SPRITE);\n for (let i = 0, v = 0; i < indices.length; i += INDICES_PER_SPRITE, v += VERTS_PER_SPRITE) {\n indices[i] = indices[i + 3] = v;\n indices[i + 1] = v + 1;\n indices[i + 2] = indices[i + 4] = v + 2;\n indices[i + 5] = v + 3;\n }\n gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);\n}\n"]}
|