@babylonjs/lite-gl 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -91,8 +91,7 @@ use.
91
91
  `GLTexture` + optional depth / stencil renderbuffer), `createFloatRenderTarget`
92
92
  (float / half-float HDR opt-in), `bindRenderTarget` (cached, null = the canvas),
93
93
  `resizeRenderTarget`, `generateRenderTargetMipMaps`, `readRenderTargetPixels`,
94
- `disposeRenderTarget`, plus the `createPingPong` / `resizePingPong` /
95
- `disposePingPong` feedback helper.
94
+ `disposeRenderTarget`.
96
95
  - **Meshes / buffers** — `createVertexBuffer`, `updateVertexBuffer`,
97
96
  `createIndexBuffer`, `bindAttributes`, `drawIndexed` (instanced), `disposeBuffer`.
98
97
  - **Depth / stencil / scissor** — `setDepthState`, `setStencilState`,
package/index.d.ts CHANGED
@@ -8,8 +8,8 @@ export type { GLEffectWrapperOptions, GLEffectWrapper, GLViewport } from "./effe
8
8
  export { createRawTexture, createFloatTexture, generateTextureMipMaps, loadTexture2D, bindTexture, disposeTexture, updateRawTexture, updateTextureSamplingMode, updateTextureWrapMode, createTextureFromHandle, } from "./texture.js";
9
9
  export type { GLTextureOptions, GLFloatTextureOptions, GLTexture } from "./texture.js";
10
10
  export { createDynamicTexture, updateDynamicTexture, clearDynamicTextureSource } from "./dynamic-texture.js";
11
- export { createRenderTarget, createFloatRenderTarget, bindRenderTarget, generateRenderTargetMipMaps, resizeRenderTarget, readRenderTargetPixels, disposeRenderTarget, createPingPong, resizePingPong, disposePingPong, } from "./render-target.js";
12
- export type { GLRenderTarget, GLRenderTargetOptions, GLFloatRenderTargetOptions, GLPingPong } from "./render-target.js";
11
+ export { createRenderTarget, createFloatRenderTarget, bindRenderTarget, generateRenderTargetMipMaps, resizeRenderTarget, readRenderTargetPixels, disposeRenderTarget, } from "./render-target.js";
12
+ export type { GLRenderTarget, GLRenderTargetOptions, GLFloatRenderTargetOptions } from "./render-target.js";
13
13
  export { createVertexBuffer, updateVertexBuffer, createIndexBuffer, disposeBuffer, bindIndexBuffer, bindAttributes, unbindInstanceAttributes, drawIndexed, createMeshVao, bindMeshVao, drawMesh, disposeMeshVao, } from "./mesh.js";
14
14
  export type { GLVertexBuffer, GLIndexBuffer, GLAttributeDescriptor, GLMeshVertexBuffer, GLMeshVao } from "./mesh.js";
15
15
  export { GLBlendMode, GLBlendEquation, setBlendMode, setBlendState, disableBlend } from "./blend.js";
package/index.js CHANGED
@@ -23,7 +23,7 @@ export { createRawTexture, createFloatTexture, generateTextureMipMaps, loadTextu
23
23
  // ─── Dynamic textures ────────────────────────────────────────────────
24
24
  export { createDynamicTexture, updateDynamicTexture, clearDynamicTextureSource } from "./dynamic-texture.js";
25
25
  // ─── Render targets ──────────────────────────────────────────────────
26
- export { createRenderTarget, createFloatRenderTarget, bindRenderTarget, generateRenderTargetMipMaps, resizeRenderTarget, readRenderTargetPixels, disposeRenderTarget, createPingPong, resizePingPong, disposePingPong, } from "./render-target.js";
26
+ export { createRenderTarget, createFloatRenderTarget, bindRenderTarget, generateRenderTargetMipMaps, resizeRenderTarget, readRenderTargetPixels, disposeRenderTarget, } from "./render-target.js";
27
27
  // ─── Meshes / buffers / instancing ───────────────────────────────────
28
28
  export { createVertexBuffer, updateVertexBuffer, createIndexBuffer, disposeBuffer, bindIndexBuffer, bindAttributes, unbindInstanceAttributes, drawIndexed, createMeshVao, bindMeshVao, drawMesh, disposeMeshVao, } from "./mesh.js";
29
29
  // ─── Blend modes ─────────────────────────────────────────────────────
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,gFAAgF;AAChF,EAAE;AACF,iFAAiF;AACjF,4EAA4E;AAC5E,2EAA2E;AAC3E,yEAAyE;AACzE,+DAA+D;AAC/D,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,wCAAwC;AAEx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ClB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,cAAc,EACd,wBAAwB,EACxB,WAAW,EACX,aAAa,EACb,WAAW,EACX,QAAQ,EACR,cAAc,GACjB,MAAM,WAAW,CAAC;AAGnB,wEAAwE;AACxE,sEAAsE;AACtE,0BAA0B;AAC1B,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGrG,wEAAwE;AACxE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAG1I,wEAAwE;AACxE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE1D,wEAAwE;AACxE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAGpH,wEAAwE;AACxE,gFAAgF;AAChF,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["// @babylonjs/lite-gl — Public API\n// Function-based, tree-shakeable WebGL2 micro-engine. Import only what you use.\n//\n// Convention (mirrors @babylonjs/lite): the public API is re-exported EXPLICITLY\n// by name — never `export *`. This keeps the public surface intentional and\n// reviewable, lets `export type` mark type-only re-exports (required under\n// `isolatedModules`), and keeps internal helpers (e.g. `bindTextureRaw`,\n// `bindTextureForUpload`) out of consumers' bundles + `.d.ts`.\n//\n// The package is `sideEffects: false` and no module has top-level side effects,\n// so a consumer that imports only the symbols it needs tree-shakes everything\n// else (sprites, html-texture, …) away.\n\n// ─── Engine / context ────────────────────────────────────────────────\nexport {\n createGLEngine,\n disposeGLEngine,\n resizeGLEngine,\n setGLEngineSize,\n wipeGLStateCache,\n getRenderWidth,\n getRenderHeight,\n getHardwareScalingLevel,\n setHardwareScalingLevel,\n getRenderingCanvas,\n onContextLost,\n offContextLost,\n onContextRestored,\n offContextRestored,\n} from \"./context.js\";\nexport type { GLEngineOptions, GLEngineCaps, GLEngineContext } from \"./context.js\";\n\n// ─── Render loop ─────────────────────────────────────────────────────\nexport { runRenderLoop, stopRenderLoop } from \"./render-loop.js\";\n\n// ─── Effects ─────────────────────────────────────────────────────────\nexport {\n createEffect,\n useEffect,\n isEffectReady,\n executeWhenCompiled,\n disposeEffect,\n setEffectFloat,\n setEffectFloat2,\n setEffectFloat3,\n setEffectFloat4,\n setEffectColor3,\n setEffectColor4,\n setEffectVector2,\n setEffectDirectColor4,\n setEffectInt,\n setEffectTexture,\n setEffectMatrix,\n setEffectMatrix3x3,\n setEffectFloatArray,\n setEffectFloatArray4,\n setEffectIntArray,\n} from \"./effect.js\";\nexport type { GLEffectOptions, GLEffect } from \"./effect.js\";\n\n// ─── Effect renderer (fullscreen quad) ───────────────────────────────\nexport { createEffectWrapper, applyEffectWrapper, drawEffect, setViewport, disposeEffectWrapper } from \"./effect-renderer.js\";\nexport type { GLEffectWrapperOptions, GLEffectWrapper, GLViewport } from \"./effect-renderer.js\";\n\n// ─── Textures ────────────────────────────────────────────────────────\nexport {\n createRawTexture,\n createFloatTexture,\n generateTextureMipMaps,\n loadTexture2D,\n bindTexture,\n disposeTexture,\n updateRawTexture,\n updateTextureSamplingMode,\n updateTextureWrapMode,\n createTextureFromHandle,\n} from \"./texture.js\";\nexport type { GLTextureOptions, GLFloatTextureOptions, GLTexture } from \"./texture.js\";\n\n// ─── Dynamic textures ────────────────────────────────────────────────\nexport { createDynamicTexture, updateDynamicTexture, clearDynamicTextureSource } from \"./dynamic-texture.js\";\n\n// ─── Render targets ──────────────────────────────────────────────────\nexport {\n createRenderTarget,\n createFloatRenderTarget,\n bindRenderTarget,\n generateRenderTargetMipMaps,\n resizeRenderTarget,\n readRenderTargetPixels,\n disposeRenderTarget,\n createPingPong,\n resizePingPong,\n disposePingPong,\n} from \"./render-target.js\";\nexport type { GLRenderTarget, GLRenderTargetOptions, GLFloatRenderTargetOptions, GLPingPong } from \"./render-target.js\";\n\n// ─── Meshes / buffers / instancing ───────────────────────────────────\nexport {\n createVertexBuffer,\n updateVertexBuffer,\n createIndexBuffer,\n disposeBuffer,\n bindIndexBuffer,\n bindAttributes,\n unbindInstanceAttributes,\n drawIndexed,\n createMeshVao,\n bindMeshVao,\n drawMesh,\n disposeMeshVao,\n} from \"./mesh.js\";\nexport type { GLVertexBuffer, GLIndexBuffer, GLAttributeDescriptor, GLMeshVertexBuffer, GLMeshVao } from \"./mesh.js\";\n\n// ─── Blend modes ─────────────────────────────────────────────────────\n// GLBlendMode / GLBlendEquation are const + same-name type; one value\n// re-export carries both.\nexport { GLBlendMode, GLBlendEquation, setBlendMode, setBlendState, disableBlend } from \"./blend.js\";\nexport type { GLBlendState } from \"./blend.js\";\n\n// ─── Depth / stencil / color-mask / clear ────────────────────────────\nexport { setDepthState, setCullState, setStencilState, setColorMask, clearEngine, generateRenderTargetStencil } from \"./depth-stencil.js\";\nexport type { GLDepthState, GLStencilState, GLClearOptions } from \"./depth-stencil.js\";\n\n// ─── Scissor ─────────────────────────────────────────────────────────\nexport { setScissor, disableScissor } from \"./scissor.js\";\n\n// ─── Sprites ─────────────────────────────────────────────────────────\nexport { createSpriteRenderer, renderSprites, setSpriteRendererTexture, disposeSpriteRenderer } from \"./sprites.js\";\nexport type { GLSprite, GLSpriteColor, GLSpriteRendererOptions, GLSpriteRenderer } from \"./sprites.js\";\n\n// ─── HTML-element textures ───────────────────────────────────────────\n// GLSamplingMode is a const + same-name type; one value re-export carries both.\nexport { createHtmlElementTexture, updateHtmlElementTexture, GLSamplingMode } from \"./html-texture.js\";\nexport type { GLHtmlElementTextureOptions } from \"./html-texture.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,gFAAgF;AAChF,EAAE;AACF,iFAAiF;AACjF,4EAA4E;AAC5E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B,MAAM,oBAAoB,CAAC;AAG5B,wEAAwE;AACxE,OAAO,EACH,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,cAAc,EACd,wBAAwB,EACxB,WAAW,EACX,aAAa,EACb,WAAW,EACX,QAAQ,EACR,cAAc,GACjB,MAAM,WAAW,CAAC;AAGnB,wEAAwE;AACxE,sEAAsE;AACtE,0BAA0B;AAC1B,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGrG,wEAAwE;AACxE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAG1I,wEAAwE;AACxE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE1D,wEAAwE;AACxE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAGpH,wEAAwE;AACxE,gFAAgF;AAChF,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["// @babylonjs/lite-gl — Public API\n// Function-based, tree-shakeable WebGL2 micro-engine. Import only what you use.\n//\n// Convention (mirrors @babylonjs/lite): the public API is re-exported EXPLICITLY\n// by name — never `export *`. This keeps the public surface intentional and\n// reviewable, lets `export type` mark type-only re-exports (required under\n// `isolatedModules`), and keeps internal helpers (e.g. `bindTextureRaw`,\n// `bindTextureForUpload`) out of consumers' bundles + `.d.ts`.\n//\n// The package is `sideEffects: false` and no module has top-level side effects,\n// so a consumer that imports only the symbols it needs tree-shakes everything\n// else (sprites, html-texture, …) away.\n\n// ─── Engine / context ────────────────────────────────────────────────\nexport {\n createGLEngine,\n disposeGLEngine,\n resizeGLEngine,\n setGLEngineSize,\n wipeGLStateCache,\n getRenderWidth,\n getRenderHeight,\n getHardwareScalingLevel,\n setHardwareScalingLevel,\n getRenderingCanvas,\n onContextLost,\n offContextLost,\n onContextRestored,\n offContextRestored,\n} from \"./context.js\";\nexport type { GLEngineOptions, GLEngineCaps, GLEngineContext } from \"./context.js\";\n\n// ─── Render loop ─────────────────────────────────────────────────────\nexport { runRenderLoop, stopRenderLoop } from \"./render-loop.js\";\n\n// ─── Effects ─────────────────────────────────────────────────────────\nexport {\n createEffect,\n useEffect,\n isEffectReady,\n executeWhenCompiled,\n disposeEffect,\n setEffectFloat,\n setEffectFloat2,\n setEffectFloat3,\n setEffectFloat4,\n setEffectColor3,\n setEffectColor4,\n setEffectVector2,\n setEffectDirectColor4,\n setEffectInt,\n setEffectTexture,\n setEffectMatrix,\n setEffectMatrix3x3,\n setEffectFloatArray,\n setEffectFloatArray4,\n setEffectIntArray,\n} from \"./effect.js\";\nexport type { GLEffectOptions, GLEffect } from \"./effect.js\";\n\n// ─── Effect renderer (fullscreen quad) ───────────────────────────────\nexport { createEffectWrapper, applyEffectWrapper, drawEffect, setViewport, disposeEffectWrapper } from \"./effect-renderer.js\";\nexport type { GLEffectWrapperOptions, GLEffectWrapper, GLViewport } from \"./effect-renderer.js\";\n\n// ─── Textures ────────────────────────────────────────────────────────\nexport {\n createRawTexture,\n createFloatTexture,\n generateTextureMipMaps,\n loadTexture2D,\n bindTexture,\n disposeTexture,\n updateRawTexture,\n updateTextureSamplingMode,\n updateTextureWrapMode,\n createTextureFromHandle,\n} from \"./texture.js\";\nexport type { GLTextureOptions, GLFloatTextureOptions, GLTexture } from \"./texture.js\";\n\n// ─── Dynamic textures ────────────────────────────────────────────────\nexport { createDynamicTexture, updateDynamicTexture, clearDynamicTextureSource } from \"./dynamic-texture.js\";\n\n// ─── Render targets ──────────────────────────────────────────────────\nexport {\n createRenderTarget,\n createFloatRenderTarget,\n bindRenderTarget,\n generateRenderTargetMipMaps,\n resizeRenderTarget,\n readRenderTargetPixels,\n disposeRenderTarget,\n} from \"./render-target.js\";\nexport type { GLRenderTarget, GLRenderTargetOptions, GLFloatRenderTargetOptions } from \"./render-target.js\";\n\n// ─── Meshes / buffers / instancing ───────────────────────────────────\nexport {\n createVertexBuffer,\n updateVertexBuffer,\n createIndexBuffer,\n disposeBuffer,\n bindIndexBuffer,\n bindAttributes,\n unbindInstanceAttributes,\n drawIndexed,\n createMeshVao,\n bindMeshVao,\n drawMesh,\n disposeMeshVao,\n} from \"./mesh.js\";\nexport type { GLVertexBuffer, GLIndexBuffer, GLAttributeDescriptor, GLMeshVertexBuffer, GLMeshVao } from \"./mesh.js\";\n\n// ─── Blend modes ─────────────────────────────────────────────────────\n// GLBlendMode / GLBlendEquation are const + same-name type; one value\n// re-export carries both.\nexport { GLBlendMode, GLBlendEquation, setBlendMode, setBlendState, disableBlend } from \"./blend.js\";\nexport type { GLBlendState } from \"./blend.js\";\n\n// ─── Depth / stencil / color-mask / clear ────────────────────────────\nexport { setDepthState, setCullState, setStencilState, setColorMask, clearEngine, generateRenderTargetStencil } from \"./depth-stencil.js\";\nexport type { GLDepthState, GLStencilState, GLClearOptions } from \"./depth-stencil.js\";\n\n// ─── Scissor ─────────────────────────────────────────────────────────\nexport { setScissor, disableScissor } from \"./scissor.js\";\n\n// ─── Sprites ─────────────────────────────────────────────────────────\nexport { createSpriteRenderer, renderSprites, setSpriteRendererTexture, disposeSpriteRenderer } from \"./sprites.js\";\nexport type { GLSprite, GLSpriteColor, GLSpriteRendererOptions, GLSpriteRenderer } from \"./sprites.js\";\n\n// ─── HTML-element textures ───────────────────────────────────────────\n// GLSamplingMode is a const + same-name type; one value re-export carries both.\nexport { createHtmlElementTexture, updateHtmlElementTexture, GLSamplingMode } from \"./html-texture.js\";\nexport type { GLHtmlElementTextureOptions } from \"./html-texture.js\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/lite-gl",
3
- "version": "0.2.0",
3
+ "version": "1.0.0",
4
4
  "description": "Function-based, tree-shakeable WebGL2 micro-engine for fullscreen effects, sprites and dynamic textures — the WebGL counterpart of @babylonjs/lite.",
5
5
  "keywords": [
6
6
  "babylon",
@@ -32,7 +32,7 @@
32
32
  }
33
33
  },
34
34
  "babylonLiteRelease": {
35
- "azureBuildId": "55390",
36
- "sourceVersion": "f548079a5add4e2903e9d3077788ddb77b91e5a0"
35
+ "azureBuildId": "55469",
36
+ "sourceVersion": "de70048c4d652302d4eb5f5b74c158a20b2015af"
37
37
  }
38
38
  }
@@ -84,20 +84,6 @@ export interface GLRenderTarget {
84
84
  /** True once the color attachment + framebuffer are allocated. */
85
85
  isReady: boolean;
86
86
  }
87
- /**
88
- * A pair of {@link GLRenderTarget}s for self-feedback effects: SAMPLE the
89
- * {@link GLPingPong.read | read} target (last frame's output) while RENDERING
90
- * into the {@link GLPingPong.write | write} target, then {@link GLPingPong.swap}.
91
- */
92
- export interface GLPingPong {
93
- /** The target to SAMPLE this frame (the previous frame's output). */
94
- readonly read: GLRenderTarget;
95
- /** The target to RENDER into this frame. */
96
- readonly write: GLRenderTarget;
97
- /** Exchange `read` and `write`. Call after rendering the `write` target each
98
- * frame. Allocation-free — flips an internal index, no objects created. */
99
- swap(): void;
100
- }
101
87
  /**
102
88
  * Create an offscreen **RGBA8** render target.
103
89
  *
@@ -202,32 +188,3 @@ export declare function readRenderTargetPixels(engine: GLEngineContext, rt: GLRe
202
188
  * @param rt - The render target to dispose, or `null`/`undefined` for a no-op.
203
189
  */
204
190
  export declare function disposeRenderTarget(engine: GLEngineContext, rt: GLRenderTarget | null | undefined): void;
205
- /**
206
- * Create a {@link GLPingPong}: two same-sized {@link GLRenderTarget}s for
207
- * self-feedback effects. `read` starts as the first target and `write` the
208
- * second; {@link GLPingPong.swap} exchanges them allocation-free.
209
- *
210
- * @param engine - The engine to create GL resources on.
211
- * @param options - Applied identically to both targets.
212
- * @returns The new {@link GLPingPong}.
213
- * @throws As {@link createRenderTarget}. If the second target fails to build the
214
- * first is disposed before rethrowing (no leak).
215
- */
216
- export declare function createPingPong(engine: GLEngineContext, options: GLRenderTargetOptions): GLPingPong;
217
- /**
218
- * Resize both targets of a {@link GLPingPong}. No-op when disposed.
219
- *
220
- * @param engine - The engine that owns `pp`.
221
- * @param pp - The ping-pong pair to resize.
222
- * @param width - New width in texels (positive integer).
223
- * @param height - New height in texels (positive integer).
224
- */
225
- export declare function resizePingPong(engine: GLEngineContext, pp: GLPingPong, width: number, height: number): void;
226
- /**
227
- * Release both targets of a {@link GLPingPong}. Idempotent, and a no-op for
228
- * `null`/`undefined` (matching {@link disposeRenderTarget}).
229
- *
230
- * @param engine - The engine that owns `pp`.
231
- * @param pp - The ping-pong pair to release, or `null`/`undefined` for a no-op.
232
- */
233
- export declare function disposePingPong(engine: GLEngineContext, pp: GLPingPong | null | undefined): void;
package/render-target.js CHANGED
@@ -261,74 +261,6 @@ export function disposeRenderTarget(engine, rt) {
261
261
  }
262
262
  }
263
263
  }
264
- /**
265
- * Create a {@link GLPingPong}: two same-sized {@link GLRenderTarget}s for
266
- * self-feedback effects. `read` starts as the first target and `write` the
267
- * second; {@link GLPingPong.swap} exchanges them allocation-free.
268
- *
269
- * @param engine - The engine to create GL resources on.
270
- * @param options - Applied identically to both targets.
271
- * @returns The new {@link GLPingPong}.
272
- * @throws As {@link createRenderTarget}. If the second target fails to build the
273
- * first is disposed before rethrowing (no leak).
274
- */
275
- export function createPingPong(engine, options) {
276
- const a = createRenderTarget(engine, options);
277
- let b;
278
- try {
279
- b = createRenderTarget(engine, options);
280
- }
281
- catch (e) {
282
- disposeRenderTarget(engine, a);
283
- throw e;
284
- }
285
- const pp = {
286
- _a: a,
287
- _b: b,
288
- _readIsA: true,
289
- _disposed: false,
290
- get read() {
291
- return pp._readIsA ? pp._a : pp._b;
292
- },
293
- get write() {
294
- return pp._readIsA ? pp._b : pp._a;
295
- },
296
- swap() {
297
- pp._readIsA = !pp._readIsA;
298
- },
299
- };
300
- return pp;
301
- }
302
- /**
303
- * Resize both targets of a {@link GLPingPong}. No-op when disposed.
304
- *
305
- * @param engine - The engine that owns `pp`.
306
- * @param pp - The ping-pong pair to resize.
307
- * @param width - New width in texels (positive integer).
308
- * @param height - New height in texels (positive integer).
309
- */
310
- export function resizePingPong(engine, pp, width, height) {
311
- if (pp._disposed) {
312
- return;
313
- }
314
- resizeRenderTarget(engine, pp._a, width, height);
315
- resizeRenderTarget(engine, pp._b, width, height);
316
- }
317
- /**
318
- * Release both targets of a {@link GLPingPong}. Idempotent, and a no-op for
319
- * `null`/`undefined` (matching {@link disposeRenderTarget}).
320
- *
321
- * @param engine - The engine that owns `pp`.
322
- * @param pp - The ping-pong pair to release, or `null`/`undefined` for a no-op.
323
- */
324
- export function disposePingPong(engine, pp) {
325
- if (pp === null || pp === undefined || pp._disposed) {
326
- return;
327
- }
328
- pp._disposed = true;
329
- disposeRenderTarget(engine, pp._a);
330
- disposeRenderTarget(engine, pp._b);
331
- }
332
264
  /* ──────────────────────────── internal helpers ──────────────────────────── */
333
265
  /** Shared private constructor. Validates size, resolves the config (given the
334
266
  * exact sized `internalFormat` by the caller — NO format-table lookup), wires
@@ -1 +1 @@
1
- {"version":3,"file":"render-target.js","sourceRoot":"","sources":["../src/render-target.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAkB,MAAM,cAAc,CAAC;AAG7F,yEAAyE;AACzE,MAAM,aAAa,GAAG,MAAM,CAAC;AAC7B,0BAA0B;AAC1B,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,qBAAqB;AACrB,MAAM,KAAK,GAAG,MAAM,CAAC;AACrB,oBAAoB;AACpB,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,wDAAwD;AACxD,MAAM,KAAK,GAAG,MAAM,CAAC;AACrB,sBAAsB;AACtB,MAAM,MAAM,GAAG,MAAM,CAAC;AACtB,6BAA6B;AAC7B,MAAM,aAAa,GAAG,M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CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;YACjC,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,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 **RGBA8** color target and\n * ships none of the HDR sized-format 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, type GLTexture } from \"./texture.js\";\nimport type { GLEngineContext } from \"./context.js\";\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.RGBA8` — the default sized internalFormat. */\nconst RGBA8 = 0x8058;\n/** GL `gl.LINEAR`. */\nconst LINEAR = 0x2601;\n/** GL `gl.CLAMP_TO_EDGE`. */\nconst CLAMP_TO_EDGE = 0x812f;\n\n/** Options for {@link createRenderTarget}. `width`/`height` are required; every\n * other field has a Babylon-matching default. The bare\n * `createRenderTarget(engine, { width, height })` makes an RGBA8 color-only\n * target with linear filtering and clamp wrapping. */\nexport interface GLRenderTargetOptions {\n /** Color attachment width in texels. Must be a positive integer. */\n width: number;\n /** Color attachment height in texels. Must be a positive integer. */\n height: number;\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 /** 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 colorTexture?: GLTexture;\n}\n\n/** Options for {@link createFloatRenderTarget} — {@link GLRenderTargetOptions}\n * plus the float color `type`. */\nexport interface GLFloatRenderTargetOptions extends GLRenderTargetOptions {\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/** 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 /** @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 * A pair of {@link GLRenderTarget}s for self-feedback effects: SAMPLE the\n * {@link GLPingPong.read | read} target (last frame's output) while RENDERING\n * into the {@link GLPingPong.write | write} target, then {@link GLPingPong.swap}.\n */\nexport interface GLPingPong {\n /** The target to SAMPLE this frame (the previous frame's output). */\n readonly read: GLRenderTarget;\n /** The target to RENDER into this frame. */\n readonly write: GLRenderTarget;\n /** Exchange `read` and `write`. Call after rendering the `write` target each\n * frame. Allocation-free — flips an internal index, no objects created. */\n swap(): void;\n /** @internal */\n _a: GLRenderTarget;\n /** @internal */\n _b: GLRenderTarget;\n /** @internal */\n _readIsA: boolean;\n /** @internal */\n _disposed: boolean;\n}\n\n/**\n * Create an offscreen **RGBA8** render target.\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 options - See {@link GLRenderTargetOptions} (`width`/`height` required).\n * @returns The new {@link GLRenderTarget}.\n * @throws If `width`/`height` are not positive integers, a GL handle could not\n * be allocated, or the resulting framebuffer is not complete. On failure every\n * partial GPU object (including an owned color texture) is released first.\n */\nexport function createRenderTarget(engine: GLEngineContext, options: GLRenderTargetOptions): GLRenderTarget {\n return buildRT(engine, options, RGBA8, RGBA, 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 options - See {@link GLFloatRenderTargetOptions}.\n * @returns The new {@link GLRenderTarget}.\n * @throws As {@link createRenderTarget}.\n */\nexport function createFloatRenderTarget(engine: GLEngineContext, options: GLFloatRenderTargetOptions): GLRenderTarget {\n const type = resolveColorType(engine, options.type ?? HALF_FLOAT);\n const internalFormat = pickSizedInternalFormat(engine.gl, RGBA, type);\n return buildRT(engine, options, 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. `rt = null` binds the default (canvas) framebuffer and resets the\n * viewport to the full canvas — the counterpart of Babylon's\n * `restoreDefaultFramebuffer`. Subsequent `drawEffect` / `drawIndexed` /\n * `clearEngine` calls write into the 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 engine - The engine.\n * @param rt - The render target to draw into, or `null` for the canvas.\n */\nexport function bindRenderTarget(engine: GLEngineContext, rt: GLRenderTarget | null): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n if (rt !== null && rt._disposed) {\n return;\n }\n const gl = engine.gl;\n const s = engine._state;\n const fb = rt === null ? null : rt._framebuffer;\n if (s.boundFramebuffer !== fb) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, fb);\n s.boundFramebuffer = fb;\n }\n engine._currentRenderTarget = rt;\n if (rt === null) {\n setViewportCached(engine, 0, 0, engine.canvas.width, engine.canvas.height);\n } else {\n setViewportCached(engine, 0, 0, rt.width, rt.height);\n }\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(engine: GLEngineContext, rt: GLRenderTarget): void {\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 engine - The engine.\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(engine: GLEngineContext, rt: GLRenderTarget, width: number, height: number): void {\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(engine, 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 * @param engine - The engine.\n * @param rt - The render target to read from.\n * @param x - Lower-left X of the read rectangle, in texels.\n * @param y - Lower-left Y of the read rectangle, in texels.\n * @param width - Read rectangle width in texels.\n * @param height - Read rectangle height in texels.\n * @param into - Optional preallocated buffer (`width*height*4` elements of the\n * matching type). Reused to avoid per-call allocation.\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(engine: GLEngineContext, rt: GLRenderTarget, x: number, y: number, width: number, height: number, into?: ArrayBufferView): ArrayBufferView {\n const elements = width * height * 4;\n if (engine._isLost || engine._disposed || rt._disposed) {\n return into ?? new Uint8Array(0);\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 const type = rt._config.type;\n let buffer = into;\n if (buffer === undefined) {\n buffer = type === gl.FLOAT ? new Float32Array(elements) : type === gl.HALF_FLOAT ? new Uint16Array(elements) : new Uint8Array(elements);\n }\n gl.readPixels(x, y, width, height, gl.RGBA, type, buffer);\n return buffer;\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 engine - The engine.\n * @param rt - The render target to dispose, or `null`/`undefined` for a no-op.\n */\nexport function disposeRenderTarget(engine: GLEngineContext, rt: GLRenderTarget | null | undefined): void {\n if (rt === null || rt === undefined || rt._disposed) {\n return;\n }\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/**\n * Create a {@link GLPingPong}: two same-sized {@link GLRenderTarget}s for\n * self-feedback effects. `read` starts as the first target and `write` the\n * second; {@link GLPingPong.swap} exchanges them allocation-free.\n *\n * @param engine - The engine to create GL resources on.\n * @param options - Applied identically to both targets.\n * @returns The new {@link GLPingPong}.\n * @throws As {@link createRenderTarget}. If the second target fails to build the\n * first is disposed before rethrowing (no leak).\n */\nexport function createPingPong(engine: GLEngineContext, options: GLRenderTargetOptions): GLPingPong {\n const a = createRenderTarget(engine, options);\n let b: GLRenderTarget;\n try {\n b = createRenderTarget(engine, options);\n } catch (e) {\n disposeRenderTarget(engine, a);\n throw e;\n }\n const pp: GLPingPong = {\n _a: a,\n _b: b,\n _readIsA: true,\n _disposed: false,\n get read(): GLRenderTarget {\n return pp._readIsA ? pp._a : pp._b;\n },\n get write(): GLRenderTarget {\n return pp._readIsA ? pp._b : pp._a;\n },\n swap(): void {\n pp._readIsA = !pp._readIsA;\n },\n };\n return pp;\n}\n\n/**\n * Resize both targets of a {@link GLPingPong}. No-op when disposed.\n *\n * @param engine - The engine that owns `pp`.\n * @param pp - The ping-pong pair to resize.\n * @param width - New width in texels (positive integer).\n * @param height - New height in texels (positive integer).\n */\nexport function resizePingPong(engine: GLEngineContext, pp: GLPingPong, width: number, height: number): void {\n if (pp._disposed) {\n return;\n }\n resizeRenderTarget(engine, pp._a, width, height);\n resizeRenderTarget(engine, pp._b, width, height);\n}\n\n/**\n * Release both targets of a {@link GLPingPong}. Idempotent, and a no-op for\n * `null`/`undefined` (matching {@link disposeRenderTarget}).\n *\n * @param engine - The engine that owns `pp`.\n * @param pp - The ping-pong pair to release, or `null`/`undefined` for a no-op.\n */\nexport function disposePingPong(engine: GLEngineContext, pp: GLPingPong | null | undefined): void {\n if (pp === null || pp === undefined || pp._disposed) {\n return;\n }\n pp._disposed = true;\n disposeRenderTarget(engine, pp._a);\n disposeRenderTarget(engine, pp._b);\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, options: GLRenderTargetOptions, internalFormat: GLenum, format: GLenum, type: GLenum): GLRenderTarget {\n const width = options.width;\n const height = options.height;\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 _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 _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 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, c.minFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, c.magFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, c.wrapS);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, 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;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAkB,MAAM,cAAc,CAAC;AAG7F,yEAAyE;AACzE,MAAM,aAAa,GAAG,MAAM,CAAC;AAC7B,0BAA0B;AAC1B,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,qBAAqB;AACrB,MAAM,KAAK,GAAG,MAAM,CAAC;AACrB,oBAAoB;AACpB,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,wDAAwD;AACxD,MAAM,KAAK,GAAG,MAAM,CAAC;AACrB,sBAAsB;AACtB,MAAM,MAAM,GAAG,MAAM,CAAC;AACtB,6BAA6B;AAC7B,MAAM,aAAa,GAAG,MAAM,CAAC;AAwG7B;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAuB,EAAE,OAA8B;IACtF,OAAO,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAuB,EAAE,OAAmC;IAChG,MAAM,IAAI,GAAG,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,IAAI,UAAU,CAAC,CAAC;IAClE,MAAM,cAAc,GAAG,uBAAuB,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACtE,OAAO,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;;;;;;;;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ChB,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 **RGBA8** color target and\n * ships none of the HDR sized-format 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, type GLTexture } from \"./texture.js\";\nimport type { GLEngineContext } from \"./context.js\";\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.RGBA8` — the default sized internalFormat. */\nconst RGBA8 = 0x8058;\n/** GL `gl.LINEAR`. */\nconst LINEAR = 0x2601;\n/** GL `gl.CLAMP_TO_EDGE`. */\nconst CLAMP_TO_EDGE = 0x812f;\n\n/** Options for {@link createRenderTarget}. `width`/`height` are required; every\n * other field has a Babylon-matching default. The bare\n * `createRenderTarget(engine, { width, height })` makes an RGBA8 color-only\n * target with linear filtering and clamp wrapping. */\nexport interface GLRenderTargetOptions {\n /** Color attachment width in texels. Must be a positive integer. */\n width: number;\n /** Color attachment height in texels. Must be a positive integer. */\n height: number;\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 /** 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 colorTexture?: GLTexture;\n}\n\n/** Options for {@link createFloatRenderTarget} — {@link GLRenderTargetOptions}\n * plus the float color `type`. */\nexport interface GLFloatRenderTargetOptions extends GLRenderTargetOptions {\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/** 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 /** @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 **RGBA8** render target.\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 options - See {@link GLRenderTargetOptions} (`width`/`height` required).\n * @returns The new {@link GLRenderTarget}.\n * @throws If `width`/`height` are not positive integers, a GL handle could not\n * be allocated, or the resulting framebuffer is not complete. On failure every\n * partial GPU object (including an owned color texture) is released first.\n */\nexport function createRenderTarget(engine: GLEngineContext, options: GLRenderTargetOptions): GLRenderTarget {\n return buildRT(engine, options, RGBA8, RGBA, 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 options - See {@link GLFloatRenderTargetOptions}.\n * @returns The new {@link GLRenderTarget}.\n * @throws As {@link createRenderTarget}.\n */\nexport function createFloatRenderTarget(engine: GLEngineContext, options: GLFloatRenderTargetOptions): GLRenderTarget {\n const type = resolveColorType(engine, options.type ?? HALF_FLOAT);\n const internalFormat = pickSizedInternalFormat(engine.gl, RGBA, type);\n return buildRT(engine, options, 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. `rt = null` binds the default (canvas) framebuffer and resets the\n * viewport to the full canvas — the counterpart of Babylon's\n * `restoreDefaultFramebuffer`. Subsequent `drawEffect` / `drawIndexed` /\n * `clearEngine` calls write into the 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 engine - The engine.\n * @param rt - The render target to draw into, or `null` for the canvas.\n */\nexport function bindRenderTarget(engine: GLEngineContext, rt: GLRenderTarget | null): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n if (rt !== null && rt._disposed) {\n return;\n }\n const gl = engine.gl;\n const s = engine._state;\n const fb = rt === null ? null : rt._framebuffer;\n if (s.boundFramebuffer !== fb) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, fb);\n s.boundFramebuffer = fb;\n }\n engine._currentRenderTarget = rt;\n if (rt === null) {\n setViewportCached(engine, 0, 0, engine.canvas.width, engine.canvas.height);\n } else {\n setViewportCached(engine, 0, 0, rt.width, rt.height);\n }\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(engine: GLEngineContext, rt: GLRenderTarget): void {\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 engine - The engine.\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(engine: GLEngineContext, rt: GLRenderTarget, width: number, height: number): void {\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(engine, 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 * @param engine - The engine.\n * @param rt - The render target to read from.\n * @param x - Lower-left X of the read rectangle, in texels.\n * @param y - Lower-left Y of the read rectangle, in texels.\n * @param width - Read rectangle width in texels.\n * @param height - Read rectangle height in texels.\n * @param into - Optional preallocated buffer (`width*height*4` elements of the\n * matching type). Reused to avoid per-call allocation.\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(engine: GLEngineContext, rt: GLRenderTarget, x: number, y: number, width: number, height: number, into?: ArrayBufferView): ArrayBufferView {\n const elements = width * height * 4;\n if (engine._isLost || engine._disposed || rt._disposed) {\n return into ?? new Uint8Array(0);\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 const type = rt._config.type;\n let buffer = into;\n if (buffer === undefined) {\n buffer = type === gl.FLOAT ? new Float32Array(elements) : type === gl.HALF_FLOAT ? new Uint16Array(elements) : new Uint8Array(elements);\n }\n gl.readPixels(x, y, width, height, gl.RGBA, type, buffer);\n return buffer;\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 engine - The engine.\n * @param rt - The render target to dispose, or `null`/`undefined` for a no-op.\n */\nexport function disposeRenderTarget(engine: GLEngineContext, rt: GLRenderTarget | null | undefined): void {\n if (rt === null || rt === undefined || rt._disposed) {\n return;\n }\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, options: GLRenderTargetOptions, internalFormat: GLenum, format: GLenum, type: GLenum): GLRenderTarget {\n const width = options.width;\n const height = options.height;\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 _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 _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 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, c.minFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, c.magFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, c.wrapS);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, 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"]}