@luma.gl/webgl 9.1.9 → 9.2.0-alpha.2
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.js +14 -9
- package/dist/adapter/converters/device-parameters.js.map +1 -1
- package/dist/adapter/converters/sampler-parameters.js +13 -2
- package/dist/adapter/converters/sampler-parameters.js.map +1 -1
- package/dist/adapter/converters/shader-formats.d.ts +67 -8
- package/dist/adapter/converters/shader-formats.d.ts.map +1 -1
- package/dist/adapter/converters/shader-formats.js +82 -52
- package/dist/adapter/converters/shader-formats.js.map +1 -1
- package/dist/adapter/converters/webgl-shadertypes.d.ts +20 -0
- package/dist/adapter/converters/webgl-shadertypes.d.ts.map +1 -0
- package/dist/adapter/converters/webgl-shadertypes.js +122 -0
- package/dist/adapter/converters/webgl-shadertypes.js.map +1 -0
- package/dist/adapter/converters/webgl-texture-table.d.ts.map +1 -1
- package/dist/adapter/converters/webgl-texture-table.js +17 -13
- package/dist/adapter/converters/webgl-texture-table.js.map +1 -1
- package/dist/adapter/converters/{vertex-formats.d.ts → webgl-vertex-formats.d.ts} +4 -4
- package/dist/adapter/converters/webgl-vertex-formats.d.ts.map +1 -0
- package/dist/adapter/converters/{vertex-formats.js → webgl-vertex-formats.js} +2 -3
- package/dist/adapter/converters/webgl-vertex-formats.js.map +1 -0
- package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-features.js.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-limits.d.ts +1 -1
- package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-limits.js +1 -1
- package/dist/adapter/device-helpers/webgl-device-limits.js.map +1 -1
- package/dist/adapter/helpers/format-utils.d.ts +3 -2
- package/dist/adapter/helpers/format-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/format-utils.js.map +1 -1
- package/dist/adapter/helpers/{get-shader-layout.d.ts → get-shader-layout-from-glsl.d.ts} +1 -1
- package/dist/adapter/helpers/get-shader-layout-from-glsl.d.ts.map +1 -0
- package/dist/adapter/helpers/{get-shader-layout.js → get-shader-layout-from-glsl.js} +12 -35
- package/dist/adapter/helpers/get-shader-layout-from-glsl.js.map +1 -0
- package/dist/adapter/helpers/set-uniform.d.ts +2 -2
- package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
- package/dist/adapter/helpers/set-uniform.js.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +2 -242
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.js +10 -99
- package/dist/adapter/helpers/webgl-texture-utils.js.map +1 -1
- package/dist/adapter/resources/webgl-buffer.d.ts +7 -7
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +29 -18
- package/dist/adapter/resources/webgl-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.d.ts +4 -3
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +5 -4
- package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.d.ts +6 -2
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +9 -4
- package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
- package/dist/adapter/resources/webgl-external-texture.js +1 -0
- package/dist/adapter/resources/webgl-external-texture.js.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.d.ts +2 -2
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +2 -2
- package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
- package/dist/adapter/resources/webgl-query-set.d.ts +2 -2
- package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-query-set.js +5 -1
- package/dist/adapter/resources/webgl-query-set.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts +1 -0
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +16 -13
- package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +5 -5
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +28 -24
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgl-sampler.js +1 -1
- package/dist/adapter/resources/webgl-sampler.js.map +1 -1
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +9 -2
- package/dist/adapter/resources/webgl-shader.js.map +1 -1
- package/dist/adapter/resources/webgl-texture-view.js +1 -1
- package/dist/adapter/resources/webgl-texture-view.js.map +1 -1
- package/dist/adapter/resources/webgl-texture.d.ts +21 -66
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +152 -320
- package/dist/adapter/resources/webgl-texture.js.map +1 -1
- package/dist/adapter/resources/webgl-transform-feedback.d.ts +1 -1
- package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-transform-feedback.js +1 -1
- package/dist/adapter/resources/webgl-transform-feedback.js.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.d.ts +1 -1
- package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +3 -2
- package/dist/adapter/resources/webgl-vertex-array.js.map +1 -1
- package/dist/adapter/webgl-adapter.d.ts +4 -3
- package/dist/adapter/webgl-adapter.d.ts.map +1 -1
- package/dist/adapter/webgl-adapter.js +43 -30
- package/dist/adapter/webgl-adapter.js.map +1 -1
- package/dist/adapter/webgl-canvas-context.d.ts +3 -24
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +5 -44
- package/dist/adapter/webgl-canvas-context.js.map +1 -1
- package/dist/adapter/webgl-device.d.ts +19 -20
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +44 -31
- package/dist/adapter/webgl-device.js.map +1 -1
- package/dist/context/debug/spector-types.d.ts.map +1 -1
- package/dist/context/debug/spector-types.js +3 -0
- package/dist/context/debug/spector-types.js.map +1 -1
- package/dist/context/debug/spector.js.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +1 -0
- package/dist/context/debug/webgl-developer-tools.js.map +1 -1
- package/dist/context/helpers/webgl-extensions.d.ts.map +1 -1
- package/dist/context/helpers/webgl-extensions.js +3 -0
- package/dist/context/helpers/webgl-extensions.js.map +1 -1
- package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
- package/dist/context/parameters/unified-parameter-api.js +7 -0
- package/dist/context/parameters/unified-parameter-api.js.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.d.ts +1 -1
- package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js +1 -0
- package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
- package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts.map +1 -1
- package/dist/context/polyfills/polyfill-webgl1-extensions.js +1 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.js.map +1 -1
- package/dist/context/state-tracker/deep-array-equal.d.ts +2 -1
- package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
- package/dist/context/state-tracker/deep-array-equal.js +4 -5
- package/dist/context/state-tracker/deep-array-equal.js.map +1 -1
- package/dist/context/state-tracker/webgl-state-tracker.d.ts.map +1 -1
- package/dist/context/state-tracker/webgl-state-tracker.js +4 -1
- package/dist/context/state-tracker/webgl-state-tracker.js.map +1 -1
- package/dist/context/state-tracker/with-parameters.js.map +1 -1
- package/dist/dist.dev.js +4788 -4801
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +3906 -3960
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/adapter/converters/device-parameters.ts +19 -9
- package/src/adapter/converters/sampler-parameters.ts +13 -2
- package/src/adapter/converters/shader-formats.ts +50 -24
- package/src/adapter/converters/webgl-shadertypes.ts +151 -0
- package/src/adapter/converters/webgl-texture-table.ts +21 -15
- package/src/adapter/converters/{vertex-formats.ts → webgl-vertex-formats.ts} +4 -5
- package/src/adapter/device-helpers/webgl-device-features.ts +1 -1
- package/src/adapter/device-helpers/webgl-device-limits.ts +1 -1
- package/src/adapter/helpers/format-utils.ts +2 -2
- package/src/adapter/helpers/{get-shader-layout.ts → get-shader-layout-from-glsl.ts} +20 -50
- package/src/adapter/helpers/set-uniform.ts +2 -2
- package/src/adapter/helpers/webgl-texture-utils.ts +12 -348
- package/src/adapter/resources/webgl-buffer.ts +43 -23
- package/src/adapter/resources/webgl-command-buffer.ts +9 -8
- package/src/adapter/resources/webgl-command-encoder.ts +18 -9
- package/src/adapter/resources/webgl-framebuffer.ts +4 -4
- package/src/adapter/resources/webgl-query-set.ts +7 -3
- package/src/adapter/resources/webgl-render-pass.ts +20 -17
- package/src/adapter/resources/webgl-render-pipeline.ts +38 -37
- package/src/adapter/resources/webgl-sampler.ts +1 -1
- package/src/adapter/resources/webgl-shader.ts +11 -2
- package/src/adapter/resources/webgl-texture-view.ts +1 -1
- package/src/adapter/resources/webgl-texture.ts +184 -394
- package/src/adapter/resources/webgl-transform-feedback.ts +2 -2
- package/src/adapter/resources/webgl-vertex-array.ts +4 -3
- package/src/adapter/webgl-adapter.ts +46 -33
- package/src/adapter/webgl-canvas-context.ts +7 -47
- package/src/adapter/webgl-device.ts +64 -44
- package/src/context/debug/spector-types.ts +5 -0
- package/src/context/debug/spector.ts +1 -1
- package/src/context/debug/webgl-developer-tools.ts +9 -3
- package/src/context/helpers/webgl-extensions.ts +3 -0
- package/src/context/parameters/unified-parameter-api.ts +9 -2
- package/src/context/parameters/webgl-parameter-tables.ts +2 -0
- package/src/context/polyfills/polyfill-webgl1-extensions.ts +1 -0
- package/src/context/state-tracker/deep-array-equal.ts +11 -6
- package/src/context/state-tracker/webgl-state-tracker.ts +5 -1
- package/src/context/state-tracker/with-parameters.ts +1 -1
- package/src/index.ts +1 -5
- package/dist/adapter/converters/vertex-formats.d.ts.map +0 -1
- package/dist/adapter/converters/vertex-formats.js.map +0 -1
- package/dist/adapter/helpers/decode-webgl-types.d.ts +0 -26
- package/dist/adapter/helpers/decode-webgl-types.d.ts.map +0 -1
- package/dist/adapter/helpers/decode-webgl-types.js +0 -102
- package/dist/adapter/helpers/decode-webgl-types.js.map +0 -1
- package/dist/adapter/helpers/get-shader-layout.d.ts.map +0 -1
- package/dist/adapter/helpers/get-shader-layout.js.map +0 -1
- package/dist/adapter/helpers/typed-array-utils.d.ts +0 -44
- package/dist/adapter/helpers/typed-array-utils.d.ts.map +0 -1
- package/dist/adapter/helpers/typed-array-utils.js +0 -107
- package/dist/adapter/helpers/typed-array-utils.js.map +0 -1
- package/dist/deprecated/accessor.d.ts +0 -53
- package/dist/deprecated/accessor.d.ts.map +0 -1
- package/dist/deprecated/accessor.js +0 -177
- package/dist/deprecated/accessor.js.map +0 -1
- package/dist/utils/split-uniforms-and-bindings.d.ts +0 -9
- package/dist/utils/split-uniforms-and-bindings.d.ts.map +0 -1
- package/dist/utils/split-uniforms-and-bindings.js +0 -21
- package/dist/utils/split-uniforms-and-bindings.js.map +0 -1
- package/src/adapter/helpers/decode-webgl-types.ts +0 -134
- package/src/adapter/helpers/typed-array-utils.ts +0 -129
- package/src/deprecated/accessor.ts +0 -225
- package/src/utils/split-uniforms-and-bindings.ts +0 -31
|
@@ -102,7 +102,7 @@ export class WEBGLTransformFeedback extends TransformFeedback {
|
|
|
102
102
|
return location >= 0 ? this.buffers[location] : null;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
bind(funcOrHandle = this.handle) {
|
|
105
|
+
bind(funcOrHandle: (() => void) | WebGLTransformFeedback | null = this.handle) {
|
|
106
106
|
if (typeof funcOrHandle !== 'function') {
|
|
107
107
|
this.gl.bindTransformFeedback(GL.TRANSFORM_FEEDBACK, funcOrHandle);
|
|
108
108
|
return this;
|
|
@@ -148,7 +148,7 @@ export class WEBGLTransformFeedback extends TransformFeedback {
|
|
|
148
148
|
return Number(locationOrName);
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
for (const varying of this.layout.varyings) {
|
|
151
|
+
for (const varying of this.layout.varyings || []) {
|
|
152
152
|
if (locationOrName === varying.name) {
|
|
153
153
|
return varying.location;
|
|
154
154
|
}
|
|
@@ -11,7 +11,7 @@ import {getBrowser} from '@probe.gl/env';
|
|
|
11
11
|
import {WebGLDevice} from '../webgl-device';
|
|
12
12
|
import {WEBGLBuffer} from '../resources/webgl-buffer';
|
|
13
13
|
|
|
14
|
-
import {getGLFromVertexType} from '../converters/vertex-formats';
|
|
14
|
+
import {getGLFromVertexType} from '../converters/webgl-vertex-formats';
|
|
15
15
|
import {fillArray} from '../../utils/fill-array';
|
|
16
16
|
|
|
17
17
|
/** VertexArrayObject wrapper */
|
|
@@ -25,7 +25,7 @@ export class WEBGLVertexArray extends VertexArray {
|
|
|
25
25
|
|
|
26
26
|
/** Attribute 0 buffer constant */
|
|
27
27
|
private buffer: WEBGLBuffer | null = null;
|
|
28
|
-
private bufferValue = null;
|
|
28
|
+
private bufferValue: TypedArray | null = null;
|
|
29
29
|
|
|
30
30
|
/** * Attribute 0 can not be disable on most desktop OpenGL based browsers */
|
|
31
31
|
static isConstantAttributeZeroSupported(device: Device): boolean {
|
|
@@ -233,7 +233,8 @@ export class WEBGLVertexArray extends VertexArray {
|
|
|
233
233
|
this.buffer = this.buffer || this.device.createBuffer({byteLength});
|
|
234
234
|
|
|
235
235
|
// Reallocate and update contents if needed
|
|
236
|
-
|
|
236
|
+
// @ts-ignore TODO fix types
|
|
237
|
+
updateNeeded ||= !compareConstantArrayValues(constantValue, this.bufferValue);
|
|
237
238
|
|
|
238
239
|
if (updateNeeded) {
|
|
239
240
|
// Create a typed array that is big enough, and fill it with the required data
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import type {WebGLDevice} from './webgl-device';
|
|
5
6
|
import {Adapter, Device, DeviceProps, log} from '@luma.gl/core';
|
|
6
|
-
import {WebGLDevice} from './webgl-device';
|
|
7
7
|
import {enforceWebGL2} from '../context/polyfills/polyfill-webgl1-extensions';
|
|
8
8
|
import {loadSpectorJS, DEFAULT_SPECTOR_PROPS} from '../context/debug/spector';
|
|
9
9
|
import {loadWebGLDeveloperTools} from '../context/debug/webgl-developer-tools';
|
|
@@ -16,12 +16,13 @@ export class WebGLAdapter extends Adapter {
|
|
|
16
16
|
|
|
17
17
|
constructor() {
|
|
18
18
|
super();
|
|
19
|
-
|
|
20
19
|
// Add spector default props to device default props, so that runtime settings are observed
|
|
21
20
|
Device.defaultProps = {...Device.defaultProps, ...DEFAULT_SPECTOR_PROPS};
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/** Force any created WebGL contexts to be WebGL2 contexts, polyfilled with WebGL1 extensions */
|
|
24
|
+
enforceWebGL2(enable: boolean): void {
|
|
25
|
+
enforceWebGL2(enable);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
/** Check if WebGL 2 is available */
|
|
@@ -29,9 +30,17 @@ export class WebGLAdapter extends Adapter {
|
|
|
29
30
|
return typeof WebGL2RenderingContext !== 'undefined';
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
override isDeviceHandle(handle: unknown): boolean {
|
|
34
|
+
// WebGL
|
|
35
|
+
if (typeof WebGL2RenderingContext !== 'undefined' && handle instanceof WebGL2RenderingContext) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof WebGLRenderingContext !== 'undefined' && handle instanceof WebGLRenderingContext) {
|
|
40
|
+
log.warn('WebGL1 is not supported', handle)();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return false;
|
|
35
44
|
}
|
|
36
45
|
|
|
37
46
|
/**
|
|
@@ -42,11 +51,12 @@ export class WebGLAdapter extends Adapter {
|
|
|
42
51
|
* @returns
|
|
43
52
|
*/
|
|
44
53
|
async attach(gl: Device | WebGL2RenderingContext): Promise<WebGLDevice> {
|
|
54
|
+
const {WebGLDevice} = await import('./webgl-device');
|
|
45
55
|
if (gl instanceof WebGLDevice) {
|
|
46
56
|
return gl;
|
|
47
57
|
}
|
|
48
58
|
// @ts-expect-error
|
|
49
|
-
if (gl?.device instanceof
|
|
59
|
+
if (gl?.device instanceof WebGLDevice) {
|
|
50
60
|
// @ts-expect-error
|
|
51
61
|
return gl.device as WebGLDevice;
|
|
52
62
|
}
|
|
@@ -63,40 +73,43 @@ export class WebGLAdapter extends Adapter {
|
|
|
63
73
|
}
|
|
64
74
|
|
|
65
75
|
async create(props: DeviceProps = {}): Promise<WebGLDevice> {
|
|
66
|
-
|
|
76
|
+
const {WebGLDevice} = await import('./webgl-device');
|
|
67
77
|
|
|
68
|
-
|
|
78
|
+
log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created')();
|
|
79
|
+
try {
|
|
80
|
+
const promises: Promise<unknown>[] = [];
|
|
69
81
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
82
|
+
// Load webgl and spector debug scripts from CDN if requested
|
|
83
|
+
if (props.debugWebGL || props.debug) {
|
|
84
|
+
promises.push(loadWebGLDeveloperTools());
|
|
85
|
+
}
|
|
74
86
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
87
|
+
if (props.debugSpectorJS) {
|
|
88
|
+
promises.push(loadSpectorJS(props));
|
|
89
|
+
}
|
|
78
90
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
91
|
+
// Wait for all the loads to settle before creating the context.
|
|
92
|
+
// The Device.create() functions are async, so in contrast to the constructor, we can `await` here.
|
|
93
|
+
const results = await Promise.allSettled(promises);
|
|
94
|
+
for (const result of results) {
|
|
95
|
+
if (result.status === 'rejected') {
|
|
96
|
+
log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
97
|
+
}
|
|
85
98
|
}
|
|
86
|
-
}
|
|
87
99
|
|
|
88
|
-
|
|
100
|
+
const device = new WebGLDevice(props);
|
|
89
101
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
${device._reused ? 'Reusing' : 'Created'} device with WebGL2 ${device.debug ? 'debug ' : ''}context: \
|
|
102
|
+
// Log some debug info about the newly created context
|
|
103
|
+
const message = `\
|
|
104
|
+
${device._reused ? 'Reusing' : 'Created'} device with WebGL2 ${device.props.debug ? 'debug ' : ''}context: \
|
|
93
105
|
${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
94
|
-
|
|
95
|
-
|
|
106
|
+
log.probe(LOG_LEVEL, message)();
|
|
107
|
+
log.table(LOG_LEVEL, device.info)();
|
|
96
108
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
109
|
+
return device;
|
|
110
|
+
} finally {
|
|
111
|
+
log.groupEnd(LOG_LEVEL)();
|
|
112
|
+
}
|
|
100
113
|
}
|
|
101
114
|
}
|
|
102
115
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {CanvasContextProps
|
|
5
|
+
import type {CanvasContextProps} from '@luma.gl/core';
|
|
6
6
|
import {CanvasContext} from '@luma.gl/core';
|
|
7
7
|
import {WebGLDevice} from './webgl-device';
|
|
8
8
|
import {WEBGLFramebuffer} from './resources/webgl-framebuffer';
|
|
@@ -12,10 +12,8 @@ import {WEBGLFramebuffer} from './resources/webgl-framebuffer';
|
|
|
12
12
|
*/
|
|
13
13
|
export class WebGLCanvasContext extends CanvasContext {
|
|
14
14
|
readonly device: WebGLDevice;
|
|
15
|
-
readonly
|
|
16
|
-
readonly depthStencilFormat: TextureFormat = 'depth24plus';
|
|
15
|
+
readonly handle: unknown = null;
|
|
17
16
|
|
|
18
|
-
presentationSize: [number, number];
|
|
19
17
|
private _framebuffer: WEBGLFramebuffer | null = null;
|
|
20
18
|
|
|
21
19
|
get [Symbol.toStringTag](): string {
|
|
@@ -26,57 +24,19 @@ export class WebGLCanvasContext extends CanvasContext {
|
|
|
26
24
|
// Note: Base class creates / looks up the canvas (unless under Node.js)
|
|
27
25
|
super(props);
|
|
28
26
|
this.device = device;
|
|
29
|
-
|
|
27
|
+
|
|
28
|
+
// Base class constructor cannot access derived methods/fields, so we need to call these functions in the subclass constructor
|
|
30
29
|
this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
|
|
31
|
-
this.
|
|
30
|
+
this._updateDevice();
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
getCurrentFramebuffer(): WEBGLFramebuffer {
|
|
35
|
-
this.update();
|
|
36
34
|
// Setting handle to null returns a reference to the default framebuffer
|
|
37
35
|
this._framebuffer = this._framebuffer || new WEBGLFramebuffer(this.device, {handle: null});
|
|
38
36
|
return this._framebuffer;
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
update() {
|
|
43
|
-
const size = this.getPixelSize();
|
|
44
|
-
const sizeChanged =
|
|
45
|
-
size[0] !== this.presentationSize[0] || size[1] !== this.presentationSize[1];
|
|
46
|
-
if (sizeChanged) {
|
|
47
|
-
this.presentationSize = size;
|
|
48
|
-
this.resize();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Resize the canvas' drawing buffer.
|
|
54
|
-
*
|
|
55
|
-
* Can match the canvas CSS size, and optionally also consider devicePixelRatio
|
|
56
|
-
* Can be called every frame
|
|
57
|
-
*
|
|
58
|
-
* Regardless of size, the drawing buffer will always be scaled to the viewport, but
|
|
59
|
-
* for best visual results, usually set to either:
|
|
60
|
-
* canvas CSS width x canvas CSS height
|
|
61
|
-
* canvas CSS width * devicePixelRatio x canvas CSS height * devicePixelRatio
|
|
62
|
-
* See http://webgl2fundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html
|
|
63
|
-
*/
|
|
64
|
-
resize(options?: {width?: number; height?: number; useDevicePixels?: boolean | number}): void {
|
|
65
|
-
if (!this.device.gl) return;
|
|
39
|
+
// IMPLEMENTATION OF ABSTRACT METHODS
|
|
66
40
|
|
|
67
|
-
|
|
68
|
-
if (this.canvas) {
|
|
69
|
-
const devicePixelRatio = this.getDevicePixelRatio(options?.useDevicePixels);
|
|
70
|
-
this.setDevicePixelRatio(devicePixelRatio, options);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
commit() {
|
|
76
|
-
// gl.commit was ultimately removed from the WebGL standard??
|
|
77
|
-
// if (this.offScreen && this.gl.commit) {
|
|
78
|
-
// // @ts-expect-error gl.commit is not officially part of WebGL2RenderingContext
|
|
79
|
-
// this.gl.commit();
|
|
80
|
-
// }
|
|
81
|
-
}
|
|
41
|
+
_updateDevice(): void {}
|
|
82
42
|
}
|
|
@@ -25,14 +25,12 @@ import type {
|
|
|
25
25
|
RenderPipelineProps,
|
|
26
26
|
ComputePipeline,
|
|
27
27
|
ComputePipelineProps,
|
|
28
|
-
// RenderPass,
|
|
29
|
-
RenderPassProps,
|
|
30
|
-
ComputePass,
|
|
31
|
-
ComputePassProps,
|
|
32
28
|
// CommandEncoder,
|
|
33
29
|
CommandEncoderProps,
|
|
34
30
|
TransformFeedbackProps,
|
|
35
|
-
QuerySetProps
|
|
31
|
+
QuerySetProps,
|
|
32
|
+
Resource,
|
|
33
|
+
VertexFormat
|
|
36
34
|
} from '@luma.gl/core';
|
|
37
35
|
import {Device, CanvasContext, log} from '@luma.gl/core';
|
|
38
36
|
import type {GLExtensions} from '@luma.gl/constants';
|
|
@@ -53,9 +51,9 @@ import {WEBGLShader} from './resources/webgl-shader';
|
|
|
53
51
|
import {WEBGLSampler} from './resources/webgl-sampler';
|
|
54
52
|
import {WEBGLTexture} from './resources/webgl-texture';
|
|
55
53
|
import {WEBGLFramebuffer} from './resources/webgl-framebuffer';
|
|
56
|
-
import {WEBGLRenderPass} from './resources/webgl-render-pass';
|
|
57
54
|
import {WEBGLRenderPipeline} from './resources/webgl-render-pipeline';
|
|
58
55
|
import {WEBGLCommandEncoder} from './resources/webgl-command-encoder';
|
|
56
|
+
import {WEBGLCommandBuffer} from './resources/webgl-command-buffer';
|
|
59
57
|
import {WEBGLVertexArray} from './resources/webgl-vertex-array';
|
|
60
58
|
import {WEBGLTransformFeedback} from './resources/webgl-transform-feedback';
|
|
61
59
|
import {WEBGLQuerySet} from './resources/webgl-query-set';
|
|
@@ -71,9 +69,7 @@ import {getWebGLExtension} from '../context/helpers/webgl-extensions';
|
|
|
71
69
|
|
|
72
70
|
/** WebGPU style Device API for a WebGL context */
|
|
73
71
|
export class WebGLDevice extends Device {
|
|
74
|
-
//
|
|
75
72
|
// Public `Device` API
|
|
76
|
-
//
|
|
77
73
|
|
|
78
74
|
/** type of this device */
|
|
79
75
|
readonly type = 'webgl';
|
|
@@ -83,20 +79,24 @@ export class WebGLDevice extends Device {
|
|
|
83
79
|
readonly handle!: WebGL2RenderingContext;
|
|
84
80
|
features!: WebGLDeviceFeatures;
|
|
85
81
|
limits!: WebGLDeviceLimits;
|
|
86
|
-
|
|
87
82
|
readonly info!: DeviceInfo;
|
|
88
83
|
readonly canvasContext!: WebGLCanvasContext;
|
|
89
84
|
|
|
85
|
+
readonly preferredColorFormat = 'rgba8unorm';
|
|
86
|
+
readonly preferredDepthFormat = 'depth24plus';
|
|
87
|
+
|
|
88
|
+
commandEncoder!: WEBGLCommandEncoder;
|
|
89
|
+
|
|
90
90
|
readonly lost: Promise<{reason: 'destroyed'; message: string}>;
|
|
91
91
|
|
|
92
92
|
private _resolveContextLost?: (value: {reason: 'destroyed'; message: string}) => void;
|
|
93
93
|
|
|
94
94
|
/** WebGL2 context. */
|
|
95
95
|
readonly gl!: WebGL2RenderingContext;
|
|
96
|
-
readonly debug: boolean = false;
|
|
97
96
|
|
|
98
|
-
/**
|
|
99
|
-
|
|
97
|
+
/** Store constants */
|
|
98
|
+
// @ts-ignore TODO fix
|
|
99
|
+
_constants: (TypedArray | null)[];
|
|
100
100
|
|
|
101
101
|
/** State used by luma.gl classes - TODO - not used? */
|
|
102
102
|
readonly _extensions: GLExtensions = {};
|
|
@@ -109,10 +109,27 @@ export class WebGLDevice extends Device {
|
|
|
109
109
|
// Public API
|
|
110
110
|
//
|
|
111
111
|
|
|
112
|
+
override get [Symbol.toStringTag](): string {
|
|
113
|
+
return 'WebGLDevice';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
override toString(): string {
|
|
117
|
+
return `${this[Symbol.toStringTag]}(${this.id})`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
override isVertexFormatSupported(format: VertexFormat): boolean {
|
|
121
|
+
switch (format) {
|
|
122
|
+
case 'unorm8x4-bgra':
|
|
123
|
+
return false;
|
|
124
|
+
default:
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
112
129
|
constructor(props: DeviceProps) {
|
|
113
130
|
super({...props, id: props.id || uid('webgl-device')});
|
|
114
131
|
|
|
115
|
-
const canvasContextProps = Device._getCanvasContextProps(props)
|
|
132
|
+
const canvasContextProps = Device._getCanvasContextProps(props)!;
|
|
116
133
|
|
|
117
134
|
// WebGL requires a canvas to be created before creating the context
|
|
118
135
|
if (!canvasContextProps) {
|
|
@@ -209,10 +226,6 @@ export class WebGLDevice extends Device {
|
|
|
209
226
|
this.features.initializeFeatures();
|
|
210
227
|
}
|
|
211
228
|
|
|
212
|
-
if (canvasContextProps.autoResize !== false) {
|
|
213
|
-
this.canvasContext.resize();
|
|
214
|
-
}
|
|
215
|
-
|
|
216
229
|
// Install context state tracking
|
|
217
230
|
const glState = new WebGLStateTracker(this.gl, {
|
|
218
231
|
log: (...args: any[]) => log.log(1, ...args)()
|
|
@@ -229,6 +242,8 @@ export class WebGLDevice extends Device {
|
|
|
229
242
|
log.level = Math.max(log.level, 1);
|
|
230
243
|
}
|
|
231
244
|
}
|
|
245
|
+
|
|
246
|
+
this.commandEncoder = new WEBGLCommandEncoder(this, {id: `${this}-command-encoder`});
|
|
232
247
|
}
|
|
233
248
|
|
|
234
249
|
/**
|
|
@@ -259,6 +274,10 @@ export class WebGLDevice extends Device {
|
|
|
259
274
|
|
|
260
275
|
// IMPLEMENTATION OF ABSTRACT DEVICE
|
|
261
276
|
|
|
277
|
+
getTextureByteAlignment(): number {
|
|
278
|
+
return 4;
|
|
279
|
+
}
|
|
280
|
+
|
|
262
281
|
createCanvasContext(props?: CanvasContextProps): CanvasContext {
|
|
263
282
|
throw new Error('WebGL only supports a single canvas');
|
|
264
283
|
}
|
|
@@ -304,20 +323,10 @@ export class WebGLDevice extends Device {
|
|
|
304
323
|
return new WEBGLRenderPipeline(this, props);
|
|
305
324
|
}
|
|
306
325
|
|
|
307
|
-
beginRenderPass(props: RenderPassProps): WEBGLRenderPass {
|
|
308
|
-
return new WEBGLRenderPass(this, props);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
326
|
createComputePipeline(props?: ComputePipelineProps): ComputePipeline {
|
|
312
327
|
throw new Error('ComputePipeline not supported in WebGL');
|
|
313
328
|
}
|
|
314
329
|
|
|
315
|
-
beginComputePass(props: ComputePassProps): ComputePass {
|
|
316
|
-
throw new Error('ComputePass not supported in WebGL');
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
private renderPass: WEBGLRenderPass | null = null;
|
|
320
|
-
|
|
321
330
|
override createCommandEncoder(props: CommandEncoderProps = {}): WEBGLCommandEncoder {
|
|
322
331
|
return new WEBGLCommandEncoder(this, props);
|
|
323
332
|
}
|
|
@@ -327,10 +336,14 @@ export class WebGLDevice extends Device {
|
|
|
327
336
|
* https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/commit
|
|
328
337
|
* Chrome's offscreen canvas does not require gl.commit
|
|
329
338
|
*/
|
|
330
|
-
submit(): void {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
339
|
+
submit(commandBuffer: WEBGLCommandBuffer): void {
|
|
340
|
+
if (!commandBuffer) {
|
|
341
|
+
commandBuffer = this.commandEncoder.finish();
|
|
342
|
+
this.commandEncoder.destroy();
|
|
343
|
+
this.commandEncoder = this.createCommandEncoder({id: `${this.id}-default-encoder`});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
commandBuffer._executeCommands();
|
|
334
347
|
}
|
|
335
348
|
|
|
336
349
|
//
|
|
@@ -432,16 +445,6 @@ export class WebGLDevice extends Device {
|
|
|
432
445
|
webglState.pop();
|
|
433
446
|
}
|
|
434
447
|
|
|
435
|
-
/**
|
|
436
|
-
* Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
|
|
437
|
-
* luma.gl ids and props can be inspected
|
|
438
|
-
*/
|
|
439
|
-
setSpectorMetadata(handle: unknown, props: Record<string, unknown>) {
|
|
440
|
-
// @ts-expect-error
|
|
441
|
-
// eslint-disable-next-line camelcase
|
|
442
|
-
handle.__SPECTOR_Metadata = props;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
448
|
/**
|
|
446
449
|
* Returns the GL.<KEY> constant that corresponds to a numeric value of a GL constant
|
|
447
450
|
* Be aware that there are some duplicates especially for constants that are 0,
|
|
@@ -471,9 +474,6 @@ export class WebGLDevice extends Device {
|
|
|
471
474
|
}, {});
|
|
472
475
|
}
|
|
473
476
|
|
|
474
|
-
/** Store constants */
|
|
475
|
-
_constants: (TypedArray | null)[];
|
|
476
|
-
|
|
477
477
|
/**
|
|
478
478
|
* Set a constant value for a location. Disabled attributes at that location will read from this value
|
|
479
479
|
* @note WebGL constants are stored globally on the WebGL context, not the VertexArray
|
|
@@ -512,6 +512,26 @@ export class WebGLDevice extends Device {
|
|
|
512
512
|
getWebGLExtension(this.gl, name, this._extensions);
|
|
513
513
|
return this._extensions;
|
|
514
514
|
}
|
|
515
|
+
|
|
516
|
+
// INTERNAL SUPPORT METHODS FOR WEBGL RESOURCES
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
|
|
520
|
+
* luma.gl ids and props can be inspected
|
|
521
|
+
*/
|
|
522
|
+
_setWebGLDebugMetadata(
|
|
523
|
+
handle: unknown,
|
|
524
|
+
resource: Resource<any>,
|
|
525
|
+
options: {spector: Record<string, unknown>}
|
|
526
|
+
): void {
|
|
527
|
+
// @ts-expect-error
|
|
528
|
+
handle.luma = resource;
|
|
529
|
+
|
|
530
|
+
const spectorMetadata = {props: options.spector, id: options.spector['id']};
|
|
531
|
+
// @ts-expect-error
|
|
532
|
+
// eslint-disable-next-line camelcase
|
|
533
|
+
handle.__SPECTOR_Metadata = spectorMetadata;
|
|
534
|
+
}
|
|
515
535
|
}
|
|
516
536
|
|
|
517
537
|
/** Set constant float array attribute */
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Forked from https://github.com/BabylonJS/Spector.js/blob/master/dist/spector.d.ts
|
|
2
2
|
/* eslint-disable camelcase, no-shadow */
|
|
3
3
|
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
|
|
4
6
|
interface IEvent<T> {
|
|
5
7
|
add(callback: (element: T) => void, context?: any): number;
|
|
6
8
|
remove(id: number): void;
|
|
@@ -1071,8 +1073,11 @@ export abstract class Spector {
|
|
|
1071
1073
|
}
|
|
1072
1074
|
protected static tryGetContextFromHelperField: unknown;
|
|
1073
1075
|
protected static tryGetContextFromCanvas: unknown;
|
|
1076
|
+
// @ts-ignore TODO
|
|
1074
1077
|
readonly onCaptureStarted: IEvent<any>;
|
|
1078
|
+
// @ts-ignore TODO
|
|
1075
1079
|
readonly onCapture: IEvent<ICapture>;
|
|
1080
|
+
// @ts-ignore TODO
|
|
1076
1081
|
readonly onError: IEvent<string>;
|
|
1077
1082
|
protected readonly logger;
|
|
1078
1083
|
protected readonly timeSpy;
|
|
@@ -112,7 +112,7 @@ function getDebugContext(
|
|
|
112
112
|
|
|
113
113
|
// DEBUG TRACING
|
|
114
114
|
|
|
115
|
-
function getFunctionString(functionName: string, functionArgs): string {
|
|
115
|
+
function getFunctionString(functionName: string, functionArgs: unknown[]): string {
|
|
116
116
|
// Cover bug in webgl-debug-tools
|
|
117
117
|
functionArgs = Array.from(functionArgs).map(arg => (arg === undefined ? 'undefined' : arg));
|
|
118
118
|
let args = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, functionArgs);
|
|
@@ -120,12 +120,18 @@ function getFunctionString(functionName: string, functionArgs): string {
|
|
|
120
120
|
return `gl.${functionName}(${args})`;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
function onGLError(
|
|
123
|
+
function onGLError(
|
|
124
|
+
props: DebugContextProps,
|
|
125
|
+
err: number,
|
|
126
|
+
functionName: string,
|
|
127
|
+
args: unknown[]
|
|
128
|
+
): void {
|
|
124
129
|
// Cover bug in webgl-debug-tools
|
|
125
130
|
args = Array.from(args).map(arg => (arg === undefined ? 'undefined' : arg));
|
|
126
131
|
const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err);
|
|
127
132
|
const functionArgs = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, args);
|
|
128
133
|
const message = `${errorMessage} in gl.${functionName}(${functionArgs})`;
|
|
134
|
+
// TODO - call device.reportError
|
|
129
135
|
log.error(message)();
|
|
130
136
|
debugger; // eslint-disable-line
|
|
131
137
|
// throw new Error(message);
|
|
@@ -135,7 +141,7 @@ function onGLError(props: DebugContextProps, err, functionName: string, args: an
|
|
|
135
141
|
function onValidateGLFunc(
|
|
136
142
|
props: DebugContextProps,
|
|
137
143
|
functionName: string,
|
|
138
|
-
functionArgs:
|
|
144
|
+
functionArgs: unknown[]
|
|
139
145
|
): void {
|
|
140
146
|
let functionString: string = '';
|
|
141
147
|
if (log.level >= 1) {
|
|
@@ -10,8 +10,11 @@ export function getWebGLExtension(
|
|
|
10
10
|
name: string,
|
|
11
11
|
extensions: GLExtensions
|
|
12
12
|
): unknown {
|
|
13
|
+
// @ts-ignore TODO
|
|
13
14
|
if (extensions[name] === undefined) {
|
|
15
|
+
// @ts-ignore TODO
|
|
14
16
|
extensions[name] = gl.getExtension(name) || null;
|
|
15
17
|
}
|
|
18
|
+
// @ts-ignore TODO
|
|
16
19
|
return extensions[name];
|
|
17
20
|
}
|
|
@@ -32,16 +32,19 @@ export function setGLParameters(gl: WebGL2RenderingContext, parameters: GLParame
|
|
|
32
32
|
|
|
33
33
|
for (const key in parameters) {
|
|
34
34
|
const glConstant = Number(key);
|
|
35
|
+
// @ts-ignore TODO
|
|
35
36
|
const setter = GL_PARAMETER_SETTERS[key];
|
|
36
37
|
if (setter) {
|
|
37
38
|
// Composite setters should only be called once, so save them
|
|
38
39
|
if (typeof setter === 'string') {
|
|
40
|
+
// @ts-ignore TODO
|
|
39
41
|
compositeSetters[setter] = true;
|
|
40
42
|
} else {
|
|
41
43
|
// if (gl[glConstant] !== undefined) {
|
|
42
44
|
// TODO - added above check since this is being called on WebGL2 parameters in WebGL1...
|
|
43
45
|
// TODO - deep equal on values? only call setter if value has changed?
|
|
44
46
|
// NOTE - the setter will automatically update this.state
|
|
47
|
+
// @ts-ignore TODO
|
|
45
48
|
setter(gl, parameters[key], glConstant);
|
|
46
49
|
}
|
|
47
50
|
}
|
|
@@ -59,6 +62,7 @@ export function setGLParameters(gl: WebGL2RenderingContext, parameters: GLParame
|
|
|
59
62
|
if (cache) {
|
|
60
63
|
for (const key in compositeSetters) {
|
|
61
64
|
// TODO - avoid calling composite setters if values have not changed.
|
|
65
|
+
// @ts-ignore TODO
|
|
62
66
|
const compositeSetter = GL_COMPOSITE_PARAMETER_SETTERS[key];
|
|
63
67
|
// Note - if `trackContextState` has been called,
|
|
64
68
|
// the setter will automatically update this.state.cache
|
|
@@ -92,15 +96,18 @@ export function getGLParameters(
|
|
|
92
96
|
if (typeof parameters === 'number') {
|
|
93
97
|
// single GL enum
|
|
94
98
|
const key = parameters;
|
|
99
|
+
// @ts-ignore TODO
|
|
95
100
|
const getter = GL_PARAMETER_GETTERS[key];
|
|
96
101
|
return getter ? getter(gl, key) : gl.getParameter(key);
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
const parameterKeys = Array.isArray(parameters) ? parameters : Object.keys(parameters);
|
|
100
105
|
|
|
101
|
-
const state = {};
|
|
106
|
+
const state: GLParameters = {};
|
|
102
107
|
for (const key of parameterKeys) {
|
|
108
|
+
// @ts-ignore TODO
|
|
103
109
|
const getter = GL_PARAMETER_GETTERS[key];
|
|
110
|
+
// @ts-ignore TODO
|
|
104
111
|
state[key] = getter ? getter(gl, Number(key)) : gl.getParameter(Number(key));
|
|
105
112
|
}
|
|
106
113
|
return state;
|
|
@@ -119,7 +126,7 @@ export function resetGLParameters(gl: WebGL2RenderingContext): void {
|
|
|
119
126
|
// Helpers
|
|
120
127
|
|
|
121
128
|
// Returns true if given object is empty, false otherwise.
|
|
122
|
-
function isObjectEmpty(object) {
|
|
129
|
+
function isObjectEmpty(object: Record<string, unknown>): boolean {
|
|
123
130
|
// @ts-ignore dummy key variable
|
|
124
131
|
for (const key in object) {
|
|
125
132
|
return false;
|
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import {TypedArray} from '@luma.gl/core';
|
|
6
|
+
|
|
5
7
|
/** deeply compare two arrays */
|
|
6
|
-
export function deepArrayEqual(
|
|
8
|
+
export function deepArrayEqual(
|
|
9
|
+
x: unknown | unknown[] | TypedArray,
|
|
10
|
+
y: unknown | unknown[] | TypedArray
|
|
11
|
+
): boolean {
|
|
7
12
|
if (x === y) {
|
|
8
13
|
return true;
|
|
9
14
|
}
|
|
10
|
-
|
|
11
|
-
const isArrayY = Array.isArray(y) || ArrayBuffer.isView(y);
|
|
12
|
-
// @ts-expect-error TODO fix
|
|
13
|
-
if (isArrayX && isArrayY && x.length === y.length) {
|
|
14
|
-
// @ts-expect-error TODO fix
|
|
15
|
+
if (isArray(x) && isArray(y) && x.length === y.length) {
|
|
15
16
|
for (let i = 0; i < x.length; ++i) {
|
|
16
17
|
if (x[i] !== y[i]) {
|
|
17
18
|
return false;
|
|
@@ -21,3 +22,7 @@ export function deepArrayEqual(x: any, y: any): boolean {
|
|
|
21
22
|
}
|
|
22
23
|
return false;
|
|
23
24
|
}
|
|
25
|
+
|
|
26
|
+
function isArray(x: unknown): x is unknown[] {
|
|
27
|
+
return Array.isArray(x) || ArrayBuffer.isView(x);
|
|
28
|
+
}
|