@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
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/webgl",
|
|
3
|
-
"version": "9.0.0-beta.
|
|
4
|
-
"description": "WebGL2 adapter for the luma.gl API",
|
|
3
|
+
"version": "9.0.0-beta.5",
|
|
4
|
+
"description": "WebGL2 adapter for the luma.gl core API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"publishConfig": {
|
|
@@ -34,22 +34,18 @@
|
|
|
34
34
|
"README.md"
|
|
35
35
|
],
|
|
36
36
|
"sideEffects": false,
|
|
37
|
-
"browser": {
|
|
38
|
-
"gl": false,
|
|
39
|
-
"gl/wrap": false
|
|
40
|
-
},
|
|
41
37
|
"scripts": {
|
|
42
|
-
"build-bundle": "ocular-bundle ./src/index.ts",
|
|
43
|
-
"
|
|
38
|
+
"build-minified-bundle": "ocular-bundle ./src/index.ts -output=dist/dist.min.js",
|
|
39
|
+
"build-dev-bundle": "ocular-bundle ./src/index.ts -output=dist/dist.dev.js -- --env=dev",
|
|
40
|
+
"prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@luma.gl/constants": "^9.0.0-beta.4"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@luma.gl/
|
|
48
|
-
"@luma.gl/core": "9.0.0-beta.4",
|
|
46
|
+
"@luma.gl/constants": "9.0.0-beta.5",
|
|
47
|
+
"@luma.gl/core": "9.0.0-beta.5",
|
|
49
48
|
"@probe.gl/env": "^4.0.2"
|
|
50
49
|
},
|
|
51
|
-
"
|
|
52
|
-
"@luma.gl/test-utils": "9.0.0-beta.4"
|
|
53
|
-
},
|
|
54
|
-
"gitHead": "bf6bb45b25d59de5b3d05dab4b2e91ad583059e6"
|
|
50
|
+
"gitHead": "793d3ab42f5a572b6cb603ea78aabaa73a873301"
|
|
55
51
|
}
|
|
@@ -291,7 +291,6 @@ function convertBlendOperationToEquation(parameter: string, value: BlendOperatio
|
|
|
291
291
|
'add': GL.FUNC_ADD,
|
|
292
292
|
'subtract': GL.FUNC_SUBTRACT,
|
|
293
293
|
'reverse-subtract': GL.FUNC_REVERSE_SUBTRACT,
|
|
294
|
-
// When using a WebGL 2 context, the following values are available additionally:
|
|
295
294
|
'min': GL.MIN,
|
|
296
295
|
'max': GL.MAX
|
|
297
296
|
} as Record<BlendOperation, GLBlendEquation>);
|
|
@@ -52,23 +52,6 @@ export function convertSamplerParametersToWebGL(props: SamplerProps): GLSamplerP
|
|
|
52
52
|
return params;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
/**
|
|
56
|
-
* Override sampler settings that are not supported by Non-Power-of-Two textures in WebGL1.
|
|
57
|
-
*/
|
|
58
|
-
export function updateSamplerParametersForNPOT(
|
|
59
|
-
parameters: GLSamplerParameters
|
|
60
|
-
): GLSamplerParameters {
|
|
61
|
-
const newParameters = {...parameters};
|
|
62
|
-
if (parameters[GL.TEXTURE_MIN_FILTER] !== GL.NEAREST) {
|
|
63
|
-
// log.warn(`texture: ${this} is Non-Power-Of-Two, forcing TEXTURE_MIN_FILTER to LINEAR`)();
|
|
64
|
-
newParameters[GL.TEXTURE_MIN_FILTER] = GL.LINEAR;
|
|
65
|
-
}
|
|
66
|
-
// log.warn(`texture: ${this} is Non-Power-Of-Two, forcing TEXTURE_WRAP_S to CLAMP_TO_EDGE`)();
|
|
67
|
-
newParameters[GL.TEXTURE_WRAP_S] = GL.CLAMP_TO_EDGE;
|
|
68
|
-
newParameters[GL.TEXTURE_WRAP_T] = GL.CLAMP_TO_EDGE;
|
|
69
|
-
return newParameters;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
55
|
// HELPERS
|
|
73
56
|
|
|
74
57
|
/** Convert address more */
|
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
import type {TextureFormat, DeviceFeature} from '@luma.gl/core';
|
|
5
5
|
import {decodeTextureFormat} from '@luma.gl/core';
|
|
6
6
|
import {GL} from '@luma.gl/constants';
|
|
7
|
-
import {
|
|
8
|
-
import { getGLFromVertexType } from './vertex-formats';
|
|
7
|
+
import {getGLFromVertexType} from './vertex-formats';
|
|
9
8
|
|
|
10
9
|
/* eslint-disable camelcase */
|
|
11
10
|
|
|
@@ -19,6 +18,9 @@ const texture_compression_etc1_webgl: DeviceFeature = 'texture-compression-etc1-
|
|
|
19
18
|
const texture_compression_pvrtc_webgl: DeviceFeature = 'texture-compression-pvrtc-webgl';
|
|
20
19
|
const texture_compression_atc_webgl: DeviceFeature = 'texture-compression-atc-webgl';
|
|
21
20
|
|
|
21
|
+
// const float32_renderable_webgl: DeviceFeature = 'float32-renderable-webgl';
|
|
22
|
+
// const float16_renderable_webgl: DeviceFeature = 'float16-renderable-webgl';
|
|
23
|
+
|
|
22
24
|
// Define local webgl extension strings to optimize minification
|
|
23
25
|
const X_S3TC = 'WEBGL_compressed_texture_s3tc'; // BC1, BC2, BC3
|
|
24
26
|
const X_S3TC_SRGB = 'WEBGL_compressed_texture_s3tc_srgb'; // BC1, BC2, BC3
|
|
@@ -31,53 +33,49 @@ const X_PVRTC = 'WEBGL_compressed_texture_pvrtc';
|
|
|
31
33
|
const X_ATC = 'WEBGL_compressed_texture_atc';
|
|
32
34
|
|
|
33
35
|
// Define local webgl extension strings to optimize minification
|
|
34
|
-
const EXT_SRGB = 'EXT_sRGB'; // https://developer.mozilla.org/en-US/docs/Web/API/EXT_sRGB
|
|
35
36
|
const EXT_TEXTURE_NORM16 = 'EXT_texture_norm16';
|
|
36
|
-
const EXT_FLOAT_WEBGL1 = 'WEBGL_color_buffer_float';
|
|
37
37
|
const EXT_FLOAT_RENDER_WEBGL2 = 'EXT_color_buffer_float';
|
|
38
38
|
// const EXT_HALF_FLOAT_WEBGL1 = 'EXT_color_buffer_half_float';
|
|
39
39
|
// const DEPTH = 'WEBGL_depth_texture';
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const checkExtensions = (gl: WebGLRenderingContext, extensions: string[]): boolean =>
|
|
44
|
-
extensions.every(extension => gl.getExtension(extension));
|
|
41
|
+
// WebGL1-only extensions
|
|
42
|
+
// const EXT_SRGB = 'EXT_sRGB'; // https://developer.mozilla.org/en-US/docs/Web/API/EXT_sRGB
|
|
45
43
|
|
|
46
44
|
// prettier-ignore
|
|
47
|
-
const TEXTURE_FEATURE_CHECKS: Partial<Record<DeviceFeature,
|
|
48
|
-
'
|
|
49
|
-
'
|
|
50
|
-
'
|
|
51
|
-
|
|
52
|
-
'
|
|
53
|
-
'
|
|
54
|
-
'texture-
|
|
55
|
-
|
|
56
|
-
'texture-
|
|
57
|
-
|
|
58
|
-
'texture-
|
|
59
|
-
|
|
60
|
-
'texture-compression-
|
|
61
|
-
'texture-compression-bc5-webgl':
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
'texture-compression-
|
|
66
|
-
'texture-compression-
|
|
67
|
-
'texture-compression-
|
|
68
|
-
'texture-compression-pvrtc-webgl': (gl) => checkExtensions(gl, [X_PVRTC]),
|
|
69
|
-
'texture-compression-atc-webgl': (gl) => checkExtensions(gl, [X_ATC])
|
|
45
|
+
const TEXTURE_FEATURE_CHECKS: Partial<Record<DeviceFeature, string[]>> = {
|
|
46
|
+
'float32-renderable-webgl': ['EXT_color_buffer_float'], // [false, 'EXT_color_buffer_float'],
|
|
47
|
+
'float16-renderable-webgl': ['EXT_color_buffer_half_float'],
|
|
48
|
+
'norm16-renderable-webgl': [EXT_TEXTURE_NORM16],
|
|
49
|
+
|
|
50
|
+
'float32-filterable-linear-webgl': ['OES_texture_float_linear'],
|
|
51
|
+
'float16-filterable-linear-webgl': ['OES_texture_half_float_linear'],
|
|
52
|
+
'texture-filterable-anisotropic-webgl': ['EXT_texture_filter_anisotropic'],
|
|
53
|
+
|
|
54
|
+
'texture-blend-float-webgl': ['EXT_float_blend'],
|
|
55
|
+
|
|
56
|
+
'texture-compression-bc': [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC],
|
|
57
|
+
// 'texture-compression-bc3-srgb-webgl': [X_S3TC_SRGB],
|
|
58
|
+
// 'texture-compression-bc3-webgl': [X_S3TC],
|
|
59
|
+
'texture-compression-bc5-webgl': [X_RGTC],
|
|
60
|
+
'texture-compression-bc7-webgl': [X_BPTC],
|
|
61
|
+
'texture-compression-etc2': [X_ETC2],
|
|
62
|
+
'texture-compression-astc': [X_ASTC],
|
|
63
|
+
'texture-compression-etc1-webgl': [X_ETC1],
|
|
64
|
+
'texture-compression-pvrtc-webgl': [X_PVRTC],
|
|
65
|
+
'texture-compression-atc-webgl': [X_ATC]
|
|
70
66
|
};
|
|
71
67
|
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
function checkTextureFeature(gl: WebGL2RenderingContext, feature: DeviceFeature): boolean {
|
|
69
|
+
const extensions = TEXTURE_FEATURE_CHECKS[feature] || [];
|
|
70
|
+
return extensions.every(extension => gl.getExtension(extension));
|
|
74
71
|
}
|
|
75
72
|
|
|
76
|
-
|
|
77
|
-
features.every(feature => checkTextureFeature(gl, feature));
|
|
73
|
+
function checkTextureFeatures(gl: WebGL2RenderingContext, features: DeviceFeature[]): boolean {
|
|
74
|
+
return features.every(feature => checkTextureFeature(gl, feature));
|
|
75
|
+
}
|
|
78
76
|
|
|
79
77
|
/** Return a list of texture feature strings (for Device.features). Mainly compressed texture support */
|
|
80
|
-
export function getTextureFeatures(gl:
|
|
78
|
+
export function getTextureFeatures(gl: WebGL2RenderingContext): DeviceFeature[] {
|
|
81
79
|
const textureFeatures = Object.keys(TEXTURE_FEATURE_CHECKS) as DeviceFeature[];
|
|
82
80
|
return textureFeatures.filter(feature => checkTextureFeature(gl, feature));
|
|
83
81
|
}
|
|
@@ -87,9 +85,6 @@ export function getTextureFeatures(gl: WebGLRenderingContext): DeviceFeature[] {
|
|
|
87
85
|
/** Map a format to webgl and constants */
|
|
88
86
|
type Format = {
|
|
89
87
|
gl?: GL;
|
|
90
|
-
/** If a different unsized format is needed in WebGL1 */
|
|
91
|
-
gl1?: GL;
|
|
92
|
-
gl1ext?: string;
|
|
93
88
|
/** format requires WebGL2, when using a WebGL 1 context, color renderbuffer formats are limited */
|
|
94
89
|
gl2ext?: string;
|
|
95
90
|
|
|
@@ -120,12 +115,12 @@ type Format = {
|
|
|
120
115
|
/** if depthTexture is set this is a depth/stencil format that can be set to a texture */
|
|
121
116
|
depthTexture?: boolean;
|
|
122
117
|
|
|
123
|
-
renderbuffer?: boolean
|
|
118
|
+
renderbuffer?: boolean;
|
|
124
119
|
};
|
|
125
120
|
|
|
126
121
|
// TABLES
|
|
127
122
|
|
|
128
|
-
/**
|
|
123
|
+
/**
|
|
129
124
|
* Texture format data -
|
|
130
125
|
* Exported but can change without notice
|
|
131
126
|
*/
|
|
@@ -134,9 +129,9 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
|
|
|
134
129
|
// Unsized formats that leave the precision up to the driver.
|
|
135
130
|
// TODO - Fix bpp constants
|
|
136
131
|
// 'r8unorm-unsized': {gl: GL.LUMINANCE, b: 4, c: 2, bpp: 4},
|
|
137
|
-
'rgb8unorm-unsized': {gl: GL.RGB,
|
|
132
|
+
'rgb8unorm-unsized': {gl: GL.RGB, b: 4, c: 2, bpp: 4,
|
|
138
133
|
dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5]},
|
|
139
|
-
'rgba8unorm-unsized': {gl: GL.RGBA,
|
|
134
|
+
'rgba8unorm-unsized': {gl: GL.RGBA, b: 4, c: 2, bpp: 4,
|
|
140
135
|
dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4, GL.UNSIGNED_SHORT_5_5_5_1]},
|
|
141
136
|
// 'rgb8unorm-srgb-unsized': {gl: GL.SRGB_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
|
|
142
137
|
// 'rgba8unorm-srgb-unsized': {gl: GL.SRGB_ALPHA_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
|
|
@@ -155,9 +150,9 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
|
|
|
155
150
|
|
|
156
151
|
'r16uint': {gl: GL.R16UI, b: 2, c: 1, renderbuffer: true},
|
|
157
152
|
'r16sint': {gl: GL.R16I, b: 2, c: 1, renderbuffer: true},
|
|
158
|
-
'r16float': {gl: GL.R16F, b: 2, c: 1, render: '
|
|
159
|
-
'r16unorm-webgl': {gl: GL.R16_EXT, b:2, c:1, f: '
|
|
160
|
-
'r16snorm-webgl': {gl: GL.R16_SNORM_EXT, b:2, c:1, f: '
|
|
153
|
+
'r16float': {gl: GL.R16F, b: 2, c: 1, render: 'float16-renderable-webgl', filter: 'float16-filterable-linear-webgl', renderbuffer: true},
|
|
154
|
+
'r16unorm-webgl': {gl: GL.R16_EXT, b:2, c:1, f: 'norm16-renderable-webgl', renderbuffer: true, x: EXT_TEXTURE_NORM16},
|
|
155
|
+
'r16snorm-webgl': {gl: GL.R16_SNORM_EXT, b:2, c:1, f: 'norm16-renderable-webgl', x: EXT_TEXTURE_NORM16},
|
|
161
156
|
|
|
162
157
|
// Packed 16-bit formats
|
|
163
158
|
'rgba4unorm-webgl': {gl: GL.RGBA4, b: 2, c: 4, wgpu: false, renderbuffer: true},
|
|
@@ -169,8 +164,8 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
|
|
|
169
164
|
'rgb8snorm-webgl': {gl: GL.RGB8_SNORM, b: 3, c: 3, wgpu: false},
|
|
170
165
|
|
|
171
166
|
// 32-bit formats
|
|
172
|
-
'rgba8unorm': {gl: GL.RGBA8,
|
|
173
|
-
'rgba8unorm-srgb': {gl: GL.SRGB8_ALPHA8,
|
|
167
|
+
'rgba8unorm': {gl: GL.RGBA8, b: 4, c: 2, bpp: 4},
|
|
168
|
+
'rgba8unorm-srgb': {gl: GL.SRGB8_ALPHA8, b: 4, c: 4, bpp: 4},
|
|
174
169
|
'rgba8snorm': {gl: GL.RGBA8_SNORM, b: 4, c: 4},
|
|
175
170
|
'rgba8uint': {gl: GL.RGBA8UI, b: 4, c: 4, bpp: 4},
|
|
176
171
|
'rgba8sint': {gl: GL.RGBA8I, b: 4, c: 4, bpp: 4},
|
|
@@ -181,54 +176,52 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
|
|
|
181
176
|
'rg16uint': {gl: GL.RG16UI, b: 4, c: 1, bpp: 4},
|
|
182
177
|
'rg16sint': {gl: GL.RG16I, b: 4, c: 2, bpp: 4},
|
|
183
178
|
// When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
|
|
184
|
-
'rg16float': {gl: GL.RG16F, bpp: 4, b: 4, c: 2, render: '
|
|
185
|
-
'rg16unorm-webgl': {gl: GL.RG16_EXT, b:2, c:2, f: '
|
|
186
|
-
'rg16snorm-webgl': {gl: GL.RG16_SNORM_EXT, b:2, c:2, f: '
|
|
179
|
+
'rg16float': {gl: GL.RG16F, bpp: 4, b: 4, c: 2, render: 'float16-renderable-webgl', filter: 'float16-filterable-linear-webgl', renderbuffer: true},
|
|
180
|
+
'rg16unorm-webgl': {gl: GL.RG16_EXT, b:2, c:2, f: 'norm16-renderable-webgl', x: EXT_TEXTURE_NORM16},
|
|
181
|
+
'rg16snorm-webgl': {gl: GL.RG16_SNORM_EXT, b:2, c:2, f: 'norm16-renderable-webgl', x: EXT_TEXTURE_NORM16},
|
|
187
182
|
|
|
188
183
|
'r32uint': {gl: GL.R32UI, b: 4, c: 1, bpp: 4, renderbuffer: true},
|
|
189
184
|
'r32sint': {gl: GL.R32I, b: 4, c: 1, bpp: 4, renderbuffer: true},
|
|
190
|
-
'r32float': {gl: GL.R32F, bpp: 4, b: 4, c: 1, render: '
|
|
185
|
+
'r32float': {gl: GL.R32F, bpp: 4, b: 4, c: 1, render: 'float32-renderable-webgl', filter: 'float32-filterable-linear-webgl'},
|
|
191
186
|
|
|
192
187
|
// Packed 32-bit formats
|
|
193
|
-
'rgb9e5ufloat': {gl: GL.RGB9_E5, b: 4, c: 3, p: 1, render: '
|
|
194
|
-
'rg11b10ufloat': {gl: GL.R11F_G11F_B10F, b: 4, c: 3, p: 1,render: '
|
|
188
|
+
'rgb9e5ufloat': {gl: GL.RGB9_E5, b: 4, c: 3, p: 1, render: 'float16-renderable-webgl', filter: 'float16-filterable-linear-webgl'},
|
|
189
|
+
'rg11b10ufloat': {gl: GL.R11F_G11F_B10F, b: 4, c: 3, p: 1,render: 'float32-renderable-webgl', renderbuffer: true},
|
|
195
190
|
'rgb10a2unorm': {gl: GL.RGB10_A2, b: 4, c: 4, p: 1, renderbuffer: true},
|
|
196
|
-
// webgl2 only
|
|
197
191
|
'rgb10a2unorm-webgl': {b: 4, c: 4, gl: GL.RGB10_A2UI, p: 1, wgpu: false, bpp: 4, renderbuffer: true},
|
|
198
192
|
|
|
199
193
|
// 48-bit formats
|
|
200
|
-
'rgb16unorm-webgl': {gl: GL.RGB16_EXT, b:2, c:3, f: '
|
|
201
|
-
'rgb16snorm-webgl': {gl: GL.RGB16_SNORM_EXT, b:2, c:3, f: '
|
|
194
|
+
'rgb16unorm-webgl': {gl: GL.RGB16_EXT, b:2, c:3, f: 'norm16-renderable-webgl', x: EXT_TEXTURE_NORM16},
|
|
195
|
+
'rgb16snorm-webgl': {gl: GL.RGB16_SNORM_EXT, b:2, c:3, f: 'norm16-renderable-webgl', x: EXT_TEXTURE_NORM16},
|
|
202
196
|
|
|
203
197
|
// 64-bit formats
|
|
204
198
|
'rg32uint': {gl: GL.RG32UI, b: 8, c: 2, renderbuffer: true},
|
|
205
199
|
'rg32sint': {gl: GL.RG32I, b: 8, c: 2, renderbuffer: true},
|
|
206
|
-
'rg32float': {gl: GL.RG32F, b: 8, c: 2, render: '
|
|
200
|
+
'rg32float': {gl: GL.RG32F, b: 8, c: 2, render: 'float32-renderable-webgl', filter: 'float32-filterable-linear-webgl', renderbuffer: true},
|
|
207
201
|
'rgba16uint': {gl: GL.RGBA16UI, b: 8, c: 4, renderbuffer: true},
|
|
208
202
|
'rgba16sint': {gl: GL.RGBA16I, b: 8, c: 4, renderbuffer: true},
|
|
209
|
-
'rgba16float': {gl: GL.RGBA16F,
|
|
210
|
-
'rgba16unorm-webgl': {gl: GL.RGBA16_EXT, b:2, c:4, f: '
|
|
211
|
-
'rgba16snorm-webgl': {gl: GL.RGBA16_SNORM_EXT, b:2, c:4, f: '
|
|
203
|
+
'rgba16float': {gl: GL.RGBA16F, b: 8, c: 4, render: 'float16-renderable-webgl', filter: 'float16-filterable-linear-webgl'},
|
|
204
|
+
'rgba16unorm-webgl': {gl: GL.RGBA16_EXT, b:2, c:4, f: 'norm16-renderable-webgl', renderbuffer: true, x: EXT_TEXTURE_NORM16},
|
|
205
|
+
'rgba16snorm-webgl': {gl: GL.RGBA16_SNORM_EXT, b:2, c:4, f: 'norm16-renderable-webgl', x: EXT_TEXTURE_NORM16},
|
|
212
206
|
|
|
213
207
|
// 96-bit formats (deprecated!)
|
|
214
|
-
'rgb32float-webgl': {gl: GL.RGB32F,
|
|
215
|
-
gl2ext: EXT_FLOAT_RENDER_WEBGL2,
|
|
216
|
-
dataFormat: GL.RGB, types: [GL.FLOAT]},
|
|
208
|
+
'rgb32float-webgl': {gl: GL.RGB32F, render: 'float32-renderable-webgl', filter: 'float32-filterable-linear-webgl',
|
|
209
|
+
gl2ext: EXT_FLOAT_RENDER_WEBGL2, dataFormat: GL.RGB, types: [GL.FLOAT]},
|
|
217
210
|
|
|
218
211
|
// 128-bit formats
|
|
219
212
|
'rgba32uint': {gl: GL.RGBA32UI, b: 16, c: 4, renderbuffer: true},
|
|
220
213
|
'rgba32sint': {gl: GL.RGBA32I, b: 16, c: 4, renderbuffer: true},
|
|
221
|
-
'rgba32float': {gl: GL.RGBA32F, b: 16, c: 4, render: '
|
|
214
|
+
'rgba32float': {gl: GL.RGBA32F, b: 16, c: 4, render: 'float32-renderable-webgl', filter: 'float32-filterable-linear-webgl', renderbuffer: true},
|
|
222
215
|
|
|
223
216
|
// Depth and stencil formats
|
|
224
|
-
'stencil8': {gl: GL.STENCIL_INDEX8,
|
|
217
|
+
'stencil8': {gl: GL.STENCIL_INDEX8, b: 1, c: 1, attachment: GL.STENCIL_ATTACHMENT, renderbuffer: true}, // 8 stencil bits
|
|
225
218
|
|
|
226
|
-
'depth16unorm': {gl: GL.DEPTH_COMPONENT16,
|
|
219
|
+
'depth16unorm': {gl: GL.DEPTH_COMPONENT16, b: 2, c: 1, attachment: GL.DEPTH_ATTACHMENT, renderbuffer: true}, // 16 depth bits
|
|
227
220
|
'depth24plus': {gl: GL.DEPTH_COMPONENT24, b: 3, c: 1, attachment: GL.DEPTH_ATTACHMENT},
|
|
228
221
|
'depth32float': {gl: GL.DEPTH_COMPONENT32F, b: 4, c: 1, attachment: GL.DEPTH_ATTACHMENT, renderbuffer: true},
|
|
229
222
|
|
|
230
223
|
// The depth component of the "depth24plus" and "depth24plus-stencil8" formats may be implemented as either a 24-bit depth value or a "depth32float" value.
|
|
231
|
-
'depth24plus-stencil8': {gl: GL.DEPTH_STENCIL,
|
|
224
|
+
'depth24plus-stencil8': {gl: GL.DEPTH_STENCIL, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, renderbuffer: true, depthTexture: true},
|
|
232
225
|
// "depth24unorm-stencil8" feature
|
|
233
226
|
'depth24unorm-stencil8': {gl: GL.DEPTH24_STENCIL8, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, renderbuffer: true},
|
|
234
227
|
// "depth32float-stencil8" feature
|
|
@@ -319,8 +312,8 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
|
|
|
319
312
|
};
|
|
320
313
|
|
|
321
314
|
/** Legal combinations for internalFormat, format and type *
|
|
322
|
-
// [GL.DEPTH_COMPONENT]: {types: [GL.UNSIGNED_SHORT, GL.UNSIGNED_INT, GL.UNSIGNED_INT_24_8]
|
|
323
|
-
// [GL.DEPTH_STENCIL]:
|
|
315
|
+
// [GL.DEPTH_COMPONENT]: {types: [GL.UNSIGNED_SHORT, GL.UNSIGNED_INT, GL.UNSIGNED_INT_24_8]},
|
|
316
|
+
// [GL.DEPTH_STENCIL]: ,
|
|
324
317
|
// Sized texture format
|
|
325
318
|
// R
|
|
326
319
|
[GL.R8]: {dataFormat: GL.RED, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
@@ -332,19 +325,19 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
|
|
|
332
325
|
[GL.RG8UI]: {dataFormat: GL.RG_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
333
326
|
// // RGB
|
|
334
327
|
[GL.RGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
335
|
-
[GL.SRGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true
|
|
336
|
-
[GL.RGB16F]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true
|
|
328
|
+
[GL.SRGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
329
|
+
[GL.RGB16F]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
337
330
|
[GL.RGB8UI]: {dataFormat: GL.RGB_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
338
331
|
// // RGBA
|
|
339
332
|
|
|
340
333
|
[GL.RGB565]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5], gl2: true},
|
|
341
334
|
[GL.R11F_G11F_B10F]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_INT_10F_11F_11F_REV, GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
342
|
-
[GL.RGB9_E5]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true
|
|
335
|
+
[GL.RGB9_E5]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
343
336
|
[GL.RGBA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
344
337
|
[GL.SRGB8_ALPHA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true, gl1ext: EXT_SRGB},
|
|
345
338
|
[GL.RGB5_A1]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_5_5_1], gl2: true},
|
|
346
339
|
[GL.RGBA4]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4], gl2: true},
|
|
347
|
-
[GL.RGBA16F]: {dataFormat: GL.RGBA, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true
|
|
340
|
+
[GL.RGBA16F]: {dataFormat: GL.RGBA, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
348
341
|
[GL.RGBA8UI]: {dataFormat: GL.RGBA_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true}
|
|
349
342
|
*/
|
|
350
343
|
|
|
@@ -445,7 +438,7 @@ const TYPE_SIZES = {
|
|
|
445
438
|
|
|
446
439
|
/** Checks if a texture format is supported */
|
|
447
440
|
export function isTextureFormatSupported(
|
|
448
|
-
gl:
|
|
441
|
+
gl: WebGL2RenderingContext,
|
|
449
442
|
formatOrGL: TextureFormat | GL
|
|
450
443
|
): boolean {
|
|
451
444
|
const format = convertGLToTextureFormat(formatOrGL);
|
|
@@ -454,21 +447,21 @@ export function isTextureFormatSupported(
|
|
|
454
447
|
return false;
|
|
455
448
|
}
|
|
456
449
|
// Check that we have a GL constant
|
|
457
|
-
if (
|
|
450
|
+
if (info.gl === undefined) {
|
|
458
451
|
return false;
|
|
459
452
|
}
|
|
460
453
|
// Check extensions
|
|
461
|
-
const extension = info.x ||
|
|
454
|
+
const extension = info.x || info.gl2ext;
|
|
462
455
|
if (extension) {
|
|
463
456
|
return Boolean(gl.getExtension(extension));
|
|
464
457
|
}
|
|
465
|
-
// if (info.gl1 === undefined && info.gl2 === undefined) {
|
|
466
|
-
// // No info - always supported
|
|
467
|
-
// }
|
|
468
458
|
return true;
|
|
469
459
|
}
|
|
470
460
|
|
|
471
|
-
export function isRenderbufferFormatSupported(
|
|
461
|
+
export function isRenderbufferFormatSupported(
|
|
462
|
+
gl: WebGL2RenderingContext,
|
|
463
|
+
format: TextureFormat
|
|
464
|
+
): boolean {
|
|
472
465
|
// Note: Order is important since the function call initializes extensions.
|
|
473
466
|
return isTextureFormatSupported(gl, format) && TEXTURE_FORMATS[format]?.renderbuffer;
|
|
474
467
|
}
|
|
@@ -480,9 +473,7 @@ export function convertGLToTextureFormat(format: GL | TextureFormat): TextureFor
|
|
|
480
473
|
if (typeof format === 'string') {
|
|
481
474
|
return format;
|
|
482
475
|
}
|
|
483
|
-
const entry = Object.entries(TEXTURE_FORMATS).find(
|
|
484
|
-
([, entry]) => entry.gl === format || entry.gl1 === format
|
|
485
|
-
);
|
|
476
|
+
const entry = Object.entries(TEXTURE_FORMATS).find(([, entry]) => entry.gl === format);
|
|
486
477
|
if (!entry) {
|
|
487
478
|
throw new Error(`Unknown texture format ${format}`);
|
|
488
479
|
}
|
|
@@ -492,9 +483,9 @@ export function convertGLToTextureFormat(format: GL | TextureFormat): TextureFor
|
|
|
492
483
|
/**
|
|
493
484
|
* Map WebGPU style texture format strings to GL constants
|
|
494
485
|
*/
|
|
495
|
-
export function convertTextureFormatToGL(format: TextureFormat
|
|
486
|
+
export function convertTextureFormatToGL(format: TextureFormat): GL | undefined {
|
|
496
487
|
const formatInfo = TEXTURE_FORMATS[format];
|
|
497
|
-
const webglFormat =
|
|
488
|
+
const webglFormat = formatInfo?.gl;
|
|
498
489
|
if (webglFormat === undefined) {
|
|
499
490
|
throw new Error(`Unsupported texture format ${format}`);
|
|
500
491
|
}
|
|
@@ -503,7 +494,7 @@ export function convertTextureFormatToGL(format: TextureFormat, isWebGL2: boolea
|
|
|
503
494
|
|
|
504
495
|
/** Checks if a texture format is supported */
|
|
505
496
|
export function getTextureFormatSupport(
|
|
506
|
-
gl:
|
|
497
|
+
gl: WebGL2RenderingContext,
|
|
507
498
|
formatOrGL: TextureFormat | GL
|
|
508
499
|
): {
|
|
509
500
|
supported: boolean;
|
|
@@ -523,7 +514,7 @@ export function getTextureFormatSupport(
|
|
|
523
514
|
// } catch {}
|
|
524
515
|
|
|
525
516
|
// Support Check that we have a GL constant
|
|
526
|
-
let supported =
|
|
517
|
+
let supported = info.gl === undefined;
|
|
527
518
|
supported = supported && checkTextureFeatures(gl, [info.f]);
|
|
528
519
|
|
|
529
520
|
// Filtering
|
|
@@ -545,7 +536,7 @@ export function getTextureFormatSupport(
|
|
|
545
536
|
|
|
546
537
|
/** Checks whether linear filtering (interpolated sampling) is available for floating point textures */
|
|
547
538
|
export function isTextureFormatFilterable(
|
|
548
|
-
gl:
|
|
539
|
+
gl: WebGL2RenderingContext,
|
|
549
540
|
formatOrGL: TextureFormat | GL
|
|
550
541
|
): boolean {
|
|
551
542
|
const format = convertGLToTextureFormat(formatOrGL);
|
|
@@ -566,22 +557,11 @@ export function isTextureFormatFilterable(
|
|
|
566
557
|
if (format.endsWith('16float')) {
|
|
567
558
|
return Boolean(gl.getExtension('OES_texture_half_float_linear'));
|
|
568
559
|
}
|
|
569
|
-
// if (typeof format === 'string') {
|
|
570
|
-
// if (format === 'rgba32float') {
|
|
571
|
-
// return gl.device.features.has('texture-renderable-rgba32float-webgl');
|
|
572
|
-
// }
|
|
573
|
-
// if (format.endsWith('32float')) {
|
|
574
|
-
// return gl.device.features.has('texture-renderable-float32-webgl');
|
|
575
|
-
// }
|
|
576
|
-
// if (format.endsWith('16float')) {
|
|
577
|
-
// return gl.device.features.has('texture-renderable-float16-webgl');
|
|
578
|
-
// }
|
|
579
|
-
// }
|
|
580
560
|
return true;
|
|
581
561
|
}
|
|
582
562
|
|
|
583
563
|
export function isTextureFormatRenderable(
|
|
584
|
-
gl:
|
|
564
|
+
gl: WebGL2RenderingContext,
|
|
585
565
|
formatOrGL: TextureFormat | GL
|
|
586
566
|
): boolean {
|
|
587
567
|
const format = convertGLToTextureFormat(formatOrGL);
|
|
@@ -595,9 +575,9 @@ export function isTextureFormatRenderable(
|
|
|
595
575
|
return true;
|
|
596
576
|
}
|
|
597
577
|
|
|
598
|
-
export function getWebGLTextureParameters(formatOrGL: TextureFormat | GL
|
|
578
|
+
export function getWebGLTextureParameters(formatOrGL: TextureFormat | GL) {
|
|
599
579
|
const format = convertGLToTextureFormat(formatOrGL);
|
|
600
|
-
const webglFormat = convertTextureFormatToGL(format
|
|
580
|
+
const webglFormat = convertTextureFormatToGL(format);
|
|
601
581
|
const decoded = decodeTextureFormat(format);
|
|
602
582
|
return {
|
|
603
583
|
format: webglFormat,
|
|
@@ -624,59 +604,11 @@ export function getDepthStencilAttachmentWebGL(
|
|
|
624
604
|
return info.attachment;
|
|
625
605
|
}
|
|
626
606
|
|
|
627
|
-
/**
|
|
628
|
-
* function to test if Float 32 bit format texture can be bound as color attachment
|
|
629
|
-
* @todo Generalize to check arbitrary formats?
|
|
630
|
-
*/
|
|
631
|
-
export function _checkFloat32ColorAttachment(
|
|
632
|
-
gl: WebGLRenderingContext,
|
|
633
|
-
internalFormat = gl.RGBA,
|
|
634
|
-
srcFormat = GL.RGBA,
|
|
635
|
-
srcType = GL.UNSIGNED_BYTE
|
|
636
|
-
) {
|
|
637
|
-
let texture: WebGLTexture | null = null;
|
|
638
|
-
let framebuffer: WebGLFramebuffer | null = null;
|
|
639
|
-
try {
|
|
640
|
-
texture = gl.createTexture();
|
|
641
|
-
gl.bindTexture(GL.TEXTURE_2D, texture);
|
|
642
|
-
|
|
643
|
-
const level = 0;
|
|
644
|
-
const width = 1;
|
|
645
|
-
const height = 1;
|
|
646
|
-
const border = 0;
|
|
647
|
-
const pixel = new Uint8Array([0, 0, 255, 255]); // opaque blue
|
|
648
|
-
gl.texImage2D(
|
|
649
|
-
gl.TEXTURE_2D,
|
|
650
|
-
level,
|
|
651
|
-
internalFormat,
|
|
652
|
-
width,
|
|
653
|
-
height,
|
|
654
|
-
border,
|
|
655
|
-
srcFormat,
|
|
656
|
-
srcType,
|
|
657
|
-
pixel
|
|
658
|
-
);
|
|
659
|
-
|
|
660
|
-
framebuffer = gl.createFramebuffer();
|
|
661
|
-
gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer);
|
|
662
|
-
gl.framebufferTexture2D(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, GL.TEXTURE_2D, texture, 0);
|
|
663
|
-
const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER) as GL === GL.FRAMEBUFFER_COMPLETE;
|
|
664
|
-
|
|
665
|
-
gl.bindTexture(GL.TEXTURE_2D, null);
|
|
666
|
-
return status;
|
|
667
|
-
} finally {
|
|
668
|
-
gl.deleteTexture(texture);
|
|
669
|
-
gl.deleteFramebuffer(framebuffer);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
|
|
673
607
|
/** TODO - VERY roundabout legacy way of calculating bytes per pixel */
|
|
674
|
-
export function getTextureFormatBytesPerPixel(
|
|
675
|
-
|
|
676
|
-
isWebGL2: boolean
|
|
677
|
-
): number {
|
|
608
|
+
export function getTextureFormatBytesPerPixel(formatOrGL: TextureFormat | GL): number {
|
|
609
|
+
// TODO remove webgl1 support
|
|
678
610
|
const format = convertGLToTextureFormat(formatOrGL);
|
|
679
|
-
const params = getWebGLTextureParameters(format
|
|
611
|
+
const params = getWebGLTextureParameters(format);
|
|
680
612
|
// NOTE(Tarek): Default to RGBA bytes
|
|
681
613
|
const channels = DATA_FORMAT_CHANNELS[params.dataFormat] || 4;
|
|
682
614
|
const channelSize = TYPE_SIZES[params.type] || 1;
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
|
|
7
|
+
import {DeviceFeature} from '@luma.gl/core';
|
|
8
|
+
import {getTextureFeatures} from '../converters/texture-formats';
|
|
9
|
+
|
|
10
|
+
/** Get WebGPU style feature strings */
|
|
11
|
+
export function getDeviceFeatures(gl: WebGL2RenderingContext): Set<DeviceFeature> {
|
|
12
|
+
const features = getWebGLFeatures(gl);
|
|
13
|
+
|
|
14
|
+
// texture features
|
|
15
|
+
// features.add('texture-compression-bc');
|
|
16
|
+
for (const textureFeature of getTextureFeatures(gl)) {
|
|
17
|
+
features.add(textureFeature);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// TODO
|
|
21
|
+
// features.add('depth-clip-control'); // GPUPrimitiveState.clampDepth
|
|
22
|
+
// features.add('depth24unorm-stencil8'); // GPUTextureFormat 'depth24unorm-stencil8'.
|
|
23
|
+
// features.add('depth32float-stencil8'); // GPUTextureFormat 'depth32float-stencil8'.
|
|
24
|
+
// features.add('timestamp-query'); // GPUQueryType "timestamp-query"
|
|
25
|
+
// "indirect-first-instance"
|
|
26
|
+
|
|
27
|
+
return features;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Extract all WebGL features */
|
|
31
|
+
export function getWebGLFeatures(gl: WebGL2RenderingContext): Set<DeviceFeature> {
|
|
32
|
+
// Enable EXT_float_blend first: https://developer.mozilla.org/en-US/docs/Web/API/EXT_float_blend
|
|
33
|
+
gl.getExtension('EXT_color_buffer_float');
|
|
34
|
+
|
|
35
|
+
const features = new Set<DeviceFeature>();
|
|
36
|
+
for (const feature of Object.keys(WEBGL_FEATURES) as DeviceFeature[]) {
|
|
37
|
+
if (isFeatureSupported(gl, feature)) {
|
|
38
|
+
features.add(feature);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return features;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isFeatureSupported(gl: WebGL2RenderingContext, feature: DeviceFeature): boolean {
|
|
45
|
+
const featureInfo = WEBGL_FEATURES[feature];
|
|
46
|
+
|
|
47
|
+
// string value requires checking the corresponding WebGL extension
|
|
48
|
+
return typeof featureInfo === 'string'
|
|
49
|
+
? Boolean(gl.getExtension(featureInfo))
|
|
50
|
+
: Boolean(featureInfo);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Defines luma.gl "feature" names and semantics
|
|
55
|
+
* when value is 'string' it is the name of the extension that enables this feature
|
|
56
|
+
*/
|
|
57
|
+
const WEBGL_FEATURES: Partial<Record<DeviceFeature, boolean | string>> = {
|
|
58
|
+
webgl: true,
|
|
59
|
+
glsl: true,
|
|
60
|
+
|
|
61
|
+
'uniforms-webgl': true,
|
|
62
|
+
'transform-feedback-webgl': true,
|
|
63
|
+
'constant-attributes-webgl': true,
|
|
64
|
+
|
|
65
|
+
'timer-query-webgl': 'EXT_disjoint_timer_query_webgl2',
|
|
66
|
+
'shader-status-async-webgl': 'KHR_parallel_shader_compile'
|
|
67
|
+
|
|
68
|
+
// Textures are handled by getTextureFeatures()
|
|
69
|
+
};
|
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
import {DeviceInfo} from '@luma.gl/core';
|
|
5
5
|
import {GL} from '@luma.gl/constants';
|
|
6
|
-
import {isWebGL2} from '../../context/context/webgl-checks';
|
|
7
6
|
|
|
8
7
|
/** @returns strings identifying the GPU vendor and driver. */
|
|
9
|
-
export function getDeviceInfo(gl:
|
|
8
|
+
export function getDeviceInfo(gl: WebGL2RenderingContext): DeviceInfo {
|
|
10
9
|
// "Masked" info is always available, but don't contain much useful information
|
|
11
10
|
const vendorMasked = gl.getParameter(GL.VENDOR);
|
|
12
11
|
const rendererMasked = gl.getParameter(GL.RENDERER);
|
|
@@ -32,10 +31,10 @@ export function getDeviceInfo(gl: WebGLRenderingContext): DeviceInfo {
|
|
|
32
31
|
// const version = gl.getParameter(GL.SHADING_LANGUAGE_VERSION) as string;
|
|
33
32
|
// const shadingLanguageVersion = parseGLSLVersion(version);
|
|
34
33
|
const shadingLanguage = 'glsl';
|
|
35
|
-
const shadingLanguageVersion =
|
|
34
|
+
const shadingLanguageVersion = 300;
|
|
36
35
|
|
|
37
36
|
return {
|
|
38
|
-
type:
|
|
37
|
+
type: 'webgl',
|
|
39
38
|
gpu,
|
|
40
39
|
gpuType,
|
|
41
40
|
gpuBackend,
|