@luma.gl/webgl 9.0.17 → 9.1.0-alpha.10
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/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/device-parameters.js +30 -12
- package/dist/adapter/converters/texture-formats.d.ts +22 -16
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +39 -47
- package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-features.js +1 -2
- package/dist/adapter/device-helpers/webgl-device-limits.js +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +300 -0
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -0
- package/dist/adapter/helpers/webgl-texture-utils.js +370 -0
- package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.js +0 -4
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +2 -2
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +6 -9
- package/dist/adapter/resources/webgl-framebuffer.d.ts +32 -5
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +42 -60
- package/dist/adapter/resources/webgl-render-pass.d.ts +3 -2
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +18 -7
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +46 -21
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +3 -3
- package/dist/adapter/resources/webgl-texture-view.d.ts +1 -1
- package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture-view.js +1 -1
- package/dist/adapter/resources/webgl-texture.d.ts +76 -172
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +397 -511
- package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -2
- package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +2 -2
- package/dist/adapter/webgl-adapter.d.ts +21 -0
- package/dist/adapter/webgl-adapter.d.ts.map +1 -0
- package/dist/adapter/webgl-adapter.js +91 -0
- package/dist/adapter/webgl-canvas-context.d.ts +3 -1
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +2 -0
- package/dist/adapter/webgl-device.d.ts +19 -30
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +35 -114
- package/dist/classic/accessor.d.ts +22 -1
- package/dist/classic/accessor.d.ts.map +1 -1
- package/dist/classic/accessor.js +1 -9
- package/dist/classic/clear.d.ts.map +1 -1
- package/dist/classic/clear.js +2 -5
- package/dist/classic/copy-and-blit.d.ts +3 -1
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +21 -18
- package/dist/classic/format-utils.d.ts.map +1 -1
- package/dist/classic/format-utils.js +0 -3
- package/dist/classic/typed-array-utils.d.ts +1 -1
- package/dist/classic/typed-array-utils.d.ts.map +1 -1
- package/dist/context/debug/spector-types.d.ts +1108 -0
- package/dist/context/debug/spector-types.d.ts.map +1 -0
- package/dist/context/debug/spector-types.js +697 -0
- package/dist/context/debug/spector.d.ts +12 -8
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +25 -18
- package/dist/context/debug/webgl-developer-tools.d.ts +1 -1
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +2 -5
- package/dist/context/parameters/webgl-parameter-tables.js +1 -1
- package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts +9 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts.map +1 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.js +181 -0
- package/dist/context/state-tracker/webgl-state-tracker.d.ts +43 -0
- package/dist/context/state-tracker/webgl-state-tracker.d.ts.map +1 -0
- package/dist/context/state-tracker/{track-context-state.js → webgl-state-tracker.js} +46 -77
- package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
- package/dist/context/state-tracker/with-parameters.js +5 -4
- package/dist/dist.dev.js +1112 -1380
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +1122 -1284
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/utils/fill-array.d.ts +8 -0
- package/dist/utils/fill-array.d.ts.map +1 -0
- package/dist/utils/fill-array.js +26 -0
- package/dist/utils/load-script.d.ts +8 -0
- package/dist/utils/load-script.d.ts.map +1 -0
- package/dist/utils/load-script.js +26 -0
- package/dist/utils/split-uniforms-and-bindings.d.ts +9 -0
- package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -0
- package/dist/utils/split-uniforms-and-bindings.js +20 -0
- package/dist/utils/uid.d.ts +7 -0
- package/dist/utils/uid.d.ts.map +1 -0
- package/dist/utils/uid.js +14 -0
- package/package.json +6 -5
- package/src/adapter/converters/device-parameters.ts +31 -13
- package/src/adapter/converters/texture-formats.ts +51 -56
- package/src/adapter/device-helpers/webgl-device-features.ts +1 -2
- package/src/adapter/device-helpers/webgl-device-limits.ts +1 -1
- package/src/adapter/helpers/webgl-texture-utils.ts +484 -0
- package/src/adapter/helpers/webgl-topology-utils.ts +0 -4
- package/src/adapter/resources/webgl-buffer.ts +2 -2
- package/src/adapter/resources/webgl-command-buffer.ts +8 -10
- package/src/adapter/resources/webgl-framebuffer.ts +22 -56
- package/src/adapter/resources/webgl-render-pass.ts +21 -9
- package/src/adapter/resources/webgl-render-pipeline.ts +50 -24
- package/src/adapter/resources/webgl-shader.ts +4 -4
- package/src/adapter/resources/webgl-texture-view.ts +1 -3
- package/src/adapter/resources/webgl-texture.ts +445 -784
- package/src/adapter/resources/webgl-vertex-array.ts +8 -7
- package/src/adapter/webgl-adapter.ts +113 -0
- package/src/adapter/webgl-canvas-context.ts +4 -1
- package/src/adapter/webgl-device.ts +40 -151
- package/src/classic/accessor.ts +31 -11
- package/src/classic/clear.ts +3 -6
- package/src/classic/copy-and-blit.ts +32 -27
- package/src/classic/format-utils.ts +0 -3
- package/src/classic/typed-array-utils.ts +1 -1
- package/src/context/debug/spector-types.ts +1154 -0
- package/src/context/debug/spector.ts +40 -30
- package/src/context/debug/webgl-developer-tools.ts +3 -7
- package/src/context/parameters/webgl-parameter-tables.ts +3 -3
- package/src/context/polyfills/polyfill-webgl1-extensions.ts +202 -0
- package/src/context/state-tracker/{track-context-state.ts → webgl-state-tracker.ts} +57 -97
- package/src/context/state-tracker/with-parameters.ts +5 -4
- package/src/index.ts +5 -13
- package/src/utils/fill-array.ts +35 -0
- package/src/utils/load-script.ts +30 -0
- package/src/utils/split-uniforms-and-bindings.ts +31 -0
- package/src/utils/uid.ts +16 -0
- package/dist/adapter/objects/constants-to-keys.d.ts +0 -3
- package/dist/adapter/objects/constants-to-keys.d.ts.map +0 -1
- package/dist/adapter/objects/constants-to-keys.js +0 -22
- package/dist/adapter/objects/webgl-renderbuffer.d.ts +0 -43
- package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +0 -1
- package/dist/adapter/objects/webgl-renderbuffer.js +0 -95
- package/dist/adapter/objects/webgl-resource.d.ts +0 -32
- package/dist/adapter/objects/webgl-resource.d.ts.map +0 -1
- package/dist/adapter/objects/webgl-resource.js +0 -114
- package/dist/context/state-tracker/track-context-state.d.ts +0 -22
- package/dist/context/state-tracker/track-context-state.d.ts.map +0 -1
- package/src/adapter/objects/constants-to-keys.ts +0 -27
- package/src/adapter/objects/webgl-renderbuffer.ts +0 -132
- package/src/adapter/objects/webgl-resource.ts +0 -183
|
@@ -1,17 +1,21 @@
|
|
|
1
|
+
import { Spector } from "./spector-types.js";
|
|
1
2
|
/** Spector debug initialization options */
|
|
2
3
|
type SpectorProps = {
|
|
4
|
+
/** Whether spector is enabled */
|
|
5
|
+
debugWithSpectorJS?: boolean;
|
|
6
|
+
/** URL to load spector script from. Typically a CDN URL */
|
|
7
|
+
spectorUrl?: string;
|
|
3
8
|
/** Canvas to monitor */
|
|
4
|
-
|
|
5
|
-
/** Whether debug is enabled. Auto-detected if ommitted */
|
|
6
|
-
debug?: boolean;
|
|
7
|
-
/** Whether spector is disabled */
|
|
8
|
-
spector?: boolean | string | object;
|
|
9
|
+
gl?: WebGL2RenderingContext;
|
|
9
10
|
};
|
|
10
11
|
declare global {
|
|
11
|
-
var SPECTOR:
|
|
12
|
+
var SPECTOR: Spector;
|
|
12
13
|
}
|
|
14
|
+
export declare const DEFAULT_SPECTOR_PROPS: Required<SpectorProps>;
|
|
13
15
|
/** Loads spector from CDN if not already installed */
|
|
14
|
-
export declare function loadSpectorJS(props
|
|
15
|
-
|
|
16
|
+
export declare function loadSpectorJS(props: {
|
|
17
|
+
spectorUrl?: string;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
export declare function initializeSpectorJS(props: SpectorProps): Spector | null;
|
|
16
20
|
export {};
|
|
17
21
|
//# sourceMappingURL=spector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spector.d.ts","sourceRoot":"","sources":["../../../src/context/debug/spector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"spector.d.ts","sourceRoot":"","sources":["../../../src/context/debug/spector.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,OAAO,EAAC,2BAAwB;AAExC,2CAA2C;AAC3C,KAAK,YAAY,GAAG;IAClB,iCAAiC;IACjC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wBAAwB;IACxB,EAAE,CAAC,EAAE,sBAAsB,CAAC;CAC7B,CAAC;AAOF,OAAO,CAAC,MAAM,CAAC;IAGb,IAAI,OAAO,EAAE,OAAO,CAAC;CACtB;AAED,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,YAAY,CAOxD,CAAC;AAEF,sDAAsD;AACtD,wBAAsB,aAAa,CAAC,KAAK,EAAE;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ/E;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,GAAG,IAAI,CAyDvE"}
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { log
|
|
5
|
-
|
|
6
|
-
spector: log.get('spector') || log.get('spectorjs')
|
|
7
|
-
};
|
|
8
|
-
// https://github.com/BabylonJS/Spector.js#basic-usage
|
|
9
|
-
const SPECTOR_CDN_URL = 'https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js';
|
|
4
|
+
import { log } from '@luma.gl/core';
|
|
5
|
+
import { loadScript } from "../../utils/load-script.js";
|
|
10
6
|
const LOG_LEVEL = 1;
|
|
11
7
|
let spector = null;
|
|
12
8
|
let initialized = false;
|
|
9
|
+
export const DEFAULT_SPECTOR_PROPS = {
|
|
10
|
+
debugWithSpectorJS: log.get('spector') || log.get('spectorjs'),
|
|
11
|
+
// https://github.com/BabylonJS/Spector.js#basic-usage
|
|
12
|
+
// https://forum.babylonjs.com/t/spectorcdn-is-temporarily-off/48241
|
|
13
|
+
// spectorUrl: 'https://spectorcdn.babylonjs.com/spector.bundle.js';
|
|
14
|
+
spectorUrl: 'https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js',
|
|
15
|
+
gl: undefined
|
|
16
|
+
};
|
|
13
17
|
/** Loads spector from CDN if not already installed */
|
|
14
18
|
export async function loadSpectorJS(props) {
|
|
15
19
|
if (!globalThis.SPECTOR) {
|
|
16
20
|
try {
|
|
17
|
-
await loadScript(
|
|
21
|
+
await loadScript(props.spectorUrl || DEFAULT_SPECTOR_PROPS.spectorUrl);
|
|
18
22
|
}
|
|
19
23
|
catch (error) {
|
|
20
24
|
log.warn(String(error));
|
|
@@ -23,12 +27,13 @@ export async function loadSpectorJS(props) {
|
|
|
23
27
|
}
|
|
24
28
|
export function initializeSpectorJS(props) {
|
|
25
29
|
props = { ...DEFAULT_SPECTOR_PROPS, ...props };
|
|
26
|
-
if (!props
|
|
30
|
+
if (!props.debugWithSpectorJS) {
|
|
27
31
|
return null;
|
|
28
32
|
}
|
|
29
|
-
if (!spector && globalThis.SPECTOR) {
|
|
30
|
-
log.probe(LOG_LEVEL, 'SPECTOR found and initialized')();
|
|
31
|
-
|
|
33
|
+
if (!spector && globalThis.SPECTOR && !globalThis.luma?.spector) {
|
|
34
|
+
log.probe(LOG_LEVEL, 'SPECTOR found and initialized. Start with `luma.spector.displayUI()`')();
|
|
35
|
+
const { Spector } = globalThis.SPECTOR;
|
|
36
|
+
spector = new Spector();
|
|
32
37
|
if (globalThis.luma) {
|
|
33
38
|
globalThis.luma.spector = spector;
|
|
34
39
|
}
|
|
@@ -47,18 +52,20 @@ export function initializeSpectorJS(props) {
|
|
|
47
52
|
// Use undocumented Spector API to open the UI with our capture
|
|
48
53
|
// See https://github.com/BabylonJS/Spector.js/blob/767ad1195a25b85a85c381f400eb50a979239eca/src/spector.ts#L124
|
|
49
54
|
spector?.getResultUI();
|
|
55
|
+
// @ts-expect-error private
|
|
50
56
|
spector?.resultView.display();
|
|
57
|
+
// @ts-expect-error private
|
|
51
58
|
spector?.resultView.addCapture(capture);
|
|
52
59
|
});
|
|
53
60
|
}
|
|
54
|
-
if (props
|
|
55
|
-
// @ts-expect-error If spector is specified as a canvas id, only monitor that canvas
|
|
56
|
-
if (typeof props.spector === 'string' && props.spector !== props.canvas.id) {
|
|
57
|
-
return spector;
|
|
58
|
-
}
|
|
61
|
+
if (props.gl) {
|
|
59
62
|
// capture startup
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
const gl = props.gl;
|
|
64
|
+
// @ts-expect-error
|
|
65
|
+
const device = gl.device;
|
|
66
|
+
spector?.startCapture(props.gl, 500); // 500 commands
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
gl.device = device;
|
|
62
69
|
new Promise(resolve => setTimeout(resolve, 2000)).then(_ => {
|
|
63
70
|
log.info('Spector capture stopped after 2 seconds')();
|
|
64
71
|
spector?.stopCapture();
|
|
@@ -13,6 +13,6 @@ declare global {
|
|
|
13
13
|
* @see https://github.com/vorg/webgl-debug
|
|
14
14
|
*/
|
|
15
15
|
export declare function loadWebGLDeveloperTools(): Promise<void>;
|
|
16
|
-
export declare function makeDebugContext(gl: WebGL2RenderingContext, props?: DebugContextProps): WebGL2RenderingContext
|
|
16
|
+
export declare function makeDebugContext(gl: WebGL2RenderingContext, props?: DebugContextProps): WebGL2RenderingContext;
|
|
17
17
|
export {};
|
|
18
18
|
//# sourceMappingURL=webgl-developer-tools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl-developer-tools.d.ts","sourceRoot":"","sources":["../../../src/context/debug/webgl-developer-tools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webgl-developer-tools.d.ts","sourceRoot":"","sources":["../../../src/context/debug/webgl-developer-tools.ts"],"names":[],"mappings":"AAYA,KAAK,iBAAiB,GAAG;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAoBF,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,eAAe,EAAE,GAAG,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC,CAO7D;AAID,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,sBAAsB,EAC1B,KAAK,GAAE,iBAAsB,GAC5B,sBAAsB,CAExB"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { log
|
|
4
|
+
import { log } from '@luma.gl/core';
|
|
5
5
|
// Rename constant to prevent inlining. We need the full set of constants for generating debug strings.
|
|
6
6
|
import { GL as GLEnum } from '@luma.gl/constants';
|
|
7
7
|
import { isBrowser } from '@probe.gl/env';
|
|
8
|
+
import { loadScript } from "../../utils/load-script.js";
|
|
8
9
|
const WEBGL_DEBUG_CDN_URL = 'https://unpkg.com/webgl-debug@2.0.1/index.js';
|
|
9
10
|
// Helper to get shared context data
|
|
10
11
|
function getWebGLContextData(gl) {
|
|
@@ -28,10 +29,6 @@ export async function loadWebGLDeveloperTools() {
|
|
|
28
29
|
// Returns (a potentially new) context with debug instrumentation turned off or on.
|
|
29
30
|
// Note that this actually returns a new context
|
|
30
31
|
export function makeDebugContext(gl, props = {}) {
|
|
31
|
-
// Return null to ensure we don't try to create a context in this case (TODO what case is that?)
|
|
32
|
-
if (!gl) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
32
|
return props.debug ? getDebugContext(gl, props) : getRealContext(gl);
|
|
36
33
|
}
|
|
37
34
|
// Returns the real context from either of the real/debug contexts
|
|
@@ -240,7 +240,7 @@ export const GL_PARAMETER_SETTERS = {
|
|
|
240
240
|
lineWidth: (gl, value) => gl.lineWidth(value),
|
|
241
241
|
polygonOffsetFill: (gl, value) => value ? gl.enable(32823) : gl.disable(32823),
|
|
242
242
|
polygonOffset: (gl, value) => gl.polygonOffset(...value),
|
|
243
|
-
sampleCoverage: (gl, value) => gl.sampleCoverage(
|
|
243
|
+
sampleCoverage: (gl, value) => gl.sampleCoverage(value[0], value[1] || false),
|
|
244
244
|
scissorTest: (gl, value) => value ? gl.enable(3089) : gl.disable(3089),
|
|
245
245
|
scissor: (gl, value) => gl.scissor(...value),
|
|
246
246
|
stencilTest: (gl, value) => value ? gl.enable(2960) : gl.disable(2960),
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make browser return WebGL2 contexts even if WebGL1 contexts are requested
|
|
3
|
+
* @param enforce
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
export declare function enforceWebGL2(enforce?: boolean): void;
|
|
7
|
+
/** Install WebGL1-only extensions on WebGL2 contexts */
|
|
8
|
+
export declare function polyfillWebGL1Extensions(gl: WebGL2RenderingContext): void;
|
|
9
|
+
//# sourceMappingURL=polyfill-webgl1-extensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfill-webgl1-extensions.d.ts","sourceRoot":"","sources":["../../../src/context/polyfills/polyfill-webgl1-extensions.ts"],"names":[],"mappings":"AA4EA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,OAAc,GAAG,IAAI,CA0B3D;AAED,wDAAwD;AACxD,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,sBAAsB,GAAG,IAAI,CAqCzE"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// Goal is to make WebGL2 contexts look like WebGL1
|
|
5
|
+
// @note Partly inspired by with some older code from the `regl` library
|
|
6
|
+
/* eslint-disable camelcase */
|
|
7
|
+
import { GL } from '@luma.gl/constants';
|
|
8
|
+
// webgl1 extensions natively supported by webgl2
|
|
9
|
+
const WEBGL1_STATIC_EXTENSIONS = {
|
|
10
|
+
WEBGL_depth_texture: {
|
|
11
|
+
UNSIGNED_INT_24_8_WEBGL: 34042
|
|
12
|
+
},
|
|
13
|
+
OES_element_index_uint: {},
|
|
14
|
+
OES_texture_float: {},
|
|
15
|
+
OES_texture_half_float: {
|
|
16
|
+
// @ts-expect-error different numbers?
|
|
17
|
+
HALF_FLOAT_OES: 5131
|
|
18
|
+
},
|
|
19
|
+
EXT_color_buffer_float: {},
|
|
20
|
+
OES_standard_derivatives: {
|
|
21
|
+
FRAGMENT_SHADER_DERIVATIVE_HINT_OES: 35723
|
|
22
|
+
},
|
|
23
|
+
EXT_frag_depth: {},
|
|
24
|
+
EXT_blend_minmax: {
|
|
25
|
+
MIN_EXT: 32775,
|
|
26
|
+
MAX_EXT: 32776
|
|
27
|
+
},
|
|
28
|
+
EXT_shader_texture_lod: {}
|
|
29
|
+
};
|
|
30
|
+
const getWEBGL_draw_buffers = (gl) => ({
|
|
31
|
+
drawBuffersWEBGL(buffers) {
|
|
32
|
+
return gl.drawBuffers(buffers);
|
|
33
|
+
},
|
|
34
|
+
COLOR_ATTACHMENT0_WEBGL: 36064,
|
|
35
|
+
COLOR_ATTACHMENT1_WEBGL: 36065,
|
|
36
|
+
COLOR_ATTACHMENT2_WEBGL: 36066,
|
|
37
|
+
COLOR_ATTACHMENT3_WEBGL: 36067
|
|
38
|
+
}); // - too many fields
|
|
39
|
+
const getOES_vertex_array_object = (gl) => ({
|
|
40
|
+
VERTEX_ARRAY_BINDING_OES: 34229,
|
|
41
|
+
createVertexArrayOES() {
|
|
42
|
+
return gl.createVertexArray();
|
|
43
|
+
},
|
|
44
|
+
deleteVertexArrayOES(vertexArray) {
|
|
45
|
+
return gl.deleteVertexArray(vertexArray);
|
|
46
|
+
},
|
|
47
|
+
isVertexArrayOES(vertexArray) {
|
|
48
|
+
return gl.isVertexArray(vertexArray);
|
|
49
|
+
},
|
|
50
|
+
bindVertexArrayOES(vertexArray) {
|
|
51
|
+
return gl.bindVertexArray(vertexArray);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const getANGLE_instanced_arrays = (gl) => ({
|
|
55
|
+
VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: 0x88fe,
|
|
56
|
+
drawArraysInstancedANGLE(...args) {
|
|
57
|
+
return gl.drawArraysInstanced(...args);
|
|
58
|
+
},
|
|
59
|
+
drawElementsInstancedANGLE(...args) {
|
|
60
|
+
return gl.drawElementsInstanced(...args);
|
|
61
|
+
},
|
|
62
|
+
vertexAttribDivisorANGLE(...args) {
|
|
63
|
+
return gl.vertexAttribDivisor(...args);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* Make browser return WebGL2 contexts even if WebGL1 contexts are requested
|
|
68
|
+
* @param enforce
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
export function enforceWebGL2(enforce = true) {
|
|
72
|
+
const prototype = HTMLCanvasElement.prototype;
|
|
73
|
+
if (!enforce && prototype.originalGetContext) {
|
|
74
|
+
// Reset the original getContext function
|
|
75
|
+
prototype.getContext = prototype.originalGetContext;
|
|
76
|
+
prototype.originalGetContext = undefined;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
// Store the original getContext function
|
|
80
|
+
prototype.originalGetContext = prototype.getContext;
|
|
81
|
+
// Override the getContext function
|
|
82
|
+
prototype.getContext = function (contextId, options) {
|
|
83
|
+
// Attempt to force WebGL2 for all WebGL1 contexts
|
|
84
|
+
if (contextId === 'webgl' || contextId === 'experimental-webgl') {
|
|
85
|
+
const context = this.originalGetContext('webgl2', options);
|
|
86
|
+
// Work around test mocking
|
|
87
|
+
if (context instanceof HTMLElement) {
|
|
88
|
+
polyfillWebGL1Extensions(context);
|
|
89
|
+
}
|
|
90
|
+
return context;
|
|
91
|
+
}
|
|
92
|
+
// For any other type, return the original context
|
|
93
|
+
return this.originalGetContext(contextId, options);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** Install WebGL1-only extensions on WebGL2 contexts */
|
|
97
|
+
export function polyfillWebGL1Extensions(gl) {
|
|
98
|
+
// Enable, to support float and half-float textures
|
|
99
|
+
gl.getExtension('EXT_color_buffer_float');
|
|
100
|
+
// WebGL1 extensions implemented using WebGL2 APIs
|
|
101
|
+
const boundExtensions = {
|
|
102
|
+
...WEBGL1_STATIC_EXTENSIONS,
|
|
103
|
+
WEBGL_disjoint_timer_query: gl.getExtension('EXT_disjoint_timer_query_webgl2'),
|
|
104
|
+
WEBGL_draw_buffers: getWEBGL_draw_buffers(gl),
|
|
105
|
+
OES_vertex_array_object: getOES_vertex_array_object(gl),
|
|
106
|
+
ANGLE_instanced_arrays: getANGLE_instanced_arrays(gl)
|
|
107
|
+
};
|
|
108
|
+
// Override gl.getExtension
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
110
|
+
const originalGetExtension = gl.getExtension;
|
|
111
|
+
gl.getExtension = function (extensionName) {
|
|
112
|
+
const ext = originalGetExtension.call(gl, extensionName);
|
|
113
|
+
if (ext) {
|
|
114
|
+
return ext;
|
|
115
|
+
}
|
|
116
|
+
// Injected extensions
|
|
117
|
+
if (extensionName in boundExtensions) {
|
|
118
|
+
return boundExtensions[extensionName];
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
};
|
|
122
|
+
// Override gl.getSupportedExtensions
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
124
|
+
const originalGetSupportedExtensions = gl.getSupportedExtensions;
|
|
125
|
+
gl.getSupportedExtensions = function () {
|
|
126
|
+
const extensions = originalGetSupportedExtensions.apply(gl) || [];
|
|
127
|
+
return extensions?.concat(Object.keys(boundExtensions));
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
// Update unsized WebGL1 formats to sized WebGL2 formats
|
|
131
|
+
// todo move to texture format file
|
|
132
|
+
// export function getInternalFormat(gl: WebGL2RenderingContext, format: GL, type: GL): GL {
|
|
133
|
+
// // webgl2 texture formats
|
|
134
|
+
// // https://webgl2fundamentals.org/webgl/lessons/webgl-data-textures.html
|
|
135
|
+
// switch (format) {
|
|
136
|
+
// case GL.DEPTH_COMPONENT:
|
|
137
|
+
// return GL.DEPTH_COMPONENT24;
|
|
138
|
+
// case GL.DEPTH_STENCIL:
|
|
139
|
+
// return GL.DEPTH24_STENCIL8;
|
|
140
|
+
// case GL.RGBA:
|
|
141
|
+
// return type === GL.HALF_FLOAT ? GL.RGBA16F : GL.RGBA32F;
|
|
142
|
+
// case GL.RGB:
|
|
143
|
+
// return type === GL.HALF_FLOAT ? GL.RGB16F : GL.RGB32F;
|
|
144
|
+
// default:
|
|
145
|
+
// return format;
|
|
146
|
+
// }
|
|
147
|
+
// }
|
|
148
|
+
/*
|
|
149
|
+
// texture type to update on the fly
|
|
150
|
+
export function getTextureType(gl: WebGL2RenderingContext, type: GL): GL {
|
|
151
|
+
if (type === HALF_FLOAT_OES) {
|
|
152
|
+
return GL.HALF_FLOAT;
|
|
153
|
+
}
|
|
154
|
+
return type;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// And texImage2D to convert the internalFormat to webgl2.
|
|
158
|
+
const webgl2 = this;
|
|
159
|
+
const origTexImage = gl.texImage2D;
|
|
160
|
+
gl.texImage2D = function (target, miplevel, iformat, a, typeFor6, c, d, typeFor9, f) {
|
|
161
|
+
if (arguments.length == 6) {
|
|
162
|
+
var ifmt = webgl2.getInternalFormat(gl, iformat, typeFor6);
|
|
163
|
+
origTexImage.apply(gl, [target, miplevel, ifmt, a, webgl.getTextureType(gl, typeFor6), c]);
|
|
164
|
+
} else {
|
|
165
|
+
// arguments.length == 9
|
|
166
|
+
var ifmt = webgl2.getInternalFormat(gl, iformat, typeFor9);
|
|
167
|
+
origTexImage.apply(gl, [
|
|
168
|
+
target,
|
|
169
|
+
miplevel,
|
|
170
|
+
ifmt,
|
|
171
|
+
a,
|
|
172
|
+
typeFor6,
|
|
173
|
+
c,
|
|
174
|
+
d,
|
|
175
|
+
webgl2.getTextureType(gl, typeFor9),
|
|
176
|
+
f
|
|
177
|
+
]);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
*/
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Support for listening to context state changes and intercepting state queries
|
|
3
|
+
* NOTE: this system does not handle buffer bindings
|
|
4
|
+
*/
|
|
5
|
+
export declare class WebGLStateTracker {
|
|
6
|
+
static get(gl: WebGL2RenderingContext): WebGLStateTracker;
|
|
7
|
+
gl: WebGL2RenderingContext;
|
|
8
|
+
program: unknown;
|
|
9
|
+
stateStack: object[];
|
|
10
|
+
enable: boolean;
|
|
11
|
+
cache: Record<string, any>;
|
|
12
|
+
log: any;
|
|
13
|
+
protected initialized: boolean;
|
|
14
|
+
constructor(gl: WebGL2RenderingContext, props?: {
|
|
15
|
+
log: any;
|
|
16
|
+
});
|
|
17
|
+
push(values?: {}): void;
|
|
18
|
+
pop(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Initialize WebGL state caching on a context
|
|
21
|
+
* can be called multiple times to enable/disable
|
|
22
|
+
*
|
|
23
|
+
* @note After calling this function, context state will be cached
|
|
24
|
+
* .push() and .pop() will be available for saving,
|
|
25
|
+
* temporarily modifying, and then restoring state.
|
|
26
|
+
*/
|
|
27
|
+
trackState(gl: WebGL2RenderingContext, options?: {
|
|
28
|
+
copyState?: boolean;
|
|
29
|
+
}): void;
|
|
30
|
+
/**
|
|
31
|
+
// interceptor for context set functions - update our cache and our stack
|
|
32
|
+
// values (Object) - the key values for this setter
|
|
33
|
+
* @param values
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
_updateCache(values: {
|
|
37
|
+
[key: number | string]: any;
|
|
38
|
+
}): {
|
|
39
|
+
valueChanged: boolean;
|
|
40
|
+
oldValue: any;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=webgl-state-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webgl-state-tracker.d.ts","sourceRoot":"","sources":["../../../src/context/state-tracker/webgl-state-tracker.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,sBAAsB,GAAG,iBAAiB;IAKzD,EAAE,EAAE,sBAAsB,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAQ;IACxB,UAAU,EAAE,MAAM,EAAE,CAAM;IAC1B,MAAM,UAAQ;IACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAS;IACnC,GAAG,MAAC;IAEJ,SAAS,CAAC,WAAW,UAAS;gBAG5B,EAAE,EAAE,sBAAsB,EAC1B,KAAK,CAAC,EAAE;QACN,GAAG,MAAC;KACL;IASH,IAAI,CAAC,MAAM,KAAK;IAIhB,GAAG;IASH;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,EAAE,sBAAsB,EAAE,OAAO,CAAC,EAAE;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAC,GAAG,IAAI;IAwB7E;;;;;OAKG;IACH,YAAY,CAAC,MAAM,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAA;KAAC;;;;CA8BnD"}
|
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
// Support for listening to context state changes and intercepting state queries
|
|
5
|
-
// NOTE: this system does not handle buffer bindings
|
|
6
|
-
import { assert } from '@luma.gl/core';
|
|
7
|
-
import { GL_PARAMETER_DEFAULTS, GL_HOOKED_SETTERS, NON_CACHE_PARAMETERS } from "../parameters/webgl-parameter-tables.js";
|
|
8
4
|
import { setGLParameters, getGLParameters } from "../parameters/unified-parameter-api.js";
|
|
9
5
|
import { deepArrayEqual } from "./deep-array-equal.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
import { GL_PARAMETER_DEFAULTS, GL_HOOKED_SETTERS, NON_CACHE_PARAMETERS } from "../parameters/webgl-parameter-tables.js";
|
|
7
|
+
// HELPER CLASS - WebGLStateTracker
|
|
8
|
+
/**
|
|
9
|
+
* Support for listening to context state changes and intercepting state queries
|
|
10
|
+
* NOTE: this system does not handle buffer bindings
|
|
11
|
+
*/
|
|
12
|
+
export class WebGLStateTracker {
|
|
13
|
+
static get(gl) {
|
|
14
|
+
// @ts-expect-error
|
|
15
|
+
return gl.state;
|
|
16
|
+
}
|
|
13
17
|
gl;
|
|
14
18
|
program = null;
|
|
15
19
|
stateStack = [];
|
|
16
20
|
enable = true;
|
|
17
|
-
cache;
|
|
21
|
+
cache = null;
|
|
18
22
|
log;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} = {}) {
|
|
23
|
+
initialized = false;
|
|
24
|
+
constructor(gl, props) {
|
|
22
25
|
this.gl = gl;
|
|
23
|
-
this.
|
|
24
|
-
this.log = log;
|
|
26
|
+
this.log = props?.log || (() => { });
|
|
25
27
|
this._updateCache = this._updateCache.bind(this);
|
|
26
28
|
Object.seal(this);
|
|
27
29
|
}
|
|
@@ -29,13 +31,39 @@ class GLState {
|
|
|
29
31
|
this.stateStack.push({});
|
|
30
32
|
}
|
|
31
33
|
pop() {
|
|
32
|
-
assert(this.stateStack.length > 0);
|
|
34
|
+
// assert(this.stateStack.length > 0);
|
|
33
35
|
// Use the saved values in the state stack to restore parameters
|
|
34
36
|
const oldValues = this.stateStack[this.stateStack.length - 1];
|
|
35
37
|
setGLParameters(this.gl, oldValues);
|
|
36
38
|
// Don't pop until we have reset parameters (to make sure other "stack frames" are not affected)
|
|
37
39
|
this.stateStack.pop();
|
|
38
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Initialize WebGL state caching on a context
|
|
43
|
+
* can be called multiple times to enable/disable
|
|
44
|
+
*
|
|
45
|
+
* @note After calling this function, context state will be cached
|
|
46
|
+
* .push() and .pop() will be available for saving,
|
|
47
|
+
* temporarily modifying, and then restoring state.
|
|
48
|
+
*/
|
|
49
|
+
trackState(gl, options) {
|
|
50
|
+
this.cache = options.copyState ? getGLParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
|
|
51
|
+
if (this.initialized) {
|
|
52
|
+
throw new Error('WebGLStateTracker');
|
|
53
|
+
}
|
|
54
|
+
this.initialized = true;
|
|
55
|
+
// @ts-expect-error
|
|
56
|
+
this.gl.state = this;
|
|
57
|
+
installProgramSpy(gl);
|
|
58
|
+
// intercept all setter functions in the table
|
|
59
|
+
for (const key in GL_HOOKED_SETTERS) {
|
|
60
|
+
const setter = GL_HOOKED_SETTERS[key];
|
|
61
|
+
installSetterSpy(gl, key, setter);
|
|
62
|
+
}
|
|
63
|
+
// intercept all getter functions in the table
|
|
64
|
+
installGetterOverride(gl, 'getParameter');
|
|
65
|
+
installGetterOverride(gl, 'isEnabled');
|
|
66
|
+
}
|
|
39
67
|
/**
|
|
40
68
|
// interceptor for context set functions - update our cache and our stack
|
|
41
69
|
// values (Object) - the key values for this setter
|
|
@@ -47,7 +75,7 @@ class GLState {
|
|
|
47
75
|
let oldValue; // = undefined
|
|
48
76
|
const oldValues = this.stateStack.length > 0 ? this.stateStack[this.stateStack.length - 1] : null;
|
|
49
77
|
for (const key in values) {
|
|
50
|
-
assert(key !== undefined);
|
|
78
|
+
// assert(key !== undefined);
|
|
51
79
|
const value = values[key];
|
|
52
80
|
const cached = this.cache[key];
|
|
53
81
|
// Check that value hasn't already been shadowed
|
|
@@ -67,65 +95,6 @@ class GLState {
|
|
|
67
95
|
return { valueChanged, oldValue };
|
|
68
96
|
}
|
|
69
97
|
}
|
|
70
|
-
function getContextState(gl) {
|
|
71
|
-
// @ts-expect-error
|
|
72
|
-
return gl.state;
|
|
73
|
-
}
|
|
74
|
-
// PUBLIC API
|
|
75
|
-
/**
|
|
76
|
-
* Initialize WebGL state caching on a context
|
|
77
|
-
* can be called multiple times to enable/disable
|
|
78
|
-
*
|
|
79
|
-
* @note After calling this function, context state will be cached
|
|
80
|
-
* gl.state.push() and gl.state.pop() will be available for saving,
|
|
81
|
-
* temporarily modifying, and then restoring state.
|
|
82
|
-
*/
|
|
83
|
-
export function trackContextState(gl, options) {
|
|
84
|
-
const { enable = true, copyState } = options;
|
|
85
|
-
assert(copyState !== undefined);
|
|
86
|
-
// @ts-expect-error
|
|
87
|
-
if (!gl.state) {
|
|
88
|
-
// @ts-ignore
|
|
89
|
-
// const {polyfillContext} = global_;
|
|
90
|
-
// if (polyfillContext) {
|
|
91
|
-
// polyfillContext(gl);
|
|
92
|
-
// }
|
|
93
|
-
// Create a state cache
|
|
94
|
-
// @ts-expect-error
|
|
95
|
-
gl.state = new GLState(gl, { copyState });
|
|
96
|
-
installProgramSpy(gl);
|
|
97
|
-
// intercept all setter functions in the table
|
|
98
|
-
for (const key in GL_HOOKED_SETTERS) {
|
|
99
|
-
const setter = GL_HOOKED_SETTERS[key];
|
|
100
|
-
installSetterSpy(gl, key, setter);
|
|
101
|
-
}
|
|
102
|
-
// intercept all getter functions in the table
|
|
103
|
-
installGetterOverride(gl, 'getParameter');
|
|
104
|
-
installGetterOverride(gl, 'isEnabled');
|
|
105
|
-
}
|
|
106
|
-
const glState = getContextState(gl);
|
|
107
|
-
glState.enable = enable;
|
|
108
|
-
return gl;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Saves current WebGL context state onto an internal per-context stack
|
|
112
|
-
*/
|
|
113
|
-
export function pushContextState(gl) {
|
|
114
|
-
let glState = getContextState(gl);
|
|
115
|
-
if (!glState) {
|
|
116
|
-
trackContextState(gl, { copyState: false });
|
|
117
|
-
glState = getContextState(gl);
|
|
118
|
-
}
|
|
119
|
-
glState.push();
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Restores previously saved WebGL context state
|
|
123
|
-
*/
|
|
124
|
-
export function popContextState(gl) {
|
|
125
|
-
const glState = getContextState(gl);
|
|
126
|
-
assert(glState);
|
|
127
|
-
glState.pop();
|
|
128
|
-
}
|
|
129
98
|
// HELPER FUNCTIONS - INSTALL GET/SET INTERCEPTORS (SPYS) ON THE CONTEXT
|
|
130
99
|
/**
|
|
131
100
|
// Overrides a WebGL2RenderingContext state "getter" function
|
|
@@ -142,7 +111,7 @@ function installGetterOverride(gl, functionName) {
|
|
|
142
111
|
// Invalid or blacklisted parameter, do not cache
|
|
143
112
|
return originalGetterFunc(pname);
|
|
144
113
|
}
|
|
145
|
-
const glState =
|
|
114
|
+
const glState = WebGLStateTracker.get(gl);
|
|
146
115
|
if (!(pname in glState.cache)) {
|
|
147
116
|
// WebGL limits are not prepopulated in the cache, call the original getter when first queried.
|
|
148
117
|
glState.cache[pname] = originalGetterFunc(pname);
|
|
@@ -181,7 +150,7 @@ function installSetterSpy(gl, functionName, setter) {
|
|
|
181
150
|
gl[functionName] = function set(...params) {
|
|
182
151
|
// Update the value
|
|
183
152
|
// Call the setter with the state cache and the params so that it can store the parameters
|
|
184
|
-
const glState =
|
|
153
|
+
const glState = WebGLStateTracker.get(gl);
|
|
185
154
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
186
155
|
const { valueChanged, oldValue } = setter(glState._updateCache, ...params);
|
|
187
156
|
// Call the original WebGL2RenderingContext func to make sure the context actually gets updated
|
|
@@ -203,7 +172,7 @@ function installSetterSpy(gl, functionName, setter) {
|
|
|
203
172
|
function installProgramSpy(gl) {
|
|
204
173
|
const originalUseProgram = gl.useProgram.bind(gl);
|
|
205
174
|
gl.useProgram = function useProgramLuma(handle) {
|
|
206
|
-
const glState =
|
|
175
|
+
const glState = WebGLStateTracker.get(gl);
|
|
207
176
|
if (glState.program !== handle) {
|
|
208
177
|
originalUseProgram(handle);
|
|
209
178
|
glState.program = handle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-parameters.d.ts","sourceRoot":"","sources":["../../../src/context/state-tracker/with-parameters.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAkB,+CAA4C;AAGlF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,sBAAsB,EAC1B,UAAU,EAAE,YAAY,GAAG;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAC,EAC9C,IAAI,EAAE,GAAG,GACR,GAAG,
|
|
1
|
+
{"version":3,"file":"with-parameters.d.ts","sourceRoot":"","sources":["../../../src/context/state-tracker/with-parameters.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAkB,+CAA4C;AAGlF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,sBAAsB,EAC1B,UAAU,EAAE,YAAY,GAAG;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAC,EAC9C,IAAI,EAAE,GAAG,GACR,GAAG,CA6BL"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { setGLParameters } from "../parameters/unified-parameter-api.js";
|
|
5
|
-
import {
|
|
5
|
+
import { WebGLStateTracker } from "./webgl-state-tracker.js";
|
|
6
6
|
/**
|
|
7
7
|
* Execute a function with a set of temporary WebGL parameter overrides
|
|
8
8
|
* - Saves current "global" WebGL context settings
|
|
@@ -17,14 +17,15 @@ export function withGLParameters(gl, parameters, func) {
|
|
|
17
17
|
return func(gl);
|
|
18
18
|
}
|
|
19
19
|
const { nocatch = true } = parameters;
|
|
20
|
-
|
|
20
|
+
const webglState = WebGLStateTracker.get(gl);
|
|
21
|
+
webglState.push();
|
|
21
22
|
setGLParameters(gl, parameters);
|
|
22
23
|
// Setup is done, call the function
|
|
23
24
|
let value;
|
|
24
25
|
if (nocatch) {
|
|
25
26
|
// Avoid try catch to minimize stack size impact for safe execution paths
|
|
26
27
|
value = func(gl);
|
|
27
|
-
|
|
28
|
+
webglState.pop();
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
30
31
|
// Wrap in a try-catch to ensure that parameters are restored on exceptions
|
|
@@ -32,7 +33,7 @@ export function withGLParameters(gl, parameters, func) {
|
|
|
32
33
|
value = func(gl);
|
|
33
34
|
}
|
|
34
35
|
finally {
|
|
35
|
-
|
|
36
|
+
webglState.pop();
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
return value;
|