@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,161 +0,0 @@
|
|
|
1
|
-
// luma.gl, MIT license
|
|
2
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
-
|
|
4
|
-
// Feature detection for WebGL
|
|
5
|
-
// Provides a function that enables simple checking of which WebGL features are
|
|
6
|
-
// available in an WebGL1 or WebGL2 environment.
|
|
7
|
-
|
|
8
|
-
import {DeviceFeature} from '@luma.gl/core';
|
|
9
|
-
import {isWebGL2} from '../../context/context/webgl-checks';
|
|
10
|
-
import {isOldIE} from './is-old-ie';
|
|
11
|
-
import {getTextureFeatures, _checkFloat32ColorAttachment} from '../converters/texture-formats';
|
|
12
|
-
|
|
13
|
-
/** Get WebGPU style feature strings */
|
|
14
|
-
export function getDeviceFeatures(gl: WebGLRenderingContext): Set<DeviceFeature> {
|
|
15
|
-
const features = getWebGLFeatures(gl);
|
|
16
|
-
|
|
17
|
-
// texture features
|
|
18
|
-
// features.add('texture-compression-bc');
|
|
19
|
-
for (const textureFeature of getTextureFeatures(gl)) {
|
|
20
|
-
features.add(textureFeature);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// TODO
|
|
24
|
-
// features.add('depth-clip-control'); // GPUPrimitiveState.clampDepth
|
|
25
|
-
// features.add('depth24unorm-stencil8'); // GPUTextureFormat 'depth24unorm-stencil8'.
|
|
26
|
-
// features.add('depth32float-stencil8'); // GPUTextureFormat 'depth32float-stencil8'.
|
|
27
|
-
// features.add('timestamp-query'); // GPUQueryType "timestamp-query"
|
|
28
|
-
// "indirect-first-instance"
|
|
29
|
-
|
|
30
|
-
return features;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Extract all WebGL features */
|
|
34
|
-
export function getWebGLFeatures(gl: WebGLRenderingContext): Set<DeviceFeature> {
|
|
35
|
-
// Enables EXT_float_blend first: https://developer.mozilla.org/en-US/docs/Web/API/EXT_float_blend
|
|
36
|
-
gl.getExtension('EXT_color_buffer_float');
|
|
37
|
-
gl.getExtension('WEBGL_color_buffer_float');
|
|
38
|
-
gl.getExtension('EXT_float_blend');
|
|
39
|
-
|
|
40
|
-
const features = new Set<DeviceFeature>();
|
|
41
|
-
for (const feature of Object.keys(WEBGL_FEATURES)) {
|
|
42
|
-
// @ts-expect-error
|
|
43
|
-
if (isFeatureSupported(gl, feature)) {
|
|
44
|
-
// @ts-expect-error
|
|
45
|
-
features.add(feature);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return features;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function isFeatureSupported(gl: WebGLRenderingContext, feature: DeviceFeature): boolean {
|
|
52
|
-
const featureInfo = WEBGL_FEATURES[feature];
|
|
53
|
-
if (!featureInfo) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const [webgl1Feature, webgl2Feature] = featureInfo || [];
|
|
58
|
-
|
|
59
|
-
// Get extension name from table
|
|
60
|
-
const featureDefinition = isWebGL2(gl) ? webgl2Feature : webgl1Feature;
|
|
61
|
-
|
|
62
|
-
// Check if the value is dependent on checking one or more extensions
|
|
63
|
-
if (typeof featureDefinition === 'boolean') {
|
|
64
|
-
return featureDefinition;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
switch (feature) {
|
|
68
|
-
case 'texture-renderable-rgba32float-webgl':
|
|
69
|
-
return isWebGL2(gl) ? Boolean(gl.getExtension(featureDefinition)) :
|
|
70
|
-
_checkFloat32ColorAttachment(gl);
|
|
71
|
-
case 'glsl-derivatives':
|
|
72
|
-
return canCompileGLSLExtension(gl, featureDefinition); // TODO options
|
|
73
|
-
case 'glsl-frag-data':
|
|
74
|
-
return canCompileGLSLExtension(gl, featureDefinition, {behavior: 'require'}); // TODO options
|
|
75
|
-
case 'glsl-frag-depth':
|
|
76
|
-
return canCompileGLSLExtension(gl, featureDefinition); // TODO options
|
|
77
|
-
default:
|
|
78
|
-
return Boolean(gl.getExtension(featureDefinition));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const compiledGLSLExtensions: Record<string, boolean> = {};
|
|
83
|
-
|
|
84
|
-
/*
|
|
85
|
-
* Enables feature detection in IE11 due to a bug where gl.getExtension may return true
|
|
86
|
-
* but fail to compile when the extension is enabled in the shader. Specifically,
|
|
87
|
-
* the OES_standard_derivatives and WEBGL_draw_buffers extensions fails to compile in IE11 even though its included
|
|
88
|
-
* in the list of supported extensions.
|
|
89
|
-
* opts allows user agent to be overridden for testing
|
|
90
|
-
* Inputs :
|
|
91
|
-
* gl : WebGL context
|
|
92
|
-
* cap : Key of WEBGL_FEATURES object identifying the extension
|
|
93
|
-
* opts :
|
|
94
|
-
* behavior : behavior of extension to be tested, by defualt `enable` is used
|
|
95
|
-
* Returns : true, if shader is compiled successfully, false otherwise
|
|
96
|
-
*/
|
|
97
|
-
export function canCompileGLSLExtension(gl: WebGLRenderingContext, extensionName, opts: {behavior?} = {}) {
|
|
98
|
-
if (!isOldIE(opts)) {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (extensionName in compiledGLSLExtensions) {
|
|
103
|
-
return compiledGLSLExtensions[extensionName];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const behavior = opts.behavior || 'enable';
|
|
107
|
-
const source = `#extension GL_${extensionName} : ${behavior}\nvoid main(void) {}`;
|
|
108
|
-
|
|
109
|
-
const shader = gl.createShader(gl.VERTEX_SHADER);
|
|
110
|
-
if (!shader) {
|
|
111
|
-
throw new Error('shader');
|
|
112
|
-
}
|
|
113
|
-
gl.shaderSource(shader, source);
|
|
114
|
-
gl.compileShader(shader);
|
|
115
|
-
const canCompile = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
|
116
|
-
gl.deleteShader(shader);
|
|
117
|
-
compiledGLSLExtensions[extensionName] = canCompile;
|
|
118
|
-
return canCompile;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** Defines luma.gl "feature" names and semantics
|
|
122
|
-
* Format: 'feature-name: [WebGL1 support, WebGL2 support] / [WebGL1 and WebGL2 support]', when support is 'string' it is the name of the extension
|
|
123
|
-
*/
|
|
124
|
-
const WEBGL_FEATURES: Partial<Record<DeviceFeature, [boolean | string, boolean | string]>> = {
|
|
125
|
-
'webgl': [true, true],
|
|
126
|
-
'webgl2': [false, true],
|
|
127
|
-
|
|
128
|
-
'timer-query-webgl': ['EXT_disjoint_timer_query', 'EXT_disjoint_timer_query_webgl2'],
|
|
129
|
-
'transform-feedback-webgl2': [false, true],
|
|
130
|
-
|
|
131
|
-
// WEBGL1 SUPPORT
|
|
132
|
-
'vertex-array-object-webgl1': ['OES_vertex_array_object', true],
|
|
133
|
-
'instanced-rendering-webgl1': ['ANGLE_instanced_arrays', true],
|
|
134
|
-
'multiple-render-targets-webgl1': ['WEBGL_draw_buffers', true],
|
|
135
|
-
'index-uint32-webgl1': ['OES_element_index_uint', true],
|
|
136
|
-
'blend-minmax-webgl1': ['EXT_blend_minmax', true],
|
|
137
|
-
'texture-blend-float-webgl1': ['EXT_float_blend', 'EXT_float_blend'],
|
|
138
|
-
|
|
139
|
-
// TEXTURES, RENDERBUFFERS
|
|
140
|
-
'texture-formats-srgb-webgl1': ['EXT_sRGB', true],
|
|
141
|
-
|
|
142
|
-
// TEXTURES
|
|
143
|
-
'texture-formats-depth-webgl1': ['WEBGL_depth_texture', true],
|
|
144
|
-
'texture-formats-float32-webgl1': ['OES_texture_float', true],
|
|
145
|
-
'texture-formats-float16-webgl1': ['OES_texture_half_float', true],
|
|
146
|
-
|
|
147
|
-
'texture-filter-linear-float32-webgl': ['OES_texture_float_linear', 'OES_texture_float_linear'],
|
|
148
|
-
'texture-filter-linear-float16-webgl': ['OES_texture_half_float_linear', 'OES_texture_half_float_linear'],
|
|
149
|
-
'texture-filter-anisotropic-webgl': ['EXT_texture_filter_anisotropic', 'EXT_texture_filter_anisotropic'],
|
|
150
|
-
|
|
151
|
-
// FRAMEBUFFERS, TEXTURES AND RENDERBUFFERS
|
|
152
|
-
'texture-renderable-rgba32float-webgl': ['WEBGL_color_buffer_float', 'EXT_color_buffer_float'], // Note override check
|
|
153
|
-
'texture-renderable-float32-webgl': [false, 'EXT_color_buffer_float'],
|
|
154
|
-
'texture-renderable-float16-webgl': ['EXT_color_buffer_half_float', 'EXT_color_buffer_half_float'],
|
|
155
|
-
|
|
156
|
-
// GLSL extensions
|
|
157
|
-
'glsl-frag-data': ['WEBGL_draw_buffers', true],
|
|
158
|
-
'glsl-frag-depth': ['EXT_frag_depth', true],
|
|
159
|
-
'glsl-derivatives': ['OES_standard_derivatives', true],
|
|
160
|
-
'glsl-texture-lod': ['EXT_shader_texture_lod', true]
|
|
161
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// luma.gl, MIT license
|
|
2
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
-
|
|
4
|
-
// opts allows user agent to be overridden for testing
|
|
5
|
-
export function isOldIE(opts = {}) {
|
|
6
|
-
const navigator = typeof window !== 'undefined' ? window.navigator || {} : {};
|
|
7
|
-
// @ts-expect-error
|
|
8
|
-
const userAgent = opts.userAgent || navigator.userAgent || '';
|
|
9
|
-
// We only care about older versions of IE (IE 11 and below). Newer versions of IE (Edge)
|
|
10
|
-
// have much better web standards support.
|
|
11
|
-
const isMSIE = userAgent.indexOf('MSIE ') !== -1;
|
|
12
|
-
const isTrident = userAgent.indexOf('Trident/') !== -1;
|
|
13
|
-
return isMSIE || isTrident;
|
|
14
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// luma.gl, MIT license
|
|
2
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
-
|
|
4
|
-
const ERR_HEADLESSGL_FAILED =
|
|
5
|
-
'Failed to create WebGL context in Node.js, headless gl returned null';
|
|
6
|
-
|
|
7
|
-
const ERR_HEADLESSGL_LOAD = '\
|
|
8
|
-
luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL \
|
|
9
|
-
contexts can not be created. This may not be an error. For example, this is a \
|
|
10
|
-
typical configuration for isorender applications running on the server.';
|
|
11
|
-
|
|
12
|
-
const CONTEXT_DEFAULTS = {
|
|
13
|
-
width: 1,
|
|
14
|
-
height: 1,
|
|
15
|
-
debug: true,
|
|
16
|
-
throwOnError: false
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/** Duck typing for the main headless gl export, a function to create contexts */
|
|
20
|
-
export type HeadlessGL = (width: number, height: number, options: Record<string, unknown>) => WebGLRenderingContext;
|
|
21
|
-
|
|
22
|
-
let headlessGL: HeadlessGL | null = null;
|
|
23
|
-
|
|
24
|
-
/** By importing `gl` and registering it with this function, contexts can be created under Node.js */
|
|
25
|
-
export function registerHeadlessGL(headlessgl: HeadlessGL) {
|
|
26
|
-
headlessGL = headlessgl;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** @returns true if headless gl is registered */
|
|
30
|
-
export function isHeadlessGLRegistered(): boolean {
|
|
31
|
-
return headlessGL !== null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Create headless gl context (for running under Node.js) */
|
|
35
|
-
export function createHeadlessContext(options?: Record<string, any>): WebGLRenderingContext {
|
|
36
|
-
options = {...CONTEXT_DEFAULTS, ...options};
|
|
37
|
-
|
|
38
|
-
const {width, height, webgl1, webgl2} = options;
|
|
39
|
-
|
|
40
|
-
if (webgl2 && !webgl1) {
|
|
41
|
-
throw new Error('headless-gl does not support WebGL2');
|
|
42
|
-
}
|
|
43
|
-
if (!headlessGL) {
|
|
44
|
-
throw new Error(ERR_HEADLESSGL_LOAD);
|
|
45
|
-
}
|
|
46
|
-
const gl = headlessGL(width, height, options);
|
|
47
|
-
if (!gl) {
|
|
48
|
-
throw new Error(ERR_HEADLESSGL_FAILED);
|
|
49
|
-
}
|
|
50
|
-
return gl;
|
|
51
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// luma.gl, MIT license
|
|
2
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
-
|
|
4
|
-
import {assert} from '@luma.gl/core';
|
|
5
|
-
|
|
6
|
-
const ERR_CONTEXT = 'Invalid WebGLRenderingContext';
|
|
7
|
-
export const ERR_WEBGL = ERR_CONTEXT;
|
|
8
|
-
export const ERR_WEBGL2 = 'Requires WebGL2';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/** Check if supplied parameter is a WebGLRenderingContext */
|
|
12
|
-
export function isWebGL(gl: any): boolean {
|
|
13
|
-
if (typeof WebGLRenderingContext !== 'undefined' && gl instanceof WebGLRenderingContext) {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
// Look for debug contexts, headless gl etc
|
|
20
|
-
return Boolean(gl && Number.isFinite(gl._version));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/** Check if supplied parameter is a WebGL2RenderingContext */
|
|
25
|
-
export function isWebGL2(gl: any): boolean {
|
|
26
|
-
if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
// Look for debug contexts, headless gl etc
|
|
30
|
-
return Boolean(gl && gl._version === 2);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
/** Returns a properly typed WebGL2RenderingContext from a WebGL1 context, or null */
|
|
35
|
-
export function getWebGL2Context(gl: WebGLRenderingContext): WebGL2RenderingContext | null {
|
|
36
|
-
// @ts-expect-error
|
|
37
|
-
return isWebGL2(gl) ? gl : null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/** Throw if supplied parameter is not a WebGLRenderingContext, otherwise return properly typed value */
|
|
42
|
-
export function assertWebGLContext(gl: any): WebGLRenderingContext {
|
|
43
|
-
assert(isWebGL(gl), ERR_CONTEXT);
|
|
44
|
-
return gl;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Throw if supplied parameter is not a WebGL2RenderingContext, otherwise return properly typed value */
|
|
48
|
-
export function assertWebGL2Context(gl: any): WebGL2RenderingContext {
|
|
49
|
-
assert(isWebGL2(gl), ERR_WEBGL2);
|
|
50
|
-
return gl;
|
|
51
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// luma.gl, MIT license
|
|
2
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Stores luma.gl specific state associated with a context
|
|
6
|
-
*/
|
|
7
|
-
export interface WebGLContextData {
|
|
8
|
-
_polyfilled: boolean;
|
|
9
|
-
_extensions: Record<string, any>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Gets luma.gl specific state from a context
|
|
14
|
-
* @returns context state
|
|
15
|
-
*/
|
|
16
|
-
export function getContextData(gl: WebGLRenderingContext): WebGLContextData {
|
|
17
|
-
// @ts-expect-error
|
|
18
|
-
const luma = gl.luma as WebGLContextData | null;
|
|
19
|
-
if (!luma) {
|
|
20
|
-
const contextState: WebGLContextData = {
|
|
21
|
-
_polyfilled: false,
|
|
22
|
-
_extensions: {}
|
|
23
|
-
};
|
|
24
|
-
// @ts-expect-error
|
|
25
|
-
gl.luma = contextState;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// @ts-expect-error
|
|
29
|
-
return gl.luma;
|
|
30
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
// luma.gl, MIT license
|
|
2
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
-
|
|
4
|
-
/* eslint-disable no-inline-comments, max-len, camelcase */
|
|
5
|
-
import {GL} from '@luma.gl/constants';
|
|
6
|
-
import {isWebGL2} from '../context/webgl-checks';
|
|
7
|
-
|
|
8
|
-
const OES_element_index = 'OES_element_index';
|
|
9
|
-
const WEBGL_draw_buffers = 'WEBGL_draw_buffers';
|
|
10
|
-
const EXT_disjoint_timer_query = 'EXT_disjoint_timer_query';
|
|
11
|
-
const EXT_disjoint_timer_query_webgl2 = 'EXT_disjoint_timer_query_webgl2';
|
|
12
|
-
const EXT_texture_filter_anisotropic = 'EXT_texture_filter_anisotropic';
|
|
13
|
-
const WEBGL_debug_renderer_info = 'WEBGL_debug_renderer_info';
|
|
14
|
-
|
|
15
|
-
const GL_FRAGMENT_SHADER_DERIVATIVE_HINT = 0x8b8b;
|
|
16
|
-
const GL_DONT_CARE = 0x1100;
|
|
17
|
-
const GL_GPU_DISJOINT_EXT = 0x8fbb;
|
|
18
|
-
const GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84ff;
|
|
19
|
-
const GL_UNMASKED_VENDOR_WEBGL = 0x9245; // vendor string of the graphics driver.
|
|
20
|
-
const GL_UNMASKED_RENDERER_WEBGL = 0x9246; // renderer string of the graphics driver.
|
|
21
|
-
|
|
22
|
-
const getWebGL2ValueOrZero = (gl) => (!isWebGL2(gl) ? 0 : undefined);
|
|
23
|
-
|
|
24
|
-
// if a function returns undefined in this table,
|
|
25
|
-
// the original getParameter will be called, defeating the override
|
|
26
|
-
const WEBGL_PARAMETERS = {
|
|
27
|
-
[GL.READ_BUFFER]: (gl) => (!isWebGL2(gl) ? GL.COLOR_ATTACHMENT0 : undefined),
|
|
28
|
-
|
|
29
|
-
// WebGL2 context parameters
|
|
30
|
-
[GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (gl) => (!isWebGL2(gl) ? GL_DONT_CARE : undefined),
|
|
31
|
-
|
|
32
|
-
[GL.RASTERIZER_DISCARD]: getWebGL2ValueOrZero,
|
|
33
|
-
|
|
34
|
-
[GL.SAMPLES]: getWebGL2ValueOrZero,
|
|
35
|
-
|
|
36
|
-
// WebGL2 extension context parameters
|
|
37
|
-
[GL_GPU_DISJOINT_EXT]: (gl: WebGLRenderingContext, getParameter) => {
|
|
38
|
-
const ext = isWebGL2(gl)
|
|
39
|
-
? gl.getExtension(EXT_disjoint_timer_query_webgl2)
|
|
40
|
-
: gl.getExtension(EXT_disjoint_timer_query);
|
|
41
|
-
return ext && ext.GPU_DISJOINT_EXT ? getParameter(ext.GPU_DISJOINT_EXT) : 0;
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
// Extension fixed values
|
|
45
|
-
[GL_UNMASKED_VENDOR_WEBGL]: (gl: WebGLRenderingContext, getParameter) => {
|
|
46
|
-
const ext = gl.getExtension(WEBGL_debug_renderer_info);
|
|
47
|
-
return getParameter((ext && ext.UNMASKED_VENDOR_WEBGL) || GL.VENDOR);
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
[GL_UNMASKED_RENDERER_WEBGL]: (gl: WebGLRenderingContext, getParameter) => {
|
|
51
|
-
const ext = gl.getExtension(WEBGL_debug_renderer_info);
|
|
52
|
-
return getParameter((ext && ext.UNMASKED_RENDERER_WEBGL) || GL.RENDERER);
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
// Extension LIMITS
|
|
56
|
-
[GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (gl: WebGLRenderingContext, getParameter) => {
|
|
57
|
-
// @ts-ignore TODO - store these on the device instance instead...
|
|
58
|
-
const ext = gl.luma?.extensions?.[EXT_texture_filter_anisotropic] ||
|
|
59
|
-
gl.getExtension('EXT_texture_filter_anisotropic');
|
|
60
|
-
return ext ? getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 1.0;
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
// WebGL2 Limits
|
|
64
|
-
[GL.MAX_3D_TEXTURE_SIZE]: getWebGL2ValueOrZero,
|
|
65
|
-
[GL.MAX_ARRAY_TEXTURE_LAYERS]: getWebGL2ValueOrZero,
|
|
66
|
-
[GL.MAX_CLIENT_WAIT_TIMEOUT_WEBGL]: getWebGL2ValueOrZero,
|
|
67
|
-
[GL.MAX_COLOR_ATTACHMENTS]: (gl: WebGLRenderingContext, getParameter) => {
|
|
68
|
-
if (!isWebGL2(gl)) {
|
|
69
|
-
const ext = gl.getExtension(WEBGL_draw_buffers);
|
|
70
|
-
return ext ? getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL) : 0;
|
|
71
|
-
}
|
|
72
|
-
return undefined;
|
|
73
|
-
},
|
|
74
|
-
[GL.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
|
|
75
|
-
[GL.MAX_COMBINED_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
|
|
76
|
-
[GL.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
|
|
77
|
-
[GL.MAX_DRAW_BUFFERS]: (gl) => {
|
|
78
|
-
if (!isWebGL2(gl)) {
|
|
79
|
-
const ext = gl.getExtension(WEBGL_draw_buffers);
|
|
80
|
-
return ext ? ext.MAX_DRAW_BUFFERS_WEBGL : 0;
|
|
81
|
-
}
|
|
82
|
-
return undefined;
|
|
83
|
-
},
|
|
84
|
-
[GL.MAX_ELEMENT_INDEX]:
|
|
85
|
-
// Guess: per webglstats.com 99.6% of webgl2 supports 2147483647
|
|
86
|
-
(gl) => (gl.getExtension(OES_element_index) ? 2147483647 : 65535),
|
|
87
|
-
[GL.MAX_ELEMENTS_INDICES]:
|
|
88
|
-
// Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
|
|
89
|
-
(gl) => (gl.getExtension(OES_element_index) ? 16777216 : 65535),
|
|
90
|
-
[GL.MAX_ELEMENTS_VERTICES]:
|
|
91
|
-
// Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
|
|
92
|
-
(gl) => 16777216,
|
|
93
|
-
[GL.MAX_FRAGMENT_INPUT_COMPONENTS]: getWebGL2ValueOrZero,
|
|
94
|
-
[GL.MAX_FRAGMENT_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
|
|
95
|
-
[GL.MAX_FRAGMENT_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
|
|
96
|
-
[GL.MAX_SAMPLES]: getWebGL2ValueOrZero,
|
|
97
|
-
[GL.MAX_SERVER_WAIT_TIMEOUT]: getWebGL2ValueOrZero,
|
|
98
|
-
[GL.MAX_TEXTURE_LOD_BIAS]: getWebGL2ValueOrZero,
|
|
99
|
-
[GL.MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]: getWebGL2ValueOrZero,
|
|
100
|
-
[GL.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS]: getWebGL2ValueOrZero,
|
|
101
|
-
[GL.MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS]: getWebGL2ValueOrZero,
|
|
102
|
-
[GL.MAX_UNIFORM_BLOCK_SIZE]: getWebGL2ValueOrZero,
|
|
103
|
-
[GL.MAX_UNIFORM_BUFFER_BINDINGS]: getWebGL2ValueOrZero,
|
|
104
|
-
[GL.MAX_VARYING_COMPONENTS]: getWebGL2ValueOrZero,
|
|
105
|
-
[GL.MAX_VERTEX_OUTPUT_COMPONENTS]: getWebGL2ValueOrZero,
|
|
106
|
-
[GL.MAX_VERTEX_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
|
|
107
|
-
[GL.MAX_VERTEX_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
|
|
108
|
-
[GL.MIN_PROGRAM_TEXEL_OFFSET]: getWebGL2ValueOrZero,
|
|
109
|
-
[GL.MAX_PROGRAM_TEXEL_OFFSET]: getWebGL2ValueOrZero,
|
|
110
|
-
[GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT]: getWebGL2ValueOrZero
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
// A "replacement" gl.getParameter that accepts "enums" from extensions and WebGL2
|
|
114
|
-
// and returns reasonably safe defaults
|
|
115
|
-
export function getParameterPolyfill(gl: WebGLRenderingContext, originalGetParameter, pname) {
|
|
116
|
-
// Return mock limits (usually 0) for WebGL2 constants to ensure these
|
|
117
|
-
// can be queries without error
|
|
118
|
-
const limit = WEBGL_PARAMETERS[pname];
|
|
119
|
-
const value = typeof limit === 'function' ? limit(gl, originalGetParameter, pname) : limit;
|
|
120
|
-
const result = value !== undefined ? value : originalGetParameter(pname);
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
// luma.gl, MIT license
|
|
2
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
-
|
|
4
|
-
// WebGL1/WebGL2 extension polyfill support
|
|
5
|
-
//
|
|
6
|
-
// Provides a function that creates polyfills for WebGL2 functions based
|
|
7
|
-
// on available extensions and installs them on a supplied target (could be
|
|
8
|
-
// the WebGLContext or its prototype, or a separate object).
|
|
9
|
-
//
|
|
10
|
-
// This is intended to be a stand-alone file with minimal dependencies,
|
|
11
|
-
// easy to reuse or repurpose in other projects.
|
|
12
|
-
|
|
13
|
-
import {assert} from '@luma.gl/core';
|
|
14
|
-
import {polyfillVertexArrayObject} from './polyfill-vertex-array-object';
|
|
15
|
-
|
|
16
|
-
import {WEBGL2_CONTEXT_POLYFILLS, WEBGL2_CONTEXT_OVERRIDES} from './polyfill-table';
|
|
17
|
-
import {getContextData} from './context-data';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Registers extensions, polyfills or mock functions for extensions in the polyfills list
|
|
21
|
-
*/
|
|
22
|
-
export function polyfillContext(gl: WebGLRenderingContext): WebGL2RenderingContext {
|
|
23
|
-
const contextState = getContextData(gl);
|
|
24
|
-
|
|
25
|
-
if (!contextState._polyfilled) {
|
|
26
|
-
polyfillVertexArrayObject(gl);
|
|
27
|
-
initializeExtensions(gl);
|
|
28
|
-
installPolyfills(gl, WEBGL2_CONTEXT_POLYFILLS);
|
|
29
|
-
installOverrides(gl, {target: contextState, target2: gl});
|
|
30
|
-
contextState._polyfilled = true;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Note - only supports a subset of WebGL2
|
|
34
|
-
return gl as WebGL2RenderingContext;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function initializeExtensions(gl: WebGLRenderingContext): void {
|
|
38
|
-
const contextState = getContextData(gl);
|
|
39
|
-
// `getSupportedExtensions` can return null when context is lost.
|
|
40
|
-
const EXTENSIONS = gl.getSupportedExtensions() || [];
|
|
41
|
-
// Generates warnings in Chrome
|
|
42
|
-
const IGNORE_EXTENSIONS = ['WEBGL_polygon_mode'];
|
|
43
|
-
for (const extensionName of EXTENSIONS) {
|
|
44
|
-
if (!IGNORE_EXTENSIONS.includes(extensionName)) {
|
|
45
|
-
const extension = gl.getExtension(extensionName);
|
|
46
|
-
contextState._extensions[extensionName] = extension;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function installPolyfills(gl: WebGLRenderingContext, polyfills): void {
|
|
52
|
-
const contextState = getContextData(gl);
|
|
53
|
-
for (const extension of Object.getOwnPropertyNames(polyfills)) {
|
|
54
|
-
if (extension !== 'overrides') {
|
|
55
|
-
polyfillExtension(gl, {extension, target: contextState, target2: gl});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Polyfills a single WebGL extension into the `target` object */
|
|
61
|
-
function polyfillExtension(gl: WebGLRenderingContext, {extension, target, target2}): void {
|
|
62
|
-
const defaults = WEBGL2_CONTEXT_POLYFILLS[extension];
|
|
63
|
-
assert(defaults);
|
|
64
|
-
|
|
65
|
-
const {meta = {}} = defaults;
|
|
66
|
-
const {suffix = ''} = meta;
|
|
67
|
-
|
|
68
|
-
const ext = gl.getExtension(extension);
|
|
69
|
-
|
|
70
|
-
for (const key of Object.keys(defaults)) {
|
|
71
|
-
const extKey = `${key}${suffix}`;
|
|
72
|
-
|
|
73
|
-
let polyfill: Function | null = null;
|
|
74
|
-
if (key === 'meta') {
|
|
75
|
-
// ignore
|
|
76
|
-
} else if (typeof gl[key] === 'function') {
|
|
77
|
-
// WebGL2 implementation is already
|
|
78
|
-
} else if (ext && typeof ext[extKey] === 'function') {
|
|
79
|
-
// pick extension implementation,if available
|
|
80
|
-
polyfill = (...args) => ext[extKey](...args);
|
|
81
|
-
} else if (typeof defaults[key] === 'function') {
|
|
82
|
-
// pick the mock implementation, if no implementation was detected
|
|
83
|
-
polyfill = defaults[key].bind(target);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (polyfill) {
|
|
87
|
-
target[key] = polyfill;
|
|
88
|
-
target2[key] = polyfill;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** Install simple overrides (mostly get* functions) */
|
|
94
|
-
function installOverrides(gl: WebGLRenderingContext, {target, target2}) {
|
|
95
|
-
Object.keys(WEBGL2_CONTEXT_OVERRIDES).forEach((key) => {
|
|
96
|
-
if (typeof WEBGL2_CONTEXT_OVERRIDES[key] === 'function') {
|
|
97
|
-
// install an override, if no implementation was detected
|
|
98
|
-
const originalFunc = gl[key] ? gl[key].bind(gl) : () => {};
|
|
99
|
-
const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null, gl, originalFunc);
|
|
100
|
-
target[key] = polyfill;
|
|
101
|
-
target2[key] = polyfill;
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}
|