@luma.gl/webgl 9.1.0-alpha.9 → 9.1.0-beta.3
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/converters/device-parameters.js +1 -0
- package/dist/adapter/converters/device-parameters.js.map +1 -0
- package/dist/adapter/converters/sampler-parameters.js +7 -4
- package/dist/adapter/converters/sampler-parameters.js.map +1 -0
- package/dist/adapter/converters/shader-formats.js +1 -0
- package/dist/adapter/converters/shader-formats.js.map +1 -0
- package/dist/adapter/converters/vertex-formats.js +1 -0
- package/dist/adapter/converters/vertex-formats.js.map +1 -0
- package/dist/adapter/converters/webgl-texture-table.d.ts +40 -0
- package/dist/adapter/converters/webgl-texture-table.d.ts.map +1 -0
- package/dist/adapter/converters/webgl-texture-table.js +304 -0
- package/dist/adapter/converters/webgl-texture-table.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 +2 -2
- package/dist/adapter/device-helpers/webgl-device-features.js.map +1 -0
- package/dist/adapter/device-helpers/webgl-device-info.js +1 -0
- package/dist/adapter/device-helpers/webgl-device-info.js.map +1 -0
- package/dist/adapter/device-helpers/webgl-device-limits.js +1 -0
- package/dist/adapter/device-helpers/webgl-device-limits.js.map +1 -0
- package/dist/adapter/helpers/decode-webgl-types.js +1 -0
- package/dist/adapter/helpers/decode-webgl-types.js.map +1 -0
- package/dist/adapter/helpers/format-utils.d.ts.map +1 -0
- package/dist/{classic → adapter/helpers}/format-utils.js +7 -0
- package/dist/adapter/helpers/format-utils.js.map +1 -0
- package/dist/adapter/helpers/get-shader-layout.d.ts +1 -1
- package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-shader-layout.js +5 -4
- package/dist/adapter/helpers/get-shader-layout.js.map +1 -0
- package/dist/adapter/helpers/parse-shader-compiler-log.js +1 -0
- package/dist/adapter/helpers/parse-shader-compiler-log.js.map +1 -0
- package/dist/adapter/helpers/set-uniform.js +1 -0
- package/dist/adapter/helpers/set-uniform.js.map +1 -0
- package/dist/adapter/helpers/typed-array-utils.d.ts.map +1 -0
- package/dist/{classic → adapter/helpers}/typed-array-utils.js +1 -0
- package/dist/adapter/helpers/typed-array-utils.js.map +1 -0
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +96 -25
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.js +225 -236
- package/dist/adapter/helpers/webgl-texture-utils.js.map +1 -0
- package/dist/adapter/helpers/webgl-topology-utils.js +1 -0
- package/dist/adapter/helpers/webgl-topology-utils.js.map +1 -0
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +4 -1
- package/dist/adapter/resources/webgl-buffer.js.map +1 -0
- package/dist/adapter/resources/webgl-command-buffer.d.ts +59 -2
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +89 -32
- package/dist/adapter/resources/webgl-command-buffer.js.map +1 -0
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +4 -0
- package/dist/adapter/resources/webgl-command-encoder.js.map +1 -0
- package/dist/adapter/resources/webgl-external-texture.js +15 -0
- package/dist/adapter/resources/webgl-external-texture.js.map +1 -0
- package/dist/adapter/resources/webgl-framebuffer.d.ts +33 -35
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +70 -75
- package/dist/adapter/resources/webgl-framebuffer.js.map +1 -0
- package/dist/adapter/resources/webgl-query-set.js +1 -0
- package/dist/adapter/resources/webgl-query-set.js.map +1 -0
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +33 -18
- package/dist/adapter/resources/webgl-render-pass.js.map +1 -0
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +3 -4
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +44 -22
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -0
- package/dist/adapter/resources/webgl-sampler.js +1 -0
- package/dist/adapter/resources/webgl-sampler.js.map +1 -0
- 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 +13 -6
- package/dist/adapter/resources/webgl-shader.js.map +1 -0
- package/dist/adapter/resources/webgl-texture-view.js +1 -0
- package/dist/adapter/resources/webgl-texture-view.js.map +1 -0
- package/dist/adapter/resources/webgl-texture.d.ts +32 -20
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +163 -218
- package/dist/adapter/resources/webgl-texture.js.map +1 -0
- package/dist/adapter/resources/webgl-transform-feedback.js +1 -0
- package/dist/adapter/resources/webgl-transform-feedback.js.map +1 -0
- package/dist/adapter/resources/webgl-vertex-array.js +1 -0
- package/dist/adapter/resources/webgl-vertex-array.js.map +1 -0
- package/dist/adapter/webgl-adapter.d.ts.map +1 -1
- package/dist/adapter/webgl-adapter.js +5 -10
- package/dist/adapter/webgl-adapter.js.map +1 -0
- package/dist/adapter/webgl-canvas-context.d.ts +4 -6
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +13 -17
- package/dist/adapter/webgl-canvas-context.js.map +1 -0
- package/dist/adapter/webgl-device.d.ts +20 -19
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +75 -51
- package/dist/adapter/webgl-device.js.map +1 -0
- package/dist/context/debug/spector-types.js +2 -1
- package/dist/context/debug/spector-types.js.map +1 -0
- 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 +7 -6
- package/dist/context/debug/spector.js.map +1 -0
- package/dist/context/debug/webgl-developer-tools.d.ts +2 -3
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +7 -19
- package/dist/context/debug/webgl-developer-tools.js.map +1 -0
- 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 +41 -32
- package/dist/context/helpers/create-browser-context.js.map +1 -0
- package/dist/context/helpers/webgl-context-data.js +1 -0
- package/dist/context/helpers/webgl-context-data.js.map +1 -0
- package/dist/context/helpers/webgl-extensions.js +1 -0
- package/dist/context/helpers/webgl-extensions.js.map +1 -0
- package/dist/context/parameters/unified-parameter-api.js +1 -0
- package/dist/context/parameters/unified-parameter-api.js.map +1 -0
- 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 +3 -2
- package/dist/context/parameters/webgl-parameter-tables.js.map +1 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.js +1 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.js.map +1 -0
- package/dist/context/state-tracker/deep-array-equal.js +1 -0
- package/dist/context/state-tracker/deep-array-equal.js.map +1 -0
- package/dist/context/state-tracker/webgl-state-tracker.js +1 -0
- package/dist/context/state-tracker/webgl-state-tracker.js.map +1 -0
- package/dist/context/state-tracker/with-parameters.js +1 -0
- package/dist/context/state-tracker/with-parameters.js.map +1 -0
- package/dist/deprecated/accessor.d.ts.map +1 -0
- package/dist/{classic → deprecated}/accessor.js +37 -1
- package/dist/deprecated/accessor.js.map +1 -0
- package/dist/dist.dev.js +2234 -2373
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +2124 -2256
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/fill-array.d.ts +4 -4
- package/dist/utils/fill-array.d.ts.map +1 -1
- package/dist/utils/fill-array.js +1 -0
- package/dist/utils/fill-array.js.map +1 -0
- package/dist/utils/load-script.js +1 -0
- package/dist/utils/load-script.js.map +1 -0
- package/dist/utils/split-uniforms-and-bindings.d.ts +1 -1
- package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/utils/split-uniforms-and-bindings.js +1 -0
- package/dist/utils/split-uniforms-and-bindings.js.map +1 -0
- package/dist/utils/uid.js +1 -0
- package/dist/utils/uid.js.map +1 -0
- package/package.json +5 -5
- package/src/adapter/converters/device-parameters.ts +3 -3
- package/src/adapter/converters/sampler-parameters.ts +6 -4
- package/src/adapter/converters/webgl-texture-table.ts +404 -0
- package/src/adapter/device-helpers/webgl-device-features.ts +5 -2
- package/src/{classic → adapter/helpers}/format-utils.ts +6 -0
- package/src/adapter/helpers/get-shader-layout.ts +7 -4
- package/src/adapter/helpers/webgl-texture-utils.ts +400 -57
- package/src/adapter/resources/webgl-buffer.ts +3 -1
- package/src/adapter/resources/webgl-command-buffer.ts +125 -41
- package/src/adapter/resources/webgl-command-encoder.ts +6 -0
- package/src/adapter/resources/webgl-external-texture.ts +14 -0
- package/src/adapter/resources/webgl-framebuffer.ts +79 -85
- package/src/adapter/resources/webgl-render-pass.ts +56 -42
- package/src/adapter/resources/webgl-render-pipeline.ts +56 -26
- package/src/adapter/resources/webgl-shader.ts +15 -7
- package/src/adapter/resources/webgl-texture.ts +188 -250
- package/src/adapter/webgl-adapter.ts +4 -12
- package/src/adapter/webgl-canvas-context.ts +16 -19
- package/src/adapter/webgl-device.ts +125 -88
- 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 +8 -31
- package/src/context/helpers/create-browser-context.ts +53 -63
- package/src/context/parameters/webgl-parameter-tables.ts +2 -2
- package/src/{classic → deprecated}/accessor.ts +44 -3
- package/src/index.ts +2 -5
- package/src/utils/fill-array.ts +4 -4
- package/src/utils/split-uniforms-and-bindings.ts +3 -3
- package/dist/adapter/converters/texture-formats.d.ts +0 -83
- package/dist/adapter/converters/texture-formats.d.ts.map +0 -1
- package/dist/adapter/converters/texture-formats.js +0 -511
- package/dist/classic/accessor.d.ts.map +0 -1
- package/dist/classic/clear.d.ts +0 -22
- package/dist/classic/clear.d.ts.map +0 -1
- package/dist/classic/clear.js +0 -86
- package/dist/classic/copy-and-blit.d.ts +0 -64
- package/dist/classic/copy-and-blit.d.ts.map +0 -1
- package/dist/classic/copy-and-blit.js +0 -194
- package/dist/classic/format-utils.d.ts.map +0 -1
- package/dist/classic/typed-array-utils.d.ts.map +0 -1
- package/src/adapter/converters/texture-formats.ts +0 -657
- package/src/classic/clear.ts +0 -115
- package/src/classic/copy-and-blit.ts +0 -323
- /package/dist/{classic → adapter/helpers}/format-utils.d.ts +0 -0
- /package/dist/{classic → adapter/helpers}/typed-array-utils.d.ts +0 -0
- /package/dist/{classic → deprecated}/accessor.d.ts +0 -0
- /package/src/{classic → adapter/helpers}/typed-array-utils.ts +0 -0
|
@@ -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,38 +12,31 @@ 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
|
|
|
19
|
+
get [Symbol.toStringTag](): string {
|
|
20
|
+
return 'WebGLCanvasContext';
|
|
21
|
+
}
|
|
22
|
+
|
|
21
23
|
constructor(device: WebGLDevice, props: CanvasContextProps) {
|
|
22
24
|
// Note: Base class creates / looks up the canvas (unless under Node.js)
|
|
23
25
|
super(props);
|
|
24
26
|
this.device = device;
|
|
25
|
-
|
|
27
|
+
|
|
28
|
+
// Base class constructor cannot access derived methods/fields, so we need to call these functions in the subclass constructor
|
|
26
29
|
this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
|
|
27
|
-
this.
|
|
30
|
+
this.updateSize([this.drawingBufferWidth, this.drawingBufferHeight]);
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
getCurrentFramebuffer(): WEBGLFramebuffer {
|
|
31
|
-
this.update();
|
|
32
34
|
// Setting handle to null returns a reference to the default framebuffer
|
|
33
35
|
this._framebuffer = this._framebuffer || new WEBGLFramebuffer(this.device, {handle: null});
|
|
34
36
|
return this._framebuffer;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
update() {
|
|
39
|
-
const size = this.getPixelSize();
|
|
40
|
-
const sizeChanged =
|
|
41
|
-
size[0] !== this.presentationSize[0] || size[1] !== this.presentationSize[1];
|
|
42
|
-
if (sizeChanged) {
|
|
43
|
-
this.presentationSize = size;
|
|
44
|
-
this.resize();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
39
|
+
updateSize(size: [number, number]): void {}
|
|
47
40
|
|
|
48
41
|
/**
|
|
49
42
|
* Resize the canvas' drawing buffer.
|
|
@@ -60,10 +53,14 @@ export class WebGLCanvasContext extends CanvasContext {
|
|
|
60
53
|
resize(options?: {width?: number; height?: number; useDevicePixels?: boolean | number}): void {
|
|
61
54
|
if (!this.device.gl) return;
|
|
62
55
|
|
|
63
|
-
|
|
56
|
+
if (this.props.autoResize) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Resize browser context. TODO - this likely needs to be rewritten
|
|
64
61
|
if (this.canvas) {
|
|
65
62
|
const devicePixelRatio = this.getDevicePixelRatio(options?.useDevicePixels);
|
|
66
|
-
this.
|
|
63
|
+
this._setDevicePixelRatio(devicePixelRatio, options);
|
|
67
64
|
return;
|
|
68
65
|
}
|
|
69
66
|
}
|
|
@@ -3,28 +3,16 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {TypedArray} from '@math.gl/types';
|
|
6
|
-
import type {DeviceProps, DeviceInfo, CanvasContextProps, TextureFormat} from '@luma.gl/core';
|
|
7
|
-
import type {Buffer, Texture, Framebuffer, VertexArray, VertexArrayProps} from '@luma.gl/core';
|
|
8
|
-
import {Device, CanvasContext, log} from '@luma.gl/core';
|
|
9
|
-
import type {GLExtensions} from '@luma.gl/constants';
|
|
10
|
-
import {WebGLStateTracker} from '../context/state-tracker/webgl-state-tracker';
|
|
11
|
-
import {createBrowserContext} from '../context/helpers/create-browser-context';
|
|
12
|
-
import {getDeviceInfo} from './device-helpers/webgl-device-info';
|
|
13
|
-
import {WebGLDeviceFeatures} from './device-helpers/webgl-device-features';
|
|
14
|
-
import {WebGLDeviceLimits} from './device-helpers/webgl-device-limits';
|
|
15
|
-
import {WebGLCanvasContext} from './webgl-canvas-context';
|
|
16
|
-
import type {Spector} from '../context/debug/spector-types';
|
|
17
|
-
import {initializeSpectorJS} from '../context/debug/spector';
|
|
18
|
-
import {makeDebugContext} from '../context/debug/webgl-developer-tools';
|
|
19
|
-
import {
|
|
20
|
-
isTextureFormatSupported,
|
|
21
|
-
isTextureFormatRenderable,
|
|
22
|
-
isTextureFormatFilterable
|
|
23
|
-
} from './converters/texture-formats';
|
|
24
|
-
import {uid} from '../utils/uid';
|
|
25
|
-
|
|
26
|
-
// WebGL classes
|
|
27
6
|
import type {
|
|
7
|
+
DeviceProps,
|
|
8
|
+
DeviceInfo,
|
|
9
|
+
DeviceTextureFormatCapabilities,
|
|
10
|
+
CanvasContextProps,
|
|
11
|
+
Buffer,
|
|
12
|
+
Texture,
|
|
13
|
+
Framebuffer,
|
|
14
|
+
VertexArray,
|
|
15
|
+
VertexArrayProps,
|
|
28
16
|
BufferProps,
|
|
29
17
|
ShaderProps,
|
|
30
18
|
// Sampler,
|
|
@@ -44,8 +32,22 @@ import type {
|
|
|
44
32
|
// CommandEncoder,
|
|
45
33
|
CommandEncoderProps,
|
|
46
34
|
TransformFeedbackProps,
|
|
47
|
-
QuerySetProps
|
|
35
|
+
QuerySetProps,
|
|
36
|
+
Resource
|
|
48
37
|
} from '@luma.gl/core';
|
|
38
|
+
import {Device, CanvasContext, log} from '@luma.gl/core';
|
|
39
|
+
import type {GLExtensions} from '@luma.gl/constants';
|
|
40
|
+
import {WebGLStateTracker} from '../context/state-tracker/webgl-state-tracker';
|
|
41
|
+
import {createBrowserContext} from '../context/helpers/create-browser-context';
|
|
42
|
+
import {getDeviceInfo} from './device-helpers/webgl-device-info';
|
|
43
|
+
import {WebGLDeviceFeatures} from './device-helpers/webgl-device-features';
|
|
44
|
+
import {WebGLDeviceLimits} from './device-helpers/webgl-device-limits';
|
|
45
|
+
import {WebGLCanvasContext} from './webgl-canvas-context';
|
|
46
|
+
import type {Spector} from '../context/debug/spector-types';
|
|
47
|
+
import {initializeSpectorJS} from '../context/debug/spector';
|
|
48
|
+
import {makeDebugContext} from '../context/debug/webgl-developer-tools';
|
|
49
|
+
import {getTextureFormatCapabilitiesWebGL} from './converters/webgl-texture-table';
|
|
50
|
+
import {uid} from '../utils/uid';
|
|
49
51
|
|
|
50
52
|
import {WEBGLBuffer} from './resources/webgl-buffer';
|
|
51
53
|
import {WEBGLShader} from './resources/webgl-shader';
|
|
@@ -59,21 +61,18 @@ import {WEBGLVertexArray} from './resources/webgl-vertex-array';
|
|
|
59
61
|
import {WEBGLTransformFeedback} from './resources/webgl-transform-feedback';
|
|
60
62
|
import {WEBGLQuerySet} from './resources/webgl-query-set';
|
|
61
63
|
|
|
62
|
-
import {readPixelsToArray, readPixelsToBuffer} from '
|
|
64
|
+
import {readPixelsToArray, readPixelsToBuffer} from './helpers/webgl-texture-utils';
|
|
63
65
|
import {
|
|
64
66
|
setGLParameters,
|
|
65
67
|
getGLParameters,
|
|
66
68
|
resetGLParameters
|
|
67
69
|
} from '../context/parameters/unified-parameter-api';
|
|
68
70
|
import {withGLParameters} from '../context/state-tracker/with-parameters';
|
|
69
|
-
import {clear} from '../classic/clear';
|
|
70
71
|
import {getWebGLExtension} from '../context/helpers/webgl-extensions';
|
|
71
72
|
|
|
72
73
|
/** WebGPU style Device API for a WebGL context */
|
|
73
74
|
export class WebGLDevice extends Device {
|
|
74
|
-
//
|
|
75
75
|
// Public `Device` API
|
|
76
|
-
//
|
|
77
76
|
|
|
78
77
|
/** type of this device */
|
|
79
78
|
readonly type = 'webgl';
|
|
@@ -82,10 +81,12 @@ export class WebGLDevice extends Device {
|
|
|
82
81
|
readonly handle: WebGL2RenderingContext;
|
|
83
82
|
features: WebGLDeviceFeatures;
|
|
84
83
|
limits: WebGLDeviceLimits;
|
|
85
|
-
|
|
86
84
|
readonly info: DeviceInfo;
|
|
87
85
|
readonly canvasContext: WebGLCanvasContext;
|
|
88
86
|
|
|
87
|
+
readonly preferredColorFormat = 'rgba8unorm';
|
|
88
|
+
readonly preferredDepthFormat = 'depth24plus';
|
|
89
|
+
|
|
89
90
|
readonly lost: Promise<{reason: 'destroyed'; message: string}>;
|
|
90
91
|
|
|
91
92
|
private _resolveContextLost?: (value: {reason: 'destroyed'; message: string}) => void;
|
|
@@ -111,35 +112,62 @@ export class WebGLDevice extends Device {
|
|
|
111
112
|
constructor(props: DeviceProps) {
|
|
112
113
|
super({...props, id: props.id || uid('webgl-device')});
|
|
113
114
|
|
|
115
|
+
// WebGL requires a canvas to be created before creating the context
|
|
116
|
+
if (!props.createCanvasContext) {
|
|
117
|
+
throw new Error('WebGLDevice requires props.createCanvasContext to be set');
|
|
118
|
+
}
|
|
119
|
+
const canvasContextProps = props.createCanvasContext === true ? {} : props.createCanvasContext;
|
|
120
|
+
|
|
114
121
|
// If attaching to an already attached context, return the attached device
|
|
115
122
|
// @ts-expect-error device is attached to context
|
|
116
|
-
|
|
123
|
+
let device: WebGLDevice | undefined = canvasContextProps.canvas?.gl?.device;
|
|
117
124
|
if (device) {
|
|
118
125
|
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
119
126
|
}
|
|
120
127
|
|
|
121
128
|
// Create and instrument context
|
|
122
|
-
|
|
123
|
-
this.canvasContext = new WebGLCanvasContext(this, {...props, canvas});
|
|
129
|
+
this.canvasContext = new WebGLCanvasContext(this, canvasContextProps);
|
|
124
130
|
|
|
125
131
|
this.lost = new Promise<{reason: 'destroyed'; message: string}>(resolve => {
|
|
126
132
|
this._resolveContextLost = resolve;
|
|
127
133
|
});
|
|
128
134
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
this.gl = this.handle;
|
|
135
|
+
const webglContextAttributes: WebGLContextAttributes = {...props.webgl};
|
|
136
|
+
// Copy props from CanvasContextProps
|
|
137
|
+
if (canvasContextProps.alphaMode === 'premultiplied') {
|
|
138
|
+
webglContextAttributes.premultipliedAlpha = true;
|
|
139
|
+
}
|
|
140
|
+
if (props.powerPreference !== undefined) {
|
|
141
|
+
webglContextAttributes.powerPreference = props.powerPreference;
|
|
142
|
+
}
|
|
138
143
|
|
|
139
|
-
|
|
144
|
+
const gl = createBrowserContext(
|
|
145
|
+
this.canvasContext.canvas,
|
|
146
|
+
{
|
|
147
|
+
onContextLost: (event: Event) =>
|
|
148
|
+
this._resolveContextLost?.({
|
|
149
|
+
reason: 'destroyed',
|
|
150
|
+
message: 'Entered sleep mode, or too many apps or browser tabs are using the GPU.'
|
|
151
|
+
}),
|
|
152
|
+
// eslint-disable-next-line no-console
|
|
153
|
+
onContextRestored: (event: Event) => console.log('WebGL context restored')
|
|
154
|
+
},
|
|
155
|
+
webglContextAttributes
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
if (!gl) {
|
|
140
159
|
throw new Error('WebGL context creation failed');
|
|
141
160
|
}
|
|
142
161
|
|
|
162
|
+
// @ts-expect-error device is attached to context
|
|
163
|
+
device = gl.device;
|
|
164
|
+
if (device) {
|
|
165
|
+
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
this.handle = gl;
|
|
169
|
+
this.gl = gl;
|
|
170
|
+
|
|
143
171
|
// Add spector debug instrumentation to context
|
|
144
172
|
// We need to trust spector integration to decide if spector should be initialized
|
|
145
173
|
// We also run spector instrumentation first, otherwise spector can clobber luma instrumentation.
|
|
@@ -152,13 +180,15 @@ export class WebGLDevice extends Device {
|
|
|
152
180
|
// initialize luma Device fields
|
|
153
181
|
this.info = getDeviceInfo(this.gl, this._extensions);
|
|
154
182
|
this.limits = new WebGLDeviceLimits(this.gl);
|
|
155
|
-
this.features = new WebGLDeviceFeatures(
|
|
156
|
-
|
|
183
|
+
this.features = new WebGLDeviceFeatures(
|
|
184
|
+
this.gl,
|
|
185
|
+
this._extensions,
|
|
186
|
+
this.props._disabledFeatures
|
|
187
|
+
);
|
|
188
|
+
if (this.props._initializeFeatures) {
|
|
157
189
|
this.features.initializeFeatures();
|
|
158
190
|
}
|
|
159
191
|
|
|
160
|
-
this.canvasContext.resize();
|
|
161
|
-
|
|
162
192
|
// Install context state tracking
|
|
163
193
|
const glState = new WebGLStateTracker(this.gl, {
|
|
164
194
|
log: (...args: any[]) => log.log(1, ...args)()
|
|
@@ -166,11 +196,14 @@ export class WebGLDevice extends Device {
|
|
|
166
196
|
glState.trackState(this.gl, {copyState: false});
|
|
167
197
|
|
|
168
198
|
// DEBUG contexts: Add luma debug instrumentation to the context, force log level to at least 1
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
199
|
+
const debugWebGL = props.debugWebGL || props.debug;
|
|
200
|
+
const traceWebGL = props.debugWebGL;
|
|
201
|
+
if (debugWebGL) {
|
|
202
|
+
this.gl = makeDebugContext(this.gl, {debugWebGL, traceWebGL});
|
|
173
203
|
log.warn('WebGL debug mode activated. Performance reduced.')();
|
|
204
|
+
if (props.debugWebGL) {
|
|
205
|
+
log.level = Math.max(log.level, 1);
|
|
206
|
+
}
|
|
174
207
|
}
|
|
175
208
|
}
|
|
176
209
|
|
|
@@ -184,18 +217,6 @@ export class WebGLDevice extends Device {
|
|
|
184
217
|
return this.gl.isContextLost();
|
|
185
218
|
}
|
|
186
219
|
|
|
187
|
-
isTextureFormatSupported(format: TextureFormat): boolean {
|
|
188
|
-
return isTextureFormatSupported(this.gl, format, this._extensions);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
isTextureFormatFilterable(format: TextureFormat): boolean {
|
|
192
|
-
return isTextureFormatFilterable(this.gl, format, this._extensions);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
isTextureFormatRenderable(format: TextureFormat): boolean {
|
|
196
|
-
return isTextureFormatRenderable(this.gl, format, this._extensions);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
220
|
// IMPLEMENTATION OF ABSTRACT DEVICE
|
|
200
221
|
|
|
201
222
|
createCanvasContext(props?: CanvasContextProps): CanvasContext {
|
|
@@ -203,12 +224,11 @@ export class WebGLDevice extends Device {
|
|
|
203
224
|
}
|
|
204
225
|
|
|
205
226
|
createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): WEBGLBuffer {
|
|
206
|
-
const newProps = this.
|
|
227
|
+
const newProps = this._normalizeBufferProps(props);
|
|
207
228
|
return new WEBGLBuffer(this, newProps);
|
|
208
229
|
}
|
|
209
230
|
|
|
210
|
-
|
|
211
|
-
_createTexture(props: TextureProps): Texture {
|
|
231
|
+
createTexture(props: TextureProps): WEBGLTexture {
|
|
212
232
|
return new WEBGLTexture(this, props);
|
|
213
233
|
}
|
|
214
234
|
|
|
@@ -325,20 +345,17 @@ export class WebGLDevice extends Device {
|
|
|
325
345
|
return withGLParameters(this.gl, parameters, func);
|
|
326
346
|
}
|
|
327
347
|
|
|
328
|
-
override clearWebGL(options?: {
|
|
329
|
-
framebuffer?: Framebuffer;
|
|
330
|
-
color?: any;
|
|
331
|
-
depth?: any;
|
|
332
|
-
stencil?: any;
|
|
333
|
-
}): void {
|
|
334
|
-
clear(this, options);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
348
|
override resetWebGL(): void {
|
|
338
349
|
log.warn('WebGLDevice.resetWebGL is deprecated, use only for debugging')();
|
|
339
350
|
resetGLParameters(this.gl);
|
|
340
351
|
}
|
|
341
352
|
|
|
353
|
+
override _getDeviceSpecificTextureFormatCapabilities(
|
|
354
|
+
capabilities: DeviceTextureFormatCapabilities
|
|
355
|
+
): DeviceTextureFormatCapabilities {
|
|
356
|
+
return getTextureFormatCapabilitiesWebGL(this.gl, capabilities, this._extensions);
|
|
357
|
+
}
|
|
358
|
+
|
|
342
359
|
//
|
|
343
360
|
// WebGL-only API (not part of `Device` API)
|
|
344
361
|
//
|
|
@@ -375,33 +392,33 @@ export class WebGLDevice extends Device {
|
|
|
375
392
|
webglState.pop();
|
|
376
393
|
}
|
|
377
394
|
|
|
378
|
-
/**
|
|
379
|
-
* Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
|
|
380
|
-
* luma.gl ids and props can be inspected
|
|
381
|
-
*/
|
|
382
|
-
setSpectorMetadata(handle: unknown, props: Record<string, unknown>) {
|
|
383
|
-
// @ts-expect-error
|
|
384
|
-
// eslint-disable-next-line camelcase
|
|
385
|
-
handle.__SPECTOR_Metadata = props;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
395
|
/**
|
|
389
396
|
* Returns the GL.<KEY> constant that corresponds to a numeric value of a GL constant
|
|
390
397
|
* Be aware that there are some duplicates especially for constants that are 0,
|
|
391
398
|
* so this isn't guaranteed to return the right key in all cases.
|
|
392
399
|
*/
|
|
393
|
-
getGLKey(value: unknown,
|
|
394
|
-
// @ts-ignore expect-error depends on settings
|
|
395
|
-
gl = gl || this.gl2 || this.gl;
|
|
400
|
+
getGLKey(value: unknown, options?: {emptyIfUnknown?: boolean}): string {
|
|
396
401
|
const number = Number(value);
|
|
397
|
-
for (const key in gl) {
|
|
402
|
+
for (const key in this.gl) {
|
|
398
403
|
// @ts-ignore expect-error depends on settings
|
|
399
|
-
if (gl[key] === number) {
|
|
404
|
+
if (this.gl[key] === number) {
|
|
400
405
|
return `GL.${key}`;
|
|
401
406
|
}
|
|
402
407
|
}
|
|
403
408
|
// No constant found. Stringify the value and return it.
|
|
404
|
-
return String(value);
|
|
409
|
+
return options?.emptyIfUnknown ? '' : String(value);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Returns a map with any GL.<KEY> constants mapped to strings, both for keys and values
|
|
414
|
+
*/
|
|
415
|
+
getGLKeys(glParameters: Record<number, unknown>): Record<string, string> {
|
|
416
|
+
const opts = {emptyIfUnknown: true};
|
|
417
|
+
return Object.entries(glParameters).reduce<Record<string, string>>((keys, [key, value]) => {
|
|
418
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
419
|
+
keys[`${key}:${this.getGLKey(key, opts)}`] = `${value}:${this.getGLKey(value, opts)}`;
|
|
420
|
+
return keys;
|
|
421
|
+
}, {});
|
|
405
422
|
}
|
|
406
423
|
|
|
407
424
|
/** Store constants */
|
|
@@ -445,6 +462,26 @@ export class WebGLDevice extends Device {
|
|
|
445
462
|
getWebGLExtension(this.gl, name, this._extensions);
|
|
446
463
|
return this._extensions;
|
|
447
464
|
}
|
|
465
|
+
|
|
466
|
+
// INTERNAL SUPPORT METHODS FOR WEBGL RESOURCES
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
|
|
470
|
+
* luma.gl ids and props can be inspected
|
|
471
|
+
*/
|
|
472
|
+
_setWebGLDebugMetadata(
|
|
473
|
+
handle: unknown,
|
|
474
|
+
resource: Resource<any>,
|
|
475
|
+
options: {spector: Record<string, unknown>}
|
|
476
|
+
): void {
|
|
477
|
+
// @ts-expect-error
|
|
478
|
+
handle.luma = resource;
|
|
479
|
+
|
|
480
|
+
const spectorMetadata = {props: options.spector, id: options.spector.id};
|
|
481
|
+
// @ts-expect-error
|
|
482
|
+
// eslint-disable-next-line camelcase
|
|
483
|
+
handle.__SPECTOR_Metadata = spectorMetadata;
|
|
484
|
+
}
|
|
448
485
|
}
|
|
449
486
|
|
|
450
487
|
/** Set constant float array attribute */
|
|
@@ -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,10 @@ 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
|
-
|
|
16
|
-
break?: string[];
|
|
14
|
+
debugWebGL?: boolean;
|
|
15
|
+
traceWebGL?: boolean;
|
|
17
16
|
};
|
|
18
17
|
|
|
19
|
-
// const DEFAULT_DEBUG_CONTEXT_PROPS: Required<DebugContextProps> = {
|
|
20
|
-
// debug: true,
|
|
21
|
-
// throwOnError: false,
|
|
22
|
-
// break: [],
|
|
23
|
-
// webgl2: false,
|
|
24
|
-
// }
|
|
25
|
-
|
|
26
18
|
type ContextData = {
|
|
27
19
|
realContext?: WebGL2RenderingContext;
|
|
28
20
|
debugContext?: WebGL2RenderingContext;
|
|
@@ -60,7 +52,7 @@ export function makeDebugContext(
|
|
|
60
52
|
gl: WebGL2RenderingContext,
|
|
61
53
|
props: DebugContextProps = {}
|
|
62
54
|
): WebGL2RenderingContext {
|
|
63
|
-
return props.
|
|
55
|
+
return props.debugWebGL || props.traceWebGL ? getDebugContext(gl, props) : getRealContext(gl);
|
|
64
56
|
}
|
|
65
57
|
|
|
66
58
|
// Returns the real context from either of the real/debug contexts
|
|
@@ -136,9 +128,7 @@ function onGLError(props: DebugContextProps, err, functionName: string, args: an
|
|
|
136
128
|
const message = `${errorMessage} in gl.${functionName}(${functionArgs})`;
|
|
137
129
|
log.error(message)();
|
|
138
130
|
debugger; // eslint-disable-line
|
|
139
|
-
|
|
140
|
-
throw new Error(message);
|
|
141
|
-
}
|
|
131
|
+
// throw new Error(message);
|
|
142
132
|
}
|
|
143
133
|
|
|
144
134
|
// Don't generate function string until it is needed
|
|
@@ -150,29 +140,16 @@ function onValidateGLFunc(
|
|
|
150
140
|
let functionString: string = '';
|
|
151
141
|
if (log.level >= 1) {
|
|
152
142
|
functionString = getFunctionString(functionName, functionArgs);
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
|
143
|
+
if (props.traceWebGL) {
|
|
144
|
+
log.log(1, functionString)();
|
|
164
145
|
}
|
|
165
146
|
}
|
|
166
147
|
|
|
167
148
|
for (const arg of functionArgs) {
|
|
168
149
|
if (arg === undefined) {
|
|
169
150
|
functionString = functionString || getFunctionString(functionName, functionArgs);
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
} else {
|
|
173
|
-
log.error(`Undefined argument: ${functionString}`)();
|
|
174
|
-
debugger; // eslint-disable-line
|
|
175
|
-
}
|
|
151
|
+
debugger; // eslint-disable-line
|
|
152
|
+
// throw new Error(`Undefined argument: ${functionString}`);
|
|
176
153
|
}
|
|
177
154
|
}
|
|
178
155
|
}
|