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