@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
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
5
|
+
import type {TypedArray, NumericArray} from '@math.gl/types';
|
|
6
|
+
import type {Device, Buffer, VertexArrayProps} from '@luma.gl/core';
|
|
7
|
+
import {VertexArray, getScratchArray} from '@luma.gl/core';
|
|
7
8
|
import {GL} from '@luma.gl/constants';
|
|
8
9
|
import {getBrowser} from '@probe.gl/env';
|
|
9
10
|
|
|
@@ -11,7 +12,7 @@ import {WebGLDevice} from '../webgl-device';
|
|
|
11
12
|
import {WEBGLBuffer} from '../resources/webgl-buffer';
|
|
12
13
|
|
|
13
14
|
import {getGLFromVertexType} from '../converters/vertex-formats';
|
|
14
|
-
|
|
15
|
+
import {fillArray} from '../../utils/fill-array';
|
|
15
16
|
|
|
16
17
|
/** VertexArrayObject wrapper */
|
|
17
18
|
export class WEBGLVertexArray extends VertexArray {
|
|
@@ -32,10 +33,10 @@ export class WEBGLVertexArray extends VertexArray {
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
// Create a VertexArray
|
|
35
|
-
constructor(device: WebGLDevice, props
|
|
36
|
+
constructor(device: WebGLDevice, props: VertexArrayProps) {
|
|
36
37
|
super(device, props);
|
|
37
38
|
this.device = device;
|
|
38
|
-
this.handle = this.device.gl.createVertexArray()
|
|
39
|
+
this.handle = this.device.gl.createVertexArray()!;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
override destroy(): void {
|
|
@@ -252,7 +253,7 @@ export class WEBGLVertexArray extends VertexArray {
|
|
|
252
253
|
* TODO - convert Arrays based on known type? (read type from accessor, don't assume Float32Array)
|
|
253
254
|
* TODO - handle single values for size 1 attributes?
|
|
254
255
|
*/
|
|
255
|
-
function normalizeConstantArrayValue(arrayValue:
|
|
256
|
+
function normalizeConstantArrayValue(arrayValue: NumericArray) {
|
|
256
257
|
if (Array.isArray(arrayValue)) {
|
|
257
258
|
return new Float32Array(arrayValue);
|
|
258
259
|
}
|
|
@@ -262,7 +263,7 @@ function normalizeConstantArrayValue(arrayValue: NumberArray) {
|
|
|
262
263
|
/**
|
|
263
264
|
*
|
|
264
265
|
*/
|
|
265
|
-
function compareConstantArrayValues(v1:
|
|
266
|
+
function compareConstantArrayValues(v1: NumericArray, v2: NumericArray): boolean {
|
|
266
267
|
if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
|
|
267
268
|
return false;
|
|
268
269
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Adapter, Device, DeviceProps, CanvasContext, log} from '@luma.gl/core';
|
|
6
|
+
import {WebGLDevice} from './webgl-device';
|
|
7
|
+
import {enforceWebGL2} from '../context/polyfills/polyfill-webgl1-extensions';
|
|
8
|
+
import {loadSpectorJS, DEFAULT_SPECTOR_PROPS} from '../context/debug/spector';
|
|
9
|
+
import {loadWebGLDeveloperTools} from '../context/debug/webgl-developer-tools';
|
|
10
|
+
|
|
11
|
+
const LOG_LEVEL = 1;
|
|
12
|
+
|
|
13
|
+
export class WebGLAdapter extends Adapter {
|
|
14
|
+
/** type of device's created by this adapter */
|
|
15
|
+
readonly type: Device['type'] = 'webgl';
|
|
16
|
+
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
|
|
20
|
+
// Add spector default props to device default props, so that runtime settings are observed
|
|
21
|
+
Device.defaultProps = {...Device.defaultProps, ...DEFAULT_SPECTOR_PROPS};
|
|
22
|
+
|
|
23
|
+
// @ts-ignore DEPRECATED For backwards compatibility luma.registerDevices
|
|
24
|
+
WebGLDevice.adapter = this;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Check if WebGL 2 is available */
|
|
28
|
+
isSupported(): boolean {
|
|
29
|
+
return typeof WebGL2RenderingContext !== 'undefined';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Force any created WebGL contexts to be WebGL2 contexts, polyfilled with WebGL1 extensions */
|
|
33
|
+
enforceWebGL2(enable: boolean): void {
|
|
34
|
+
enforceWebGL2(enable);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Get a device instance from a GL context
|
|
39
|
+
* Creates and instruments the device if not already created
|
|
40
|
+
* @param gl
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
async attach(gl: Device | WebGL2RenderingContext): Promise<WebGLDevice> {
|
|
44
|
+
if (gl instanceof WebGLDevice) {
|
|
45
|
+
return gl;
|
|
46
|
+
}
|
|
47
|
+
// @ts-expect-error
|
|
48
|
+
if (gl?.device instanceof Device) {
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
return gl.device as WebGLDevice;
|
|
51
|
+
}
|
|
52
|
+
if (!isWebGL(gl)) {
|
|
53
|
+
throw new Error('Invalid WebGL2RenderingContext');
|
|
54
|
+
}
|
|
55
|
+
return new WebGLDevice({gl: gl as WebGL2RenderingContext});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async create(props: DeviceProps = {}): Promise<WebGLDevice> {
|
|
59
|
+
log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created')();
|
|
60
|
+
|
|
61
|
+
const promises: Promise<unknown>[] = [];
|
|
62
|
+
|
|
63
|
+
// Load webgl and spector debug scripts from CDN if requested
|
|
64
|
+
if (props.debug) {
|
|
65
|
+
promises.push(loadWebGLDeveloperTools());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (props.debugWithSpectorJS) {
|
|
69
|
+
promises.push(loadSpectorJS(props));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Wait for page to load: if canvas is a string we need to query the DOM for the canvas element.
|
|
73
|
+
// We only wait when props.canvas is string to avoids setting the global page onload callback unless necessary.
|
|
74
|
+
if (typeof props.canvas === 'string') {
|
|
75
|
+
promises.push(CanvasContext.pageLoaded);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Wait for all the loads to settle before creating the context.
|
|
79
|
+
// The Device.create() functions are async, so in contrast to the constructor, we can `await` here.
|
|
80
|
+
const results = await Promise.allSettled(promises);
|
|
81
|
+
for (const result of results) {
|
|
82
|
+
if (result.status === 'rejected') {
|
|
83
|
+
log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
log.probe(LOG_LEVEL + 1, 'DOM is loaded')();
|
|
88
|
+
|
|
89
|
+
const device = new WebGLDevice(props);
|
|
90
|
+
|
|
91
|
+
// Log some debug info about the newly created context
|
|
92
|
+
const message = `\
|
|
93
|
+
Created ${device.type}${device.debug ? ' debug' : ''} context: \
|
|
94
|
+
${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
95
|
+
log.probe(LOG_LEVEL, message)();
|
|
96
|
+
log.table(LOG_LEVEL, device.info)();
|
|
97
|
+
|
|
98
|
+
log.groupEnd(LOG_LEVEL)();
|
|
99
|
+
|
|
100
|
+
return device;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Check if supplied parameter is a WebGL2RenderingContext */
|
|
105
|
+
function isWebGL(gl: any): boolean {
|
|
106
|
+
if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
// Look for debug contexts, headless gl etc
|
|
110
|
+
return Boolean(gl && Number.isFinite(gl._version));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const webgl2Adapter = new WebGLAdapter();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {CanvasContextProps} from '@luma.gl/core';
|
|
5
|
+
import type {CanvasContextProps, TextureFormat} 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,6 +12,9 @@ import {WEBGLFramebuffer} from './resources/webgl-framebuffer';
|
|
|
12
12
|
*/
|
|
13
13
|
export class WebGLCanvasContext extends CanvasContext {
|
|
14
14
|
readonly device: WebGLDevice;
|
|
15
|
+
readonly format: TextureFormat = 'rgba8unorm';
|
|
16
|
+
readonly depthStencilFormat: TextureFormat = 'depth24plus';
|
|
17
|
+
|
|
15
18
|
presentationSize: [number, number];
|
|
16
19
|
private _framebuffer: WEBGLFramebuffer | null = null;
|
|
17
20
|
|
|
@@ -2,37 +2,26 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
TextureFormat,
|
|
10
|
-
VertexArray,
|
|
11
|
-
VertexArrayProps,
|
|
12
|
-
Framebuffer,
|
|
13
|
-
Buffer,
|
|
14
|
-
Texture,
|
|
15
|
-
TypedArray
|
|
16
|
-
} from '@luma.gl/core';
|
|
17
|
-
import {Device, CanvasContext, log, uid, assert} from '@luma.gl/core';
|
|
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';
|
|
18
9
|
import type {GLExtensions} from '@luma.gl/constants';
|
|
19
|
-
import {
|
|
20
|
-
popContextState,
|
|
21
|
-
pushContextState,
|
|
22
|
-
trackContextState
|
|
23
|
-
} from '../context/state-tracker/track-context-state';
|
|
10
|
+
import {WebGLStateTracker} from '../context/state-tracker/webgl-state-tracker';
|
|
24
11
|
import {createBrowserContext} from '../context/helpers/create-browser-context';
|
|
25
12
|
import {getDeviceInfo} from './device-helpers/webgl-device-info';
|
|
26
13
|
import {WebGLDeviceFeatures} from './device-helpers/webgl-device-features';
|
|
27
14
|
import {WebGLDeviceLimits} from './device-helpers/webgl-device-limits';
|
|
28
15
|
import {WebGLCanvasContext} from './webgl-canvas-context';
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
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';
|
|
31
19
|
import {
|
|
32
20
|
isTextureFormatSupported,
|
|
33
21
|
isTextureFormatRenderable,
|
|
34
22
|
isTextureFormatFilterable
|
|
35
23
|
} from './converters/texture-formats';
|
|
24
|
+
import {uid} from '../utils/uid';
|
|
36
25
|
|
|
37
26
|
// WebGL classes
|
|
38
27
|
import type {
|
|
@@ -80,17 +69,12 @@ import {withGLParameters} from '../context/state-tracker/with-parameters';
|
|
|
80
69
|
import {clear} from '../classic/clear';
|
|
81
70
|
import {getWebGLExtension} from '../context/helpers/webgl-extensions';
|
|
82
71
|
|
|
83
|
-
const LOG_LEVEL = 1;
|
|
84
|
-
|
|
85
72
|
/** WebGPU style Device API for a WebGL context */
|
|
86
73
|
export class WebGLDevice extends Device {
|
|
87
74
|
//
|
|
88
75
|
// Public `Device` API
|
|
89
76
|
//
|
|
90
77
|
|
|
91
|
-
/** type of this device */
|
|
92
|
-
static readonly type: string = 'webgl';
|
|
93
|
-
|
|
94
78
|
/** type of this device */
|
|
95
79
|
readonly type = 'webgl';
|
|
96
80
|
|
|
@@ -106,86 +90,19 @@ export class WebGLDevice extends Device {
|
|
|
106
90
|
|
|
107
91
|
private _resolveContextLost?: (value: {reason: 'destroyed'; message: string}) => void;
|
|
108
92
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
/** Check if WebGL 2 is available */
|
|
114
|
-
static isSupported(): boolean {
|
|
115
|
-
return typeof WebGL2RenderingContext !== 'undefined';
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Get a device instance from a GL context
|
|
120
|
-
* Creates and instruments the device if not already created
|
|
121
|
-
* @param gl
|
|
122
|
-
* @returns
|
|
123
|
-
*/
|
|
124
|
-
static attach(gl: Device | WebGL2RenderingContext): WebGLDevice {
|
|
125
|
-
if (gl instanceof WebGLDevice) {
|
|
126
|
-
return gl;
|
|
127
|
-
}
|
|
128
|
-
// @ts-expect-error
|
|
129
|
-
if (gl?.device instanceof Device) {
|
|
130
|
-
// @ts-expect-error
|
|
131
|
-
return gl.device as WebGLDevice;
|
|
132
|
-
}
|
|
133
|
-
if (!isWebGL(gl)) {
|
|
134
|
-
throw new Error('Invalid WebGL2RenderingContext');
|
|
135
|
-
}
|
|
136
|
-
return new WebGLDevice({gl: gl as WebGL2RenderingContext});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
static async create(props: DeviceProps = {}): Promise<WebGLDevice> {
|
|
140
|
-
log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created')();
|
|
141
|
-
|
|
142
|
-
const promises: Promise<unknown>[] = [];
|
|
143
|
-
|
|
144
|
-
// Load webgl and spector debug scripts from CDN if requested
|
|
145
|
-
if (props.debug) {
|
|
146
|
-
promises.push(loadWebGLDeveloperTools());
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (props.spector) {
|
|
150
|
-
promises.push(loadSpectorJS());
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Wait for page to load: if canvas is a string we need to query the DOM for the canvas element.
|
|
154
|
-
// We only wait when props.canvas is string to avoids setting the global page onload callback unless necessary.
|
|
155
|
-
if (typeof props.canvas === 'string') {
|
|
156
|
-
promises.push(CanvasContext.pageLoaded);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Wait for all the loads to settle before creating the context.
|
|
160
|
-
// The Device.create() functions are async, so in contrast to the constructor, we can `await` here.
|
|
161
|
-
const results = await Promise.allSettled(promises);
|
|
162
|
-
for (const result of results) {
|
|
163
|
-
if (result.status === 'rejected') {
|
|
164
|
-
log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
log.probe(LOG_LEVEL + 1, 'DOM is loaded')();
|
|
169
|
-
|
|
170
|
-
// @ts-expect-error
|
|
171
|
-
if (props.gl?.device) {
|
|
172
|
-
log.warn('reattaching existing device')();
|
|
173
|
-
return WebGLDevice.attach(props.gl);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const device = new WebGLDevice(props);
|
|
93
|
+
/** WebGL2 context. */
|
|
94
|
+
readonly gl: WebGL2RenderingContext;
|
|
95
|
+
readonly debug: boolean = false;
|
|
177
96
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
Created ${device.type}${device.debug ? ' debug' : ''} context: \
|
|
181
|
-
${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
182
|
-
log.probe(LOG_LEVEL, message)();
|
|
183
|
-
log.table(LOG_LEVEL, device.info)();
|
|
97
|
+
/** State used by luma.gl classes: TODO - move to canvasContext*/
|
|
98
|
+
readonly _canvasSizeInfo = {clientWidth: 0, clientHeight: 0, devicePixelRatio: 1};
|
|
184
99
|
|
|
185
|
-
|
|
100
|
+
/** State used by luma.gl classes - TODO - not used? */
|
|
101
|
+
readonly _extensions: GLExtensions = {};
|
|
102
|
+
_polyfilled: boolean = false;
|
|
186
103
|
|
|
187
|
-
|
|
188
|
-
|
|
104
|
+
/** Instance of Spector.js (if initialized) */
|
|
105
|
+
spectorJS: Spector;
|
|
189
106
|
|
|
190
107
|
//
|
|
191
108
|
// Public API
|
|
@@ -209,8 +126,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
209
126
|
this._resolveContextLost = resolve;
|
|
210
127
|
});
|
|
211
128
|
|
|
212
|
-
|
|
213
|
-
gl ||= createBrowserContext(this.canvasContext.canvas, {
|
|
129
|
+
this.handle = createBrowserContext(this.canvasContext.canvas, {
|
|
214
130
|
...props,
|
|
215
131
|
onContextLost: (event: Event) =>
|
|
216
132
|
this._resolveContextLost?.({
|
|
@@ -218,22 +134,22 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
218
134
|
message: 'Entered sleep mode, or too many apps or browser tabs are using the GPU.'
|
|
219
135
|
})
|
|
220
136
|
});
|
|
137
|
+
this.gl = this.handle;
|
|
221
138
|
|
|
222
|
-
if (!
|
|
139
|
+
if (!this.handle) {
|
|
223
140
|
throw new Error('WebGL context creation failed');
|
|
224
141
|
}
|
|
225
142
|
|
|
226
|
-
|
|
227
|
-
|
|
143
|
+
// Add spector debug instrumentation to context
|
|
144
|
+
// We need to trust spector integration to decide if spector should be initialized
|
|
145
|
+
// We also run spector instrumentation first, otherwise spector can clobber luma instrumentation.
|
|
146
|
+
this.spectorJS = initializeSpectorJS({...this.props, gl: this.handle});
|
|
228
147
|
|
|
148
|
+
// Instrument context
|
|
229
149
|
(this.gl as any).device = this; // Update GL context: Link webgl context back to device
|
|
230
150
|
(this.gl as any)._version = 2; // Update GL context: Store WebGL version field on gl context (HACK to identify debug contexts)
|
|
231
151
|
|
|
232
|
-
|
|
233
|
-
this.spectorJS = initializeSpectorJS({...this.props, canvas: this.handle.canvas});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// luma Device fields
|
|
152
|
+
// initialize luma Device fields
|
|
237
153
|
this.info = getDeviceInfo(this.gl, this._extensions);
|
|
238
154
|
this.limits = new WebGLDeviceLimits(this.gl);
|
|
239
155
|
this.features = new WebGLDeviceFeatures(this.gl, this._extensions, this.props.disabledFeatures);
|
|
@@ -244,15 +160,12 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
244
160
|
this.canvasContext.resize();
|
|
245
161
|
|
|
246
162
|
// Install context state tracking
|
|
247
|
-
|
|
248
|
-
const {enable = true, copyState = false} = props;
|
|
249
|
-
trackContextState(this.gl, {
|
|
250
|
-
enable,
|
|
251
|
-
copyState,
|
|
163
|
+
const glState = new WebGLStateTracker(this.gl, {
|
|
252
164
|
log: (...args: any[]) => log.log(1, ...args)()
|
|
253
165
|
});
|
|
166
|
+
glState.trackState(this.gl, {copyState: false});
|
|
254
167
|
|
|
255
|
-
// DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1
|
|
168
|
+
// DEBUG contexts: Add luma debug instrumentation to the context, force log level to at least 1
|
|
256
169
|
if (props.debug) {
|
|
257
170
|
this.gl = makeDebugContext(this.gl, {...props, throwOnError: true});
|
|
258
171
|
this.debug = true;
|
|
@@ -271,10 +184,6 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
271
184
|
return this.gl.isContextLost();
|
|
272
185
|
}
|
|
273
186
|
|
|
274
|
-
getSize(): [number, number] {
|
|
275
|
-
return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];
|
|
276
|
-
}
|
|
277
|
-
|
|
278
187
|
isTextureFormatSupported(format: TextureFormat): boolean {
|
|
279
188
|
return isTextureFormatSupported(this.gl, format, this._extensions);
|
|
280
189
|
}
|
|
@@ -298,7 +207,8 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
298
207
|
return new WEBGLBuffer(this, newProps);
|
|
299
208
|
}
|
|
300
209
|
|
|
301
|
-
_createTexture(props: TextureProps): WEBGLTexture {
|
|
210
|
+
// _createTexture(props: TextureProps): WEBGLTexture {
|
|
211
|
+
_createTexture(props: TextureProps): Texture {
|
|
302
212
|
return new WEBGLTexture(this, props);
|
|
303
213
|
}
|
|
304
214
|
|
|
@@ -348,7 +258,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
348
258
|
|
|
349
259
|
private renderPass: WEBGLRenderPass | null = null;
|
|
350
260
|
|
|
351
|
-
override createCommandEncoder(props
|
|
261
|
+
override createCommandEncoder(props: CommandEncoderProps = {}): WEBGLCommandEncoder {
|
|
352
262
|
return new WEBGLCommandEncoder(this, props);
|
|
353
263
|
}
|
|
354
264
|
|
|
@@ -433,20 +343,6 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
433
343
|
// WebGL-only API (not part of `Device` API)
|
|
434
344
|
//
|
|
435
345
|
|
|
436
|
-
/** WebGL2 context. */
|
|
437
|
-
readonly gl: WebGL2RenderingContext;
|
|
438
|
-
readonly debug: boolean = false;
|
|
439
|
-
|
|
440
|
-
/** State used by luma.gl classes: TODO - move to canvasContext*/
|
|
441
|
-
readonly _canvasSizeInfo = {clientWidth: 0, clientHeight: 0, devicePixelRatio: 1};
|
|
442
|
-
|
|
443
|
-
/** State used by luma.gl classes - TODO - not used? */
|
|
444
|
-
readonly _extensions: GLExtensions = {};
|
|
445
|
-
_polyfilled: boolean = false;
|
|
446
|
-
|
|
447
|
-
/** Instance of Spector.js (if initialized) */
|
|
448
|
-
spectorJS: unknown;
|
|
449
|
-
|
|
450
346
|
/**
|
|
451
347
|
* Triggers device (or WebGL context) loss.
|
|
452
348
|
* @note primarily intended for testing how application reacts to device loss
|
|
@@ -469,12 +365,14 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
469
365
|
|
|
470
366
|
/** Save current WebGL context state onto an internal stack */
|
|
471
367
|
pushState(): void {
|
|
472
|
-
|
|
368
|
+
const webglState = WebGLStateTracker.get(this.gl);
|
|
369
|
+
webglState.push();
|
|
473
370
|
}
|
|
474
371
|
|
|
475
372
|
/** Restores previously saved context state */
|
|
476
373
|
popState(): void {
|
|
477
|
-
|
|
374
|
+
const webglState = WebGLStateTracker.get(this.gl);
|
|
375
|
+
webglState.pop();
|
|
478
376
|
}
|
|
479
377
|
|
|
480
378
|
/**
|
|
@@ -538,7 +436,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
538
436
|
setConstantUintArray(this, location, constant as Uint32Array);
|
|
539
437
|
break;
|
|
540
438
|
default:
|
|
541
|
-
|
|
439
|
+
throw new Error('constant');
|
|
542
440
|
}
|
|
543
441
|
}
|
|
544
442
|
|
|
@@ -549,15 +447,6 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
549
447
|
}
|
|
550
448
|
}
|
|
551
449
|
|
|
552
|
-
/** Check if supplied parameter is a WebGL2RenderingContext */
|
|
553
|
-
function isWebGL(gl: any): boolean {
|
|
554
|
-
if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
|
|
555
|
-
return true;
|
|
556
|
-
}
|
|
557
|
-
// Look for debug contexts, headless gl etc
|
|
558
|
-
return Boolean(gl && Number.isFinite(gl._version));
|
|
559
|
-
}
|
|
560
|
-
|
|
561
450
|
/** Set constant float array attribute */
|
|
562
451
|
function setConstantFloatArray(device: WebGLDevice, location: number, array: Float32Array): void {
|
|
563
452
|
switch (array.length) {
|
|
@@ -574,7 +463,7 @@ function setConstantFloatArray(device: WebGLDevice, location: number, array: Flo
|
|
|
574
463
|
device.gl.vertexAttrib4fv(location, array);
|
|
575
464
|
break;
|
|
576
465
|
default:
|
|
577
|
-
|
|
466
|
+
// assert(false);
|
|
578
467
|
}
|
|
579
468
|
}
|
|
580
469
|
|
package/src/classic/accessor.ts
CHANGED
|
@@ -2,10 +2,39 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {Buffer} from '@luma.gl/core';
|
|
6
6
|
import {GL} from '@luma.gl/constants';
|
|
7
7
|
import {getTypedArrayFromGLType} from './typed-array-utils';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Attribute descriptor object
|
|
11
|
+
* @deprecated Use ShaderLayout
|
|
12
|
+
*/
|
|
13
|
+
export interface AccessorObject {
|
|
14
|
+
buffer?: Buffer;
|
|
15
|
+
// format: VertexFormat;
|
|
16
|
+
offset?: number;
|
|
17
|
+
// can now be described with single WebGPU-style `format` string
|
|
18
|
+
|
|
19
|
+
//
|
|
20
|
+
stride?: number;
|
|
21
|
+
|
|
22
|
+
/** @deprecated - Use accessor.stepMode */
|
|
23
|
+
divisor?: number;
|
|
24
|
+
|
|
25
|
+
/** @deprecated - Infer from format */
|
|
26
|
+
type?: number;
|
|
27
|
+
/** @deprecated - Infer from format */
|
|
28
|
+
size?: number;
|
|
29
|
+
/** @deprecated - Infer from format */
|
|
30
|
+
normalized?: boolean;
|
|
31
|
+
/** @deprecated - Infer from format */
|
|
32
|
+
integer?: boolean;
|
|
33
|
+
|
|
34
|
+
/** @deprecated */
|
|
35
|
+
index?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
9
38
|
const DEFAULT_ACCESSOR_VALUES = {
|
|
10
39
|
offset: 0,
|
|
11
40
|
stride: 0,
|
|
@@ -16,13 +45,6 @@ const DEFAULT_ACCESSOR_VALUES = {
|
|
|
16
45
|
integer: false
|
|
17
46
|
};
|
|
18
47
|
|
|
19
|
-
const PROP_CHECKS = {
|
|
20
|
-
deprecatedProps: {
|
|
21
|
-
instanced: 'divisor',
|
|
22
|
-
isInstanced: 'divisor'
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
48
|
export class Accessor implements AccessorObject {
|
|
27
49
|
offset?: number;
|
|
28
50
|
stride?: number;
|
|
@@ -43,7 +65,7 @@ export class Accessor implements AccessorObject {
|
|
|
43
65
|
}
|
|
44
66
|
|
|
45
67
|
static getBytesPerVertex(accessor: AccessorObject): number {
|
|
46
|
-
assert(accessor.size);
|
|
68
|
+
// assert(accessor.size);
|
|
47
69
|
// TODO: using `FLOAT` when type is not specified,
|
|
48
70
|
// ensure this assumption is valid or force API to specify type.
|
|
49
71
|
const ArrayType = getTypedArrayFromGLType(accessor.type || GL.FLOAT);
|
|
@@ -82,8 +104,6 @@ export class Accessor implements AccessorObject {
|
|
|
82
104
|
|
|
83
105
|
// eslint-disable-next-line complexity, max-statements
|
|
84
106
|
_assign(props: AccessorObject = {}): this {
|
|
85
|
-
props = checkProps('Accessor', props, PROP_CHECKS);
|
|
86
|
-
|
|
87
107
|
if (props.type !== undefined) {
|
|
88
108
|
this.type = props.type;
|
|
89
109
|
|
package/src/classic/clear.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {Device, Framebuffer
|
|
5
|
+
import {Device, Framebuffer} from '@luma.gl/core';
|
|
6
6
|
import {WebGLDevice} from '../adapter/webgl-device';
|
|
7
7
|
import {withGLParameters} from '../context/state-tracker/with-parameters';
|
|
8
8
|
|
|
@@ -16,9 +16,6 @@ const GL_DEPTH = 0x1801;
|
|
|
16
16
|
const GL_STENCIL = 0x1802;
|
|
17
17
|
const GL_DEPTH_STENCIL = 0x84f9;
|
|
18
18
|
|
|
19
|
-
// Should disappear if asserts are removed
|
|
20
|
-
const ERR_ARGUMENTS = 'clear: bad arguments';
|
|
21
|
-
|
|
22
19
|
/**
|
|
23
20
|
* Optionally clears depth, color and stencil buffers
|
|
24
21
|
* @deprecated Set clear color when creating a RenderPass.
|
|
@@ -57,7 +54,7 @@ export function clear(
|
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
56
|
|
|
60
|
-
assert(clearFlags !== 0, ERR_ARGUMENTS);
|
|
57
|
+
// assert(clearFlags !== 0, ERR_ARGUMENTS);
|
|
61
58
|
|
|
62
59
|
// Temporarily set any clear "colors" and call clear
|
|
63
60
|
const gl = (device as WebGLDevice).gl;
|
|
@@ -112,7 +109,7 @@ export function clearBuffer(
|
|
|
112
109
|
break;
|
|
113
110
|
|
|
114
111
|
default:
|
|
115
|
-
|
|
112
|
+
// assert(false, ERR_ARGUMENTS);
|
|
116
113
|
}
|
|
117
114
|
});
|
|
118
115
|
}
|