@luma.gl/webgl 9.1.0-alpha.14 → 9.1.0-alpha.16
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 +3 -3
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +24 -22
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.js +6 -224
- package/dist/adapter/resources/webgl-command-buffer.js +15 -15
- package/dist/adapter/resources/webgl-framebuffer.d.ts +2 -3
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +10 -11
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +24 -11
- package/dist/adapter/resources/webgl-shader.d.ts +1 -0
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +6 -4
- package/dist/adapter/webgl-adapter.d.ts.map +1 -1
- package/dist/adapter/webgl-adapter.js +4 -10
- package/dist/adapter/webgl-device.d.ts +1 -2
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +33 -14
- package/dist/context/debug/spector-types.js +1 -1
- package/dist/context/debug/spector.d.ts +5 -5
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +6 -6
- package/dist/context/debug/webgl-developer-tools.d.ts +1 -3
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +4 -19
- package/dist/context/helpers/create-browser-context.d.ts +6 -22
- package/dist/context/helpers/create-browser-context.d.ts.map +1 -1
- package/dist/context/helpers/create-browser-context.js +26 -32
- package/dist/dist.dev.js +1762 -1749
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +1660 -1653
- package/dist/index.cjs.map +4 -4
- package/package.json +4 -4
- package/src/adapter/converters/device-parameters.ts +3 -3
- package/src/adapter/helpers/webgl-texture-utils.ts +33 -30
- package/src/adapter/resources/webgl-command-buffer.ts +16 -16
- package/src/adapter/resources/webgl-framebuffer.ts +12 -12
- package/src/adapter/resources/webgl-render-pipeline.ts +26 -11
- package/src/adapter/resources/webgl-shader.ts +7 -5
- package/src/adapter/webgl-adapter.ts +4 -12
- package/src/adapter/webgl-device.ts +67 -40
- package/src/context/debug/spector-types.ts +1 -1
- package/src/context/debug/spector.ts +11 -11
- package/src/context/debug/webgl-developer-tools.ts +5 -31
- package/src/context/helpers/create-browser-context.ts +39 -64
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
import {log} from '@luma.gl/core';
|
|
6
6
|
import {loadScript} from '../../utils/load-script';
|
|
7
7
|
|
|
8
|
-
import {Spector} from './spector-types';
|
|
8
|
+
import type {Spector} from './spector-types';
|
|
9
9
|
|
|
10
10
|
/** Spector debug initialization options */
|
|
11
11
|
type SpectorProps = {
|
|
12
|
-
/** Whether spector is enabled */
|
|
13
|
-
|
|
12
|
+
/** Whether spector.js is enabled */
|
|
13
|
+
debugSpectorJS?: boolean;
|
|
14
14
|
/** URL to load spector script from. Typically a CDN URL */
|
|
15
|
-
|
|
15
|
+
debugSpectorJSUrl?: string;
|
|
16
16
|
/** Canvas to monitor */
|
|
17
17
|
gl?: WebGL2RenderingContext;
|
|
18
18
|
};
|
|
@@ -29,19 +29,19 @@ declare global {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export const DEFAULT_SPECTOR_PROPS: Required<SpectorProps> = {
|
|
32
|
-
|
|
32
|
+
debugSpectorJS: log.get('debug-spectorjs'),
|
|
33
33
|
// https://github.com/BabylonJS/Spector.js#basic-usage
|
|
34
34
|
// https://forum.babylonjs.com/t/spectorcdn-is-temporarily-off/48241
|
|
35
35
|
// spectorUrl: 'https://spectorcdn.babylonjs.com/spector.bundle.js';
|
|
36
|
-
|
|
36
|
+
debugSpectorJSUrl: 'https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js',
|
|
37
37
|
gl: undefined!
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
/** Loads spector from CDN if not already installed */
|
|
41
|
-
export async function loadSpectorJS(props: {
|
|
41
|
+
export async function loadSpectorJS(props: {debugSpectorJSUrl?: string}): Promise<void> {
|
|
42
42
|
if (!globalThis.SPECTOR) {
|
|
43
43
|
try {
|
|
44
|
-
await loadScript(props.
|
|
44
|
+
await loadScript(props.debugSpectorJSUrl || DEFAULT_SPECTOR_PROPS.debugSpectorJSUrl);
|
|
45
45
|
} catch (error) {
|
|
46
46
|
log.warn(String(error));
|
|
47
47
|
}
|
|
@@ -50,14 +50,14 @@ export async function loadSpectorJS(props: {spectorUrl?: string}): Promise<void>
|
|
|
50
50
|
|
|
51
51
|
export function initializeSpectorJS(props: SpectorProps): Spector | null {
|
|
52
52
|
props = {...DEFAULT_SPECTOR_PROPS, ...props};
|
|
53
|
-
if (!props.
|
|
53
|
+
if (!props.debugSpectorJS) {
|
|
54
54
|
return null;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
if (!spector && globalThis.SPECTOR && !globalThis.luma?.spector) {
|
|
58
58
|
log.probe(LOG_LEVEL, 'SPECTOR found and initialized. Start with `luma.spector.displayUI()`')();
|
|
59
|
-
const {Spector} = globalThis.SPECTOR as any;
|
|
60
|
-
spector = new
|
|
59
|
+
const {Spector: SpectorJS} = globalThis.SPECTOR as any;
|
|
60
|
+
spector = new SpectorJS();
|
|
61
61
|
if (globalThis.luma) {
|
|
62
62
|
(globalThis.luma as any).spector = spector;
|
|
63
63
|
}
|
|
@@ -11,18 +11,9 @@ import {loadScript} from '../../utils/load-script';
|
|
|
11
11
|
const WEBGL_DEBUG_CDN_URL = 'https://unpkg.com/webgl-debug@2.0.1/index.js';
|
|
12
12
|
|
|
13
13
|
type DebugContextProps = {
|
|
14
|
-
|
|
15
|
-
throwOnError?: boolean;
|
|
16
|
-
break?: string[];
|
|
14
|
+
debugWebGL?: boolean;
|
|
17
15
|
};
|
|
18
16
|
|
|
19
|
-
// const DEFAULT_DEBUG_CONTEXT_PROPS: Required<DebugContextProps> = {
|
|
20
|
-
// debug: true,
|
|
21
|
-
// throwOnError: false,
|
|
22
|
-
// break: [],
|
|
23
|
-
// webgl2: false,
|
|
24
|
-
// }
|
|
25
|
-
|
|
26
17
|
type ContextData = {
|
|
27
18
|
realContext?: WebGL2RenderingContext;
|
|
28
19
|
debugContext?: WebGL2RenderingContext;
|
|
@@ -60,7 +51,7 @@ export function makeDebugContext(
|
|
|
60
51
|
gl: WebGL2RenderingContext,
|
|
61
52
|
props: DebugContextProps = {}
|
|
62
53
|
): WebGL2RenderingContext {
|
|
63
|
-
return props.
|
|
54
|
+
return props.debugWebGL ? getDebugContext(gl, props) : getRealContext(gl);
|
|
64
55
|
}
|
|
65
56
|
|
|
66
57
|
// Returns the real context from either of the real/debug contexts
|
|
@@ -136,9 +127,7 @@ function onGLError(props: DebugContextProps, err, functionName: string, args: an
|
|
|
136
127
|
const message = `${errorMessage} in gl.${functionName}(${functionArgs})`;
|
|
137
128
|
log.error(message)();
|
|
138
129
|
debugger; // eslint-disable-line
|
|
139
|
-
|
|
140
|
-
throw new Error(message);
|
|
141
|
-
}
|
|
130
|
+
// throw new Error(message);
|
|
142
131
|
}
|
|
143
132
|
|
|
144
133
|
// Don't generate function string until it is needed
|
|
@@ -153,26 +142,11 @@ function onValidateGLFunc(
|
|
|
153
142
|
log.log(1, functionString)();
|
|
154
143
|
}
|
|
155
144
|
|
|
156
|
-
// If array of breakpoint strings supplied, check if any of them is contained in current GLEnum function
|
|
157
|
-
if (props.break && props.break.length > 0) {
|
|
158
|
-
functionString = functionString || getFunctionString(functionName, functionArgs);
|
|
159
|
-
const isBreakpoint = props.break.every(
|
|
160
|
-
(breakOn: string) => functionString.indexOf(breakOn) !== -1
|
|
161
|
-
);
|
|
162
|
-
if (isBreakpoint) {
|
|
163
|
-
debugger; // eslint-disable-line
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
145
|
for (const arg of functionArgs) {
|
|
168
146
|
if (arg === undefined) {
|
|
169
147
|
functionString = functionString || getFunctionString(functionName, functionArgs);
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
} else {
|
|
173
|
-
log.error(`Undefined argument: ${functionString}`)();
|
|
174
|
-
debugger; // eslint-disable-line
|
|
175
|
-
}
|
|
148
|
+
debugger; // eslint-disable-line
|
|
149
|
+
// throw new Error(`Undefined argument: ${functionString}`);
|
|
176
150
|
}
|
|
177
151
|
}
|
|
178
152
|
}
|
|
@@ -5,37 +5,13 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* ContextProps
|
|
7
7
|
* @param onContextLost
|
|
8
|
-
* @param onContextRestored
|
|
9
|
-
*
|
|
10
|
-
* BROWSER CONTEXT PARAMETERS
|
|
11
|
-
* @param debug Instrument context (at the expense of performance).
|
|
12
|
-
* @param alpha Default render target has an alpha buffer.
|
|
13
|
-
* @param depth Default render target has a depth buffer of at least 16 bits.
|
|
14
|
-
* @param stencil Default render target has a stencil buffer of at least 8 bits.
|
|
15
|
-
* @param antialias Boolean that indicates whether or not to perform anti-aliasing.
|
|
16
|
-
* @param premultipliedAlpha Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.
|
|
17
|
-
* @param preserveDrawingBuffer Default render target buffers will not be automatically cleared and will preserve their values until cleared or overwritten
|
|
18
|
-
* @param failIfMajorPerformanceCaveat Do not create if the system performance is low.
|
|
8
|
+
* @param onContextRestored *
|
|
19
9
|
*/
|
|
20
10
|
type ContextProps = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
antialias?: boolean; // indicates whether or not to perform anti-aliasing.
|
|
26
|
-
depth?: boolean; // indicates that the drawing buffer has a depth buffer of at least 16 bits.
|
|
27
|
-
failIfMajorPerformanceCaveat?: boolean; // indicates if a context will be created if the system performance is low or if no hardware GPU is available.
|
|
28
|
-
powerPreference?: 'default' | 'high-performance' | 'low-power';
|
|
29
|
-
premultipliedAlpha?: boolean; // page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.
|
|
30
|
-
preserveDrawingBuffer?: boolean; // buffers will not be cleared and will preserve their values until cleared or overwritten by the author.
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const DEFAULT_CONTEXT_PROPS: ContextProps = {
|
|
34
|
-
powerPreference: 'high-performance', // After all, most apps are using WebGL for performance reasons
|
|
35
|
-
// eslint-disable-next-line no-console
|
|
36
|
-
onContextLost: () => console.error('WebGL context lost'),
|
|
37
|
-
// eslint-disable-next-line no-console
|
|
38
|
-
onContextRestored: () => console.info('WebGL context restored')
|
|
11
|
+
/** Called when a context is lost */
|
|
12
|
+
onContextLost: (event: Event) => void;
|
|
13
|
+
/** Called when a context is restored */
|
|
14
|
+
onContextRestored: (event: Event) => void;
|
|
39
15
|
};
|
|
40
16
|
|
|
41
17
|
/**
|
|
@@ -45,52 +21,51 @@ const DEFAULT_CONTEXT_PROPS: ContextProps = {
|
|
|
45
21
|
*/
|
|
46
22
|
export function createBrowserContext(
|
|
47
23
|
canvas: HTMLCanvasElement | OffscreenCanvas,
|
|
48
|
-
props: ContextProps
|
|
24
|
+
props: ContextProps,
|
|
25
|
+
webglContextAttributes: WebGLContextAttributes
|
|
49
26
|
): WebGL2RenderingContext {
|
|
50
|
-
props = {...DEFAULT_CONTEXT_PROPS, ...props};
|
|
51
|
-
|
|
52
27
|
// Try to extract any extra information about why context creation failed
|
|
53
|
-
|
|
54
|
-
const onCreateError = error => (errorMessage = error.statusMessage || errorMessage);
|
|
55
|
-
canvas.addEventListener('webglcontextcreationerror', onCreateError, false);
|
|
56
|
-
|
|
57
|
-
// Create the desired context
|
|
58
|
-
let gl: WebGL2RenderingContext | null = null;
|
|
28
|
+
const errorMessage = null;
|
|
29
|
+
// const onCreateError = error => (errorMessage = error.statusMessage || errorMessage);
|
|
59
30
|
|
|
60
|
-
//
|
|
31
|
+
// Avoid multiple listeners?
|
|
32
|
+
// canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);
|
|
33
|
+
// canvas.addEventListener('webglcontextcreationerror', onCreateError, false);
|
|
61
34
|
|
|
62
|
-
|
|
63
|
-
|
|
35
|
+
const webglProps: WebGLContextAttributes = {
|
|
36
|
+
preserveDrawingBuffer: true,
|
|
37
|
+
// failIfMajorPerformanceCaveat: true,
|
|
38
|
+
...webglContextAttributes
|
|
39
|
+
};
|
|
64
40
|
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
// props.failIfMajorPerformanceCaveat = false;
|
|
68
|
-
|
|
69
|
-
// if (!gl && props.webgl1) {
|
|
70
|
-
// gl = canvas.getContext('webgl', props);
|
|
71
|
-
// }
|
|
41
|
+
// Create the desired context
|
|
42
|
+
let gl: WebGL2RenderingContext | null = null;
|
|
72
43
|
|
|
73
|
-
//
|
|
74
|
-
canvas.
|
|
44
|
+
// Create a webgl2 context
|
|
45
|
+
gl ||= canvas.getContext('webgl2', webglProps);
|
|
46
|
+
|
|
47
|
+
// Creation failed with failIfMajorPerformanceCaveat - Try a Software GPU
|
|
48
|
+
if (!gl && !webglContextAttributes.failIfMajorPerformanceCaveat) {
|
|
49
|
+
webglProps.failIfMajorPerformanceCaveat = false;
|
|
50
|
+
gl = canvas.getContext('webgl', webglProps) as WebGL2RenderingContext;
|
|
51
|
+
// @ts-expect-error
|
|
52
|
+
gl.luma ||= {};
|
|
53
|
+
// @ts-expect-error
|
|
54
|
+
gl.luma.softwareRenderer = true;
|
|
55
|
+
}
|
|
75
56
|
|
|
76
57
|
if (!gl) {
|
|
77
58
|
throw new Error(`Failed to create WebGL context: ${errorMessage || 'Unknown error'}`);
|
|
78
59
|
}
|
|
79
60
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
canvas.addEventListener(
|
|
89
|
-
'webglcontextrestored',
|
|
90
|
-
(event: Event) => onContextRestored(event),
|
|
91
|
-
false
|
|
92
|
-
);
|
|
93
|
-
}
|
|
61
|
+
// Carefully extract and wrap callbacks to prevent addEventListener from rebinding them.
|
|
62
|
+
const {onContextLost, onContextRestored} = props;
|
|
63
|
+
canvas.addEventListener('webglcontextlost', (event: Event) => onContextLost(event), false);
|
|
64
|
+
canvas.addEventListener(
|
|
65
|
+
'webglcontextrestored',
|
|
66
|
+
(event: Event) => onContextRestored(event),
|
|
67
|
+
false
|
|
68
|
+
);
|
|
94
69
|
|
|
95
70
|
return gl;
|
|
96
71
|
}
|