@luma.gl/webgl 9.0.0-beta.5 → 9.0.0-beta.7
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 +128 -71
- package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/sampler-parameters.js +20 -19
- package/dist/adapter/converters/shader-formats.d.ts.map +1 -1
- package/dist/adapter/converters/shader-formats.js +40 -20
- package/dist/adapter/converters/texture-formats.d.ts +16 -11
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +224 -205
- package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
- package/dist/adapter/converters/vertex-formats.js +22 -21
- package/dist/adapter/device-helpers/webgl-device-features.d.ts +19 -5
- package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-features.js +89 -43
- package/dist/adapter/device-helpers/webgl-device-info.d.ts +2 -1
- package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-info.js +22 -19
- package/dist/adapter/device-helpers/webgl-device-limits.d.ts +33 -48
- package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-limits.js +42 -87
- package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -1
- package/dist/adapter/helpers/decode-webgl-types.js +47 -46
- package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-shader-layout.js +35 -34
- package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
- package/dist/adapter/helpers/parse-shader-compiler-log.js +3 -2
- package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
- package/dist/adapter/helpers/set-uniform.js +42 -41
- package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.js +40 -39
- package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
- package/dist/adapter/objects/constants-to-keys.js +2 -1
- package/dist/adapter/objects/webgl-renderbuffer.d.ts +2 -2
- package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-renderbuffer.js +30 -17
- package/dist/adapter/objects/webgl-resource.d.ts +2 -24
- package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-resource.js +6 -101
- package/dist/adapter/resources/webgl-buffer.d.ts +1 -1
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +16 -15
- package/dist/adapter/resources/webgl-command-buffer.d.ts +1 -1
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +32 -31
- package/dist/adapter/resources/webgl-command-encoder.d.ts +8 -3
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +4 -2
- package/dist/adapter/resources/webgl-external-texture.js +6 -5
- package/dist/adapter/resources/webgl-framebuffer.d.ts +6 -10
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +60 -53
- package/dist/adapter/resources/webgl-query-set.d.ts +44 -0
- package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -0
- package/dist/adapter/resources/webgl-query-set.js +136 -0
- package/dist/adapter/resources/webgl-render-pass.d.ts +3 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +20 -12
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +4 -5
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +52 -61
- package/dist/adapter/resources/webgl-sampler.d.ts +1 -1
- package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-sampler.js +5 -4
- package/dist/adapter/resources/webgl-shader.d.ts +3 -2
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +15 -9
- package/dist/adapter/resources/webgl-texture-view.d.ts +14 -0
- package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -0
- package/dist/adapter/resources/webgl-texture-view.js +18 -0
- package/dist/adapter/resources/webgl-texture.d.ts +6 -4
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +39 -32
- 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 +10 -10
- package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -3
- package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +10 -9
- package/dist/adapter/webgl-canvas-context.d.ts +2 -2
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +3 -2
- package/dist/adapter/webgl-device.d.ts +35 -30
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +110 -109
- package/dist/classic/accessor.d.ts.map +1 -1
- package/dist/classic/accessor.js +8 -7
- package/dist/classic/clear.d.ts.map +1 -1
- package/dist/classic/clear.js +5 -4
- package/dist/classic/copy-and-blit.d.ts +1 -1
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +19 -19
- package/dist/classic/format-utils.d.ts.map +1 -1
- package/dist/classic/format-utils.js +16 -15
- package/dist/classic/typed-array-utils.d.ts.map +1 -1
- package/dist/classic/typed-array-utils.js +20 -19
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +2 -1
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +7 -6
- package/dist/context/{context → helpers}/create-browser-context.d.ts.map +1 -1
- package/dist/context/{context → helpers}/create-browser-context.js +2 -1
- package/dist/context/{context/context-data.d.ts → helpers/webgl-context-data.d.ts} +2 -3
- package/dist/context/helpers/webgl-context-data.d.ts.map +1 -0
- package/dist/context/helpers/webgl-context-data.js +21 -0
- package/dist/context/helpers/webgl-extensions.d.ts +4 -0
- package/dist/context/helpers/webgl-extensions.d.ts.map +1 -0
- package/dist/context/helpers/webgl-extensions.js +10 -0
- package/dist/context/parameters/unified-parameter-api.d.ts +3 -4
- package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
- package/dist/context/parameters/unified-parameter-api.js +7 -11
- package/dist/context/parameters/webgl-parameter-tables.d.ts +12 -13
- package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js +302 -295
- package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
- package/dist/context/state-tracker/deep-array-equal.js +2 -1
- package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
- package/dist/context/state-tracker/track-context-state.js +5 -4
- package/dist/context/state-tracker/with-parameters.d.ts +2 -3
- package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
- package/dist/context/state-tracker/with-parameters.js +6 -8
- package/dist/dist.dev.js +1635 -1387
- package/dist/index.cjs +1766 -1534
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +25 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -23
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -1
- package/dist.min.js +6 -6
- package/package.json +4 -4
- package/src/adapter/converters/device-parameters.ts +114 -27
- package/src/adapter/converters/sampler-parameters.ts +12 -3
- package/src/adapter/converters/shader-formats.ts +47 -22
- package/src/adapter/converters/texture-formats.ts +138 -114
- package/src/adapter/converters/vertex-formats.ts +3 -3
- package/src/adapter/device-helpers/webgl-device-features.ts +102 -50
- package/src/adapter/device-helpers/webgl-device-info.ts +28 -19
- package/src/adapter/device-helpers/webgl-device-limits.ts +46 -150
- package/src/adapter/helpers/decode-webgl-types.ts +13 -7
- package/src/adapter/helpers/get-shader-layout.ts +4 -3
- package/src/adapter/helpers/parse-shader-compiler-log.ts +10 -6
- package/src/adapter/helpers/set-uniform.ts +2 -1
- package/src/adapter/helpers/webgl-topology-utils.ts +10 -3
- package/src/adapter/objects/constants-to-keys.ts +2 -1
- package/src/adapter/objects/webgl-renderbuffer.ts +36 -14
- package/src/adapter/objects/webgl-resource.ts +7 -125
- package/src/adapter/resources/webgl-buffer.ts +4 -3
- package/src/adapter/resources/webgl-command-buffer.ts +5 -5
- package/src/adapter/resources/webgl-command-encoder.ts +14 -11
- package/src/adapter/resources/webgl-external-texture.ts +6 -5
- package/src/adapter/resources/webgl-framebuffer.ts +61 -53
- package/src/adapter/resources/webgl-query-set.ts +171 -0
- package/src/adapter/resources/webgl-render-pass.ts +20 -11
- package/src/adapter/resources/webgl-render-pipeline.ts +54 -54
- package/src/adapter/resources/webgl-sampler.ts +2 -1
- package/src/adapter/resources/webgl-shader.ts +12 -5
- package/src/adapter/resources/webgl-texture-view.ts +28 -0
- package/src/adapter/resources/webgl-texture.ts +14 -3
- package/src/adapter/resources/webgl-transform-feedback.ts +2 -7
- package/src/adapter/resources/webgl-vertex-array.ts +4 -3
- package/src/adapter/webgl-canvas-context.ts +6 -4
- package/src/adapter/webgl-device.ts +116 -107
- package/src/classic/accessor.ts +5 -4
- package/src/classic/clear.ts +14 -8
- package/src/classic/copy-and-blit.ts +11 -4
- package/src/classic/format-utils.ts +2 -1
- package/src/classic/typed-array-utils.ts +3 -7
- package/src/context/debug/spector.ts +9 -6
- package/src/context/debug/webgl-developer-tools.ts +27 -14
- package/src/context/{context → helpers}/create-browser-context.ts +3 -2
- package/src/context/helpers/webgl-context-data.ts +31 -0
- package/src/context/helpers/webgl-extensions.ts +17 -0
- package/src/context/parameters/unified-parameter-api.ts +6 -17
- package/src/context/parameters/webgl-parameter-tables.ts +69 -32
- package/src/context/state-tracker/deep-array-equal.ts +2 -1
- package/src/context/state-tracker/track-context-state.ts +11 -6
- package/src/context/state-tracker/with-parameters.ts +8 -8
- package/src/index.ts +7 -6
- package/src/types.ts +2 -1
- package/dist/adapter/device-helpers/device-features.d.ts +0 -6
- package/dist/adapter/device-helpers/device-features.d.ts.map +0 -1
- package/dist/adapter/device-helpers/device-features.js +0 -65
- package/dist/adapter/device-helpers/device-limits.d.ts +0 -50
- package/dist/adapter/device-helpers/device-limits.d.ts.map +0 -1
- package/dist/adapter/device-helpers/device-limits.js +0 -92
- package/dist/adapter/device-helpers/get-device-info.d.ts +0 -4
- package/dist/adapter/device-helpers/get-device-info.d.ts.map +0 -1
- package/dist/adapter/device-helpers/get-device-info.js +0 -87
- package/dist/context/context/context-data.d.ts.map +0 -1
- package/dist/context/context/context-data.js +0 -33
- package/src/context/context/context-data.ts +0 -44
- /package/dist/context/{context → helpers}/create-browser-context.d.ts +0 -0
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import type {
|
|
5
6
|
DeviceProps,
|
|
6
7
|
DeviceInfo,
|
|
7
|
-
DeviceLimits,
|
|
8
|
-
DeviceFeature,
|
|
9
8
|
CanvasContextProps,
|
|
10
9
|
TextureFormat,
|
|
11
10
|
VertexArray,
|
|
@@ -16,16 +15,16 @@ import type {
|
|
|
16
15
|
TypedArray
|
|
17
16
|
} from '@luma.gl/core';
|
|
18
17
|
import {Device, CanvasContext, log, uid, assert} from '@luma.gl/core';
|
|
19
|
-
import {
|
|
18
|
+
import type {GLExtensions} from '@luma.gl/constants';
|
|
20
19
|
import {
|
|
21
20
|
popContextState,
|
|
22
21
|
pushContextState,
|
|
23
22
|
trackContextState
|
|
24
23
|
} from '../context/state-tracker/track-context-state';
|
|
25
|
-
import {createBrowserContext} from '../context/
|
|
24
|
+
import {createBrowserContext} from '../context/helpers/create-browser-context';
|
|
26
25
|
import {getDeviceInfo} from './device-helpers/webgl-device-info';
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
26
|
+
import {WebGLDeviceFeatures} from './device-helpers/webgl-device-features';
|
|
27
|
+
import {WebGLDeviceLimits} from './device-helpers/webgl-device-limits';
|
|
29
28
|
import {WebGLCanvasContext} from './webgl-canvas-context';
|
|
30
29
|
import {loadSpectorJS, initializeSpectorJS} from '../context/debug/spector';
|
|
31
30
|
import {loadWebGLDeveloperTools, makeDebugContext} from '../context/debug/webgl-developer-tools';
|
|
@@ -55,7 +54,8 @@ import type {
|
|
|
55
54
|
ComputePassProps,
|
|
56
55
|
// CommandEncoder,
|
|
57
56
|
CommandEncoderProps,
|
|
58
|
-
TransformFeedbackProps
|
|
57
|
+
TransformFeedbackProps,
|
|
58
|
+
QuerySetProps
|
|
59
59
|
} from '@luma.gl/core';
|
|
60
60
|
|
|
61
61
|
import {WEBGLBuffer} from './resources/webgl-buffer';
|
|
@@ -68,11 +68,13 @@ import {WEBGLRenderPipeline} from './resources/webgl-render-pipeline';
|
|
|
68
68
|
import {WEBGLCommandEncoder} from './resources/webgl-command-encoder';
|
|
69
69
|
import {WEBGLVertexArray} from './resources/webgl-vertex-array';
|
|
70
70
|
import {WEBGLTransformFeedback} from './resources/webgl-transform-feedback';
|
|
71
|
+
import {WEBGLQuerySet} from './resources/webgl-query-set';
|
|
71
72
|
|
|
72
73
|
import {readPixelsToArray, readPixelsToBuffer} from '../classic/copy-and-blit';
|
|
73
74
|
import {setGLParameters, getGLParameters} from '../context/parameters/unified-parameter-api';
|
|
74
75
|
import {withGLParameters} from '../context/state-tracker/with-parameters';
|
|
75
76
|
import {clear} from '../classic/clear';
|
|
77
|
+
import {getWebGLExtension} from '../context/helpers/webgl-extensions';
|
|
76
78
|
|
|
77
79
|
const LOG_LEVEL = 1;
|
|
78
80
|
|
|
@@ -82,37 +84,33 @@ export class WebGLDevice extends Device {
|
|
|
82
84
|
// Public `Device` API
|
|
83
85
|
//
|
|
84
86
|
|
|
85
|
-
|
|
87
|
+
/** type of this device */
|
|
88
|
+
static readonly type: string = 'webgl';
|
|
86
89
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
readonly info: DeviceInfo;
|
|
92
|
-
readonly canvasContext: WebGLCanvasContext;
|
|
90
|
+
/** type of this device */
|
|
91
|
+
readonly type = 'webgl';
|
|
93
92
|
|
|
93
|
+
/** The underlying WebGL context */
|
|
94
94
|
readonly handle: WebGL2RenderingContext;
|
|
95
|
+
features: WebGLDeviceFeatures;
|
|
96
|
+
limits: WebGLDeviceLimits;
|
|
95
97
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return this._features;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
get limits(): DeviceLimits {
|
|
102
|
-
this._limits = this._limits || getDeviceLimits(this.gl);
|
|
103
|
-
return this._limits;
|
|
104
|
-
}
|
|
98
|
+
readonly info: DeviceInfo;
|
|
99
|
+
readonly canvasContext: WebGLCanvasContext;
|
|
105
100
|
|
|
106
101
|
readonly lost: Promise<{reason: 'destroyed'; message: string}>;
|
|
107
102
|
|
|
108
103
|
private _resolveContextLost?: (value: {reason: 'destroyed'; message: string}) => void;
|
|
109
|
-
private _features?: Set<DeviceFeature>;
|
|
110
|
-
private _limits?: DeviceLimits;
|
|
111
104
|
|
|
112
105
|
//
|
|
113
106
|
// Static methods, expected to be present by `luma.createDevice()`
|
|
114
107
|
//
|
|
115
108
|
|
|
109
|
+
/** Check if WebGL 2 is available */
|
|
110
|
+
static isSupported(): boolean {
|
|
111
|
+
return typeof WebGL2RenderingContext !== 'undefined';
|
|
112
|
+
}
|
|
113
|
+
|
|
116
114
|
/**
|
|
117
115
|
* Get a device instance from a GL context
|
|
118
116
|
* Creates and instruments the device if not already created
|
|
@@ -137,27 +135,37 @@ export class WebGLDevice extends Device {
|
|
|
137
135
|
static async create(props: DeviceProps = {}): Promise<WebGLDevice> {
|
|
138
136
|
log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created')();
|
|
139
137
|
|
|
140
|
-
|
|
141
|
-
// to avoid setting page onload callback unless necessary
|
|
142
|
-
if (typeof props.canvas === 'string') {
|
|
143
|
-
await CanvasContext.pageLoaded;
|
|
144
|
-
}
|
|
138
|
+
const promises: Promise<unknown>[] = [];
|
|
145
139
|
|
|
146
140
|
// Load webgl and spector debug scripts from CDN if requested
|
|
147
|
-
if (
|
|
148
|
-
|
|
141
|
+
if (props.debug) {
|
|
142
|
+
promises.push(loadWebGLDeveloperTools());
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (props.spector) {
|
|
146
|
+
promises.push(loadSpectorJS());
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Wait for page to load: if canvas is a string we need to query the DOM for the canvas element.
|
|
150
|
+
// We only wait when props.canvas is string to avoids setting the global page onload callback unless necessary.
|
|
151
|
+
if (typeof props.canvas === 'string') {
|
|
152
|
+
promises.push(CanvasContext.pageLoaded);
|
|
149
153
|
}
|
|
150
154
|
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
+
// Wait for all the loads to settle before creating the context.
|
|
156
|
+
// The Device.create() functions are async, so in contrast to the constructor, we can `await` here.
|
|
157
|
+
const results = await Promise.allSettled(promises);
|
|
158
|
+
for (const result of results) {
|
|
159
|
+
if (result.status === 'rejected') {
|
|
160
|
+
log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
161
|
+
}
|
|
155
162
|
}
|
|
156
163
|
|
|
157
164
|
log.probe(LOG_LEVEL + 1, 'DOM is loaded')();
|
|
158
165
|
|
|
159
166
|
// @ts-expect-error
|
|
160
|
-
if (props.gl
|
|
167
|
+
if (props.gl?.device) {
|
|
168
|
+
log.warn('reattaching existing device')();
|
|
161
169
|
return WebGLDevice.attach(props.gl);
|
|
162
170
|
}
|
|
163
171
|
|
|
@@ -165,7 +173,7 @@ export class WebGLDevice extends Device {
|
|
|
165
173
|
|
|
166
174
|
// Log some debug info about the newly created context
|
|
167
175
|
const message = `\
|
|
168
|
-
Created ${device.
|
|
176
|
+
Created ${device.type}${device.debug ? ' debug' : ''} context: \
|
|
169
177
|
${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
170
178
|
log.probe(LOG_LEVEL, message)();
|
|
171
179
|
log.table(LOG_LEVEL, device.info)();
|
|
@@ -190,41 +198,42 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
190
198
|
}
|
|
191
199
|
|
|
192
200
|
// Create and instrument context
|
|
193
|
-
const canvas = props.canvas || props.
|
|
201
|
+
const canvas = props.gl?.canvas || props.canvas;
|
|
194
202
|
this.canvasContext = new WebGLCanvasContext(this, {...props, canvas});
|
|
195
203
|
|
|
196
204
|
this.lost = new Promise<{reason: 'destroyed'; message: string}>(resolve => {
|
|
197
205
|
this._resolveContextLost = resolve;
|
|
198
206
|
});
|
|
199
207
|
|
|
200
|
-
const onContextLost = (event: Event) =>
|
|
201
|
-
this._resolveContextLost?.({
|
|
202
|
-
reason: 'destroyed',
|
|
203
|
-
message: 'Computer entered sleep mode, or too many apps or browser tabs are using the GPU.'
|
|
204
|
-
});
|
|
205
|
-
|
|
206
208
|
let gl: WebGL2RenderingContext | null = props.gl || null;
|
|
207
|
-
gl
|
|
208
|
-
|
|
209
|
-
(
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
gl ||= createBrowserContext(this.canvasContext.canvas, {
|
|
210
|
+
...props,
|
|
211
|
+
onContextLost: (event: Event) =>
|
|
212
|
+
this._resolveContextLost?.({
|
|
213
|
+
reason: 'destroyed',
|
|
214
|
+
message: 'Entered sleep mode, or too many apps or browser tabs are using the GPU.'
|
|
215
|
+
})
|
|
216
|
+
});
|
|
217
|
+
|
|
213
218
|
if (!gl) {
|
|
214
219
|
throw new Error('WebGL context creation failed');
|
|
215
220
|
}
|
|
216
221
|
|
|
217
222
|
this.handle = gl;
|
|
218
|
-
this.gl =
|
|
219
|
-
|
|
223
|
+
this.gl = gl;
|
|
224
|
+
|
|
225
|
+
(this.gl as any).device = this; // Update GL context: Link webgl context back to device
|
|
226
|
+
(this.gl as any)._version = 2; // Update GL context: Store WebGL version field on gl context (HACK to identify debug contexts)
|
|
220
227
|
|
|
221
228
|
// luma Device fields
|
|
222
|
-
this.info = getDeviceInfo(this.gl);
|
|
229
|
+
this.info = getDeviceInfo(this.gl, this._extensions);
|
|
230
|
+
this.limits = new WebGLDeviceLimits(this.gl);
|
|
231
|
+
this.features = new WebGLDeviceFeatures(this.gl, this._extensions, this.props.disabledFeatures);
|
|
232
|
+
if (this.props.initalizeFeatures) {
|
|
233
|
+
this.features.initializeFeatures();
|
|
234
|
+
}
|
|
223
235
|
|
|
224
|
-
|
|
225
|
-
this.gl.device = this;
|
|
226
|
-
// @ts-expect-error Annotate webgl context to handle
|
|
227
|
-
this.gl._version = this.isWebGL2 ? 2 : 1;
|
|
236
|
+
this.canvasContext.resize();
|
|
228
237
|
|
|
229
238
|
// Install context state tracking
|
|
230
239
|
// @ts-expect-error - hidden parameters
|
|
@@ -236,26 +245,23 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
236
245
|
});
|
|
237
246
|
|
|
238
247
|
// DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1
|
|
239
|
-
if (
|
|
248
|
+
if (props.debug) {
|
|
240
249
|
this.gl = makeDebugContext(this.gl, {...props, throwOnError: true});
|
|
241
250
|
this.debug = true;
|
|
242
251
|
log.level = Math.max(log.level, 1);
|
|
243
252
|
log.warn('WebGL debug mode activated. Performance reduced.')();
|
|
244
253
|
}
|
|
245
254
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const canvas = this.handle.canvas || (props.canvas as HTMLCanvasElement);
|
|
249
|
-
this.spector = initializeSpectorJS({...this.props, canvas});
|
|
255
|
+
if (props.spector) {
|
|
256
|
+
this.spectorJS = initializeSpectorJS({...this.props, canvas: this.handle.canvas});
|
|
250
257
|
}
|
|
251
258
|
}
|
|
252
259
|
|
|
253
260
|
/**
|
|
254
261
|
* Destroys the context
|
|
255
|
-
* @note Has no effect for browser contexts, there is no browser API for destroying contexts
|
|
262
|
+
* @note Has no effect for WebGL browser contexts, there is no browser API for destroying contexts
|
|
256
263
|
*/
|
|
257
|
-
destroy(): void {
|
|
258
|
-
}
|
|
264
|
+
destroy(): void {}
|
|
259
265
|
|
|
260
266
|
get isLost(): boolean {
|
|
261
267
|
return this.gl.isContextLost();
|
|
@@ -266,15 +272,15 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
266
272
|
}
|
|
267
273
|
|
|
268
274
|
isTextureFormatSupported(format: TextureFormat): boolean {
|
|
269
|
-
return isTextureFormatSupported(this.gl, format);
|
|
275
|
+
return isTextureFormatSupported(this.gl, format, this._extensions);
|
|
270
276
|
}
|
|
271
277
|
|
|
272
278
|
isTextureFormatFilterable(format: TextureFormat): boolean {
|
|
273
|
-
return isTextureFormatFilterable(this.gl, format);
|
|
279
|
+
return isTextureFormatFilterable(this.gl, format, this._extensions);
|
|
274
280
|
}
|
|
275
281
|
|
|
276
282
|
isTextureFormatRenderable(format: TextureFormat): boolean {
|
|
277
|
-
return isTextureFormatRenderable(this.gl, format);
|
|
283
|
+
return isTextureFormatRenderable(this.gl, format, this._extensions);
|
|
278
284
|
}
|
|
279
285
|
|
|
280
286
|
// IMPLEMENTATION OF ABSTRACT DEVICE
|
|
@@ -308,12 +314,20 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
308
314
|
return new WEBGLFramebuffer(this, props);
|
|
309
315
|
}
|
|
310
316
|
|
|
311
|
-
|
|
312
|
-
return new
|
|
317
|
+
createVertexArray(props: VertexArrayProps): VertexArray {
|
|
318
|
+
return new WEBGLVertexArray(this, props);
|
|
313
319
|
}
|
|
314
320
|
|
|
315
|
-
|
|
316
|
-
return new
|
|
321
|
+
createTransformFeedback(props: TransformFeedbackProps): WEBGLTransformFeedback {
|
|
322
|
+
return new WEBGLTransformFeedback(this, props);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
createQuerySet(props: QuerySetProps): WEBGLQuerySet {
|
|
326
|
+
return new WEBGLQuerySet(this, props);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
createRenderPipeline(props: RenderPipelineProps): WEBGLRenderPipeline {
|
|
330
|
+
return new WEBGLRenderPipeline(this, props);
|
|
317
331
|
}
|
|
318
332
|
|
|
319
333
|
beginRenderPass(props: RenderPassProps): WEBGLRenderPass {
|
|
@@ -328,21 +342,8 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
328
342
|
throw new Error('ComputePass not supported in WebGL');
|
|
329
343
|
}
|
|
330
344
|
|
|
331
|
-
createTransformFeedback(props: TransformFeedbackProps): WEBGLTransformFeedback {
|
|
332
|
-
return new WEBGLTransformFeedback(this, props);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
345
|
private renderPass: WEBGLRenderPass | null = null;
|
|
336
346
|
|
|
337
|
-
getDefaultRenderPass(): WEBGLRenderPass {
|
|
338
|
-
this.renderPass =
|
|
339
|
-
this.renderPass ||
|
|
340
|
-
this.beginRenderPass({
|
|
341
|
-
framebuffer: this.canvasContext.getCurrentFramebuffer()
|
|
342
|
-
});
|
|
343
|
-
return this.renderPass;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
347
|
override createCommandEncoder(props?: CommandEncoderProps): WEBGLCommandEncoder {
|
|
347
348
|
return new WEBGLCommandEncoder(this, props);
|
|
348
349
|
}
|
|
@@ -360,7 +361,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
360
361
|
|
|
361
362
|
//
|
|
362
363
|
// TEMPORARY HACKS - will be removed in v9.1
|
|
363
|
-
//
|
|
364
|
+
//
|
|
364
365
|
|
|
365
366
|
/** @deprecated - should use command encoder */
|
|
366
367
|
override readPixelsToArrayWebGL(
|
|
@@ -399,21 +400,26 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
399
400
|
}
|
|
400
401
|
|
|
401
402
|
override setParametersWebGL(parameters: any): void {
|
|
402
|
-
setGLParameters(this, parameters);
|
|
403
|
+
setGLParameters(this.gl, parameters);
|
|
403
404
|
}
|
|
404
405
|
|
|
405
406
|
override getParametersWebGL(parameters: any): any {
|
|
406
|
-
return getGLParameters(this, parameters);
|
|
407
|
+
return getGLParameters(this.gl, parameters);
|
|
407
408
|
}
|
|
408
409
|
|
|
409
410
|
override withParametersWebGL(parameters: any, func: any): any {
|
|
410
|
-
withGLParameters(this, parameters, func);
|
|
411
|
+
withGLParameters(this.gl, parameters, func);
|
|
411
412
|
}
|
|
412
413
|
|
|
413
|
-
override clearWebGL(options?: {
|
|
414
|
+
override clearWebGL(options?: {
|
|
415
|
+
framebuffer?: Framebuffer;
|
|
416
|
+
color?: any;
|
|
417
|
+
depth?: any;
|
|
418
|
+
stencil?: any;
|
|
419
|
+
}): void {
|
|
414
420
|
clear(this, options);
|
|
415
421
|
}
|
|
416
|
-
|
|
422
|
+
|
|
417
423
|
//
|
|
418
424
|
// WebGL-only API (not part of `Device` API)
|
|
419
425
|
//
|
|
@@ -426,19 +432,11 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
426
432
|
readonly _canvasSizeInfo = {clientWidth: 0, clientHeight: 0, devicePixelRatio: 1};
|
|
427
433
|
|
|
428
434
|
/** State used by luma.gl classes - TODO - not used? */
|
|
429
|
-
readonly _extensions:
|
|
435
|
+
readonly _extensions: GLExtensions = {};
|
|
430
436
|
_polyfilled: boolean = false;
|
|
431
437
|
|
|
432
438
|
/** Instance of Spector.js (if initialized) */
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
private _webglLimits?: WebGLLimits;
|
|
436
|
-
|
|
437
|
-
/** Return WebGL specific limits */
|
|
438
|
-
get webglLimits(): WebGLLimits {
|
|
439
|
-
this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);
|
|
440
|
-
return this._webglLimits;
|
|
441
|
-
}
|
|
439
|
+
spectorJS: unknown;
|
|
442
440
|
|
|
443
441
|
/**
|
|
444
442
|
* Triggers device (or WebGL context) loss.
|
|
@@ -446,7 +444,8 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
446
444
|
*/
|
|
447
445
|
override loseDevice(): boolean {
|
|
448
446
|
let deviceLossTriggered = false;
|
|
449
|
-
const
|
|
447
|
+
const extensions = this.getExtension('WEBGL_lose_context');
|
|
448
|
+
const ext = extensions.WEBGL_lose_context;
|
|
450
449
|
if (ext) {
|
|
451
450
|
deviceLossTriggered = true;
|
|
452
451
|
ext.loseContext();
|
|
@@ -507,11 +506,15 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
507
506
|
* so they need to be updated before every render
|
|
508
507
|
* @todo - remember/cache values to avoid setting them unnecessarily?
|
|
509
508
|
*/
|
|
510
|
-
|
|
511
|
-
|
|
509
|
+
setConstantAttributeWebGL(location: number, constant: TypedArray): void {
|
|
510
|
+
const maxVertexAttributes = this.limits.maxVertexAttributes;
|
|
511
|
+
this._constants = this._constants || new Array(maxVertexAttributes).fill(null);
|
|
512
512
|
const currentConstant = this._constants[location];
|
|
513
513
|
if (currentConstant && compareConstantArrayValues(currentConstant, constant)) {
|
|
514
|
-
log.info(
|
|
514
|
+
log.info(
|
|
515
|
+
1,
|
|
516
|
+
`setConstantAttributeWebGL(${location}) could have been skipped, value unchanged`
|
|
517
|
+
)();
|
|
515
518
|
}
|
|
516
519
|
this._constants[location] = constant;
|
|
517
520
|
|
|
@@ -529,6 +532,12 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
529
532
|
assert(false);
|
|
530
533
|
}
|
|
531
534
|
}
|
|
535
|
+
|
|
536
|
+
/** Ensure extensions are only requested once */
|
|
537
|
+
getExtension(name: keyof GLExtensions): GLExtensions {
|
|
538
|
+
getWebGLExtension(this.gl, name, this._extensions);
|
|
539
|
+
return this._extensions;
|
|
540
|
+
}
|
|
532
541
|
}
|
|
533
542
|
|
|
534
543
|
/** Check if supplied parameter is a WebGL2RenderingContext */
|
package/src/classic/accessor.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import {assert, checkProps, Buffer, AccessorObject} from '@luma.gl/core';
|
|
@@ -58,7 +59,7 @@ export class Accessor implements AccessorObject {
|
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
constructor(...accessors: AccessorObject[]) {
|
|
61
|
-
accessors.forEach(
|
|
62
|
+
accessors.forEach(accessor => this._assign(accessor)); // Merge in sequence
|
|
62
63
|
Object.freeze(this);
|
|
63
64
|
}
|
|
64
65
|
|
|
@@ -151,10 +152,10 @@ export class Accessor implements AccessorObject {
|
|
|
151
152
|
if (this.divisor === undefined) delete this.divisor;
|
|
152
153
|
if (this.normalized === undefined) delete this.normalized;
|
|
153
154
|
if (this.integer === undefined) delete this.integer;
|
|
154
|
-
|
|
155
|
+
|
|
155
156
|
if (this.buffer === undefined) delete this.buffer;
|
|
156
157
|
if (this.index === undefined) delete this.index;
|
|
157
|
-
|
|
158
|
+
|
|
158
159
|
return this;
|
|
159
160
|
}
|
|
160
161
|
}
|
package/src/classic/clear.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import {Device, Framebuffer, assert} from '@luma.gl/core';
|
|
@@ -18,8 +19,8 @@ const GL_DEPTH_STENCIL = 0x84f9;
|
|
|
18
19
|
// Should disappear if asserts are removed
|
|
19
20
|
const ERR_ARGUMENTS = 'clear: bad arguments';
|
|
20
21
|
|
|
21
|
-
/**
|
|
22
|
-
* Optionally clears depth, color and stencil buffers
|
|
22
|
+
/**
|
|
23
|
+
* Optionally clears depth, color and stencil buffers
|
|
23
24
|
* @deprecated Set clear color when creating a RenderPass.
|
|
24
25
|
*/
|
|
25
26
|
export function clear(
|
|
@@ -59,21 +60,26 @@ export function clear(
|
|
|
59
60
|
assert(clearFlags !== 0, ERR_ARGUMENTS);
|
|
60
61
|
|
|
61
62
|
// Temporarily set any clear "colors" and call clear
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
const gl = (device as WebGLDevice).gl;
|
|
64
|
+
withGLParameters(gl, parameters, () => {
|
|
64
65
|
gl.clear(clearFlags);
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
/**
|
|
69
|
-
* WebGL2 - clear a specific drawing buffer
|
|
69
|
+
/**
|
|
70
|
+
* WebGL2 - clear a specific drawing buffer
|
|
70
71
|
* @deprecated Set clear color when creating a RenderPass
|
|
71
72
|
*/
|
|
72
73
|
export function clearBuffer(
|
|
73
74
|
device: Device,
|
|
74
75
|
options?: {framebuffer?: Framebuffer; buffer?: any; drawBuffer?: any; value?: any}
|
|
75
76
|
) {
|
|
76
|
-
const {
|
|
77
|
+
const {
|
|
78
|
+
framebuffer = null,
|
|
79
|
+
buffer = GL_COLOR,
|
|
80
|
+
drawBuffer = 0,
|
|
81
|
+
value = [0, 0, 0, 0]
|
|
82
|
+
} = options || {};
|
|
77
83
|
const gl = (device as WebGLDevice).gl;
|
|
78
84
|
withGLParameters(gl, {framebuffer}, () => {
|
|
79
85
|
// Method selection per OpenGL ES 3 docs
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import {assert, Buffer, Texture, Framebuffer, FramebufferProps} from '@luma.gl/core';
|
|
5
6
|
import {GL} from '@luma.gl/constants';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
+
import {WEBGLTextureView} from '../adapter/resources/webgl-texture-view';
|
|
8
9
|
import {WEBGLFramebuffer} from '../adapter/resources/webgl-framebuffer';
|
|
9
10
|
import {getGLTypeFromTypedArray, getTypedArrayFromGLType} from './typed-array-utils';
|
|
10
11
|
import {glFormatToComponents, glTypeToBytes} from './format-utils';
|
|
@@ -66,7 +67,7 @@ export function readPixelsToArray(
|
|
|
66
67
|
// Deduce the type from color attachment if not provided.
|
|
67
68
|
sourceType =
|
|
68
69
|
sourceType ||
|
|
69
|
-
(framebuffer.colorAttachments[attachment] as
|
|
70
|
+
(framebuffer.colorAttachments[attachment] as WEBGLTextureView)?.texture?.type ||
|
|
70
71
|
GL.UNSIGNED_BYTE;
|
|
71
72
|
|
|
72
73
|
// Deduce type and allocated pixelArray if needed
|
|
@@ -106,7 +107,13 @@ export function readPixelsToBuffer(
|
|
|
106
107
|
sourceType?: number;
|
|
107
108
|
}
|
|
108
109
|
): WEBGLBuffer {
|
|
109
|
-
const {
|
|
110
|
+
const {
|
|
111
|
+
target,
|
|
112
|
+
sourceX = 0,
|
|
113
|
+
sourceY = 0,
|
|
114
|
+
sourceFormat = GL.RGBA,
|
|
115
|
+
targetByteOffset = 0
|
|
116
|
+
} = options || {};
|
|
110
117
|
// following parameters are auto deduced if not provided
|
|
111
118
|
let {sourceWidth, sourceHeight, sourceType} = options || {};
|
|
112
119
|
const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import {TypedArray, TypedArrayConstructor} from '@luma.gl/core';
|
|
@@ -108,12 +109,7 @@ export function flipRows(options: {
|
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
|
|
112
|
-
export function scalePixels(options: {
|
|
113
|
-
data: TypedArray;
|
|
114
|
-
width: number;
|
|
115
|
-
height: number;
|
|
116
|
-
}): {
|
|
112
|
+
export function scalePixels(options: {data: TypedArray; width: number; height: number}): {
|
|
117
113
|
data: Uint8Array;
|
|
118
114
|
width: number;
|
|
119
115
|
height: number;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import {log, loadScript} from '@luma.gl/core';
|
|
@@ -34,8 +35,8 @@ export async function loadSpectorJS(props?: SpectorProps) {
|
|
|
34
35
|
if (!globalThis.SPECTOR) {
|
|
35
36
|
try {
|
|
36
37
|
await loadScript(SPECTOR_CDN_URL);
|
|
37
|
-
} catch(error) {
|
|
38
|
-
log.warn(String(error))
|
|
38
|
+
} catch (error) {
|
|
39
|
+
log.warn(String(error));
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
}
|
|
@@ -64,14 +65,16 @@ export function initializeSpectorJS(props?: SpectorProps) {
|
|
|
64
65
|
// enables recording some extra information merged in the capture like texture memory sizes and formats
|
|
65
66
|
spector.spyCanvases();
|
|
66
67
|
// A callback when results are ready
|
|
67
|
-
spector?.onCaptureStarted.add((capture: unknown) =>
|
|
68
|
+
spector?.onCaptureStarted.add((capture: unknown) =>
|
|
69
|
+
log.info('Spector capture started:', capture)()
|
|
70
|
+
);
|
|
68
71
|
spector?.onCapture.add((capture: unknown) => {
|
|
69
72
|
log.info('Spector capture complete:', capture)();
|
|
70
73
|
// Use undocumented Spector API to open the UI with our capture
|
|
71
74
|
// See https://github.com/BabylonJS/Spector.js/blob/767ad1195a25b85a85c381f400eb50a979239eca/src/spector.ts#L124
|
|
72
|
-
spector?.getResultUI()
|
|
75
|
+
spector?.getResultUI();
|
|
73
76
|
spector?.resultView.display();
|
|
74
|
-
spector?.resultView.addCapture(capture)
|
|
77
|
+
spector?.resultView.addCapture(capture);
|
|
75
78
|
});
|
|
76
79
|
}
|
|
77
80
|
|