@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,12 +1,12 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { Device, CanvasContext, log, uid, assert } from '@luma.gl/core';
|
|
2
|
-
import { isBrowser } from '@probe.gl/env';
|
|
3
|
-
import { polyfillContext } from "../context/polyfill/polyfill-context.js";
|
|
4
5
|
import { popContextState, pushContextState, trackContextState } from "../context/state-tracker/track-context-state.js";
|
|
5
|
-
import { createBrowserContext } from "../context/
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { getDeviceLimits, getWebGLLimits } from "./device-helpers/device-limits.js";
|
|
6
|
+
import { createBrowserContext } from "../context/helpers/create-browser-context.js";
|
|
7
|
+
import { getDeviceInfo } from "./device-helpers/webgl-device-info.js";
|
|
8
|
+
import { WebGLDeviceFeatures } from "./device-helpers/webgl-device-features.js";
|
|
9
|
+
import { WebGLDeviceLimits } from "./device-helpers/webgl-device-limits.js";
|
|
10
10
|
import { WebGLCanvasContext } from "./webgl-canvas-context.js";
|
|
11
11
|
import { loadSpectorJS, initializeSpectorJS } from "../context/debug/spector.js";
|
|
12
12
|
import { loadWebGLDeveloperTools, makeDebugContext } from "../context/debug/webgl-developer-tools.js";
|
|
@@ -21,364 +21,439 @@ import { WEBGLRenderPipeline } from "./resources/webgl-render-pipeline.js";
|
|
|
21
21
|
import { WEBGLCommandEncoder } from "./resources/webgl-command-encoder.js";
|
|
22
22
|
import { WEBGLVertexArray } from "./resources/webgl-vertex-array.js";
|
|
23
23
|
import { WEBGLTransformFeedback } from "./resources/webgl-transform-feedback.js";
|
|
24
|
+
import { WEBGLQuerySet } from "./resources/webgl-query-set.js";
|
|
24
25
|
import { readPixelsToArray, readPixelsToBuffer } from "../classic/copy-and-blit.js";
|
|
26
|
+
import { setGLParameters, getGLParameters } from "../context/parameters/unified-parameter-api.js";
|
|
27
|
+
import { withGLParameters } from "../context/state-tracker/with-parameters.js";
|
|
28
|
+
import { clear } from "../classic/clear.js";
|
|
29
|
+
import { getWebGLExtension } from "../context/helpers/webgl-extensions.js";
|
|
25
30
|
const LOG_LEVEL = 1;
|
|
31
|
+
/** WebGPU style Device API for a WebGL context */
|
|
26
32
|
export class WebGLDevice extends Device {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
33
|
+
//
|
|
34
|
+
// Public `Device` API
|
|
35
|
+
//
|
|
36
|
+
/** type of this device */
|
|
37
|
+
static type = 'webgl';
|
|
38
|
+
/** type of this device */
|
|
39
|
+
type = 'webgl';
|
|
40
|
+
/** The underlying WebGL context */
|
|
41
|
+
handle;
|
|
42
|
+
features;
|
|
43
|
+
limits;
|
|
44
|
+
info;
|
|
45
|
+
canvasContext;
|
|
46
|
+
lost;
|
|
47
|
+
_resolveContextLost;
|
|
48
|
+
//
|
|
49
|
+
// Static methods, expected to be present by `luma.createDevice()`
|
|
50
|
+
//
|
|
51
|
+
/** Check if WebGL 2 is available */
|
|
52
|
+
static isSupported() {
|
|
53
|
+
return typeof WebGL2RenderingContext !== 'undefined';
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get a device instance from a GL context
|
|
57
|
+
* Creates and instruments the device if not already created
|
|
58
|
+
* @param gl
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
static attach(gl) {
|
|
62
|
+
if (gl instanceof WebGLDevice) {
|
|
63
|
+
return gl;
|
|
64
|
+
}
|
|
65
|
+
// @ts-expect-error
|
|
66
|
+
if (gl?.device instanceof Device) {
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
return gl.device;
|
|
69
|
+
}
|
|
70
|
+
if (!isWebGL(gl)) {
|
|
71
|
+
throw new Error('Invalid WebGL2RenderingContext');
|
|
72
|
+
}
|
|
73
|
+
return new WebGLDevice({ gl: gl });
|
|
74
|
+
}
|
|
75
|
+
static async create(props = {}) {
|
|
76
|
+
log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created')();
|
|
77
|
+
const promises = [];
|
|
78
|
+
// Load webgl and spector debug scripts from CDN if requested
|
|
79
|
+
if (props.debug) {
|
|
80
|
+
promises.push(loadWebGLDeveloperTools());
|
|
81
|
+
}
|
|
82
|
+
if (props.spector) {
|
|
83
|
+
promises.push(loadSpectorJS());
|
|
84
|
+
}
|
|
85
|
+
// Wait for page to load: if canvas is a string we need to query the DOM for the canvas element.
|
|
86
|
+
// We only wait when props.canvas is string to avoids setting the global page onload callback unless necessary.
|
|
87
|
+
if (typeof props.canvas === 'string') {
|
|
88
|
+
promises.push(CanvasContext.pageLoaded);
|
|
89
|
+
}
|
|
90
|
+
// Wait for all the loads to settle before creating the context.
|
|
91
|
+
// The Device.create() functions are async, so in contrast to the constructor, we can `await` here.
|
|
92
|
+
const results = await Promise.allSettled(promises);
|
|
93
|
+
for (const result of results) {
|
|
94
|
+
if (result.status === 'rejected') {
|
|
95
|
+
log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
log.probe(LOG_LEVEL + 1, 'DOM is loaded')();
|
|
99
|
+
// @ts-expect-error
|
|
100
|
+
if (props.gl?.device) {
|
|
101
|
+
log.warn('reattaching existing device')();
|
|
102
|
+
return WebGLDevice.attach(props.gl);
|
|
103
|
+
}
|
|
104
|
+
const device = new WebGLDevice(props);
|
|
105
|
+
// Log some debug info about the newly created context
|
|
106
|
+
const message = `\
|
|
107
|
+
Created ${device.type}${device.debug ? ' debug' : ''} context: \
|
|
74
108
|
${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
109
|
+
log.probe(LOG_LEVEL, message)();
|
|
110
|
+
log.table(LOG_LEVEL, device.info)();
|
|
111
|
+
log.groupEnd(LOG_LEVEL)();
|
|
112
|
+
return device;
|
|
113
|
+
}
|
|
114
|
+
//
|
|
115
|
+
// Public API
|
|
116
|
+
//
|
|
117
|
+
constructor(props) {
|
|
118
|
+
super({ ...props, id: props.id || uid('webgl-device') });
|
|
119
|
+
// If attaching to an already attached context, return the attached device
|
|
120
|
+
// @ts-expect-error device is attached to context
|
|
121
|
+
const device = props.gl?.device;
|
|
122
|
+
if (device) {
|
|
123
|
+
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
124
|
+
}
|
|
125
|
+
// Create and instrument context
|
|
126
|
+
const canvas = props.gl?.canvas || props.canvas;
|
|
127
|
+
this.canvasContext = new WebGLCanvasContext(this, { ...props, canvas });
|
|
128
|
+
this.lost = new Promise(resolve => {
|
|
129
|
+
this._resolveContextLost = resolve;
|
|
130
|
+
});
|
|
131
|
+
let gl = props.gl || null;
|
|
132
|
+
gl ||= createBrowserContext(this.canvasContext.canvas, {
|
|
133
|
+
...props,
|
|
134
|
+
onContextLost: (event) => this._resolveContextLost?.({
|
|
135
|
+
reason: 'destroyed',
|
|
136
|
+
message: 'Entered sleep mode, or too many apps or browser tabs are using the GPU.'
|
|
137
|
+
})
|
|
138
|
+
});
|
|
139
|
+
if (!gl) {
|
|
140
|
+
throw new Error('WebGL context creation failed');
|
|
141
|
+
}
|
|
142
|
+
this.handle = gl;
|
|
143
|
+
this.gl = gl;
|
|
144
|
+
this.gl.device = this; // Update GL context: Link webgl context back to device
|
|
145
|
+
this.gl._version = 2; // Update GL context: Store WebGL version field on gl context (HACK to identify debug contexts)
|
|
146
|
+
// luma Device fields
|
|
147
|
+
this.info = getDeviceInfo(this.gl, this._extensions);
|
|
148
|
+
this.limits = new WebGLDeviceLimits(this.gl);
|
|
149
|
+
this.features = new WebGLDeviceFeatures(this.gl, this._extensions, this.props.disabledFeatures);
|
|
150
|
+
if (this.props.initalizeFeatures) {
|
|
151
|
+
this.features.initializeFeatures();
|
|
152
|
+
}
|
|
153
|
+
this.canvasContext.resize();
|
|
154
|
+
// Install context state tracking
|
|
155
|
+
// @ts-expect-error - hidden parameters
|
|
156
|
+
const { enable = true, copyState = false } = props;
|
|
157
|
+
trackContextState(this.gl, {
|
|
158
|
+
enable,
|
|
159
|
+
copyState,
|
|
160
|
+
log: (...args) => log.log(1, ...args)()
|
|
161
|
+
});
|
|
162
|
+
// DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1
|
|
163
|
+
if (props.debug) {
|
|
164
|
+
this.gl = makeDebugContext(this.gl, { ...props, throwOnError: true });
|
|
165
|
+
this.debug = true;
|
|
166
|
+
log.level = Math.max(log.level, 1);
|
|
167
|
+
log.warn('WebGL debug mode activated. Performance reduced.')();
|
|
168
|
+
}
|
|
169
|
+
if (props.spector) {
|
|
170
|
+
this.spectorJS = initializeSpectorJS({ ...this.props, canvas: this.handle.canvas });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Destroys the context
|
|
175
|
+
* @note Has no effect for WebGL browser contexts, there is no browser API for destroying contexts
|
|
176
|
+
*/
|
|
177
|
+
destroy() { }
|
|
178
|
+
get isLost() {
|
|
179
|
+
return this.gl.isContextLost();
|
|
180
|
+
}
|
|
181
|
+
getSize() {
|
|
182
|
+
return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];
|
|
183
|
+
}
|
|
184
|
+
isTextureFormatSupported(format) {
|
|
185
|
+
return isTextureFormatSupported(this.gl, format, this._extensions);
|
|
186
|
+
}
|
|
187
|
+
isTextureFormatFilterable(format) {
|
|
188
|
+
return isTextureFormatFilterable(this.gl, format, this._extensions);
|
|
189
|
+
}
|
|
190
|
+
isTextureFormatRenderable(format) {
|
|
191
|
+
return isTextureFormatRenderable(this.gl, format, this._extensions);
|
|
192
|
+
}
|
|
193
|
+
// IMPLEMENTATION OF ABSTRACT DEVICE
|
|
194
|
+
createCanvasContext(props) {
|
|
195
|
+
throw new Error('WebGL only supports a single canvas');
|
|
196
|
+
}
|
|
197
|
+
createBuffer(props) {
|
|
198
|
+
const newProps = this._getBufferProps(props);
|
|
199
|
+
return new WEBGLBuffer(this, newProps);
|
|
200
|
+
}
|
|
201
|
+
_createTexture(props) {
|
|
202
|
+
return new WEBGLTexture(this, props);
|
|
203
|
+
}
|
|
204
|
+
createExternalTexture(props) {
|
|
205
|
+
throw new Error('createExternalTexture() not implemented'); // return new Program(props);
|
|
206
|
+
}
|
|
207
|
+
createSampler(props) {
|
|
208
|
+
return new WEBGLSampler(this, props);
|
|
209
|
+
}
|
|
210
|
+
createShader(props) {
|
|
211
|
+
return new WEBGLShader(this, props);
|
|
212
|
+
}
|
|
213
|
+
createFramebuffer(props) {
|
|
214
|
+
return new WEBGLFramebuffer(this, props);
|
|
215
|
+
}
|
|
216
|
+
createVertexArray(props) {
|
|
217
|
+
return new WEBGLVertexArray(this, props);
|
|
218
|
+
}
|
|
219
|
+
createTransformFeedback(props) {
|
|
220
|
+
return new WEBGLTransformFeedback(this, props);
|
|
221
|
+
}
|
|
222
|
+
createQuerySet(props) {
|
|
223
|
+
return new WEBGLQuerySet(this, props);
|
|
224
|
+
}
|
|
225
|
+
createRenderPipeline(props) {
|
|
226
|
+
return new WEBGLRenderPipeline(this, props);
|
|
227
|
+
}
|
|
228
|
+
beginRenderPass(props) {
|
|
229
|
+
return new WEBGLRenderPass(this, props);
|
|
230
|
+
}
|
|
231
|
+
createComputePipeline(props) {
|
|
232
|
+
throw new Error('ComputePipeline not supported in WebGL');
|
|
233
|
+
}
|
|
234
|
+
beginComputePass(props) {
|
|
235
|
+
throw new Error('ComputePass not supported in WebGL');
|
|
236
|
+
}
|
|
237
|
+
renderPass = null;
|
|
238
|
+
createCommandEncoder(props) {
|
|
239
|
+
return new WEBGLCommandEncoder(this, props);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Offscreen Canvas Support: Commit the frame
|
|
243
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/commit
|
|
244
|
+
* Chrome's offscreen canvas does not require gl.commit
|
|
245
|
+
*/
|
|
246
|
+
submit() {
|
|
247
|
+
this.renderPass?.end();
|
|
248
|
+
this.renderPass = null;
|
|
249
|
+
// this.canvasContext.commit();
|
|
250
|
+
}
|
|
251
|
+
//
|
|
252
|
+
// TEMPORARY HACKS - will be removed in v9.1
|
|
253
|
+
//
|
|
254
|
+
/** @deprecated - should use command encoder */
|
|
255
|
+
readPixelsToArrayWebGL(source, options) {
|
|
256
|
+
return readPixelsToArray(source, options);
|
|
257
|
+
}
|
|
258
|
+
/** @deprecated - should use command encoder */
|
|
259
|
+
readPixelsToBufferWebGL(source, options) {
|
|
260
|
+
return readPixelsToBuffer(source, options);
|
|
261
|
+
}
|
|
262
|
+
setParametersWebGL(parameters) {
|
|
263
|
+
setGLParameters(this.gl, parameters);
|
|
264
|
+
}
|
|
265
|
+
getParametersWebGL(parameters) {
|
|
266
|
+
return getGLParameters(this.gl, parameters);
|
|
267
|
+
}
|
|
268
|
+
withParametersWebGL(parameters, func) {
|
|
269
|
+
withGLParameters(this.gl, parameters, func);
|
|
270
|
+
}
|
|
271
|
+
clearWebGL(options) {
|
|
272
|
+
clear(this, options);
|
|
273
|
+
}
|
|
274
|
+
//
|
|
275
|
+
// WebGL-only API (not part of `Device` API)
|
|
276
|
+
//
|
|
277
|
+
/** WebGL2 context. */
|
|
278
|
+
gl;
|
|
279
|
+
debug = false;
|
|
280
|
+
/** State used by luma.gl classes: TODO - move to canvasContext*/
|
|
281
|
+
_canvasSizeInfo = { clientWidth: 0, clientHeight: 0, devicePixelRatio: 1 };
|
|
282
|
+
/** State used by luma.gl classes - TODO - not used? */
|
|
283
|
+
_extensions = {};
|
|
284
|
+
_polyfilled = false;
|
|
285
|
+
/** Instance of Spector.js (if initialized) */
|
|
286
|
+
spectorJS;
|
|
287
|
+
/**
|
|
288
|
+
* Triggers device (or WebGL context) loss.
|
|
289
|
+
* @note primarily intended for testing how application reacts to device loss
|
|
290
|
+
*/
|
|
291
|
+
loseDevice() {
|
|
292
|
+
let deviceLossTriggered = false;
|
|
293
|
+
const extensions = this.getExtension('WEBGL_lose_context');
|
|
294
|
+
const ext = extensions.WEBGL_lose_context;
|
|
295
|
+
if (ext) {
|
|
296
|
+
deviceLossTriggered = true;
|
|
297
|
+
ext.loseContext();
|
|
298
|
+
// ext.loseContext should trigger context loss callback but the platform may not do this, so do it explicitly
|
|
299
|
+
}
|
|
300
|
+
this._resolveContextLost?.({
|
|
301
|
+
reason: 'destroyed',
|
|
302
|
+
message: 'Application triggered context loss'
|
|
303
|
+
});
|
|
304
|
+
return deviceLossTriggered;
|
|
305
|
+
}
|
|
306
|
+
/** Save current WebGL context state onto an internal stack */
|
|
307
|
+
pushState() {
|
|
308
|
+
pushContextState(this.gl);
|
|
309
|
+
}
|
|
310
|
+
/** Restores previously saved context state */
|
|
311
|
+
popState() {
|
|
312
|
+
popContextState(this.gl);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
|
|
316
|
+
* luma.gl ids and props can be inspected
|
|
317
|
+
*/
|
|
318
|
+
setSpectorMetadata(handle, props) {
|
|
319
|
+
// @ts-expect-error
|
|
320
|
+
// eslint-disable-next-line camelcase
|
|
321
|
+
handle.__SPECTOR_Metadata = props;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Returns the GL.<KEY> constant that corresponds to a numeric value of a GL constant
|
|
325
|
+
* Be aware that there are some duplicates especially for constants that are 0,
|
|
326
|
+
* so this isn't guaranteed to return the right key in all cases.
|
|
327
|
+
*/
|
|
328
|
+
getGLKey(value, gl) {
|
|
329
|
+
// @ts-ignore expect-error depends on settings
|
|
330
|
+
gl = gl || this.gl2 || this.gl;
|
|
331
|
+
const number = Number(value);
|
|
332
|
+
for (const key in gl) {
|
|
333
|
+
// @ts-ignore expect-error depends on settings
|
|
334
|
+
if (gl[key] === number) {
|
|
335
|
+
return `GL.${key}`;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
// No constant found. Stringify the value and return it.
|
|
339
|
+
return String(value);
|
|
340
|
+
}
|
|
341
|
+
/** Store constants */
|
|
342
|
+
_constants;
|
|
343
|
+
/**
|
|
344
|
+
* Set a constant value for a location. Disabled attributes at that location will read from this value
|
|
345
|
+
* @note WebGL constants are stored globally on the WebGL context, not the VertexArray
|
|
346
|
+
* so they need to be updated before every render
|
|
347
|
+
* @todo - remember/cache values to avoid setting them unnecessarily?
|
|
348
|
+
*/
|
|
349
|
+
setConstantAttributeWebGL(location, constant) {
|
|
350
|
+
const maxVertexAttributes = this.limits.maxVertexAttributes;
|
|
351
|
+
this._constants = this._constants || new Array(maxVertexAttributes).fill(null);
|
|
352
|
+
const currentConstant = this._constants[location];
|
|
353
|
+
if (currentConstant && compareConstantArrayValues(currentConstant, constant)) {
|
|
354
|
+
log.info(1, `setConstantAttributeWebGL(${location}) could have been skipped, value unchanged`)();
|
|
355
|
+
}
|
|
356
|
+
this._constants[location] = constant;
|
|
357
|
+
switch (constant.constructor) {
|
|
358
|
+
case Float32Array:
|
|
359
|
+
setConstantFloatArray(this, location, constant);
|
|
360
|
+
break;
|
|
361
|
+
case Int32Array:
|
|
362
|
+
setConstantIntArray(this, location, constant);
|
|
363
|
+
break;
|
|
364
|
+
case Uint32Array:
|
|
365
|
+
setConstantUintArray(this, location, constant);
|
|
366
|
+
break;
|
|
367
|
+
default:
|
|
368
|
+
assert(false);
|
|
160
369
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
webgl2: this.isWebGL2,
|
|
168
|
-
throwOnError: true
|
|
169
|
-
});
|
|
170
|
-
this.gl2 = this.gl;
|
|
171
|
-
this.debug = true;
|
|
172
|
-
log.level = Math.max(log.level, 1);
|
|
173
|
-
log.warn('WebGL debug mode activated. Performance reduced.')();
|
|
174
|
-
}
|
|
175
|
-
if (isBrowser() && props.spector) {
|
|
176
|
-
const canvas = this.handle.canvas || props.canvas;
|
|
177
|
-
this.spector = initializeSpectorJS({
|
|
178
|
-
...this.props,
|
|
179
|
-
canvas
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
destroy() {
|
|
184
|
-
const ext = this.gl.getExtension('STACKGL_destroy_context');
|
|
185
|
-
if (ext) {
|
|
186
|
-
ext.destroy();
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
get isLost() {
|
|
190
|
-
return this.gl.isContextLost();
|
|
191
|
-
}
|
|
192
|
-
getSize() {
|
|
193
|
-
return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];
|
|
194
|
-
}
|
|
195
|
-
isTextureFormatSupported(format) {
|
|
196
|
-
return isTextureFormatSupported(this.gl, format);
|
|
197
|
-
}
|
|
198
|
-
isTextureFormatFilterable(format) {
|
|
199
|
-
return isTextureFormatFilterable(this.gl, format);
|
|
200
|
-
}
|
|
201
|
-
isTextureFormatRenderable(format) {
|
|
202
|
-
return isTextureFormatRenderable(this.gl, format);
|
|
203
|
-
}
|
|
204
|
-
assertWebGL2() {
|
|
205
|
-
if (!this.gl2) {
|
|
206
|
-
throw new Error('Requires WebGL2');
|
|
207
|
-
}
|
|
208
|
-
return this.gl2;
|
|
209
|
-
}
|
|
210
|
-
createCanvasContext(props) {
|
|
211
|
-
throw new Error('WebGL only supports a single canvas');
|
|
212
|
-
}
|
|
213
|
-
createBuffer(props) {
|
|
214
|
-
const newProps = this._getBufferProps(props);
|
|
215
|
-
return new WEBGLBuffer(this, newProps);
|
|
216
|
-
}
|
|
217
|
-
_createTexture(props) {
|
|
218
|
-
return new WEBGLTexture(this, props);
|
|
219
|
-
}
|
|
220
|
-
createExternalTexture(props) {
|
|
221
|
-
throw new Error('createExternalTexture() not implemented');
|
|
222
|
-
}
|
|
223
|
-
createSampler(props) {
|
|
224
|
-
return new WEBGLSampler(this, props);
|
|
225
|
-
}
|
|
226
|
-
createShader(props) {
|
|
227
|
-
return new WEBGLShader(this, props);
|
|
228
|
-
}
|
|
229
|
-
createFramebuffer(props) {
|
|
230
|
-
return new WEBGLFramebuffer(this, props);
|
|
231
|
-
}
|
|
232
|
-
createRenderPipeline(props) {
|
|
233
|
-
return new WEBGLRenderPipeline(this, props);
|
|
234
|
-
}
|
|
235
|
-
createVertexArray(props) {
|
|
236
|
-
return new WEBGLVertexArray(this, props);
|
|
237
|
-
}
|
|
238
|
-
beginRenderPass(props) {
|
|
239
|
-
return new WEBGLRenderPass(this, props);
|
|
240
|
-
}
|
|
241
|
-
createComputePipeline(props) {
|
|
242
|
-
throw new Error('ComputePipeline not supported in WebGL');
|
|
243
|
-
}
|
|
244
|
-
beginComputePass(props) {
|
|
245
|
-
throw new Error('ComputePass not supported in WebGL');
|
|
246
|
-
}
|
|
247
|
-
createTransformFeedback(props) {
|
|
248
|
-
return new WEBGLTransformFeedback(this, props);
|
|
249
|
-
}
|
|
250
|
-
getDefaultRenderPass() {
|
|
251
|
-
this.renderPass = this.renderPass || this.beginRenderPass({
|
|
252
|
-
framebuffer: this.canvasContext.getCurrentFramebuffer()
|
|
253
|
-
});
|
|
254
|
-
return this.renderPass;
|
|
255
|
-
}
|
|
256
|
-
createCommandEncoder(props) {
|
|
257
|
-
return new WEBGLCommandEncoder(this, props);
|
|
258
|
-
}
|
|
259
|
-
submit() {
|
|
260
|
-
var _this$renderPass;
|
|
261
|
-
(_this$renderPass = this.renderPass) === null || _this$renderPass === void 0 ? void 0 : _this$renderPass.end();
|
|
262
|
-
this.renderPass = null;
|
|
263
|
-
}
|
|
264
|
-
readPixelsToArrayWebGL(source, options) {
|
|
265
|
-
return readPixelsToArray(source, options);
|
|
266
|
-
}
|
|
267
|
-
readPixelsToBufferWebGL2(source, options) {
|
|
268
|
-
return readPixelsToBuffer(source, options);
|
|
269
|
-
}
|
|
270
|
-
get webglLimits() {
|
|
271
|
-
this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);
|
|
272
|
-
return this._webglLimits;
|
|
273
|
-
}
|
|
274
|
-
loseDevice() {
|
|
275
|
-
var _this$_resolveContext2;
|
|
276
|
-
let deviceLossTriggered = false;
|
|
277
|
-
const ext = this.gl.getExtension('WEBGL_lose_context');
|
|
278
|
-
if (ext) {
|
|
279
|
-
deviceLossTriggered = true;
|
|
280
|
-
ext.loseContext();
|
|
281
|
-
}
|
|
282
|
-
(_this$_resolveContext2 = this._resolveContextLost) === null || _this$_resolveContext2 === void 0 ? void 0 : _this$_resolveContext2.call(this, {
|
|
283
|
-
reason: 'destroyed',
|
|
284
|
-
message: 'Application triggered context loss'
|
|
285
|
-
});
|
|
286
|
-
return deviceLossTriggered;
|
|
287
|
-
}
|
|
288
|
-
pushState() {
|
|
289
|
-
pushContextState(this.gl);
|
|
290
|
-
}
|
|
291
|
-
popState() {
|
|
292
|
-
popContextState(this.gl);
|
|
293
|
-
}
|
|
294
|
-
setSpectorMetadata(handle, props) {
|
|
295
|
-
handle.__SPECTOR_Metadata = props;
|
|
296
|
-
}
|
|
297
|
-
getGLKey(value, gl) {
|
|
298
|
-
gl = gl || this.gl2 || this.gl;
|
|
299
|
-
const number = Number(value);
|
|
300
|
-
for (const key in gl) {
|
|
301
|
-
if (gl[key] === number) {
|
|
302
|
-
return `GL.${key}`;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
return String(value);
|
|
306
|
-
}
|
|
307
|
-
setConstantAttribute(location, constant) {
|
|
308
|
-
this._constants = this._constants || new Array(this.limits.maxVertexAttributes).fill(null);
|
|
309
|
-
const currentConstant = this._constants[location];
|
|
310
|
-
if (currentConstant && compareConstantArrayValues(currentConstant, constant)) {
|
|
311
|
-
log.info(1, `setConstantAttribute(${location}) could have been skipped, value unchanged`)();
|
|
312
|
-
}
|
|
313
|
-
this._constants[location] = constant;
|
|
314
|
-
switch (constant.constructor) {
|
|
315
|
-
case Float32Array:
|
|
316
|
-
setConstantFloatArray(this, location, constant);
|
|
317
|
-
break;
|
|
318
|
-
case Int32Array:
|
|
319
|
-
setConstantIntArray(this, location, constant);
|
|
320
|
-
break;
|
|
321
|
-
case Uint32Array:
|
|
322
|
-
setConstantUintArray(this, location, constant);
|
|
323
|
-
break;
|
|
324
|
-
default:
|
|
325
|
-
assert(false);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
370
|
+
}
|
|
371
|
+
/** Ensure extensions are only requested once */
|
|
372
|
+
getExtension(name) {
|
|
373
|
+
getWebGLExtension(this.gl, name, this._extensions);
|
|
374
|
+
return this._extensions;
|
|
375
|
+
}
|
|
328
376
|
}
|
|
329
|
-
|
|
377
|
+
/** Check if supplied parameter is a WebGL2RenderingContext */
|
|
330
378
|
function isWebGL(gl) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
return
|
|
336
|
-
}
|
|
337
|
-
return Boolean(gl && Number.isFinite(gl._version));
|
|
338
|
-
}
|
|
339
|
-
function isWebGL2(gl) {
|
|
340
|
-
if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
|
|
341
|
-
return true;
|
|
342
|
-
}
|
|
343
|
-
return Boolean(gl && gl._version === 2);
|
|
379
|
+
if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
// Look for debug contexts, headless gl etc
|
|
383
|
+
return Boolean(gl && Number.isFinite(gl._version));
|
|
344
384
|
}
|
|
385
|
+
/** Set constant float array attribute */
|
|
345
386
|
function setConstantFloatArray(device, location, array) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
387
|
+
switch (array.length) {
|
|
388
|
+
case 1:
|
|
389
|
+
device.gl.vertexAttrib1fv(location, array);
|
|
390
|
+
break;
|
|
391
|
+
case 2:
|
|
392
|
+
device.gl.vertexAttrib2fv(location, array);
|
|
393
|
+
break;
|
|
394
|
+
case 3:
|
|
395
|
+
device.gl.vertexAttrib3fv(location, array);
|
|
396
|
+
break;
|
|
397
|
+
case 4:
|
|
398
|
+
device.gl.vertexAttrib4fv(location, array);
|
|
399
|
+
break;
|
|
400
|
+
default:
|
|
401
|
+
assert(false);
|
|
402
|
+
}
|
|
362
403
|
}
|
|
404
|
+
/** Set constant signed int array attribute */
|
|
363
405
|
function setConstantIntArray(device, location, array) {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
406
|
+
device.gl.vertexAttribI4iv(location, array);
|
|
407
|
+
// TODO - not clear if we need to use the special forms, more testing needed
|
|
408
|
+
// switch (array.length) {
|
|
409
|
+
// case 1:
|
|
410
|
+
// gl.vertexAttribI1iv(location, array);
|
|
411
|
+
// break;
|
|
412
|
+
// case 2:
|
|
413
|
+
// gl.vertexAttribI2iv(location, array);
|
|
414
|
+
// break;
|
|
415
|
+
// case 3:
|
|
416
|
+
// gl.vertexAttribI3iv(location, array);
|
|
417
|
+
// break;
|
|
418
|
+
// case 4:
|
|
419
|
+
// break;
|
|
420
|
+
// default:
|
|
421
|
+
// assert(false);
|
|
422
|
+
// }
|
|
367
423
|
}
|
|
424
|
+
/** Set constant unsigned int array attribute */
|
|
368
425
|
function setConstantUintArray(device, location, array) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
426
|
+
device.gl.vertexAttribI4uiv(location, array);
|
|
427
|
+
// TODO - not clear if we need to use the special forms, more testing needed
|
|
428
|
+
// switch (array.length) {
|
|
429
|
+
// case 1:
|
|
430
|
+
// gl.vertexAttribI1uiv(location, array);
|
|
431
|
+
// break;
|
|
432
|
+
// case 2:
|
|
433
|
+
// gl.vertexAttribI2uiv(location, array);
|
|
434
|
+
// break;
|
|
435
|
+
// case 3:
|
|
436
|
+
// gl.vertexAttribI3uiv(location, array);
|
|
437
|
+
// break;
|
|
438
|
+
// case 4:
|
|
439
|
+
// gl.vertexAttribI4uiv(location, array);
|
|
440
|
+
// break;
|
|
441
|
+
// default:
|
|
442
|
+
// assert(false);
|
|
443
|
+
// }
|
|
372
444
|
}
|
|
445
|
+
/**
|
|
446
|
+
* Compares contents of two typed arrays
|
|
447
|
+
* @todo max length?
|
|
448
|
+
*/
|
|
373
449
|
function compareConstantArrayValues(v1, v2) {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
450
|
+
if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
|
|
451
|
+
return false;
|
|
452
|
+
}
|
|
453
|
+
for (let i = 0; i < v1.length; ++i) {
|
|
454
|
+
if (v1[i] !== v2[i]) {
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return true;
|
|
383
459
|
}
|
|
384
|
-
//# sourceMappingURL=webgl-device.js.map
|