@itwin/webgl-compatibility 4.0.0-dev.8 → 4.0.0-dev.81
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/CHANGELOG.md +41 -1
- package/lib/cjs/Capabilities.d.ts +103 -103
- package/lib/cjs/Capabilities.d.ts.map +1 -1
- package/lib/cjs/Capabilities.js +341 -341
- package/lib/cjs/Capabilities.js.map +1 -1
- package/lib/cjs/RenderCompatibility.d.ts +128 -128
- package/lib/cjs/RenderCompatibility.d.ts.map +1 -1
- package/lib/cjs/RenderCompatibility.js +118 -118
- package/lib/cjs/RenderCompatibility.js.map +1 -1
- package/lib/cjs/webgl-compatibility.d.ts +9 -9
- package/lib/cjs/webgl-compatibility.js +29 -25
- package/lib/cjs/webgl-compatibility.js.map +1 -1
- package/lib/esm/Capabilities.d.ts +103 -103
- package/lib/esm/Capabilities.d.ts.map +1 -1
- package/lib/esm/Capabilities.js +338 -337
- package/lib/esm/Capabilities.js.map +1 -1
- package/lib/esm/RenderCompatibility.d.ts +128 -128
- package/lib/esm/RenderCompatibility.d.ts.map +1 -1
- package/lib/esm/RenderCompatibility.js +114 -114
- package/lib/esm/RenderCompatibility.js.map +1 -1
- package/lib/esm/webgl-compatibility.d.ts +9 -9
- package/lib/esm/webgl-compatibility.js +13 -13
- package/lib/esm/webgl-compatibility.js.map +1 -1
- package/package.json +12 -12
package/lib/cjs/Capabilities.js
CHANGED
|
@@ -1,342 +1,342 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
/** @packageDocumentation
|
|
7
|
-
* @module Compatibility
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.Capabilities = exports.DepthType = exports.RenderType = void 0;
|
|
11
|
-
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
-
const RenderCompatibility_1 = require("./RenderCompatibility");
|
|
13
|
-
const knownExtensions = [
|
|
14
|
-
"WEBGL_draw_buffers",
|
|
15
|
-
"OES_element_index_uint",
|
|
16
|
-
"OES_texture_float",
|
|
17
|
-
"OES_texture_float_linear",
|
|
18
|
-
"OES_texture_half_float",
|
|
19
|
-
"OES_texture_half_float_linear",
|
|
20
|
-
"EXT_texture_filter_anisotropic",
|
|
21
|
-
"WEBGL_depth_texture",
|
|
22
|
-
"EXT_color_buffer_float",
|
|
23
|
-
"EXT_shader_texture_lod",
|
|
24
|
-
"EXT_frag_depth",
|
|
25
|
-
"ANGLE_instanced_arrays",
|
|
26
|
-
"OES_vertex_array_object",
|
|
27
|
-
"WEBGL_lose_context",
|
|
28
|
-
"EXT_disjoint_timer_query",
|
|
29
|
-
"EXT_disjoint_timer_query_webgl2",
|
|
30
|
-
"OES_standard_derivatives",
|
|
31
|
-
"EXT_float_blend",
|
|
32
|
-
];
|
|
33
|
-
/** Describes the type of a render target. Used by Capabilities to represent maximum precision render target available on host system.
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
var RenderType;
|
|
37
|
-
(function (RenderType) {
|
|
38
|
-
RenderType[RenderType["TextureUnsignedByte"] = 0] = "TextureUnsignedByte";
|
|
39
|
-
RenderType[RenderType["TextureHalfFloat"] = 1] = "TextureHalfFloat";
|
|
40
|
-
RenderType[RenderType["TextureFloat"] = 2] = "TextureFloat";
|
|
41
|
-
})(RenderType = exports.RenderType || (exports.RenderType = {}));
|
|
42
|
-
/**
|
|
43
|
-
* Describes the type of a depth buffer. Used by Capabilities to represent maximum depth buffer precision available on host system.
|
|
44
|
-
* Note: the commented-out values are unimplemented but left in place for reference, in case desired for future implementation.
|
|
45
|
-
* @internal
|
|
46
|
-
*/
|
|
47
|
-
var DepthType;
|
|
48
|
-
(function (DepthType) {
|
|
49
|
-
DepthType[DepthType["RenderBufferUnsignedShort16"] = 0] = "RenderBufferUnsignedShort16";
|
|
50
|
-
// TextureUnsignedShort16, // core to WebGL2; available to WebGL1 via WEBGL_depth_texture
|
|
51
|
-
// TextureUnsignedInt24, // core to WebGL2
|
|
52
|
-
DepthType[DepthType["TextureUnsignedInt24Stencil8"] = 1] = "TextureUnsignedInt24Stencil8";
|
|
53
|
-
DepthType[DepthType["TextureUnsignedInt32"] = 2] = "TextureUnsignedInt32";
|
|
54
|
-
// TextureFloat32, // core to WebGL2
|
|
55
|
-
// TextureFloat32Stencil8, // core to WeBGL2
|
|
56
|
-
})(DepthType = exports.DepthType || (exports.DepthType = {}));
|
|
57
|
-
const maxTexSizeAllowed = 4096; // many devices and browsers have issues with source textures larger than this
|
|
58
|
-
// Regexes to match Intel UHD/HD 620/630 integrated GPUS that suffer from GraphicsDriverBugs.fragDepthDoesNotDisableEarlyZ.
|
|
59
|
-
const buggyIntelMatchers = [
|
|
60
|
-
// Original unmasked renderer string when workaround we implemented.
|
|
61
|
-
/ANGLE \(Intel\(R\) (U)?HD Graphics 6(2|3)0 Direct3D11/,
|
|
62
|
-
// New unmasked renderer string circa October 2021.
|
|
63
|
-
/ANGLE \(Intel, Intel\(R\) (U)?HD Graphics 6(2|3)0 Direct3D11/,
|
|
64
|
-
];
|
|
65
|
-
// Regexes to match Mali GPUs known to suffer from GraphicsDriverBugs.msaaWillHang.
|
|
66
|
-
const buggyMaliMatchers = [
|
|
67
|
-
/Mali-G71/,
|
|
68
|
-
/Mali-G72/,
|
|
69
|
-
/Mali-G76/,
|
|
70
|
-
];
|
|
71
|
-
// Regexes to match as many Intel integrated GPUs as possible.
|
|
72
|
-
// https://en.wikipedia.org/wiki/List_of_Intel_graphics_processing_units
|
|
73
|
-
const integratedIntelGpuMatchers = [
|
|
74
|
-
/(U)?HD Graphics/,
|
|
75
|
-
/Iris/,
|
|
76
|
-
];
|
|
77
|
-
function isIntegratedGraphics(args) {
|
|
78
|
-
if (args.unmaskedRenderer && args.unmaskedRenderer.includes("Intel") && integratedIntelGpuMatchers.some((x) => x.test(args.unmaskedRenderer)))
|
|
79
|
-
return true;
|
|
80
|
-
// NB: For now, we do not attempt to detect AMD integrated graphics.
|
|
81
|
-
// It appears that AMD integrated graphics are not usually paired with a graphics card so detecting integrated usage there is less important than Intel.
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
/** Describes the rendering capabilities of the host system.
|
|
85
|
-
* @internal
|
|
86
|
-
*/
|
|
87
|
-
class Capabilities {
|
|
88
|
-
constructor() {
|
|
89
|
-
this._maxRenderType = RenderType.TextureUnsignedByte;
|
|
90
|
-
this._maxDepthType = DepthType.RenderBufferUnsignedShort16;
|
|
91
|
-
this._maxTextureSize = 0;
|
|
92
|
-
this._maxColorAttachments = 0;
|
|
93
|
-
this._maxDrawBuffers = 0;
|
|
94
|
-
this._maxFragTextureUnits = 0;
|
|
95
|
-
this._maxVertTextureUnits = 0;
|
|
96
|
-
this._maxVertAttribs = 0;
|
|
97
|
-
this._maxVertUniformVectors = 0;
|
|
98
|
-
this._maxVaryingVectors = 0;
|
|
99
|
-
this._maxFragUniformVectors = 0;
|
|
100
|
-
this._maxAntialiasSamples = 1;
|
|
101
|
-
this._supportsCreateImageBitmap = false;
|
|
102
|
-
this._maxTexSizeAllow = maxTexSizeAllowed;
|
|
103
|
-
this._extensionMap = {}; // Use this map to store actual extension objects retrieved from GL.
|
|
104
|
-
this._presentFeatures = []; // List of features the system can support (not necessarily dependent on extensions)
|
|
105
|
-
this._isWebGL2 = false;
|
|
106
|
-
this._isMobile = false;
|
|
107
|
-
this._driverBugs = {};
|
|
108
|
-
}
|
|
109
|
-
get maxRenderType() { return this._maxRenderType; }
|
|
110
|
-
get maxDepthType() { return this._maxDepthType; }
|
|
111
|
-
get maxTextureSize() { return this._maxTextureSize; }
|
|
112
|
-
get maxTexSizeAllow() { return this._maxTexSizeAllow; }
|
|
113
|
-
get supportsCreateImageBitmap() { return this._supportsCreateImageBitmap; }
|
|
114
|
-
get maxColorAttachments() { return this._maxColorAttachments; }
|
|
115
|
-
get maxDrawBuffers() { return this._maxDrawBuffers; }
|
|
116
|
-
get maxFragTextureUnits() { return this._maxFragTextureUnits; }
|
|
117
|
-
get maxVertTextureUnits() { return this._maxVertTextureUnits; }
|
|
118
|
-
get maxVertAttribs() { return this._maxVertAttribs; }
|
|
119
|
-
get maxVertUniformVectors() { return this._maxVertUniformVectors; }
|
|
120
|
-
get maxVaryingVectors() { return this._maxVaryingVectors; }
|
|
121
|
-
get maxFragUniformVectors() { return this._maxFragUniformVectors; }
|
|
122
|
-
get maxAntialiasSamples() { return this._maxAntialiasSamples; }
|
|
123
|
-
get isWebGL2() { return this._isWebGL2; }
|
|
124
|
-
get driverBugs() { return this._driverBugs; }
|
|
125
|
-
/** These getters check for existence of extension objects to determine availability of features. In WebGL2, could just return true for some. */
|
|
126
|
-
get supportsNonPowerOf2Textures() { return false; }
|
|
127
|
-
get supportsDrawBuffers() { return this._isWebGL2 || this.queryExtensionObject("WEBGL_draw_buffers") !== undefined; }
|
|
128
|
-
get supportsInstancing() { return this._isWebGL2 || this.queryExtensionObject("ANGLE_instanced_arrays") !== undefined; }
|
|
129
|
-
get supports32BitElementIndex() { return this._isWebGL2 || this.queryExtensionObject("OES_element_index_uint") !== undefined; }
|
|
130
|
-
get supportsTextureFloat() { return this._isWebGL2 || this.queryExtensionObject("OES_texture_float") !== undefined; }
|
|
131
|
-
get supportsTextureFloatLinear() { return this._isWebGL2 || this.queryExtensionObject("OES_texture_float_linear") !== undefined; }
|
|
132
|
-
get supportsTextureHalfFloat() { return this._isWebGL2 || this.queryExtensionObject("OES_texture_half_float") !== undefined; }
|
|
133
|
-
get supportsTextureHalfFloatLinear() { return this._isWebGL2 || this.queryExtensionObject("OES_texture_half_float_linear") !== undefined; }
|
|
134
|
-
get supportsTextureFilterAnisotropic() { return this.queryExtensionObject("EXT_texture_filter_anisotropic") !== undefined; }
|
|
135
|
-
get supportsShaderTextureLOD() { return this._isWebGL2 || this.queryExtensionObject("EXT_shader_texture_lod") !== undefined; }
|
|
136
|
-
get supportsVertexArrayObjects() { return this._isWebGL2 || this.queryExtensionObject("OES_vertex_array_object") !== undefined; }
|
|
137
|
-
get supportsFragDepth() { return this._isWebGL2 || this.queryExtensionObject("EXT_frag_depth") !== undefined; }
|
|
138
|
-
get supportsDisjointTimerQuery() { return (this._isWebGL2 && this.queryExtensionObject("EXT_disjoint_timer_query_webgl2") !== undefined) || this.queryExtensionObject("EXT_disjoint_timer_query") !== undefined; }
|
|
139
|
-
get supportsStandardDerivatives() { return this._isWebGL2 || this.queryExtensionObject("OES_standard_derivatives") !== undefined; }
|
|
140
|
-
get supportsMRTTransparency() { return this.maxColorAttachments >= 2; }
|
|
141
|
-
get supportsMRTPickShaders() { return this.maxColorAttachments >= 3; }
|
|
142
|
-
get supportsShadowMaps() {
|
|
143
|
-
return this.supportsTextureFloat || this.supportsTextureHalfFloat;
|
|
144
|
-
}
|
|
145
|
-
get supportsAntiAliasing() { return this._isWebGL2 && this.maxAntialiasSamples > 1; }
|
|
146
|
-
get isMobile() { return this._isMobile; }
|
|
147
|
-
findExtension(name) {
|
|
148
|
-
const ext = this._extensionMap[name];
|
|
149
|
-
return null !== ext ? ext : undefined;
|
|
150
|
-
}
|
|
151
|
-
/** Queries an extension object if available. This is necessary for other parts of the system to access some constants within extensions. */
|
|
152
|
-
queryExtensionObject(ext) {
|
|
153
|
-
return this.findExtension(ext);
|
|
154
|
-
}
|
|
155
|
-
get _hasRequiredTextureUnits() { return this.maxFragTextureUnits >= 4 && this.maxVertTextureUnits >= 5; }
|
|
156
|
-
/** Return an array containing any features not supported by the system as compared to the input array. */
|
|
157
|
-
_findMissingFeatures(featuresToSeek) {
|
|
158
|
-
const missingFeatures = [];
|
|
159
|
-
for (const featureName of featuresToSeek) {
|
|
160
|
-
if (-1 === this._presentFeatures.indexOf(featureName))
|
|
161
|
-
missingFeatures.push(featureName);
|
|
162
|
-
}
|
|
163
|
-
return missingFeatures;
|
|
164
|
-
}
|
|
165
|
-
/** Populate and return an array containing features that this system supports. */
|
|
166
|
-
_gatherFeatures() {
|
|
167
|
-
const features = [];
|
|
168
|
-
// simply check for presence of various extensions if that gives enough information
|
|
169
|
-
if (this._isWebGL2 || this._extensionMap["OES_element_index_uint"] !== undefined)
|
|
170
|
-
features.push(RenderCompatibility_1.WebGLFeature.UintElementIndex);
|
|
171
|
-
if (this._isWebGL2 || this._extensionMap["ANGLE_instanced_arrays"] !== undefined)
|
|
172
|
-
features.push(RenderCompatibility_1.WebGLFeature.Instancing);
|
|
173
|
-
if (this.supportsMRTTransparency)
|
|
174
|
-
features.push(RenderCompatibility_1.WebGLFeature.MrtTransparency);
|
|
175
|
-
if (this.supportsMRTPickShaders)
|
|
176
|
-
features.push(RenderCompatibility_1.WebGLFeature.MrtPick);
|
|
177
|
-
if (this.supportsShadowMaps)
|
|
178
|
-
features.push(RenderCompatibility_1.WebGLFeature.ShadowMaps);
|
|
179
|
-
if (this._hasRequiredTextureUnits)
|
|
180
|
-
features.push(RenderCompatibility_1.WebGLFeature.MinimalTextureUnits);
|
|
181
|
-
if (this.supportsFragDepth)
|
|
182
|
-
features.push(RenderCompatibility_1.WebGLFeature.FragDepth);
|
|
183
|
-
if (this.supportsStandardDerivatives)
|
|
184
|
-
features.push(RenderCompatibility_1.WebGLFeature.StandardDerivatives);
|
|
185
|
-
if (this.supportsAntiAliasing)
|
|
186
|
-
features.push(RenderCompatibility_1.WebGLFeature.AntiAliasing);
|
|
187
|
-
if (DepthType.TextureUnsignedInt24Stencil8 === this._maxDepthType)
|
|
188
|
-
features.push(RenderCompatibility_1.WebGLFeature.DepthTexture);
|
|
189
|
-
// check if at least half-float rendering is available based on maximum discovered renderable target
|
|
190
|
-
if (RenderType.TextureUnsignedByte !== this._maxRenderType)
|
|
191
|
-
features.push(RenderCompatibility_1.WebGLFeature.FloatRendering);
|
|
192
|
-
return features;
|
|
193
|
-
}
|
|
194
|
-
/** Retrieve compatibility status based on presence of various features. */
|
|
195
|
-
_getCompatibilityStatus(missingRequiredFeatures, missingOptionalFeatures) {
|
|
196
|
-
let status = RenderCompatibility_1.WebGLRenderCompatibilityStatus.AllOkay;
|
|
197
|
-
if (missingOptionalFeatures.length > 0)
|
|
198
|
-
status = RenderCompatibility_1.WebGLRenderCompatibilityStatus.MissingOptionalFeatures;
|
|
199
|
-
if (missingRequiredFeatures.length > 0)
|
|
200
|
-
status = RenderCompatibility_1.WebGLRenderCompatibilityStatus.MissingRequiredFeatures;
|
|
201
|
-
return status;
|
|
202
|
-
}
|
|
203
|
-
/** Initializes the capabilities based on a GL context. Must be called first. */
|
|
204
|
-
init(gl, disabledExtensions) {
|
|
205
|
-
const gl2 = !(gl instanceof WebGLRenderingContext) ? gl : undefined;
|
|
206
|
-
this._isWebGL2 = undefined !== gl2;
|
|
207
|
-
this._isMobile = core_bentley_1.ProcessDetector.isMobileBrowser;
|
|
208
|
-
const debugInfo = gl.getExtension("WEBGL_debug_renderer_info");
|
|
209
|
-
const unmaskedRenderer = debugInfo !== null ? gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) : undefined;
|
|
210
|
-
const unmaskedVendor = debugInfo !== null ? gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL) : undefined;
|
|
211
|
-
this._driverBugs = {};
|
|
212
|
-
if (unmaskedRenderer && buggyIntelMatchers.some((x) => x.test(unmaskedRenderer)))
|
|
213
|
-
this._driverBugs.fragDepthDoesNotDisableEarlyZ = true;
|
|
214
|
-
if (unmaskedRenderer && buggyMaliMatchers.some((x) => x.test(unmaskedRenderer)))
|
|
215
|
-
this._driverBugs.msaaWillHang = true;
|
|
216
|
-
this._maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
|
217
|
-
this._supportsCreateImageBitmap = typeof createImageBitmap === "function" && core_bentley_1.ProcessDetector.isChromium && !core_bentley_1.ProcessDetector.isIOSBrowser;
|
|
218
|
-
this._maxTexSizeAllow = Math.min(this._maxTextureSize, maxTexSizeAllowed);
|
|
219
|
-
this._maxFragTextureUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
|
|
220
|
-
this._maxVertTextureUnits = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
|
|
221
|
-
this._maxVertAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
222
|
-
this._maxVertUniformVectors = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);
|
|
223
|
-
this._maxVaryingVectors = gl.getParameter(gl.MAX_VARYING_VECTORS);
|
|
224
|
-
this._maxFragUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS);
|
|
225
|
-
this._maxAntialiasSamples = this._driverBugs.msaaWillHang ? 1 : (this._isWebGL2 && undefined !== gl2 ? gl.getParameter(gl2.MAX_SAMPLES) : 1);
|
|
226
|
-
const extensions = gl.getSupportedExtensions(); // This just retrieves a list of available extensions (not necessarily enabled).
|
|
227
|
-
if (extensions) {
|
|
228
|
-
for (const extStr of extensions) {
|
|
229
|
-
const ext = extStr;
|
|
230
|
-
if (-1 === knownExtensions.indexOf(ext))
|
|
231
|
-
continue;
|
|
232
|
-
else if (undefined !== disabledExtensions && -1 !== disabledExtensions.indexOf(ext))
|
|
233
|
-
continue;
|
|
234
|
-
const extObj = gl.getExtension(ext); // This call enables the extension and returns a WebGLObject containing extension instance.
|
|
235
|
-
if (null !== extObj)
|
|
236
|
-
this._extensionMap[ext] = extObj;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (this._isWebGL2 && undefined !== gl2) {
|
|
240
|
-
this._maxColorAttachments = gl.getParameter(gl2.MAX_COLOR_ATTACHMENTS);
|
|
241
|
-
this._maxDrawBuffers = gl.getParameter(gl2.MAX_DRAW_BUFFERS);
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
const dbExt = this.queryExtensionObject("WEBGL_draw_buffers");
|
|
245
|
-
this._maxColorAttachments = dbExt !== undefined ? gl.getParameter(dbExt.MAX_COLOR_ATTACHMENTS_WEBGL) : 1;
|
|
246
|
-
this._maxDrawBuffers = dbExt !== undefined ? gl.getParameter(dbExt.MAX_DRAW_BUFFERS_WEBGL) : 1;
|
|
247
|
-
}
|
|
248
|
-
// Determine the maximum color-renderable attachment type.
|
|
249
|
-
const allowFloatRender = (undefined === disabledExtensions || -1 === disabledExtensions.indexOf("OES_texture_float"))
|
|
250
|
-
// iOS>=15 allows full-float rendering. However, it does not actually work on non-M1 devices.
|
|
251
|
-
// Because of this, for now we disallow full float rendering on iOS devices.
|
|
252
|
-
// ###TODO: Re-assess this after future iOS updates.
|
|
253
|
-
&& !core_bentley_1.ProcessDetector.isIOSBrowser
|
|
254
|
-
// Samsung Galaxy Note 8 exhibits same issue as described above for iOS >= 15.
|
|
255
|
-
// It uses specifically Mali-G71 MP20 but reports its renderer as follows.
|
|
256
|
-
// Samsung Galaxy A50 and S9 exhibits same issue; they use Mali-G72.
|
|
257
|
-
// HUAWEI P30 exhibits same issue; it uses Mali-G76.
|
|
258
|
-
&& unmaskedRenderer !== "Mali-G71" && unmaskedRenderer !== "Mali-G72" && unmaskedRenderer !== "Mali-G76";
|
|
259
|
-
if (allowFloatRender && undefined !== this.queryExtensionObject("EXT_float_blend") && this.isTextureRenderable(gl, gl.FLOAT)) {
|
|
260
|
-
this._maxRenderType = RenderType.TextureFloat;
|
|
261
|
-
}
|
|
262
|
-
else if (this.isWebGL2) {
|
|
263
|
-
this._maxRenderType = (this.isTextureRenderable(gl, gl.HALF_FLOAT)) ? RenderType.TextureHalfFloat : RenderType.TextureUnsignedByte;
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
const hfExt = this.queryExtensionObject("OES_texture_half_float");
|
|
267
|
-
this._maxRenderType = (hfExt !== undefined && this.isTextureRenderable(gl, hfExt.HALF_FLOAT_OES)) ? RenderType.TextureHalfFloat : RenderType.TextureUnsignedByte;
|
|
268
|
-
}
|
|
269
|
-
// Determine the maximum depth attachment type.
|
|
270
|
-
// this._maxDepthType = this.queryExtensionObject("WEBGL_depth_texture") !== undefined ? DepthType.TextureUnsignedInt32 : DepthType.RenderBufferUnsignedShort16;
|
|
271
|
-
this._maxDepthType = this._isWebGL2 || this.queryExtensionObject("WEBGL_depth_texture") !== undefined ? DepthType.TextureUnsignedInt24Stencil8 : DepthType.RenderBufferUnsignedShort16;
|
|
272
|
-
this._presentFeatures = this._gatherFeatures();
|
|
273
|
-
const missingRequiredFeatures = this._findMissingFeatures(Capabilities.requiredFeatures);
|
|
274
|
-
const missingOptionalFeatures = this._findMissingFeatures(Capabilities.optionalFeatures);
|
|
275
|
-
return {
|
|
276
|
-
status: this._getCompatibilityStatus(missingRequiredFeatures, missingOptionalFeatures),
|
|
277
|
-
missingRequiredFeatures,
|
|
278
|
-
missingOptionalFeatures,
|
|
279
|
-
unmaskedRenderer,
|
|
280
|
-
unmaskedVendor,
|
|
281
|
-
usingIntegratedGraphics: isIntegratedGraphics({ unmaskedVendor, unmaskedRenderer }),
|
|
282
|
-
driverBugs: { ...this._driverBugs },
|
|
283
|
-
userAgent: navigator.userAgent,
|
|
284
|
-
createdContext: gl,
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
static create(gl, disabledExtensions) {
|
|
288
|
-
const caps = new Capabilities();
|
|
289
|
-
const compatibility = caps.init(gl, disabledExtensions);
|
|
290
|
-
if (RenderCompatibility_1.WebGLRenderCompatibilityStatus.CannotCreateContext === compatibility.status || RenderCompatibility_1.WebGLRenderCompatibilityStatus.MissingRequiredFeatures === compatibility.status)
|
|
291
|
-
return undefined;
|
|
292
|
-
return caps;
|
|
293
|
-
}
|
|
294
|
-
/** Determines if a particular texture type is color-renderable on the host system. */
|
|
295
|
-
isTextureRenderable(gl, texType) {
|
|
296
|
-
const tex = gl.createTexture();
|
|
297
|
-
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
298
|
-
if (this.isWebGL2) {
|
|
299
|
-
if (gl.FLOAT === texType)
|
|
300
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, 1, 1, 0, gl.RGBA, texType, null);
|
|
301
|
-
else
|
|
302
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, 1, 1, 0, gl.RGBA, texType, null);
|
|
303
|
-
}
|
|
304
|
-
else
|
|
305
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, texType, null);
|
|
306
|
-
const fb = gl.createFramebuffer();
|
|
307
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
|
|
308
|
-
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
|
|
309
|
-
const fbStatus = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
|
|
310
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
311
|
-
gl.deleteFramebuffer(fb);
|
|
312
|
-
gl.deleteTexture(tex);
|
|
313
|
-
gl.getError(); // clear any errors
|
|
314
|
-
return fbStatus === gl.FRAMEBUFFER_COMPLETE;
|
|
315
|
-
}
|
|
316
|
-
setMaxAnisotropy(desiredMax, gl) {
|
|
317
|
-
const ext = this.queryExtensionObject("EXT_texture_filter_anisotropic");
|
|
318
|
-
if (undefined === ext)
|
|
319
|
-
return;
|
|
320
|
-
if (undefined === this._maxAnisotropy)
|
|
321
|
-
this._maxAnisotropy = gl.getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
|
|
322
|
-
const max = (undefined !== desiredMax) ? Math.min(desiredMax, this._maxAnisotropy) : this._maxAnisotropy;
|
|
323
|
-
gl.texParameterf(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, max);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
RenderCompatibility_1.WebGLFeature.
|
|
329
|
-
RenderCompatibility_1.WebGLFeature.
|
|
330
|
-
RenderCompatibility_1.WebGLFeature.
|
|
331
|
-
RenderCompatibility_1.WebGLFeature.
|
|
332
|
-
RenderCompatibility_1.WebGLFeature.
|
|
333
|
-
RenderCompatibility_1.WebGLFeature.
|
|
334
|
-
RenderCompatibility_1.WebGLFeature.
|
|
335
|
-
RenderCompatibility_1.WebGLFeature.
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
RenderCompatibility_1.WebGLFeature.
|
|
340
|
-
|
|
341
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Compatibility
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Capabilities = exports.DepthType = exports.RenderType = void 0;
|
|
11
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
+
const RenderCompatibility_1 = require("./RenderCompatibility");
|
|
13
|
+
const knownExtensions = [
|
|
14
|
+
"WEBGL_draw_buffers",
|
|
15
|
+
"OES_element_index_uint",
|
|
16
|
+
"OES_texture_float",
|
|
17
|
+
"OES_texture_float_linear",
|
|
18
|
+
"OES_texture_half_float",
|
|
19
|
+
"OES_texture_half_float_linear",
|
|
20
|
+
"EXT_texture_filter_anisotropic",
|
|
21
|
+
"WEBGL_depth_texture",
|
|
22
|
+
"EXT_color_buffer_float",
|
|
23
|
+
"EXT_shader_texture_lod",
|
|
24
|
+
"EXT_frag_depth",
|
|
25
|
+
"ANGLE_instanced_arrays",
|
|
26
|
+
"OES_vertex_array_object",
|
|
27
|
+
"WEBGL_lose_context",
|
|
28
|
+
"EXT_disjoint_timer_query",
|
|
29
|
+
"EXT_disjoint_timer_query_webgl2",
|
|
30
|
+
"OES_standard_derivatives",
|
|
31
|
+
"EXT_float_blend",
|
|
32
|
+
];
|
|
33
|
+
/** Describes the type of a render target. Used by Capabilities to represent maximum precision render target available on host system.
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
var RenderType;
|
|
37
|
+
(function (RenderType) {
|
|
38
|
+
RenderType[RenderType["TextureUnsignedByte"] = 0] = "TextureUnsignedByte";
|
|
39
|
+
RenderType[RenderType["TextureHalfFloat"] = 1] = "TextureHalfFloat";
|
|
40
|
+
RenderType[RenderType["TextureFloat"] = 2] = "TextureFloat";
|
|
41
|
+
})(RenderType = exports.RenderType || (exports.RenderType = {}));
|
|
42
|
+
/**
|
|
43
|
+
* Describes the type of a depth buffer. Used by Capabilities to represent maximum depth buffer precision available on host system.
|
|
44
|
+
* Note: the commented-out values are unimplemented but left in place for reference, in case desired for future implementation.
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
var DepthType;
|
|
48
|
+
(function (DepthType) {
|
|
49
|
+
DepthType[DepthType["RenderBufferUnsignedShort16"] = 0] = "RenderBufferUnsignedShort16";
|
|
50
|
+
// TextureUnsignedShort16, // core to WebGL2; available to WebGL1 via WEBGL_depth_texture
|
|
51
|
+
// TextureUnsignedInt24, // core to WebGL2
|
|
52
|
+
DepthType[DepthType["TextureUnsignedInt24Stencil8"] = 1] = "TextureUnsignedInt24Stencil8";
|
|
53
|
+
DepthType[DepthType["TextureUnsignedInt32"] = 2] = "TextureUnsignedInt32";
|
|
54
|
+
// TextureFloat32, // core to WebGL2
|
|
55
|
+
// TextureFloat32Stencil8, // core to WeBGL2
|
|
56
|
+
})(DepthType = exports.DepthType || (exports.DepthType = {}));
|
|
57
|
+
const maxTexSizeAllowed = 4096; // many devices and browsers have issues with source textures larger than this
|
|
58
|
+
// Regexes to match Intel UHD/HD 620/630 integrated GPUS that suffer from GraphicsDriverBugs.fragDepthDoesNotDisableEarlyZ.
|
|
59
|
+
const buggyIntelMatchers = [
|
|
60
|
+
// Original unmasked renderer string when workaround we implemented.
|
|
61
|
+
/ANGLE \(Intel\(R\) (U)?HD Graphics 6(2|3)0 Direct3D11/,
|
|
62
|
+
// New unmasked renderer string circa October 2021.
|
|
63
|
+
/ANGLE \(Intel, Intel\(R\) (U)?HD Graphics 6(2|3)0 Direct3D11/,
|
|
64
|
+
];
|
|
65
|
+
// Regexes to match Mali GPUs known to suffer from GraphicsDriverBugs.msaaWillHang.
|
|
66
|
+
const buggyMaliMatchers = [
|
|
67
|
+
/Mali-G71/,
|
|
68
|
+
/Mali-G72/,
|
|
69
|
+
/Mali-G76/,
|
|
70
|
+
];
|
|
71
|
+
// Regexes to match as many Intel integrated GPUs as possible.
|
|
72
|
+
// https://en.wikipedia.org/wiki/List_of_Intel_graphics_processing_units
|
|
73
|
+
const integratedIntelGpuMatchers = [
|
|
74
|
+
/(U)?HD Graphics/,
|
|
75
|
+
/Iris/,
|
|
76
|
+
];
|
|
77
|
+
function isIntegratedGraphics(args) {
|
|
78
|
+
if (args.unmaskedRenderer && args.unmaskedRenderer.includes("Intel") && integratedIntelGpuMatchers.some((x) => x.test(args.unmaskedRenderer)))
|
|
79
|
+
return true;
|
|
80
|
+
// NB: For now, we do not attempt to detect AMD integrated graphics.
|
|
81
|
+
// It appears that AMD integrated graphics are not usually paired with a graphics card so detecting integrated usage there is less important than Intel.
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
/** Describes the rendering capabilities of the host system.
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
class Capabilities {
|
|
88
|
+
constructor() {
|
|
89
|
+
this._maxRenderType = RenderType.TextureUnsignedByte;
|
|
90
|
+
this._maxDepthType = DepthType.RenderBufferUnsignedShort16;
|
|
91
|
+
this._maxTextureSize = 0;
|
|
92
|
+
this._maxColorAttachments = 0;
|
|
93
|
+
this._maxDrawBuffers = 0;
|
|
94
|
+
this._maxFragTextureUnits = 0;
|
|
95
|
+
this._maxVertTextureUnits = 0;
|
|
96
|
+
this._maxVertAttribs = 0;
|
|
97
|
+
this._maxVertUniformVectors = 0;
|
|
98
|
+
this._maxVaryingVectors = 0;
|
|
99
|
+
this._maxFragUniformVectors = 0;
|
|
100
|
+
this._maxAntialiasSamples = 1;
|
|
101
|
+
this._supportsCreateImageBitmap = false;
|
|
102
|
+
this._maxTexSizeAllow = maxTexSizeAllowed;
|
|
103
|
+
this._extensionMap = {}; // Use this map to store actual extension objects retrieved from GL.
|
|
104
|
+
this._presentFeatures = []; // List of features the system can support (not necessarily dependent on extensions)
|
|
105
|
+
this._isWebGL2 = false;
|
|
106
|
+
this._isMobile = false;
|
|
107
|
+
this._driverBugs = {};
|
|
108
|
+
}
|
|
109
|
+
get maxRenderType() { return this._maxRenderType; }
|
|
110
|
+
get maxDepthType() { return this._maxDepthType; }
|
|
111
|
+
get maxTextureSize() { return this._maxTextureSize; }
|
|
112
|
+
get maxTexSizeAllow() { return this._maxTexSizeAllow; }
|
|
113
|
+
get supportsCreateImageBitmap() { return this._supportsCreateImageBitmap; }
|
|
114
|
+
get maxColorAttachments() { return this._maxColorAttachments; }
|
|
115
|
+
get maxDrawBuffers() { return this._maxDrawBuffers; }
|
|
116
|
+
get maxFragTextureUnits() { return this._maxFragTextureUnits; }
|
|
117
|
+
get maxVertTextureUnits() { return this._maxVertTextureUnits; }
|
|
118
|
+
get maxVertAttribs() { return this._maxVertAttribs; }
|
|
119
|
+
get maxVertUniformVectors() { return this._maxVertUniformVectors; }
|
|
120
|
+
get maxVaryingVectors() { return this._maxVaryingVectors; }
|
|
121
|
+
get maxFragUniformVectors() { return this._maxFragUniformVectors; }
|
|
122
|
+
get maxAntialiasSamples() { return this._maxAntialiasSamples; }
|
|
123
|
+
get isWebGL2() { return this._isWebGL2; }
|
|
124
|
+
get driverBugs() { return this._driverBugs; }
|
|
125
|
+
/** These getters check for existence of extension objects to determine availability of features. In WebGL2, could just return true for some. */
|
|
126
|
+
get supportsNonPowerOf2Textures() { return false; }
|
|
127
|
+
get supportsDrawBuffers() { return this._isWebGL2 || this.queryExtensionObject("WEBGL_draw_buffers") !== undefined; }
|
|
128
|
+
get supportsInstancing() { return this._isWebGL2 || this.queryExtensionObject("ANGLE_instanced_arrays") !== undefined; }
|
|
129
|
+
get supports32BitElementIndex() { return this._isWebGL2 || this.queryExtensionObject("OES_element_index_uint") !== undefined; }
|
|
130
|
+
get supportsTextureFloat() { return this._isWebGL2 || this.queryExtensionObject("OES_texture_float") !== undefined; }
|
|
131
|
+
get supportsTextureFloatLinear() { return this._isWebGL2 || this.queryExtensionObject("OES_texture_float_linear") !== undefined; }
|
|
132
|
+
get supportsTextureHalfFloat() { return this._isWebGL2 || this.queryExtensionObject("OES_texture_half_float") !== undefined; }
|
|
133
|
+
get supportsTextureHalfFloatLinear() { return this._isWebGL2 || this.queryExtensionObject("OES_texture_half_float_linear") !== undefined; }
|
|
134
|
+
get supportsTextureFilterAnisotropic() { return this.queryExtensionObject("EXT_texture_filter_anisotropic") !== undefined; }
|
|
135
|
+
get supportsShaderTextureLOD() { return this._isWebGL2 || this.queryExtensionObject("EXT_shader_texture_lod") !== undefined; }
|
|
136
|
+
get supportsVertexArrayObjects() { return this._isWebGL2 || this.queryExtensionObject("OES_vertex_array_object") !== undefined; }
|
|
137
|
+
get supportsFragDepth() { return this._isWebGL2 || this.queryExtensionObject("EXT_frag_depth") !== undefined; }
|
|
138
|
+
get supportsDisjointTimerQuery() { return (this._isWebGL2 && this.queryExtensionObject("EXT_disjoint_timer_query_webgl2") !== undefined) || this.queryExtensionObject("EXT_disjoint_timer_query") !== undefined; }
|
|
139
|
+
get supportsStandardDerivatives() { return this._isWebGL2 || this.queryExtensionObject("OES_standard_derivatives") !== undefined; }
|
|
140
|
+
get supportsMRTTransparency() { return this.maxColorAttachments >= 2; }
|
|
141
|
+
get supportsMRTPickShaders() { return this.maxColorAttachments >= 3; }
|
|
142
|
+
get supportsShadowMaps() {
|
|
143
|
+
return this.supportsTextureFloat || this.supportsTextureHalfFloat;
|
|
144
|
+
}
|
|
145
|
+
get supportsAntiAliasing() { return this._isWebGL2 && this.maxAntialiasSamples > 1; }
|
|
146
|
+
get isMobile() { return this._isMobile; }
|
|
147
|
+
findExtension(name) {
|
|
148
|
+
const ext = this._extensionMap[name];
|
|
149
|
+
return null !== ext ? ext : undefined;
|
|
150
|
+
}
|
|
151
|
+
/** Queries an extension object if available. This is necessary for other parts of the system to access some constants within extensions. */
|
|
152
|
+
queryExtensionObject(ext) {
|
|
153
|
+
return this.findExtension(ext);
|
|
154
|
+
}
|
|
155
|
+
get _hasRequiredTextureUnits() { return this.maxFragTextureUnits >= 4 && this.maxVertTextureUnits >= 5; }
|
|
156
|
+
/** Return an array containing any features not supported by the system as compared to the input array. */
|
|
157
|
+
_findMissingFeatures(featuresToSeek) {
|
|
158
|
+
const missingFeatures = [];
|
|
159
|
+
for (const featureName of featuresToSeek) {
|
|
160
|
+
if (-1 === this._presentFeatures.indexOf(featureName))
|
|
161
|
+
missingFeatures.push(featureName);
|
|
162
|
+
}
|
|
163
|
+
return missingFeatures;
|
|
164
|
+
}
|
|
165
|
+
/** Populate and return an array containing features that this system supports. */
|
|
166
|
+
_gatherFeatures() {
|
|
167
|
+
const features = [];
|
|
168
|
+
// simply check for presence of various extensions if that gives enough information
|
|
169
|
+
if (this._isWebGL2 || this._extensionMap["OES_element_index_uint"] !== undefined)
|
|
170
|
+
features.push(RenderCompatibility_1.WebGLFeature.UintElementIndex);
|
|
171
|
+
if (this._isWebGL2 || this._extensionMap["ANGLE_instanced_arrays"] !== undefined)
|
|
172
|
+
features.push(RenderCompatibility_1.WebGLFeature.Instancing);
|
|
173
|
+
if (this.supportsMRTTransparency)
|
|
174
|
+
features.push(RenderCompatibility_1.WebGLFeature.MrtTransparency);
|
|
175
|
+
if (this.supportsMRTPickShaders)
|
|
176
|
+
features.push(RenderCompatibility_1.WebGLFeature.MrtPick);
|
|
177
|
+
if (this.supportsShadowMaps)
|
|
178
|
+
features.push(RenderCompatibility_1.WebGLFeature.ShadowMaps);
|
|
179
|
+
if (this._hasRequiredTextureUnits)
|
|
180
|
+
features.push(RenderCompatibility_1.WebGLFeature.MinimalTextureUnits);
|
|
181
|
+
if (this.supportsFragDepth)
|
|
182
|
+
features.push(RenderCompatibility_1.WebGLFeature.FragDepth);
|
|
183
|
+
if (this.supportsStandardDerivatives)
|
|
184
|
+
features.push(RenderCompatibility_1.WebGLFeature.StandardDerivatives);
|
|
185
|
+
if (this.supportsAntiAliasing)
|
|
186
|
+
features.push(RenderCompatibility_1.WebGLFeature.AntiAliasing);
|
|
187
|
+
if (DepthType.TextureUnsignedInt24Stencil8 === this._maxDepthType)
|
|
188
|
+
features.push(RenderCompatibility_1.WebGLFeature.DepthTexture);
|
|
189
|
+
// check if at least half-float rendering is available based on maximum discovered renderable target
|
|
190
|
+
if (RenderType.TextureUnsignedByte !== this._maxRenderType)
|
|
191
|
+
features.push(RenderCompatibility_1.WebGLFeature.FloatRendering);
|
|
192
|
+
return features;
|
|
193
|
+
}
|
|
194
|
+
/** Retrieve compatibility status based on presence of various features. */
|
|
195
|
+
_getCompatibilityStatus(missingRequiredFeatures, missingOptionalFeatures) {
|
|
196
|
+
let status = RenderCompatibility_1.WebGLRenderCompatibilityStatus.AllOkay;
|
|
197
|
+
if (missingOptionalFeatures.length > 0)
|
|
198
|
+
status = RenderCompatibility_1.WebGLRenderCompatibilityStatus.MissingOptionalFeatures;
|
|
199
|
+
if (missingRequiredFeatures.length > 0)
|
|
200
|
+
status = RenderCompatibility_1.WebGLRenderCompatibilityStatus.MissingRequiredFeatures;
|
|
201
|
+
return status;
|
|
202
|
+
}
|
|
203
|
+
/** Initializes the capabilities based on a GL context. Must be called first. */
|
|
204
|
+
init(gl, disabledExtensions) {
|
|
205
|
+
const gl2 = !(gl instanceof WebGLRenderingContext) ? gl : undefined;
|
|
206
|
+
this._isWebGL2 = undefined !== gl2;
|
|
207
|
+
this._isMobile = core_bentley_1.ProcessDetector.isMobileBrowser;
|
|
208
|
+
const debugInfo = gl.getExtension("WEBGL_debug_renderer_info");
|
|
209
|
+
const unmaskedRenderer = debugInfo !== null ? gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) : undefined;
|
|
210
|
+
const unmaskedVendor = debugInfo !== null ? gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL) : undefined;
|
|
211
|
+
this._driverBugs = {};
|
|
212
|
+
if (unmaskedRenderer && buggyIntelMatchers.some((x) => x.test(unmaskedRenderer)))
|
|
213
|
+
this._driverBugs.fragDepthDoesNotDisableEarlyZ = true;
|
|
214
|
+
if (unmaskedRenderer && buggyMaliMatchers.some((x) => x.test(unmaskedRenderer)))
|
|
215
|
+
this._driverBugs.msaaWillHang = true;
|
|
216
|
+
this._maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
|
217
|
+
this._supportsCreateImageBitmap = typeof createImageBitmap === "function" && core_bentley_1.ProcessDetector.isChromium && !core_bentley_1.ProcessDetector.isIOSBrowser;
|
|
218
|
+
this._maxTexSizeAllow = Math.min(this._maxTextureSize, maxTexSizeAllowed);
|
|
219
|
+
this._maxFragTextureUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
|
|
220
|
+
this._maxVertTextureUnits = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
|
|
221
|
+
this._maxVertAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
222
|
+
this._maxVertUniformVectors = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);
|
|
223
|
+
this._maxVaryingVectors = gl.getParameter(gl.MAX_VARYING_VECTORS);
|
|
224
|
+
this._maxFragUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS);
|
|
225
|
+
this._maxAntialiasSamples = this._driverBugs.msaaWillHang ? 1 : (this._isWebGL2 && undefined !== gl2 ? gl.getParameter(gl2.MAX_SAMPLES) : 1);
|
|
226
|
+
const extensions = gl.getSupportedExtensions(); // This just retrieves a list of available extensions (not necessarily enabled).
|
|
227
|
+
if (extensions) {
|
|
228
|
+
for (const extStr of extensions) {
|
|
229
|
+
const ext = extStr;
|
|
230
|
+
if (-1 === knownExtensions.indexOf(ext))
|
|
231
|
+
continue;
|
|
232
|
+
else if (undefined !== disabledExtensions && -1 !== disabledExtensions.indexOf(ext))
|
|
233
|
+
continue;
|
|
234
|
+
const extObj = gl.getExtension(ext); // This call enables the extension and returns a WebGLObject containing extension instance.
|
|
235
|
+
if (null !== extObj)
|
|
236
|
+
this._extensionMap[ext] = extObj;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (this._isWebGL2 && undefined !== gl2) {
|
|
240
|
+
this._maxColorAttachments = gl.getParameter(gl2.MAX_COLOR_ATTACHMENTS);
|
|
241
|
+
this._maxDrawBuffers = gl.getParameter(gl2.MAX_DRAW_BUFFERS);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
const dbExt = this.queryExtensionObject("WEBGL_draw_buffers");
|
|
245
|
+
this._maxColorAttachments = dbExt !== undefined ? gl.getParameter(dbExt.MAX_COLOR_ATTACHMENTS_WEBGL) : 1;
|
|
246
|
+
this._maxDrawBuffers = dbExt !== undefined ? gl.getParameter(dbExt.MAX_DRAW_BUFFERS_WEBGL) : 1;
|
|
247
|
+
}
|
|
248
|
+
// Determine the maximum color-renderable attachment type.
|
|
249
|
+
const allowFloatRender = (undefined === disabledExtensions || -1 === disabledExtensions.indexOf("OES_texture_float"))
|
|
250
|
+
// iOS>=15 allows full-float rendering. However, it does not actually work on non-M1 devices.
|
|
251
|
+
// Because of this, for now we disallow full float rendering on iOS devices.
|
|
252
|
+
// ###TODO: Re-assess this after future iOS updates.
|
|
253
|
+
&& !core_bentley_1.ProcessDetector.isIOSBrowser
|
|
254
|
+
// Samsung Galaxy Note 8 exhibits same issue as described above for iOS >= 15.
|
|
255
|
+
// It uses specifically Mali-G71 MP20 but reports its renderer as follows.
|
|
256
|
+
// Samsung Galaxy A50 and S9 exhibits same issue; they use Mali-G72.
|
|
257
|
+
// HUAWEI P30 exhibits same issue; it uses Mali-G76.
|
|
258
|
+
&& unmaskedRenderer !== "Mali-G71" && unmaskedRenderer !== "Mali-G72" && unmaskedRenderer !== "Mali-G76";
|
|
259
|
+
if (allowFloatRender && undefined !== this.queryExtensionObject("EXT_float_blend") && this.isTextureRenderable(gl, gl.FLOAT)) {
|
|
260
|
+
this._maxRenderType = RenderType.TextureFloat;
|
|
261
|
+
}
|
|
262
|
+
else if (this.isWebGL2) {
|
|
263
|
+
this._maxRenderType = (this.isTextureRenderable(gl, gl.HALF_FLOAT)) ? RenderType.TextureHalfFloat : RenderType.TextureUnsignedByte;
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
const hfExt = this.queryExtensionObject("OES_texture_half_float");
|
|
267
|
+
this._maxRenderType = (hfExt !== undefined && this.isTextureRenderable(gl, hfExt.HALF_FLOAT_OES)) ? RenderType.TextureHalfFloat : RenderType.TextureUnsignedByte;
|
|
268
|
+
}
|
|
269
|
+
// Determine the maximum depth attachment type.
|
|
270
|
+
// this._maxDepthType = this.queryExtensionObject("WEBGL_depth_texture") !== undefined ? DepthType.TextureUnsignedInt32 : DepthType.RenderBufferUnsignedShort16;
|
|
271
|
+
this._maxDepthType = this._isWebGL2 || this.queryExtensionObject("WEBGL_depth_texture") !== undefined ? DepthType.TextureUnsignedInt24Stencil8 : DepthType.RenderBufferUnsignedShort16;
|
|
272
|
+
this._presentFeatures = this._gatherFeatures();
|
|
273
|
+
const missingRequiredFeatures = this._findMissingFeatures(Capabilities.requiredFeatures);
|
|
274
|
+
const missingOptionalFeatures = this._findMissingFeatures(Capabilities.optionalFeatures);
|
|
275
|
+
return {
|
|
276
|
+
status: this._getCompatibilityStatus(missingRequiredFeatures, missingOptionalFeatures),
|
|
277
|
+
missingRequiredFeatures,
|
|
278
|
+
missingOptionalFeatures,
|
|
279
|
+
unmaskedRenderer,
|
|
280
|
+
unmaskedVendor,
|
|
281
|
+
usingIntegratedGraphics: isIntegratedGraphics({ unmaskedVendor, unmaskedRenderer }),
|
|
282
|
+
driverBugs: { ...this._driverBugs },
|
|
283
|
+
userAgent: navigator.userAgent,
|
|
284
|
+
createdContext: gl,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
static create(gl, disabledExtensions) {
|
|
288
|
+
const caps = new Capabilities();
|
|
289
|
+
const compatibility = caps.init(gl, disabledExtensions);
|
|
290
|
+
if (RenderCompatibility_1.WebGLRenderCompatibilityStatus.CannotCreateContext === compatibility.status || RenderCompatibility_1.WebGLRenderCompatibilityStatus.MissingRequiredFeatures === compatibility.status)
|
|
291
|
+
return undefined;
|
|
292
|
+
return caps;
|
|
293
|
+
}
|
|
294
|
+
/** Determines if a particular texture type is color-renderable on the host system. */
|
|
295
|
+
isTextureRenderable(gl, texType) {
|
|
296
|
+
const tex = gl.createTexture();
|
|
297
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
298
|
+
if (this.isWebGL2) {
|
|
299
|
+
if (gl.FLOAT === texType)
|
|
300
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, 1, 1, 0, gl.RGBA, texType, null);
|
|
301
|
+
else
|
|
302
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, 1, 1, 0, gl.RGBA, texType, null);
|
|
303
|
+
}
|
|
304
|
+
else
|
|
305
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, texType, null);
|
|
306
|
+
const fb = gl.createFramebuffer();
|
|
307
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
|
|
308
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
|
|
309
|
+
const fbStatus = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
|
|
310
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
311
|
+
gl.deleteFramebuffer(fb);
|
|
312
|
+
gl.deleteTexture(tex);
|
|
313
|
+
gl.getError(); // clear any errors
|
|
314
|
+
return fbStatus === gl.FRAMEBUFFER_COMPLETE;
|
|
315
|
+
}
|
|
316
|
+
setMaxAnisotropy(desiredMax, gl) {
|
|
317
|
+
const ext = this.queryExtensionObject("EXT_texture_filter_anisotropic");
|
|
318
|
+
if (undefined === ext)
|
|
319
|
+
return;
|
|
320
|
+
if (undefined === this._maxAnisotropy)
|
|
321
|
+
this._maxAnisotropy = gl.getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
|
|
322
|
+
const max = (undefined !== desiredMax) ? Math.min(desiredMax, this._maxAnisotropy) : this._maxAnisotropy;
|
|
323
|
+
gl.texParameterf(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, max);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
Capabilities.optionalFeatures = [
|
|
327
|
+
RenderCompatibility_1.WebGLFeature.MrtTransparency,
|
|
328
|
+
RenderCompatibility_1.WebGLFeature.MrtPick,
|
|
329
|
+
RenderCompatibility_1.WebGLFeature.DepthTexture,
|
|
330
|
+
RenderCompatibility_1.WebGLFeature.FloatRendering,
|
|
331
|
+
RenderCompatibility_1.WebGLFeature.Instancing,
|
|
332
|
+
RenderCompatibility_1.WebGLFeature.ShadowMaps,
|
|
333
|
+
RenderCompatibility_1.WebGLFeature.FragDepth,
|
|
334
|
+
RenderCompatibility_1.WebGLFeature.StandardDerivatives,
|
|
335
|
+
RenderCompatibility_1.WebGLFeature.AntiAliasing,
|
|
336
|
+
];
|
|
337
|
+
Capabilities.requiredFeatures = [
|
|
338
|
+
RenderCompatibility_1.WebGLFeature.UintElementIndex,
|
|
339
|
+
RenderCompatibility_1.WebGLFeature.MinimalTextureUnits,
|
|
340
|
+
];
|
|
341
|
+
exports.Capabilities = Capabilities;
|
|
342
342
|
//# sourceMappingURL=Capabilities.js.map
|