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