@luma.gl/webgl 9.0.0-beta.1 → 9.0.0-beta.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 +295 -156
- package/dist/adapter/converters/sampler-parameters.d.ts +0 -4
- package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/sampler-parameters.js +73 -67
- package/dist/adapter/converters/shader-formats.d.ts.map +1 -1
- package/dist/adapter/converters/shader-formats.js +53 -46
- package/dist/adapter/converters/texture-formats.d.ts +17 -21
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +481 -879
- package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
- package/dist/adapter/converters/vertex-formats.js +53 -61
- package/dist/adapter/device-helpers/webgl-device-features.d.ts +20 -0
- package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -0
- package/dist/adapter/device-helpers/webgl-device-features.js +98 -0
- package/dist/adapter/device-helpers/webgl-device-info.d.ts +5 -0
- package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -0
- package/dist/adapter/device-helpers/webgl-device-info.js +90 -0
- package/dist/adapter/device-helpers/webgl-device-limits.d.ts +35 -0
- package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -0
- package/dist/adapter/device-helpers/webgl-device-limits.js +47 -0
- package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -1
- package/dist/adapter/helpers/decode-webgl-types.js +88 -76
- 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 +261 -225
- package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
- package/dist/adapter/helpers/parse-shader-compiler-log.js +47 -37
- package/dist/adapter/helpers/set-uniform.d.ts +1 -1
- package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
- package/dist/adapter/helpers/set-uniform.js +68 -82
- package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.js +78 -93
- package/dist/adapter/objects/constants-to-keys.d.ts +1 -1
- package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
- package/dist/adapter/objects/constants-to-keys.js +19 -12
- 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 +86 -77
- package/dist/adapter/objects/webgl-resource.d.ts +3 -25
- package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-resource.js +102 -147
- package/dist/adapter/resources/webgl-buffer.d.ts +3 -4
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +159 -117
- 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 +266 -168
- 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 +33 -39
- package/dist/adapter/resources/webgl-external-texture.js +93 -1
- package/dist/adapter/resources/webgl-framebuffer.d.ts +8 -12
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +174 -139
- 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 +124 -90
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +15 -6
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +362 -221
- package/dist/adapter/resources/webgl-sampler.d.ts +1 -3
- package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-sampler.js +43 -33
- package/dist/adapter/resources/webgl-shader.d.ts +12 -2
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +114 -47
- 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 +8 -10
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +616 -694
- package/dist/adapter/resources/webgl-transform-feedback.d.ts +2 -2
- package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-transform-feedback.js +141 -143
- 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 +229 -157
- 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 +58 -36
- package/dist/adapter/webgl-device.d.ts +50 -44
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +427 -352
- package/dist/classic/accessor.d.ts.map +1 -1
- package/dist/classic/accessor.js +132 -101
- package/dist/classic/clear.d.ts +2 -2
- package/dist/classic/clear.d.ts.map +1 -1
- package/dist/classic/clear.js +73 -72
- 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 +174 -175
- package/dist/classic/format-utils.d.ts +2 -2
- package/dist/classic/format-utils.d.ts.map +1 -1
- package/dist/classic/format-utils.js +39 -32
- package/dist/classic/typed-array-utils.d.ts.map +1 -1
- package/dist/classic/typed-array-utils.js +96 -81
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +55 -50
- package/dist/context/debug/webgl-developer-tools.d.ts +1 -2
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +104 -77
- package/dist/context/{context → helpers}/create-browser-context.d.ts +1 -6
- package/dist/context/helpers/create-browser-context.d.ts.map +1 -0
- package/dist/context/helpers/create-browser-context.js +67 -0
- package/dist/context/{polyfill/context-data.d.ts → helpers/webgl-context-data.d.ts} +2 -2
- 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 +92 -47
- package/dist/context/parameters/webgl-parameter-tables.d.ts +109 -99
- package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js +463 -404
- package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
- package/dist/context/state-tracker/deep-array-equal.js +19 -14
- package/dist/context/state-tracker/track-context-state.d.ts +4 -4
- package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
- package/dist/context/state-tracker/track-context-state.js +188 -123
- 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 +42 -28
- package/dist/dist.dev.js +4465 -7235
- package/dist/dist.min.js +10 -0
- package/dist/index.cjs +2146 -3116
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +25 -31
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -1
- package/dist.min.js +9 -42
- package/package.json +10 -15
- package/src/adapter/converters/device-parameters.ts +114 -28
- package/src/adapter/converters/sampler-parameters.ts +12 -20
- package/src/adapter/converters/shader-formats.ts +47 -22
- package/src/adapter/converters/texture-formats.ts +183 -227
- package/src/adapter/converters/vertex-formats.ts +3 -3
- package/src/adapter/device-helpers/webgl-device-features.ts +121 -0
- package/src/adapter/device-helpers/{get-device-info.ts → webgl-device-info.ts} +30 -22
- package/src/adapter/device-helpers/webgl-device-limits.ts +53 -0
- package/src/adapter/helpers/decode-webgl-types.ts +13 -7
- package/src/adapter/helpers/get-shader-layout.ts +21 -31
- package/src/adapter/helpers/parse-shader-compiler-log.ts +10 -6
- package/src/adapter/helpers/set-uniform.ts +3 -4
- package/src/adapter/helpers/webgl-topology-utils.ts +10 -3
- package/src/adapter/objects/constants-to-keys.ts +3 -2
- package/src/adapter/objects/webgl-renderbuffer.ts +38 -16
- package/src/adapter/objects/webgl-resource.ts +8 -141
- package/src/adapter/resources/webgl-buffer.ts +10 -14
- package/src/adapter/resources/webgl-command-buffer.ts +24 -34
- package/src/adapter/resources/webgl-command-encoder.ts +14 -11
- package/src/adapter/resources/webgl-external-texture.ts +7 -7
- package/src/adapter/resources/webgl-framebuffer.ts +65 -58
- package/src/adapter/resources/webgl-query-set.ts +171 -0
- package/src/adapter/resources/webgl-render-pass.ts +27 -18
- package/src/adapter/resources/webgl-render-pipeline.ts +148 -73
- package/src/adapter/resources/webgl-sampler.ts +7 -10
- package/src/adapter/resources/webgl-shader.ts +65 -11
- package/src/adapter/resources/webgl-texture-view.ts +28 -0
- package/src/adapter/resources/webgl-texture.ts +43 -106
- package/src/adapter/resources/webgl-transform-feedback.ts +16 -22
- package/src/adapter/resources/webgl-vertex-array.ts +20 -21
- package/src/adapter/webgl-canvas-context.ts +7 -11
- package/src/adapter/webgl-device.ts +142 -162
- package/src/classic/accessor.ts +5 -4
- package/src/classic/clear.ts +25 -20
- package/src/classic/copy-and-blit.ts +12 -6
- 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 +31 -20
- package/src/context/{context → helpers}/create-browser-context.ts +9 -33
- package/src/context/{polyfill/context-data.ts → helpers/webgl-context-data.ts} +3 -2
- 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 +118 -90
- package/src/context/state-tracker/deep-array-equal.ts +2 -1
- package/src/context/state-tracker/track-context-state.ts +29 -23
- package/src/context/state-tracker/with-parameters.ts +8 -8
- package/src/index.ts +16 -56
- package/src/types.ts +2 -1
- package/dist/adapter/converters/device-parameters.js.map +0 -1
- package/dist/adapter/converters/sampler-parameters.js.map +0 -1
- package/dist/adapter/converters/shader-formats.js.map +0 -1
- package/dist/adapter/converters/texture-formats.js.map +0 -1
- package/dist/adapter/converters/vertex-formats.js.map +0 -1
- package/dist/adapter/device-helpers/device-features.d.ts +0 -9
- package/dist/adapter/device-helpers/device-features.d.ts.map +0 -1
- package/dist/adapter/device-helpers/device-features.js +0 -96
- package/dist/adapter/device-helpers/device-features.js.map +0 -1
- package/dist/adapter/device-helpers/device-limits.d.ts +0 -52
- package/dist/adapter/device-helpers/device-limits.d.ts.map +0 -1
- package/dist/adapter/device-helpers/device-limits.js +0 -87
- package/dist/adapter/device-helpers/device-limits.js.map +0 -1
- 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 -71
- package/dist/adapter/device-helpers/get-device-info.js.map +0 -1
- package/dist/adapter/device-helpers/is-old-ie.d.ts +0 -2
- package/dist/adapter/device-helpers/is-old-ie.d.ts.map +0 -1
- package/dist/adapter/device-helpers/is-old-ie.js +0 -9
- package/dist/adapter/device-helpers/is-old-ie.js.map +0 -1
- package/dist/adapter/helpers/decode-webgl-types.js.map +0 -1
- package/dist/adapter/helpers/get-shader-layout.js.map +0 -1
- package/dist/adapter/helpers/parse-shader-compiler-log.js.map +0 -1
- package/dist/adapter/helpers/set-uniform.js.map +0 -1
- package/dist/adapter/helpers/webgl-topology-utils.js.map +0 -1
- package/dist/adapter/objects/constants-to-keys.js.map +0 -1
- package/dist/adapter/objects/webgl-renderbuffer.js.map +0 -1
- package/dist/adapter/objects/webgl-resource.js.map +0 -1
- package/dist/adapter/resources/webgl-buffer.js.map +0 -1
- package/dist/adapter/resources/webgl-command-buffer.js.map +0 -1
- package/dist/adapter/resources/webgl-command-encoder.js.map +0 -1
- package/dist/adapter/resources/webgl-external-texture.js.map +0 -1
- package/dist/adapter/resources/webgl-framebuffer.js.map +0 -1
- package/dist/adapter/resources/webgl-render-pass.js.map +0 -1
- package/dist/adapter/resources/webgl-render-pipeline.js.map +0 -1
- package/dist/adapter/resources/webgl-sampler.js.map +0 -1
- package/dist/adapter/resources/webgl-shader.js.map +0 -1
- package/dist/adapter/resources/webgl-texture.js.map +0 -1
- package/dist/adapter/resources/webgl-transform-feedback.js.map +0 -1
- package/dist/adapter/resources/webgl-vertex-array.js.map +0 -1
- package/dist/adapter/webgl-canvas-context.js.map +0 -1
- package/dist/adapter/webgl-device.js.map +0 -1
- package/dist/classic/accessor.js.map +0 -1
- package/dist/classic/clear.js.map +0 -1
- package/dist/classic/copy-and-blit.js.map +0 -1
- package/dist/classic/format-utils.js.map +0 -1
- package/dist/classic/typed-array-utils.js.map +0 -1
- package/dist/context/context/create-browser-context.d.ts.map +0 -1
- package/dist/context/context/create-browser-context.js +0 -53
- package/dist/context/context/create-browser-context.js.map +0 -1
- package/dist/context/context/create-headless-context.d.ts +0 -9
- package/dist/context/context/create-headless-context.d.ts.map +0 -1
- package/dist/context/context/create-headless-context.js +0 -42
- package/dist/context/context/create-headless-context.js.map +0 -1
- package/dist/context/context/webgl-checks.d.ts +0 -13
- package/dist/context/context/webgl-checks.d.ts.map +0 -1
- package/dist/context/context/webgl-checks.js +0 -31
- package/dist/context/context/webgl-checks.js.map +0 -1
- package/dist/context/debug/spector.js.map +0 -1
- package/dist/context/debug/webgl-developer-tools.js.map +0 -1
- package/dist/context/parameters/unified-parameter-api.js.map +0 -1
- package/dist/context/parameters/webgl-parameter-tables.js.map +0 -1
- package/dist/context/polyfill/context-data.d.ts.map +0 -1
- package/dist/context/polyfill/context-data.js +0 -12
- package/dist/context/polyfill/context-data.js.map +0 -1
- package/dist/context/polyfill/get-parameter-polyfill.d.ts +0 -2
- package/dist/context/polyfill/get-parameter-polyfill.d.ts.map +0 -1
- package/dist/context/polyfill/get-parameter-polyfill.js +0 -85
- package/dist/context/polyfill/get-parameter-polyfill.js.map +0 -1
- package/dist/context/polyfill/polyfill-context.d.ts +0 -5
- package/dist/context/polyfill/polyfill-context.d.ts.map +0 -1
- package/dist/context/polyfill/polyfill-context.js +0 -87
- package/dist/context/polyfill/polyfill-context.js.map +0 -1
- package/dist/context/polyfill/polyfill-table.d.ts +0 -48
- package/dist/context/polyfill/polyfill-table.d.ts.map +0 -1
- package/dist/context/polyfill/polyfill-table.js +0 -137
- package/dist/context/polyfill/polyfill-table.js.map +0 -1
- package/dist/context/polyfill/polyfill-vertex-array-object.d.ts +0 -2
- package/dist/context/polyfill/polyfill-vertex-array-object.d.ts.map +0 -1
- package/dist/context/polyfill/polyfill-vertex-array-object.js +0 -265
- package/dist/context/polyfill/polyfill-vertex-array-object.js.map +0 -1
- package/dist/context/state-tracker/deep-array-equal.js.map +0 -1
- package/dist/context/state-tracker/track-context-state.js.map +0 -1
- package/dist/context/state-tracker/with-parameters.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/src/adapter/device-helpers/device-features.ts +0 -161
- package/src/adapter/device-helpers/device-limits.ts +0 -155
- package/src/adapter/device-helpers/is-old-ie.ts +0 -14
- package/src/context/context/create-headless-context.ts +0 -51
- package/src/context/context/webgl-checks.ts +0 -51
- package/src/context/polyfill/get-parameter-polyfill.ts +0 -122
- package/src/context/polyfill/polyfill-context.ts +0 -104
- package/src/context/polyfill/polyfill-table.ts +0 -167
- package/src/context/polyfill/polyfill-vertex-array-object.ts +0 -365
|
@@ -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,21 +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 {
|
|
20
|
-
import {polyfillContext} from '../context/polyfill/polyfill-context';
|
|
18
|
+
import type {GLExtensions} from '@luma.gl/constants';
|
|
21
19
|
import {
|
|
22
20
|
popContextState,
|
|
23
21
|
pushContextState,
|
|
24
22
|
trackContextState
|
|
25
23
|
} from '../context/state-tracker/track-context-state';
|
|
26
|
-
import {createBrowserContext} from '../context/
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} from '../context/context/create-headless-context';
|
|
31
|
-
import {getDeviceInfo} from './device-helpers/get-device-info';
|
|
32
|
-
import {getDeviceFeatures} from './device-helpers/device-features';
|
|
33
|
-
import {getDeviceLimits, getWebGLLimits, WebGLLimits} from './device-helpers/device-limits';
|
|
24
|
+
import {createBrowserContext} from '../context/helpers/create-browser-context';
|
|
25
|
+
import {getDeviceInfo} from './device-helpers/webgl-device-info';
|
|
26
|
+
import {WebGLDeviceFeatures} from './device-helpers/webgl-device-features';
|
|
27
|
+
import {WebGLDeviceLimits} from './device-helpers/webgl-device-limits';
|
|
34
28
|
import {WebGLCanvasContext} from './webgl-canvas-context';
|
|
35
29
|
import {loadSpectorJS, initializeSpectorJS} from '../context/debug/spector';
|
|
36
30
|
import {loadWebGLDeveloperTools, makeDebugContext} from '../context/debug/webgl-developer-tools';
|
|
@@ -60,7 +54,8 @@ import type {
|
|
|
60
54
|
ComputePassProps,
|
|
61
55
|
// CommandEncoder,
|
|
62
56
|
CommandEncoderProps,
|
|
63
|
-
TransformFeedbackProps
|
|
57
|
+
TransformFeedbackProps,
|
|
58
|
+
QuerySetProps
|
|
64
59
|
} from '@luma.gl/core';
|
|
65
60
|
|
|
66
61
|
import {WEBGLBuffer} from './resources/webgl-buffer';
|
|
@@ -73,8 +68,13 @@ import {WEBGLRenderPipeline} from './resources/webgl-render-pipeline';
|
|
|
73
68
|
import {WEBGLCommandEncoder} from './resources/webgl-command-encoder';
|
|
74
69
|
import {WEBGLVertexArray} from './resources/webgl-vertex-array';
|
|
75
70
|
import {WEBGLTransformFeedback} from './resources/webgl-transform-feedback';
|
|
71
|
+
import {WEBGLQuerySet} from './resources/webgl-query-set';
|
|
76
72
|
|
|
77
73
|
import {readPixelsToArray, readPixelsToBuffer} from '../classic/copy-and-blit';
|
|
74
|
+
import {setGLParameters, getGLParameters} from '../context/parameters/unified-parameter-api';
|
|
75
|
+
import {withGLParameters} from '../context/state-tracker/with-parameters';
|
|
76
|
+
import {clear} from '../classic/clear';
|
|
77
|
+
import {getWebGLExtension} from '../context/helpers/webgl-extensions';
|
|
78
78
|
|
|
79
79
|
const LOG_LEVEL = 1;
|
|
80
80
|
|
|
@@ -84,44 +84,40 @@ export class WebGLDevice extends Device {
|
|
|
84
84
|
// Public `Device` API
|
|
85
85
|
//
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
/** type of this device */
|
|
88
|
+
static readonly type: string = 'webgl';
|
|
88
89
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
/** type of this device */
|
|
91
|
+
readonly type = 'webgl';
|
|
92
|
+
|
|
93
|
+
/** The underlying WebGL context */
|
|
94
|
+
readonly handle: WebGL2RenderingContext;
|
|
95
|
+
features: WebGLDeviceFeatures;
|
|
96
|
+
limits: WebGLDeviceLimits;
|
|
92
97
|
|
|
93
98
|
readonly info: DeviceInfo;
|
|
94
99
|
readonly canvasContext: WebGLCanvasContext;
|
|
95
100
|
|
|
96
|
-
readonly handle: WebGLRenderingContext;
|
|
97
|
-
|
|
98
|
-
get features(): Set<DeviceFeature> {
|
|
99
|
-
this._features = this._features || getDeviceFeatures(this.gl);
|
|
100
|
-
return this._features;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
get limits(): DeviceLimits {
|
|
104
|
-
this._limits = this._limits || getDeviceLimits(this.gl);
|
|
105
|
-
return this._limits;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
101
|
readonly lost: Promise<{reason: 'destroyed'; message: string}>;
|
|
109
102
|
|
|
110
103
|
private _resolveContextLost?: (value: {reason: 'destroyed'; message: string}) => void;
|
|
111
|
-
private _features?: Set<DeviceFeature>;
|
|
112
|
-
private _limits?: DeviceLimits;
|
|
113
104
|
|
|
114
105
|
//
|
|
115
106
|
// Static methods, expected to be present by `luma.createDevice()`
|
|
116
107
|
//
|
|
117
108
|
|
|
109
|
+
/** Check if WebGL 2 is available */
|
|
110
|
+
static isSupported(): boolean {
|
|
111
|
+
return typeof WebGL2RenderingContext !== 'undefined';
|
|
112
|
+
}
|
|
113
|
+
|
|
118
114
|
/**
|
|
119
115
|
* Get a device instance from a GL context
|
|
120
116
|
* Creates and instruments the device if not already created
|
|
121
117
|
* @param gl
|
|
122
118
|
* @returns
|
|
123
119
|
*/
|
|
124
|
-
static attach(gl: Device |
|
|
120
|
+
static attach(gl: Device | WebGL2RenderingContext): WebGLDevice {
|
|
125
121
|
if (gl instanceof WebGLDevice) {
|
|
126
122
|
return gl;
|
|
127
123
|
}
|
|
@@ -131,35 +127,45 @@ export class WebGLDevice extends Device {
|
|
|
131
127
|
return gl.device as WebGLDevice;
|
|
132
128
|
}
|
|
133
129
|
if (!isWebGL(gl)) {
|
|
134
|
-
throw new Error('Invalid
|
|
130
|
+
throw new Error('Invalid WebGL2RenderingContext');
|
|
135
131
|
}
|
|
136
|
-
return new WebGLDevice({gl: gl as
|
|
132
|
+
return new WebGLDevice({gl: gl as WebGL2RenderingContext});
|
|
137
133
|
}
|
|
138
134
|
|
|
139
135
|
static async create(props: DeviceProps = {}): Promise<WebGLDevice> {
|
|
140
136
|
log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created')();
|
|
141
137
|
|
|
142
|
-
|
|
143
|
-
// to avoid setting page onload callback unless necessary
|
|
144
|
-
if (typeof props.canvas === 'string') {
|
|
145
|
-
await CanvasContext.pageLoaded;
|
|
146
|
-
}
|
|
138
|
+
const promises: Promise<unknown>[] = [];
|
|
147
139
|
|
|
148
140
|
// Load webgl and spector debug scripts from CDN if requested
|
|
149
|
-
if (
|
|
150
|
-
|
|
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);
|
|
151
153
|
}
|
|
152
154
|
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
+
}
|
|
157
162
|
}
|
|
158
163
|
|
|
159
164
|
log.probe(LOG_LEVEL + 1, 'DOM is loaded')();
|
|
160
165
|
|
|
161
166
|
// @ts-expect-error
|
|
162
|
-
if (props.gl
|
|
167
|
+
if (props.gl?.device) {
|
|
168
|
+
log.warn('reattaching existing device')();
|
|
163
169
|
return WebGLDevice.attach(props.gl);
|
|
164
170
|
}
|
|
165
171
|
|
|
@@ -167,7 +173,7 @@ export class WebGLDevice extends Device {
|
|
|
167
173
|
|
|
168
174
|
// Log some debug info about the newly created context
|
|
169
175
|
const message = `\
|
|
170
|
-
Created ${device.
|
|
176
|
+
Created ${device.type}${device.debug ? ' debug' : ''} context: \
|
|
171
177
|
${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
172
178
|
log.probe(LOG_LEVEL, message)();
|
|
173
179
|
log.table(LOG_LEVEL, device.info)();
|
|
@@ -192,48 +198,42 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
192
198
|
}
|
|
193
199
|
|
|
194
200
|
// Create and instrument context
|
|
195
|
-
const canvas = props.canvas || props.
|
|
201
|
+
const canvas = props.gl?.canvas || props.canvas;
|
|
196
202
|
this.canvasContext = new WebGLCanvasContext(this, {...props, canvas});
|
|
197
203
|
|
|
198
204
|
this.lost = new Promise<{reason: 'destroyed'; message: string}>(resolve => {
|
|
199
205
|
this._resolveContextLost = resolve;
|
|
200
206
|
});
|
|
201
207
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
(isBrowser()
|
|
212
|
-
? createBrowserContext(this.canvasContext.canvas, {...props, onContextLost})
|
|
213
|
-
: null);
|
|
214
|
-
gl = gl || (!isBrowser() ? createHeadlessContext({...props, onContextLost}) : null);
|
|
208
|
+
let gl: WebGL2RenderingContext | null = props.gl || null;
|
|
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
|
+
});
|
|
215
217
|
|
|
216
218
|
if (!gl) {
|
|
217
219
|
throw new Error('WebGL context creation failed');
|
|
218
220
|
}
|
|
219
221
|
|
|
220
222
|
this.handle = gl;
|
|
221
|
-
this.gl =
|
|
222
|
-
this.gl2 = this.gl as WebGL2RenderingContext;
|
|
223
|
-
this.isWebGL2 = isWebGL2(this.gl);
|
|
224
|
-
this.isWebGL1 = !this.isWebGL2;
|
|
225
|
-
this.canvasContext.resize();
|
|
223
|
+
this.gl = gl;
|
|
226
224
|
|
|
227
|
-
//
|
|
228
|
-
this.
|
|
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)
|
|
229
227
|
|
|
230
|
-
//
|
|
231
|
-
this.
|
|
232
|
-
|
|
233
|
-
this.
|
|
228
|
+
// luma Device fields
|
|
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
|
+
}
|
|
234
235
|
|
|
235
|
-
|
|
236
|
-
polyfillContext(this.gl);
|
|
236
|
+
this.canvasContext.resize();
|
|
237
237
|
|
|
238
238
|
// Install context state tracking
|
|
239
239
|
// @ts-expect-error - hidden parameters
|
|
@@ -245,31 +245,23 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
245
245
|
});
|
|
246
246
|
|
|
247
247
|
// DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1
|
|
248
|
-
if (
|
|
249
|
-
this.gl = makeDebugContext(this.gl, {...props,
|
|
250
|
-
this.gl2 = this.gl as WebGL2RenderingContext;
|
|
248
|
+
if (props.debug) {
|
|
249
|
+
this.gl = makeDebugContext(this.gl, {...props, throwOnError: true});
|
|
251
250
|
this.debug = true;
|
|
252
251
|
log.level = Math.max(log.level, 1);
|
|
253
252
|
log.warn('WebGL debug mode activated. Performance reduced.')();
|
|
254
253
|
}
|
|
255
254
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const canvas = this.handle.canvas || (props.canvas as HTMLCanvasElement);
|
|
259
|
-
this.spector = initializeSpectorJS({...this.props, canvas});
|
|
255
|
+
if (props.spector) {
|
|
256
|
+
this.spectorJS = initializeSpectorJS({...this.props, canvas: this.handle.canvas});
|
|
260
257
|
}
|
|
261
258
|
}
|
|
262
259
|
|
|
263
260
|
/**
|
|
264
261
|
* Destroys the context
|
|
265
|
-
* @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
|
|
266
263
|
*/
|
|
267
|
-
destroy(): void {
|
|
268
|
-
const ext = this.gl.getExtension('STACKGL_destroy_context');
|
|
269
|
-
if (ext) {
|
|
270
|
-
ext.destroy();
|
|
271
|
-
}
|
|
272
|
-
}
|
|
264
|
+
destroy(): void {}
|
|
273
265
|
|
|
274
266
|
get isLost(): boolean {
|
|
275
267
|
return this.gl.isContextLost();
|
|
@@ -280,25 +272,15 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
280
272
|
}
|
|
281
273
|
|
|
282
274
|
isTextureFormatSupported(format: TextureFormat): boolean {
|
|
283
|
-
return isTextureFormatSupported(this.gl, format);
|
|
275
|
+
return isTextureFormatSupported(this.gl, format, this._extensions);
|
|
284
276
|
}
|
|
285
277
|
|
|
286
278
|
isTextureFormatFilterable(format: TextureFormat): boolean {
|
|
287
|
-
return isTextureFormatFilterable(this.gl, format);
|
|
279
|
+
return isTextureFormatFilterable(this.gl, format, this._extensions);
|
|
288
280
|
}
|
|
289
281
|
|
|
290
282
|
isTextureFormatRenderable(format: TextureFormat): boolean {
|
|
291
|
-
return isTextureFormatRenderable(this.gl, format);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// WEBGL SPECIFIC METHODS
|
|
295
|
-
|
|
296
|
-
/** Returns a WebGL2RenderingContext or throws an error */
|
|
297
|
-
assertWebGL2(): WebGL2RenderingContext {
|
|
298
|
-
if (!this.gl2) {
|
|
299
|
-
throw new Error('Requires WebGL2');
|
|
300
|
-
}
|
|
301
|
-
return this.gl2;
|
|
283
|
+
return isTextureFormatRenderable(this.gl, format, this._extensions);
|
|
302
284
|
}
|
|
303
285
|
|
|
304
286
|
// IMPLEMENTATION OF ABSTRACT DEVICE
|
|
@@ -332,12 +314,20 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
332
314
|
return new WEBGLFramebuffer(this, props);
|
|
333
315
|
}
|
|
334
316
|
|
|
335
|
-
|
|
336
|
-
return new
|
|
317
|
+
createVertexArray(props: VertexArrayProps): VertexArray {
|
|
318
|
+
return new WEBGLVertexArray(this, props);
|
|
337
319
|
}
|
|
338
320
|
|
|
339
|
-
|
|
340
|
-
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);
|
|
341
331
|
}
|
|
342
332
|
|
|
343
333
|
beginRenderPass(props: RenderPassProps): WEBGLRenderPass {
|
|
@@ -352,28 +342,15 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
352
342
|
throw new Error('ComputePass not supported in WebGL');
|
|
353
343
|
}
|
|
354
344
|
|
|
355
|
-
createTransformFeedback(props: TransformFeedbackProps): WEBGLTransformFeedback {
|
|
356
|
-
return new WEBGLTransformFeedback(this, props);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
345
|
private renderPass: WEBGLRenderPass | null = null;
|
|
360
346
|
|
|
361
|
-
getDefaultRenderPass(): WEBGLRenderPass {
|
|
362
|
-
this.renderPass =
|
|
363
|
-
this.renderPass ||
|
|
364
|
-
this.beginRenderPass({
|
|
365
|
-
framebuffer: this.canvasContext.getCurrentFramebuffer()
|
|
366
|
-
});
|
|
367
|
-
return this.renderPass;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
347
|
override createCommandEncoder(props?: CommandEncoderProps): WEBGLCommandEncoder {
|
|
371
348
|
return new WEBGLCommandEncoder(this, props);
|
|
372
349
|
}
|
|
373
350
|
|
|
374
351
|
/**
|
|
375
352
|
* Offscreen Canvas Support: Commit the frame
|
|
376
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/
|
|
353
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/commit
|
|
377
354
|
* Chrome's offscreen canvas does not require gl.commit
|
|
378
355
|
*/
|
|
379
356
|
submit(): void {
|
|
@@ -384,7 +361,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
384
361
|
|
|
385
362
|
//
|
|
386
363
|
// TEMPORARY HACKS - will be removed in v9.1
|
|
387
|
-
//
|
|
364
|
+
//
|
|
388
365
|
|
|
389
366
|
/** @deprecated - should use command encoder */
|
|
390
367
|
override readPixelsToArrayWebGL(
|
|
@@ -405,7 +382,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
405
382
|
}
|
|
406
383
|
|
|
407
384
|
/** @deprecated - should use command encoder */
|
|
408
|
-
override
|
|
385
|
+
override readPixelsToBufferWebGL(
|
|
409
386
|
source: Framebuffer | Texture,
|
|
410
387
|
options?: {
|
|
411
388
|
sourceX?: number;
|
|
@@ -422,38 +399,44 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
422
399
|
return readPixelsToBuffer(source, options);
|
|
423
400
|
}
|
|
424
401
|
|
|
402
|
+
override setParametersWebGL(parameters: any): void {
|
|
403
|
+
setGLParameters(this.gl, parameters);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
override getParametersWebGL(parameters: any): any {
|
|
407
|
+
return getGLParameters(this.gl, parameters);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
override withParametersWebGL(parameters: any, func: any): any {
|
|
411
|
+
withGLParameters(this.gl, parameters, func);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
override clearWebGL(options?: {
|
|
415
|
+
framebuffer?: Framebuffer;
|
|
416
|
+
color?: any;
|
|
417
|
+
depth?: any;
|
|
418
|
+
stencil?: any;
|
|
419
|
+
}): void {
|
|
420
|
+
clear(this, options);
|
|
421
|
+
}
|
|
422
|
+
|
|
425
423
|
//
|
|
426
424
|
// WebGL-only API (not part of `Device` API)
|
|
427
425
|
//
|
|
428
426
|
|
|
429
|
-
/**
|
|
430
|
-
readonly gl:
|
|
431
|
-
/** WebGL2 typed context. Need to check isWebGL2 or isWebGL1 before using. */
|
|
432
|
-
readonly gl2: WebGL2RenderingContext | null = null;
|
|
427
|
+
/** WebGL2 context. */
|
|
428
|
+
readonly gl: WebGL2RenderingContext;
|
|
433
429
|
readonly debug: boolean = false;
|
|
434
430
|
|
|
435
|
-
/** `true` if this is a WebGL1 context. @note `false` if WebGL2 */
|
|
436
|
-
readonly isWebGL1: boolean;
|
|
437
|
-
/** `true` if this is a WebGL2 context. @note `false` if WebGL1 */
|
|
438
|
-
readonly isWebGL2: boolean;
|
|
439
|
-
|
|
440
431
|
/** State used by luma.gl classes: TODO - move to canvasContext*/
|
|
441
432
|
readonly _canvasSizeInfo = {clientWidth: 0, clientHeight: 0, devicePixelRatio: 1};
|
|
442
433
|
|
|
443
434
|
/** State used by luma.gl classes - TODO - not used? */
|
|
444
|
-
readonly _extensions:
|
|
435
|
+
readonly _extensions: GLExtensions = {};
|
|
445
436
|
_polyfilled: boolean = false;
|
|
446
437
|
|
|
447
438
|
/** Instance of Spector.js (if initialized) */
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
private _webglLimits?: WebGLLimits;
|
|
451
|
-
|
|
452
|
-
/** Return WebGL specific limits */
|
|
453
|
-
get webglLimits(): WebGLLimits {
|
|
454
|
-
this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);
|
|
455
|
-
return this._webglLimits;
|
|
456
|
-
}
|
|
439
|
+
spectorJS: unknown;
|
|
457
440
|
|
|
458
441
|
/**
|
|
459
442
|
* Triggers device (or WebGL context) loss.
|
|
@@ -461,7 +444,8 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
461
444
|
*/
|
|
462
445
|
override loseDevice(): boolean {
|
|
463
446
|
let deviceLossTriggered = false;
|
|
464
|
-
const
|
|
447
|
+
const extensions = this.getExtension('WEBGL_lose_context');
|
|
448
|
+
const ext = extensions.WEBGL_lose_context;
|
|
465
449
|
if (ext) {
|
|
466
450
|
deviceLossTriggered = true;
|
|
467
451
|
ext.loseContext();
|
|
@@ -499,7 +483,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
499
483
|
* Be aware that there are some duplicates especially for constants that are 0,
|
|
500
484
|
* so this isn't guaranteed to return the right key in all cases.
|
|
501
485
|
*/
|
|
502
|
-
getGLKey(value: unknown, gl?:
|
|
486
|
+
getGLKey(value: unknown, gl?: WebGL2RenderingContext): string {
|
|
503
487
|
// @ts-ignore expect-error depends on settings
|
|
504
488
|
gl = gl || this.gl2 || this.gl;
|
|
505
489
|
const number = Number(value);
|
|
@@ -522,11 +506,15 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
522
506
|
* so they need to be updated before every render
|
|
523
507
|
* @todo - remember/cache values to avoid setting them unnecessarily?
|
|
524
508
|
*/
|
|
525
|
-
|
|
526
|
-
|
|
509
|
+
setConstantAttributeWebGL(location: number, constant: TypedArray): void {
|
|
510
|
+
const maxVertexAttributes = this.limits.maxVertexAttributes;
|
|
511
|
+
this._constants = this._constants || new Array(maxVertexAttributes).fill(null);
|
|
527
512
|
const currentConstant = this._constants[location];
|
|
528
513
|
if (currentConstant && compareConstantArrayValues(currentConstant, constant)) {
|
|
529
|
-
log.info(
|
|
514
|
+
log.info(
|
|
515
|
+
1,
|
|
516
|
+
`setConstantAttributeWebGL(${location}) could have been skipped, value unchanged`
|
|
517
|
+
)();
|
|
530
518
|
}
|
|
531
519
|
this._constants[location] = constant;
|
|
532
520
|
|
|
@@ -544,27 +532,21 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
544
532
|
assert(false);
|
|
545
533
|
}
|
|
546
534
|
}
|
|
547
|
-
}
|
|
548
535
|
|
|
549
|
-
/**
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
return
|
|
553
|
-
}
|
|
554
|
-
if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
|
|
555
|
-
return true;
|
|
536
|
+
/** Ensure extensions are only requested once */
|
|
537
|
+
getExtension(name: keyof GLExtensions): GLExtensions {
|
|
538
|
+
getWebGLExtension(this.gl, name, this._extensions);
|
|
539
|
+
return this._extensions;
|
|
556
540
|
}
|
|
557
|
-
// Look for debug contexts, headless gl etc
|
|
558
|
-
return Boolean(gl && Number.isFinite(gl._version));
|
|
559
541
|
}
|
|
560
542
|
|
|
561
543
|
/** Check if supplied parameter is a WebGL2RenderingContext */
|
|
562
|
-
function
|
|
544
|
+
function isWebGL(gl: any): boolean {
|
|
563
545
|
if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
|
|
564
546
|
return true;
|
|
565
547
|
}
|
|
566
548
|
// Look for debug contexts, headless gl etc
|
|
567
|
-
return Boolean(gl && gl._version
|
|
549
|
+
return Boolean(gl && Number.isFinite(gl._version));
|
|
568
550
|
}
|
|
569
551
|
|
|
570
552
|
/** Set constant float array attribute */
|
|
@@ -589,8 +571,7 @@ function setConstantFloatArray(device: WebGLDevice, location: number, array: Flo
|
|
|
589
571
|
|
|
590
572
|
/** Set constant signed int array attribute */
|
|
591
573
|
function setConstantIntArray(device: WebGLDevice, location: number, array: Int32Array): void {
|
|
592
|
-
device.
|
|
593
|
-
device.gl2?.vertexAttribI4iv(location, array);
|
|
574
|
+
device.gl.vertexAttribI4iv(location, array);
|
|
594
575
|
// TODO - not clear if we need to use the special forms, more testing needed
|
|
595
576
|
// switch (array.length) {
|
|
596
577
|
// case 1:
|
|
@@ -611,8 +592,7 @@ function setConstantIntArray(device: WebGLDevice, location: number, array: Int32
|
|
|
611
592
|
|
|
612
593
|
/** Set constant unsigned int array attribute */
|
|
613
594
|
function setConstantUintArray(device: WebGLDevice, location: number, array: Uint32Array) {
|
|
614
|
-
device.
|
|
615
|
-
device.gl2?.vertexAttribI4uiv(location, array);
|
|
595
|
+
device.gl.vertexAttribI4uiv(location, array);
|
|
616
596
|
// TODO - not clear if we need to use the special forms, more testing needed
|
|
617
597
|
// switch (array.length) {
|
|
618
598
|
// case 1:
|
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,15 +19,14 @@ 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(
|
|
26
|
-
|
|
27
|
+
device: Device,
|
|
27
28
|
options?: {framebuffer?: Framebuffer; color?: any; depth?: any; stencil?: any}
|
|
28
29
|
): void {
|
|
29
|
-
const device = WebGLDevice.attach(gl);
|
|
30
30
|
const {framebuffer = null, color = null, depth = null, stencil = null} = options || {};
|
|
31
31
|
const parameters: any = {};
|
|
32
32
|
|
|
@@ -60,50 +60,55 @@ export function clear(
|
|
|
60
60
|
assert(clearFlags !== 0, ERR_ARGUMENTS);
|
|
61
61
|
|
|
62
62
|
// Temporarily set any clear "colors" and call clear
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
const gl = (device as WebGLDevice).gl;
|
|
64
|
+
withGLParameters(gl, parameters, () => {
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
const {
|
|
78
|
+
framebuffer = null,
|
|
79
|
+
buffer = GL_COLOR,
|
|
80
|
+
drawBuffer = 0,
|
|
81
|
+
value = [0, 0, 0, 0]
|
|
82
|
+
} = options || {};
|
|
83
|
+
const gl = (device as WebGLDevice).gl;
|
|
84
|
+
withGLParameters(gl, {framebuffer}, () => {
|
|
80
85
|
// Method selection per OpenGL ES 3 docs
|
|
81
86
|
switch (buffer) {
|
|
82
87
|
case GL_COLOR:
|
|
83
88
|
switch (value.constructor) {
|
|
84
89
|
case Int32Array:
|
|
85
|
-
|
|
90
|
+
gl.clearBufferiv(buffer, drawBuffer, value);
|
|
86
91
|
break;
|
|
87
92
|
case Uint32Array:
|
|
88
|
-
|
|
93
|
+
gl.clearBufferuiv(buffer, drawBuffer, value);
|
|
89
94
|
break;
|
|
90
95
|
case Float32Array:
|
|
91
96
|
default:
|
|
92
|
-
|
|
97
|
+
gl.clearBufferfv(buffer, drawBuffer, value);
|
|
93
98
|
}
|
|
94
99
|
break;
|
|
95
100
|
|
|
96
101
|
case GL_DEPTH:
|
|
97
|
-
|
|
102
|
+
gl.clearBufferfv(GL_DEPTH, 0, [value]);
|
|
98
103
|
break;
|
|
99
104
|
|
|
100
105
|
case GL_STENCIL:
|
|
101
|
-
|
|
106
|
+
gl.clearBufferiv(GL_STENCIL, 0, [value]);
|
|
102
107
|
break;
|
|
103
108
|
|
|
104
109
|
case GL_DEPTH_STENCIL:
|
|
105
110
|
const [depth, stencil] = value;
|
|
106
|
-
|
|
111
|
+
gl.clearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);
|
|
107
112
|
break;
|
|
108
113
|
|
|
109
114
|
default:
|