@kirknock/node-openxr-webgl 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +54 -2
- package/dist/default-framebuffer.d.ts +25 -0
- package/dist/default-framebuffer.js +100 -0
- package/dist/default-framebuffer.js.map +1 -0
- package/dist/diagnostics.d.ts +15 -0
- package/dist/diagnostics.js +87 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/generated/gl-constants.gen.d.ts +11 -0
- package/dist/generated/gl-constants.gen.js +2410 -0
- package/dist/generated/gl-constants.gen.js.map +1 -0
- package/dist/gl-caps.d.ts +9 -0
- package/dist/gl-caps.js +144 -0
- package/dist/gl-caps.js.map +1 -0
- package/dist/gl-objects.d.ts +76 -0
- package/dist/gl-objects.js +104 -0
- package/dist/gl-objects.js.map +1 -0
- package/dist/gl-programs.d.ts +78 -0
- package/dist/gl-programs.js +245 -0
- package/dist/gl-programs.js.map +1 -0
- package/dist/gles-ffi.d.ts +69 -0
- package/dist/gles-ffi.js +209 -0
- package/dist/gles-ffi.js.map +1 -0
- package/dist/gles-session.d.ts +17 -0
- package/dist/gles-session.js +78 -0
- package/dist/gles-session.js.map +1 -0
- package/dist/gles3-bindings.d.ts +10 -0
- package/dist/gles3-bindings.js +306 -0
- package/dist/gles3-bindings.js.map +1 -0
- package/dist/platform.d.ts +21 -0
- package/dist/platform.js +56 -0
- package/dist/platform.js.map +1 -0
- package/dist/swapchains.d.ts +27 -0
- package/dist/swapchains.js +87 -0
- package/dist/swapchains.js.map +1 -0
- package/dist/tex-upload.d.ts +47 -0
- package/dist/tex-upload.js +196 -0
- package/dist/tex-upload.js.map +1 -0
- package/dist/tools/pattern.d.ts +1 -0
- package/dist/tools/pattern.js +98 -0
- package/dist/tools/pattern.js.map +1 -0
- package/dist/tools/probe-env.d.ts +1 -0
- package/dist/tools/probe-env.js +45 -0
- package/dist/tools/probe-env.js.map +1 -0
- package/dist/tools/probe-input.d.ts +1 -0
- package/dist/tools/probe-input.js +65 -0
- package/dist/tools/probe-input.js.map +1 -0
- package/dist/webgl2-engine.d.ts +14 -0
- package/dist/webgl2-engine.js +25 -0
- package/dist/webgl2-engine.js.map +1 -0
- package/dist/webgl2-shim.d.ts +267 -0
- package/dist/webgl2-shim.js +364 -0
- package/dist/webgl2-shim.js.map +1 -0
- package/package.json +82 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kirknock
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @kirknock/node-openxr-webgl
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/kirknock/node-openxr-webgl/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@kirknock/node-openxr-webgl)
|
|
5
|
+
|
|
6
|
+
The WebGL2 renderer: `startNodeXR()` (`platform.ts`), an OpenXR session on
|
|
7
|
+
the EGL/GLES 3 context (`gles-session.ts`, `gles-ffi.ts`, `swapchains.ts`)
|
|
8
|
+
and the first-party WebGL2 shim over that context: `webgl2-shim.ts`
|
|
9
|
+
assembles it from `gl-objects.ts`, `tex-upload.ts`, `default-framebuffer.ts`,
|
|
10
|
+
`gl-programs.ts` and `gl-caps.ts`; `webgl2-engine.ts` sets it up for Babylon.
|
|
11
|
+
Tools: `pattern`, `probe-input`, `probe-env`.
|
|
12
|
+
|
|
13
|
+
Linux only: needs `libEGL.so.1` and `libGLESv2.so.2` (Mesa is fine) and,
|
|
14
|
+
for XR sessions, an OpenXR runtime.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @kirknock/node-openxr-webgl @kirknock/node-openxr-core @babylonjs/core@9.33.2 koffi@2.16.3
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Modules are imported by path, e.g.
|
|
23
|
+
`@kirknock/node-openxr-webgl/platform.js`.
|
|
24
|
+
|
|
25
|
+
## Development
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm ci
|
|
29
|
+
npm run build # dist/
|
|
30
|
+
npm run lint && npm run typecheck
|
|
31
|
+
npm run test:gl # EGL/GLES 3 context (llvmpipe ok): WebGL2 shim + Babylon, 2D canvas
|
|
32
|
+
npm run test:xr # live OpenXR runtime (XR_RUNTIME_JSON): WebXR conformance
|
|
33
|
+
npm run push # build + yalc push to local consumers
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`npm run gen:gl` regenerates `src/generated/gl-constants.gen.ts` from the
|
|
37
|
+
system GLES headers. Tests run on the `nodexr-test` runner from
|
|
38
|
+
[`@kirknock/node-openxr-core`](https://www.npmjs.com/package/@kirknock/node-openxr-core).
|
|
39
|
+
|
|
40
|
+
## Releasing
|
|
41
|
+
|
|
42
|
+
Bump `version` in `package.json`, commit, then push a matching tag:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm version patch # or minor / major / prerelease --preid beta
|
|
46
|
+
git push --follow-tags
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The `Release` workflow checks the tag, lints, runs the gl tests on Mesa
|
|
50
|
+
llvmpipe, publishes to npm via trusted publishing (with provenance) and
|
|
51
|
+
creates a GitHub release with the tarball attached.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RawGl } from "./gles3-bindings.js";
|
|
2
|
+
export declare class DefaultFramebuffer {
|
|
3
|
+
private readonly raw;
|
|
4
|
+
private dummy;
|
|
5
|
+
private scratchRead;
|
|
6
|
+
private present;
|
|
7
|
+
private presentDepthStencil;
|
|
8
|
+
private presentSize;
|
|
9
|
+
private presentActive;
|
|
10
|
+
constructor(raw: RawGl);
|
|
11
|
+
/** The GL name standing in for WebGL's default framebuffer right now. */
|
|
12
|
+
name(): number;
|
|
13
|
+
/**
|
|
14
|
+
* Makes the default framebuffer an FBO whose color attachment is
|
|
15
|
+
* `colorTexture` (a foreign texture, e.g. the acquired swapchain image) with
|
|
16
|
+
* a depth/stencil renderbuffer of its size; `null` restores the dummy.
|
|
17
|
+
* Leaves the default framebuffer bound.
|
|
18
|
+
*/
|
|
19
|
+
setTarget(colorTexture: number | null, width: number, height: number): void;
|
|
20
|
+
/** RGBA8 pixels of a foreign texture through a scratch FBO (diagnostics); rebinds the default framebuffer. */
|
|
21
|
+
readForeignTexturePixels(name: number, width: number, height: number): Uint8Array;
|
|
22
|
+
private ensureDummy;
|
|
23
|
+
/** Current integer GL state (e.g. a binding), for save/restore. */
|
|
24
|
+
private integer;
|
|
25
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What WebGL's default framebuffer (bindFramebuffer(target, null)) is on the
|
|
3
|
+
* shim. Surfaceless EGL has NO default framebuffer: Babylon's main-pass
|
|
4
|
+
* clear/bind of "framebuffer 0" would raise INVALID_FRAMEBUFFER_OPERATION.
|
|
5
|
+
* So null binds a hidden dummy FBO, a valid (never displayed) "canvas" —
|
|
6
|
+
* or, while a target is set, an FBO on the acquired swapchain image, which is
|
|
7
|
+
* what an XRWebGLLayer with a null framebuffer renders into.
|
|
8
|
+
*
|
|
9
|
+
* Everything here may run lazily inside a WebGL call, so it restores the GL
|
|
10
|
+
* bindings it touches: engines cache theirs, and a leaked glBindTexture once
|
|
11
|
+
* made the next upload land in the wrong texture (smoke:canvas2d).
|
|
12
|
+
*/
|
|
13
|
+
import { GL_CONSTANTS as C } from "./generated/gl-constants.gen.js";
|
|
14
|
+
export class DefaultFramebuffer {
|
|
15
|
+
raw;
|
|
16
|
+
dummy = null;
|
|
17
|
+
scratchRead = null;
|
|
18
|
+
present = null;
|
|
19
|
+
presentDepthStencil = null;
|
|
20
|
+
presentSize = { width: 0, height: 0 };
|
|
21
|
+
presentActive = false;
|
|
22
|
+
constructor(raw) {
|
|
23
|
+
this.raw = raw;
|
|
24
|
+
}
|
|
25
|
+
/** The GL name standing in for WebGL's default framebuffer right now. */
|
|
26
|
+
name() {
|
|
27
|
+
return this.presentActive && this.present !== null ? this.present : this.ensureDummy();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Makes the default framebuffer an FBO whose color attachment is
|
|
31
|
+
* `colorTexture` (a foreign texture, e.g. the acquired swapchain image) with
|
|
32
|
+
* a depth/stencil renderbuffer of its size; `null` restores the dummy.
|
|
33
|
+
* Leaves the default framebuffer bound.
|
|
34
|
+
*/
|
|
35
|
+
setTarget(colorTexture, width, height) {
|
|
36
|
+
const raw = this.raw;
|
|
37
|
+
if (colorTexture === null) {
|
|
38
|
+
this.presentActive = false;
|
|
39
|
+
raw.glBindFramebuffer(C.FRAMEBUFFER, this.ensureDummy());
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this.present ??= genName(raw.glGenFramebuffers);
|
|
43
|
+
raw.glBindFramebuffer(C.FRAMEBUFFER, this.present);
|
|
44
|
+
if (this.presentDepthStencil === null || this.presentSize.width !== width || this.presentSize.height !== height) {
|
|
45
|
+
this.presentDepthStencil ??= genName(raw.glGenRenderbuffers);
|
|
46
|
+
const previousRenderbuffer = this.integer(C.RENDERBUFFER_BINDING);
|
|
47
|
+
raw.glBindRenderbuffer(C.RENDERBUFFER, this.presentDepthStencil);
|
|
48
|
+
raw.glRenderbufferStorage(C.RENDERBUFFER, C.DEPTH24_STENCIL8, width, height);
|
|
49
|
+
raw.glBindRenderbuffer(C.RENDERBUFFER, previousRenderbuffer);
|
|
50
|
+
raw.glFramebufferRenderbuffer(C.FRAMEBUFFER, C.DEPTH_STENCIL_ATTACHMENT, C.RENDERBUFFER, this.presentDepthStencil);
|
|
51
|
+
this.presentSize = { width, height };
|
|
52
|
+
}
|
|
53
|
+
raw.glFramebufferTexture2D(C.FRAMEBUFFER, C.COLOR_ATTACHMENT0, C.TEXTURE_2D, colorTexture, 0);
|
|
54
|
+
const status = Number(raw.glCheckFramebufferStatus(C.FRAMEBUFFER));
|
|
55
|
+
if (status !== C.FRAMEBUFFER_COMPLETE) {
|
|
56
|
+
throw new Error(`webgl2-shim: default framebuffer target incomplete (0x${status.toString(16)})`);
|
|
57
|
+
}
|
|
58
|
+
this.presentActive = true;
|
|
59
|
+
}
|
|
60
|
+
/** RGBA8 pixels of a foreign texture through a scratch FBO (diagnostics); rebinds the default framebuffer. */
|
|
61
|
+
readForeignTexturePixels(name, width, height) {
|
|
62
|
+
const raw = this.raw;
|
|
63
|
+
this.scratchRead ??= genName(raw.glGenFramebuffers);
|
|
64
|
+
raw.glBindFramebuffer(C.FRAMEBUFFER, this.scratchRead);
|
|
65
|
+
raw.glFramebufferTexture2D(C.FRAMEBUFFER, C.COLOR_ATTACHMENT0, C.TEXTURE_2D, name, 0);
|
|
66
|
+
const pixels = new Uint8Array(width * height * 4);
|
|
67
|
+
raw.glReadPixels(0, 0, width, height, C.RGBA, C.UNSIGNED_BYTE, pixels);
|
|
68
|
+
raw.glBindFramebuffer(C.FRAMEBUFFER, this.name());
|
|
69
|
+
return pixels;
|
|
70
|
+
}
|
|
71
|
+
ensureDummy() {
|
|
72
|
+
if (this.dummy !== null)
|
|
73
|
+
return this.dummy;
|
|
74
|
+
const raw = this.raw;
|
|
75
|
+
const fbo = genName(raw.glGenFramebuffers);
|
|
76
|
+
const texture = genName(raw.glGenTextures);
|
|
77
|
+
// Runs inside bindFramebuffer(null): restore the caller's texture binding.
|
|
78
|
+
const previousTexture = this.integer(C.TEXTURE_BINDING_2D);
|
|
79
|
+
raw.glBindTexture(C.TEXTURE_2D, texture);
|
|
80
|
+
raw.glTexImage2D(C.TEXTURE_2D, 0, C.RGBA8, 16, 16, 0, C.RGBA, C.UNSIGNED_BYTE, null);
|
|
81
|
+
raw.glBindTexture(C.TEXTURE_2D, previousTexture);
|
|
82
|
+
raw.glBindFramebuffer(C.FRAMEBUFFER, fbo);
|
|
83
|
+
raw.glFramebufferTexture2D(C.FRAMEBUFFER, C.COLOR_ATTACHMENT0, C.TEXTURE_2D, texture, 0);
|
|
84
|
+
raw.glBindFramebuffer(C.FRAMEBUFFER, 0);
|
|
85
|
+
this.dummy = fbo;
|
|
86
|
+
return fbo;
|
|
87
|
+
}
|
|
88
|
+
/** Current integer GL state (e.g. a binding), for save/restore. */
|
|
89
|
+
integer(pname) {
|
|
90
|
+
const out = new Int32Array(1);
|
|
91
|
+
this.raw.glGetIntegerv(pname, out);
|
|
92
|
+
return out[0];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function genName(gen) {
|
|
96
|
+
const out = new Uint32Array(1);
|
|
97
|
+
gen(1, out);
|
|
98
|
+
return out[0];
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=default-framebuffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-framebuffer.js","sourceRoot":"","sources":["../src/default-framebuffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,MAAM,iCAAiC,CAAC;AAGpE,MAAM,OAAO,kBAAkB;IAQA;IAPrB,KAAK,GAAkB,IAAI,CAAC;IAC5B,WAAW,GAAkB,IAAI,CAAC;IAClC,OAAO,GAAkB,IAAI,CAAC;IAC9B,mBAAmB,GAAkB,IAAI,CAAC;IAC1C,WAAW,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IACtC,aAAa,GAAG,KAAK,CAAC;IAE9B,YAA6B,GAAU;QAAV,QAAG,GAAH,GAAG,CAAO;IAAG,CAAC;IAE3C,yEAAyE;IACzE,IAAI;QACF,OAAO,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;IACzF,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,YAA2B,EAAE,KAAa,EAAE,MAAc;QAClE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACrB,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;YAC1B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;YAC3B,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;YACzD,OAAO;QACT,CAAC;QACD,IAAI,CAAC,OAAO,KAAK,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAChD,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,WAAW,EAAE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l2-shim.js";
|
|
3
|
+
export declare class PlatformDiagnostics {
|
|
4
|
+
private readonly gl;
|
|
5
|
+
/** Last pixel sample, for the DONE line (empty without XR_PIXEL_DEBUG). */
|
|
6
|
+
lastSample: string;
|
|
7
|
+
private whiteBaseline;
|
|
8
|
+
private engineStore;
|
|
9
|
+
constructor(gl: WebGL2Shim & WebGL2ShimExtras);
|
|
10
|
+
init(): Promise<void>;
|
|
11
|
+
/** Called with the rendered image still acquired. */
|
|
12
|
+
frameRendered(frame: number, glName: number, width: number, height: number, views: EyeViewPose[]): void;
|
|
13
|
+
private logPose;
|
|
14
|
+
private sceneProbe;
|
|
15
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform diagnostics, log-only, app-agnostic, all off by default. Those
|
|
3
|
+
* that read pixels read back the whole rendered side-by-side swapchain image
|
|
4
|
+
* (left eye | right eye), which makes the CPU wait for the GPU:
|
|
5
|
+
*
|
|
6
|
+
* - XR_PIXEL_DEBUG (every 30 frames): left/right eye centre, left-eye top
|
|
7
|
+
* - XR_INPUT_DEBUG (every 30 frames): raw OpenXR eye pose vs the
|
|
8
|
+
* position of Babylon's active (XR) camera
|
|
9
|
+
* - XR_SCENE_DEBUG (every frame — reads back each frame, costs fps):
|
|
10
|
+
* floor-flash probe — near-white share of the left eye's lower third;
|
|
11
|
+
* logged every 30 frames and on spikes, with the meshes drawn then
|
|
12
|
+
*/
|
|
13
|
+
import { debugLogger } from "@kirknock/node-openxr-core/log.js";
|
|
14
|
+
const pixelDebugLog = debugLogger("pixel", "main");
|
|
15
|
+
const poseDebugLog = debugLogger("input", "pose:debug");
|
|
16
|
+
const sceneDebugLog = debugLogger("scene", "scene:debug");
|
|
17
|
+
export class PlatformDiagnostics {
|
|
18
|
+
gl;
|
|
19
|
+
/** Last pixel sample, for the DONE line (empty without XR_PIXEL_DEBUG). */
|
|
20
|
+
lastSample = "";
|
|
21
|
+
whiteBaseline = -1;
|
|
22
|
+
engineStore = null;
|
|
23
|
+
constructor(gl) {
|
|
24
|
+
this.gl = gl;
|
|
25
|
+
}
|
|
26
|
+
async init() {
|
|
27
|
+
if (poseDebugLog.enabled || sceneDebugLog.enabled) {
|
|
28
|
+
const { EngineStore } = await import("@babylonjs/core/Engines/engineStore.js");
|
|
29
|
+
this.engineStore = EngineStore;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Called with the rendered image still acquired. */
|
|
33
|
+
frameRendered(frame, glName, width, height, views) {
|
|
34
|
+
if (poseDebugLog.enabled && frame % 30 === 0)
|
|
35
|
+
this.logPose(frame, views);
|
|
36
|
+
const sample = pixelDebugLog.enabled && frame % 30 === 0;
|
|
37
|
+
if (!sample && !sceneDebugLog.enabled)
|
|
38
|
+
return;
|
|
39
|
+
const px = this.gl.readForeignTexturePixels(glName, width, height);
|
|
40
|
+
if (sample) {
|
|
41
|
+
const at = (x, y) => {
|
|
42
|
+
const i = (Math.floor(y) * width + Math.floor(x)) * 4;
|
|
43
|
+
return `${px[i]},${px[i + 1]},${px[i + 2]},${px[i + 3]}`;
|
|
44
|
+
};
|
|
45
|
+
this.lastSample = `frame ${frame}: left-eye center=(${at(width / 4, height / 2)}) right-eye center=(${at((3 * width) / 4, height / 2)}) top=(${at(width / 4, height - 5)})`;
|
|
46
|
+
pixelDebugLog.info(this.lastSample);
|
|
47
|
+
}
|
|
48
|
+
if (sceneDebugLog.enabled)
|
|
49
|
+
this.sceneProbe(frame, px, width, height);
|
|
50
|
+
}
|
|
51
|
+
logPose(frame, views) {
|
|
52
|
+
const v = views[0];
|
|
53
|
+
if (v === undefined)
|
|
54
|
+
return;
|
|
55
|
+
const f = (n) => n.toFixed(3);
|
|
56
|
+
const cam = this.engineStore?.LastCreatedScene?.activeCamera?.globalPosition;
|
|
57
|
+
poseDebugLog.info(`frame ${frame} eye0 pos=(${f(v.position.x)},${f(v.position.y)},${f(v.position.z)}) ` +
|
|
58
|
+
`quat=(${f(v.orientation.x)},${f(v.orientation.y)},${f(v.orientation.z)},${f(v.orientation.w)}) ` +
|
|
59
|
+
`fov=(l${f(v.fov.angleLeft)} r${f(v.fov.angleRight)} u${f(v.fov.angleUp)} d${f(v.fov.angleDown)})` +
|
|
60
|
+
(cam !== undefined ? ` -> babylon camera=(${f(cam.x)},${f(cam.y)},${f(cam.z)})` : ""));
|
|
61
|
+
}
|
|
62
|
+
sceneProbe(frame, px, width, height) {
|
|
63
|
+
let white = 0;
|
|
64
|
+
let n = 0;
|
|
65
|
+
for (let y = 0; y < Math.floor(height / 3); y += 4) {
|
|
66
|
+
for (let x = 0; x < width / 2; x += 4) {
|
|
67
|
+
const i = (y * width + x) * 4;
|
|
68
|
+
n++;
|
|
69
|
+
if (px[i] > 200 && px[i + 1] > 200 && px[i + 2] > 200)
|
|
70
|
+
white++;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const pct = (100 * white) / n;
|
|
74
|
+
const base = this.whiteBaseline;
|
|
75
|
+
const spike = base >= 0 && pct > Math.max(5, base * 4);
|
|
76
|
+
this.whiteBaseline = base < 0 ? pct : base * 0.95 + Math.min(pct, base * 2 + 1) * 0.05;
|
|
77
|
+
if (!spike && frame % 30 !== 0)
|
|
78
|
+
return;
|
|
79
|
+
sceneDebugLog.info(`frame ${frame}: floorWhite=${pct.toFixed(1)}% baseline=${this.whiteBaseline.toFixed(1)}%${spike ? " SPIKE" : ""}`);
|
|
80
|
+
if (spike) {
|
|
81
|
+
const active = this.engineStore?.LastCreatedScene?.getActiveMeshes();
|
|
82
|
+
const drawn = active === undefined ? [] : active.data.slice(0, active.length).map((m) => `${m.name}(${m.material?.name ?? "-"})`);
|
|
83
|
+
sceneDebugLog.info(`frame ${frame}: drawn=[${drawn.join(" ")}]`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["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G,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI,IAAI,GAAG,GAAG,CAAC,CAAC;YAClI,aAAa,CAAC,IAAI,CAAC,SAAS,KAAK,YAAY,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MACHINE-GENERATED — do not edit by hand.
|
|
3
|
+
* Source: system GLES headers, gl2.h/gl3.h/gl31.h/gl32.h/gl2ext.h/gl3ext.h
|
|
4
|
+
* (4136 numeric GL defines parsed)
|
|
5
|
+
* + packages/webgl/scripts/gen-gl-constants.mjs WEBGL_EXTRA table.
|
|
6
|
+
* Regenerate: node packages/webgl/scripts/gen-gl-constants.mjs
|
|
7
|
+
*
|
|
8
|
+
* WebGL2 enum values on the shim context (WebGL2 uses GL ES values 1:1).
|
|
9
|
+
*/
|
|
10
|
+
export declare const GL_CONSTANTS: Readonly<Record<string, number>>;
|
|
11
|
+
export declare const GL_CONSTANT_COUNT = 2397;
|