@babylonjs/lite-gl 1.23.0 → 1.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +103 -6
- package/blend.d.ts +1 -1
- package/blend.js +1 -1
- package/blend.js.map +1 -1
- package/context.d.ts +52 -4
- package/context.js +108 -11
- package/context.js.map +1 -1
- package/depth-stencil.d.ts +4 -16
- package/depth-stencil.js +10 -11
- package/depth-stencil.js.map +1 -1
- package/dynamic-texture.d.ts +6 -3
- package/dynamic-texture.js +16 -4
- package/dynamic-texture.js.map +1 -1
- package/effect-renderer.d.ts +1 -11
- package/effect-renderer.js.map +1 -1
- package/effect.d.ts +16 -29
- package/effect.js +52 -19
- package/effect.js.map +1 -1
- package/family.d.ts +474 -0
- package/family.js +14 -0
- package/family.js.map +1 -0
- package/framebuffer-validation.d.ts +20 -0
- package/framebuffer-validation.js +37 -0
- package/framebuffer-validation.js.map +1 -0
- package/html-texture.d.ts +2 -2
- package/html-texture.js.map +1 -1
- package/index.d.ts +10 -7
- package/index.js +5 -4
- package/index.js.map +1 -1
- package/mesh.d.ts +72 -15
- package/mesh.js +221 -64
- package/mesh.js.map +1 -1
- package/native/command-stream.d.ts +1 -0
- package/native/command-stream.js +135 -0
- package/native/command-stream.js.map +1 -0
- package/native/context.d.ts +26 -0
- package/native/context.js +89 -0
- package/native/context.js.map +1 -0
- package/native/effect.d.ts +44 -0
- package/native/effect.js +276 -0
- package/native/effect.js.map +1 -0
- package/native/family.d.ts +75 -0
- package/native/family.js +2 -0
- package/native/family.js.map +1 -0
- package/native/identity.d.ts +11 -0
- package/native/identity.js +2 -0
- package/native/identity.js.map +1 -0
- package/native/index.d.ts +25 -0
- package/native/index.js +7 -0
- package/native/index.js.map +1 -0
- package/native/mesh.d.ts +53 -0
- package/native/mesh.js +137 -0
- package/native/mesh.js.map +1 -0
- package/native/render-target.d.ts +35 -0
- package/native/render-target.js +159 -0
- package/native/render-target.js.map +1 -0
- package/native/runtime.d.ts +1 -0
- package/native/runtime.js +12 -0
- package/native/runtime.js.map +1 -0
- package/native/state.d.ts +19 -0
- package/native/state.js +104 -0
- package/native/state.js.map +1 -0
- package/native/texture.d.ts +37 -0
- package/native/texture.js +86 -0
- package/native/texture.js.map +1 -0
- package/package.json +11 -3
- package/render-target.d.ts +18 -9
- package/render-target.js +84 -31
- package/render-target.js.map +1 -1
- package/scissor.d.ts +3 -3
- package/scissor.js +2 -2
- package/scissor.js.map +1 -1
- package/sprites.d.ts +5 -3
- package/sprites.js +24 -23
- package/sprites.js.map +1 -1
- package/state.d.ts +26 -13
- package/state.js +15 -15
- package/state.js.map +1 -1
- package/text/_gpu/text-instances.js +1 -1
- package/text/_gpu/text-instances.js.map +1 -1
- package/text/text-renderer.js.map +1 -1
- package/texture-3d.d.ts +2 -1
- package/texture-3d.js +7 -2
- package/texture-3d.js.map +1 -1
- package/texture-source.d.ts +4 -2
- package/texture-source.js +3 -2
- package/texture-source.js.map +1 -1
- package/texture.d.ts +18 -8
- package/texture.js +61 -35
- package/texture.js.map +1 -1
- package/web-family.d.ts +88 -0
- package/web-family.js +2 -0
- package/web-family.js.map +1 -0
package/render-target.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* carries the `RGBA16F` / `RGBA32F` table, so RGBA8 consumers tree-shake it
|
|
20
20
|
* away).
|
|
21
21
|
*
|
|
22
|
-
*
|
|
22
|
+
* Unless the engine is host-owned (`createHostOwnedGLEngine`), the full color/depth/stencil GPU set is rebuilt automatically on
|
|
23
23
|
* `webglcontextrestored` — the render target registers itself with the engine's
|
|
24
24
|
* `_renderTargets` registry, and the context-restore protocol calls its
|
|
25
25
|
* `_restore` closure AFTER the standalone texture replay. A caller-supplied
|
|
@@ -27,6 +27,41 @@
|
|
|
27
27
|
* there first; the RT then re-attaches its freshly-swapped handle.
|
|
28
28
|
*/
|
|
29
29
|
import { bindTextureForUpload, pickSizedInternalFormat, resolveLdrInternalFormat, setBoundTextureParams } from "./texture.js";
|
|
30
|
+
import { validateFramebuffer } from "./framebuffer-validation.js";
|
|
31
|
+
/**
|
|
32
|
+
* Presents a retained composition target to the whole canvas without disturbing
|
|
33
|
+
* its contents; an active scissor rectangle does not clip the presentation.
|
|
34
|
+
* Presentation copies framebuffers, which WebGL2 forbids into a multisampled
|
|
35
|
+
* canvas, so it throws for an engine created with `antialias: true`.
|
|
36
|
+
*/
|
|
37
|
+
export function presentRenderTarget(target) {
|
|
38
|
+
const engine = target._engine;
|
|
39
|
+
if (engine._isLost || engine._disposed || target._disposed || !target.isReady) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const gl = engine.gl;
|
|
43
|
+
const s = engine._state;
|
|
44
|
+
restoreDefaultFramebuffer(engine);
|
|
45
|
+
// Queried with the canvas framebuffer bound; its sample count is fixed when the context is created.
|
|
46
|
+
engine._canvasSamples ??= Number(gl.getParameter(gl.SAMPLES));
|
|
47
|
+
if (engine._canvasSamples > 0) {
|
|
48
|
+
throw new Error("lite-gl: presentRenderTarget cannot copy into a multisampled canvas; create the engine without antialias");
|
|
49
|
+
}
|
|
50
|
+
let scissorEnabled = s.scissorEnabled;
|
|
51
|
+
if (scissorEnabled === -1) {
|
|
52
|
+
scissorEnabled = gl.isEnabled(gl.SCISSOR_TEST) ? 1 : 0;
|
|
53
|
+
}
|
|
54
|
+
if (scissorEnabled === 1) {
|
|
55
|
+
gl.disable(gl.SCISSOR_TEST);
|
|
56
|
+
}
|
|
57
|
+
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, target._framebuffer);
|
|
58
|
+
gl.blitFramebuffer(0, 0, target.width, target.height, 0, 0, engine.canvas.width, engine.canvas.height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
|
|
59
|
+
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null);
|
|
60
|
+
if (scissorEnabled === 1) {
|
|
61
|
+
gl.enable(gl.SCISSOR_TEST);
|
|
62
|
+
}
|
|
63
|
+
s.scissorEnabled = scissorEnabled;
|
|
64
|
+
}
|
|
30
65
|
/** GL `gl.UNSIGNED_BYTE` — the default (RGBA8) color attachment type. */
|
|
31
66
|
const UNSIGNED_BYTE = 0x1401;
|
|
32
67
|
/** GL `gl.HALF_FLOAT`. */
|
|
@@ -52,13 +87,14 @@ const CLAMP_TO_EDGE = 0x812f;
|
|
|
52
87
|
* caller-managed (BYO) one. Mirrors Babylon's `createRenderTargetTexture`.
|
|
53
88
|
*
|
|
54
89
|
* @param engine - The engine to allocate GL resources on.
|
|
55
|
-
* @param width - Color attachment width in texels. Must be a positive integer.
|
|
56
|
-
* @param height - Color attachment height in texels. Must be a positive integer.
|
|
90
|
+
* @param width - Color attachment width in texels. Must be a positive integer up to `caps.maxTextureSize`.
|
|
91
|
+
* @param height - Color attachment height in texels. Must be a positive integer up to `caps.maxTextureSize`.
|
|
57
92
|
* @param options - See {@link GLRenderTargetOptions}.
|
|
58
93
|
* @returns The new {@link GLRenderTarget}.
|
|
59
94
|
* @throws If `format` is not `RGBA` / `RG` / `RED`, `width`/`height` are not
|
|
60
|
-
* positive integers
|
|
61
|
-
* framebuffer is not complete
|
|
95
|
+
* positive integers up to `caps.maxTextureSize`, a GL handle could not be allocated, or the resulting
|
|
96
|
+
* framebuffer is not complete (unless `setFramebufferValidation(engine, false)`
|
|
97
|
+
* opted out of completeness checks). On failure every partial GPU object (including
|
|
62
98
|
* an owned color texture) is released first.
|
|
63
99
|
*/
|
|
64
100
|
export function createRenderTarget(engine, width, height, options) {
|
|
@@ -80,8 +116,8 @@ export function createRenderTarget(engine, width, height, options) {
|
|
|
80
116
|
* supports (mirroring Babylon's `getTextureType`).
|
|
81
117
|
*
|
|
82
118
|
* @param engine - The engine to allocate GL resources on.
|
|
83
|
-
* @param width - Color attachment width in texels. Must be a positive integer.
|
|
84
|
-
* @param height - Color attachment height in texels. Must be a positive integer.
|
|
119
|
+
* @param width - Color attachment width in texels. Must be a positive integer up to `caps.maxTextureSize`.
|
|
120
|
+
* @param height - Color attachment height in texels. Must be a positive integer up to `caps.maxTextureSize`.
|
|
85
121
|
* @param options - See {@link GLFloatRenderTargetOptions}.
|
|
86
122
|
* @returns The new {@link GLRenderTarget}.
|
|
87
123
|
* @throws As {@link createRenderTarget}.
|
|
@@ -157,15 +193,16 @@ export function generateRenderTargetMipMaps(rt) {
|
|
|
157
193
|
* restore hook.
|
|
158
194
|
*
|
|
159
195
|
* @param rt - The render target to resize.
|
|
160
|
-
* @param width - New width in texels (
|
|
161
|
-
* @param height - New height in texels (
|
|
196
|
+
* @param width - New width in texels (1 to `caps.maxTextureSize`).
|
|
197
|
+
* @param height - New height in texels (1 to `caps.maxTextureSize`).
|
|
198
|
+
* @throws If the size is invalid; the target keeps its current size.
|
|
162
199
|
*/
|
|
163
200
|
export function resizeRenderTarget(rt, width, height) {
|
|
164
201
|
const engine = rt._engine;
|
|
165
202
|
if (rt._disposed) {
|
|
166
203
|
return;
|
|
167
204
|
}
|
|
168
|
-
validateSize(width, height);
|
|
205
|
+
validateSize(engine, width, height);
|
|
169
206
|
if (rt.width === width && rt.height === height) {
|
|
170
207
|
return;
|
|
171
208
|
}
|
|
@@ -345,7 +382,7 @@ export function disposeRenderTarget(rt) {
|
|
|
345
382
|
* the owned-or-BYO color texture, allocates the GPU set atomically, and
|
|
346
383
|
* registers the target. */
|
|
347
384
|
function buildRT(engine, width, height, options, internalFormat, format, type) {
|
|
348
|
-
validateSize(width, height);
|
|
385
|
+
validateSize(engine, width, height);
|
|
349
386
|
const gl = engine.gl;
|
|
350
387
|
const byo = options.colorTexture;
|
|
351
388
|
const config = {
|
|
@@ -385,7 +422,6 @@ function buildRT(engine, width, height, options, internalFormat, format, type) {
|
|
|
385
422
|
_engine: engine,
|
|
386
423
|
_disposed: false,
|
|
387
424
|
_deleteGpu: () => { },
|
|
388
|
-
_restore: () => { },
|
|
389
425
|
};
|
|
390
426
|
rt._deleteGpu = (glc) => {
|
|
391
427
|
const s = engine._state;
|
|
@@ -410,15 +446,29 @@ function buildRT(engine, width, height, options, internalFormat, format, type) {
|
|
|
410
446
|
rt.texture.isReady = false;
|
|
411
447
|
rt.isReady = false;
|
|
412
448
|
};
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
449
|
+
if (!engine._noRestore) {
|
|
450
|
+
rt._restore = (target) => {
|
|
451
|
+
// Resilient: a restore failure must not break the engine's restore loop.
|
|
452
|
+
try {
|
|
453
|
+
// The restored context may support a smaller size; fail before
|
|
454
|
+
// re-specifying storage and leave the target not ready.
|
|
455
|
+
validateSize(target, rt.width, rt.height);
|
|
456
|
+
const tex = rt.texture;
|
|
457
|
+
// A BYO raw texture replays its last upload; apply a resize made
|
|
458
|
+
// during loss before reattaching it (contents discarded, as in resize).
|
|
459
|
+
if (!config.ownsColorTexture && (tex.width !== rt.width || tex.height !== rt.height)) {
|
|
460
|
+
tex._updateRaw?.(target, null, rt.width, rt.height, 4);
|
|
461
|
+
}
|
|
462
|
+
allocateRenderTargetGpu(target, rt);
|
|
463
|
+
}
|
|
464
|
+
catch (err) {
|
|
465
|
+
// Loss leaves the flag set; a target whose rebuild failed must not
|
|
466
|
+
// report ready over its dead framebuffer.
|
|
467
|
+
rt.isReady = false;
|
|
468
|
+
console.error("lite-gl: render target restore failed", err);
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
}
|
|
422
472
|
allocateRenderTargetGpu(engine, rt);
|
|
423
473
|
engine._renderTargets.push(rt);
|
|
424
474
|
return rt;
|
|
@@ -435,15 +485,20 @@ function resolveColorType(engine, type) {
|
|
|
435
485
|
}
|
|
436
486
|
return type;
|
|
437
487
|
}
|
|
438
|
-
/** Validate a render-target size is a pair of positive integers
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
488
|
+
/** Validate a render-target size is a pair of positive integers within the
|
|
489
|
+
* engine's `MAX_TEXTURE_SIZE`. Checked before any storage is (re)specified:
|
|
490
|
+
* WebGL rejects an oversized `texImage2D` without throwing, and a caller-owned
|
|
491
|
+
* color texture would keep its old storage, completing the framebuffer at the
|
|
492
|
+
* wrong size. */
|
|
493
|
+
function validateSize(engine, width, height) {
|
|
494
|
+
const max = engine.caps.maxTextureSize;
|
|
495
|
+
if (!Number.isInteger(width) || !Number.isInteger(height) || width < 1 || height < 1 || width > max || height > max) {
|
|
496
|
+
throw new Error(`lite-gl: render target size must be positive integers up to ${max}, got ${width}x${height}`);
|
|
442
497
|
}
|
|
443
498
|
}
|
|
444
499
|
/**
|
|
445
500
|
* (Re)allocate the color texture (iff owned), framebuffer and depth/stencil
|
|
446
|
-
* renderbuffer into fresh handles, attach them, and validate completeness.
|
|
501
|
+
* renderbuffer into fresh handles, attach them, and validate completeness (unless opted out).
|
|
447
502
|
* Shared by create / resize / context-restore. No-op on a lost/disposed context.
|
|
448
503
|
*
|
|
449
504
|
* ATOMIC: captures the previously-bound framebuffer and restores it in a
|
|
@@ -458,7 +513,8 @@ function allocateRenderTargetGpu(engine, rt) {
|
|
|
458
513
|
const gl = engine.gl;
|
|
459
514
|
const s = engine._state;
|
|
460
515
|
const c = rt._config;
|
|
461
|
-
|
|
516
|
+
// An unknown (wiped) binding is restored as the canvas.
|
|
517
|
+
const prevFb = s.boundFramebuffer ?? null;
|
|
462
518
|
let createdTexture = null;
|
|
463
519
|
let fb = null;
|
|
464
520
|
let rb = null;
|
|
@@ -508,10 +564,7 @@ function allocateRenderTargetGpu(engine, rt) {
|
|
|
508
564
|
}
|
|
509
565
|
// A helper-attached stencil replaces/augments the depth-only buffer.
|
|
510
566
|
rt._rebuildDepthStencil?.(engine);
|
|
511
|
-
|
|
512
|
-
if (status !== gl.FRAMEBUFFER_COMPLETE) {
|
|
513
|
-
throw new Error(`lite-gl: render target framebuffer incomplete (status 0x${status.toString(16)})`);
|
|
514
|
-
}
|
|
567
|
+
validateFramebuffer(engine, false);
|
|
515
568
|
rt.isReady = true;
|
|
516
569
|
}
|
|
517
570
|
catch (e) {
|
package/render-target.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;AAG9I,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,mBAAmB;AACnB,MAAM,GAAG,GAAG,MAAM,CAAC;AACnB,kBAAkB;AAClB,MAAM,EAAE,GAAG,MAAM,CAAC;AAClB,sBAAsB;AACtB,MAAM,MAAM,GAAG,MAAM,CAAC;AACtB,6BAA6B;AAC7B,MAAM,aAAa,GAAG,MAAM,CAAC;AA8I7B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAuB,EAAE,KAAa,EAAE,MAAc,EAAE,OAA+B;IACtH,MAAM,IAAI,GAAG,OAAO,IAAI,EAAE,CAAC;IAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC;IACnC,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,EAAE,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,+CAA+C,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAC1F,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,wBAAwB,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,aA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,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 * 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/** 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,IAAI,KAAK,CAAC,0GAA0G,CAAC,CAAC;IAChI,CAAC;IACD,IAAI,cAAc,GAAG,CAAC,CAAC,cAAc,CAAC;IACtC,IAAI,cAAc,KAA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,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
|
*/
|
|
@@ -17,8 +17,8 @@ import type { GLEngineContext } from "./context.js";
|
|
|
17
17
|
* @param engine - The engine.
|
|
18
18
|
* @param x - Lower-left X of the scissor rectangle, in pixels.
|
|
19
19
|
* @param y - Lower-left Y of the scissor rectangle, in pixels.
|
|
20
|
-
* @param width - Rectangle width in pixels.
|
|
21
|
-
* @param height - Rectangle height in pixels.
|
|
20
|
+
* @param width - Rectangle width in pixels; a nonnegative integer.
|
|
21
|
+
* @param height - Rectangle height in pixels; a nonnegative integer.
|
|
22
22
|
*/
|
|
23
23
|
export declare function setScissor(engine: GLEngineContext, x: number, y: number, width: number, height: number): void;
|
|
24
24
|
/**
|
package/scissor.js
CHANGED
|
@@ -8,8 +8,8 @@ const SCISSOR_TEST = 0x0c11;
|
|
|
8
8
|
* @param engine - The engine.
|
|
9
9
|
* @param x - Lower-left X of the scissor rectangle, in pixels.
|
|
10
10
|
* @param y - Lower-left Y of the scissor rectangle, in pixels.
|
|
11
|
-
* @param width - Rectangle width in pixels.
|
|
12
|
-
* @param height - Rectangle height in pixels.
|
|
11
|
+
* @param width - Rectangle width in pixels; a nonnegative integer.
|
|
12
|
+
* @param height - Rectangle height in pixels; a nonnegative integer.
|
|
13
13
|
*/
|
|
14
14
|
export function setScissor(engine, x, y, width, height) {
|
|
15
15
|
if (engine._isLost || engine._disposed) {
|
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
|