@luma.gl/webgl 9.0.0-beta.5 → 9.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/device-parameters.js +128 -71
- package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/sampler-parameters.js +20 -19
- package/dist/adapter/converters/shader-formats.d.ts.map +1 -1
- package/dist/adapter/converters/shader-formats.js +40 -20
- package/dist/adapter/converters/texture-formats.d.ts +16 -11
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +224 -205
- package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
- package/dist/adapter/converters/vertex-formats.js +22 -21
- package/dist/adapter/device-helpers/webgl-device-features.d.ts +19 -5
- package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-features.js +89 -43
- package/dist/adapter/device-helpers/webgl-device-info.d.ts +2 -1
- package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-info.js +22 -19
- package/dist/adapter/device-helpers/webgl-device-limits.d.ts +33 -48
- package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-limits.js +42 -87
- package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -1
- package/dist/adapter/helpers/decode-webgl-types.js +47 -46
- package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-shader-layout.js +35 -34
- package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
- package/dist/adapter/helpers/parse-shader-compiler-log.js +3 -2
- package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
- package/dist/adapter/helpers/set-uniform.js +42 -41
- package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.js +40 -39
- package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
- package/dist/adapter/objects/constants-to-keys.js +2 -1
- package/dist/adapter/objects/webgl-renderbuffer.d.ts +2 -2
- package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-renderbuffer.js +30 -17
- package/dist/adapter/objects/webgl-resource.d.ts +2 -24
- package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-resource.js +6 -101
- package/dist/adapter/resources/webgl-buffer.d.ts +1 -1
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +16 -15
- package/dist/adapter/resources/webgl-command-buffer.d.ts +1 -1
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +32 -31
- package/dist/adapter/resources/webgl-command-encoder.d.ts +8 -3
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +4 -2
- package/dist/adapter/resources/webgl-external-texture.js +6 -5
- package/dist/adapter/resources/webgl-framebuffer.d.ts +6 -10
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +60 -53
- package/dist/adapter/resources/webgl-query-set.d.ts +44 -0
- package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -0
- package/dist/adapter/resources/webgl-query-set.js +136 -0
- package/dist/adapter/resources/webgl-render-pass.d.ts +3 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +20 -12
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +4 -5
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +52 -61
- package/dist/adapter/resources/webgl-sampler.d.ts +1 -1
- package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-sampler.js +5 -4
- package/dist/adapter/resources/webgl-shader.d.ts +3 -2
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +15 -9
- package/dist/adapter/resources/webgl-texture-view.d.ts +14 -0
- package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -0
- package/dist/adapter/resources/webgl-texture-view.js +18 -0
- package/dist/adapter/resources/webgl-texture.d.ts +6 -4
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +39 -32
- 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 +10 -10
- package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -3
- package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +10 -9
- package/dist/adapter/webgl-canvas-context.d.ts +2 -2
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +3 -2
- package/dist/adapter/webgl-device.d.ts +35 -30
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +110 -109
- package/dist/classic/accessor.d.ts.map +1 -1
- package/dist/classic/accessor.js +8 -7
- package/dist/classic/clear.d.ts.map +1 -1
- package/dist/classic/clear.js +5 -4
- package/dist/classic/copy-and-blit.d.ts +1 -1
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +19 -19
- package/dist/classic/format-utils.d.ts.map +1 -1
- package/dist/classic/format-utils.js +16 -15
- package/dist/classic/typed-array-utils.d.ts.map +1 -1
- package/dist/classic/typed-array-utils.js +20 -19
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +2 -1
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +7 -6
- package/dist/context/{context → helpers}/create-browser-context.d.ts.map +1 -1
- package/dist/context/{context → helpers}/create-browser-context.js +2 -1
- package/dist/context/{context/context-data.d.ts → helpers/webgl-context-data.d.ts} +2 -3
- package/dist/context/helpers/webgl-context-data.d.ts.map +1 -0
- package/dist/context/helpers/webgl-context-data.js +21 -0
- package/dist/context/helpers/webgl-extensions.d.ts +4 -0
- package/dist/context/helpers/webgl-extensions.d.ts.map +1 -0
- package/dist/context/helpers/webgl-extensions.js +10 -0
- package/dist/context/parameters/unified-parameter-api.d.ts +3 -4
- package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
- package/dist/context/parameters/unified-parameter-api.js +7 -11
- package/dist/context/parameters/webgl-parameter-tables.d.ts +12 -13
- package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js +302 -295
- package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
- package/dist/context/state-tracker/deep-array-equal.js +2 -1
- package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
- package/dist/context/state-tracker/track-context-state.js +5 -4
- package/dist/context/state-tracker/with-parameters.d.ts +2 -3
- package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
- package/dist/context/state-tracker/with-parameters.js +6 -8
- package/dist/dist.dev.js +1635 -1387
- package/dist/index.cjs +1766 -1534
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +25 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -23
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -1
- package/dist.min.js +6 -6
- package/package.json +4 -4
- package/src/adapter/converters/device-parameters.ts +114 -27
- package/src/adapter/converters/sampler-parameters.ts +12 -3
- package/src/adapter/converters/shader-formats.ts +47 -22
- package/src/adapter/converters/texture-formats.ts +138 -114
- package/src/adapter/converters/vertex-formats.ts +3 -3
- package/src/adapter/device-helpers/webgl-device-features.ts +102 -50
- package/src/adapter/device-helpers/webgl-device-info.ts +28 -19
- package/src/adapter/device-helpers/webgl-device-limits.ts +46 -150
- package/src/adapter/helpers/decode-webgl-types.ts +13 -7
- package/src/adapter/helpers/get-shader-layout.ts +4 -3
- package/src/adapter/helpers/parse-shader-compiler-log.ts +10 -6
- package/src/adapter/helpers/set-uniform.ts +2 -1
- package/src/adapter/helpers/webgl-topology-utils.ts +10 -3
- package/src/adapter/objects/constants-to-keys.ts +2 -1
- package/src/adapter/objects/webgl-renderbuffer.ts +36 -14
- package/src/adapter/objects/webgl-resource.ts +7 -125
- package/src/adapter/resources/webgl-buffer.ts +4 -3
- package/src/adapter/resources/webgl-command-buffer.ts +5 -5
- package/src/adapter/resources/webgl-command-encoder.ts +14 -11
- package/src/adapter/resources/webgl-external-texture.ts +6 -5
- package/src/adapter/resources/webgl-framebuffer.ts +61 -53
- package/src/adapter/resources/webgl-query-set.ts +171 -0
- package/src/adapter/resources/webgl-render-pass.ts +20 -11
- package/src/adapter/resources/webgl-render-pipeline.ts +54 -54
- package/src/adapter/resources/webgl-sampler.ts +2 -1
- package/src/adapter/resources/webgl-shader.ts +12 -5
- package/src/adapter/resources/webgl-texture-view.ts +28 -0
- package/src/adapter/resources/webgl-texture.ts +14 -3
- package/src/adapter/resources/webgl-transform-feedback.ts +2 -7
- package/src/adapter/resources/webgl-vertex-array.ts +4 -3
- package/src/adapter/webgl-canvas-context.ts +6 -4
- package/src/adapter/webgl-device.ts +116 -107
- package/src/classic/accessor.ts +5 -4
- package/src/classic/clear.ts +14 -8
- package/src/classic/copy-and-blit.ts +11 -4
- package/src/classic/format-utils.ts +2 -1
- package/src/classic/typed-array-utils.ts +3 -7
- package/src/context/debug/spector.ts +9 -6
- package/src/context/debug/webgl-developer-tools.ts +27 -14
- package/src/context/{context → helpers}/create-browser-context.ts +3 -2
- package/src/context/helpers/webgl-context-data.ts +31 -0
- package/src/context/helpers/webgl-extensions.ts +17 -0
- package/src/context/parameters/unified-parameter-api.ts +6 -17
- package/src/context/parameters/webgl-parameter-tables.ts +69 -32
- package/src/context/state-tracker/deep-array-equal.ts +2 -1
- package/src/context/state-tracker/track-context-state.ts +11 -6
- package/src/context/state-tracker/with-parameters.ts +8 -8
- package/src/index.ts +7 -6
- package/src/types.ts +2 -1
- package/dist/adapter/device-helpers/device-features.d.ts +0 -6
- package/dist/adapter/device-helpers/device-features.d.ts.map +0 -1
- package/dist/adapter/device-helpers/device-features.js +0 -65
- package/dist/adapter/device-helpers/device-limits.d.ts +0 -50
- package/dist/adapter/device-helpers/device-limits.d.ts.map +0 -1
- package/dist/adapter/device-helpers/device-limits.js +0 -92
- package/dist/adapter/device-helpers/get-device-info.d.ts +0 -4
- package/dist/adapter/device-helpers/get-device-info.d.ts.map +0 -1
- package/dist/adapter/device-helpers/get-device-info.js +0 -87
- package/dist/context/context/context-data.d.ts.map +0 -1
- package/dist/context/context/context-data.js +0 -33
- package/src/context/context/context-data.ts +0 -44
- /package/dist/context/{context → helpers}/create-browser-context.d.ts +0 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import type {TextureFormat, DeviceFeature} from '@luma.gl/core';
|
|
5
6
|
import {decodeTextureFormat} from '@luma.gl/core';
|
|
6
|
-
import {GL} from '@luma.gl/constants';
|
|
7
|
+
import {GL, GLExtensions} from '@luma.gl/constants';
|
|
8
|
+
import {getWebGLExtension} from '../../context/helpers/webgl-extensions';
|
|
7
9
|
import {getGLFromVertexType} from './vertex-formats';
|
|
8
10
|
|
|
9
11
|
/* eslint-disable camelcase */
|
|
@@ -18,8 +20,15 @@ const texture_compression_etc1_webgl: DeviceFeature = 'texture-compression-etc1-
|
|
|
18
20
|
const texture_compression_pvrtc_webgl: DeviceFeature = 'texture-compression-pvrtc-webgl';
|
|
19
21
|
const texture_compression_atc_webgl: DeviceFeature = 'texture-compression-atc-webgl';
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
const float32_renderable: DeviceFeature = 'float32-renderable-webgl';
|
|
24
|
+
const float16_renderable: DeviceFeature = 'float16-renderable-webgl';
|
|
25
|
+
const rgb9e5ufloat_renderable: DeviceFeature = 'rgb9e5ufloat_renderable-webgl';
|
|
26
|
+
const snorm8_renderable: DeviceFeature = 'snorm8-renderable-webgl';
|
|
27
|
+
const norm16_renderable: DeviceFeature = 'norm16-renderable-webgl';
|
|
28
|
+
const snorm16_renderable: DeviceFeature = 'snorm16-renderable-webgl';
|
|
29
|
+
|
|
30
|
+
const float32_filterable: DeviceFeature = 'float32-filterable';
|
|
31
|
+
const float16_filterable: DeviceFeature = 'float16-filterable-webgl';
|
|
23
32
|
|
|
24
33
|
// Define local webgl extension strings to optimize minification
|
|
25
34
|
const X_S3TC = 'WEBGL_compressed_texture_s3tc'; // BC1, BC2, BC3
|
|
@@ -33,22 +42,21 @@ const X_PVRTC = 'WEBGL_compressed_texture_pvrtc';
|
|
|
33
42
|
const X_ATC = 'WEBGL_compressed_texture_atc';
|
|
34
43
|
|
|
35
44
|
// Define local webgl extension strings to optimize minification
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
// const DEPTH = 'WEBGL_depth_texture';
|
|
40
|
-
|
|
41
|
-
// WebGL1-only extensions
|
|
42
|
-
// const EXT_SRGB = 'EXT_sRGB'; // https://developer.mozilla.org/en-US/docs/Web/API/EXT_sRGB
|
|
45
|
+
const EXT_texture_norm16 = 'EXT_texture_norm16';
|
|
46
|
+
const EXT_render_snorm = 'EXT_render_snorm';
|
|
47
|
+
const EXT_color_buffer_float = 'EXT_color_buffer_float';
|
|
43
48
|
|
|
44
49
|
// prettier-ignore
|
|
45
|
-
const
|
|
46
|
-
'float32-renderable-webgl': ['EXT_color_buffer_float'],
|
|
50
|
+
export const TEXTURE_FEATURES: Partial<Record<DeviceFeature, string[]>> = {
|
|
51
|
+
'float32-renderable-webgl': ['EXT_color_buffer_float'],
|
|
47
52
|
'float16-renderable-webgl': ['EXT_color_buffer_half_float'],
|
|
48
|
-
'
|
|
53
|
+
'rgb9e5ufloat_renderable-webgl': ['WEBGL_render_shared_exponent'],
|
|
54
|
+
'snorm8-renderable-webgl': [EXT_render_snorm],
|
|
55
|
+
'norm16-renderable-webgl': [EXT_texture_norm16],
|
|
56
|
+
'snorm16-renderable-webgl': [EXT_texture_norm16, EXT_render_snorm],
|
|
49
57
|
|
|
50
|
-
'float32-filterable
|
|
51
|
-
'float16-filterable-
|
|
58
|
+
'float32-filterable': ['OES_texture_float_linear'],
|
|
59
|
+
'float16-filterable-webgl': ['OES_texture_half_float_linear'],
|
|
52
60
|
'texture-filterable-anisotropic-webgl': ['EXT_texture_filter_anisotropic'],
|
|
53
61
|
|
|
54
62
|
'texture-blend-float-webgl': ['EXT_float_blend'],
|
|
@@ -65,19 +73,27 @@ const TEXTURE_FEATURE_CHECKS: Partial<Record<DeviceFeature, string[]>> = {
|
|
|
65
73
|
'texture-compression-atc-webgl': [X_ATC]
|
|
66
74
|
};
|
|
67
75
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
/** Return a list of texture feature strings (for Device.features). Mainly compressed texture support */
|
|
77
|
+
// export function getTextureFeatures(
|
|
78
|
+
// gl: WebGL2RenderingContext,
|
|
79
|
+
// extensions: GLExtensions
|
|
80
|
+
// ): DeviceFeature[] {
|
|
81
|
+
// const textureFeatures = Object.keys(TEXTURE_FEATURES) as DeviceFeature[];
|
|
82
|
+
// return textureFeatures.filter(feature => checkTextureFeature(gl, feature, extensions));
|
|
83
|
+
// }
|
|
84
|
+
|
|
85
|
+
export function isTextureFeature(feature: DeviceFeature): boolean {
|
|
86
|
+
return feature in TEXTURE_FEATURES;
|
|
75
87
|
}
|
|
76
88
|
|
|
77
|
-
/**
|
|
78
|
-
export function
|
|
79
|
-
|
|
80
|
-
|
|
89
|
+
/** Checks a texture feature (for Device.features). Mainly compressed texture support */
|
|
90
|
+
export function checkTextureFeature(
|
|
91
|
+
gl: WebGL2RenderingContext,
|
|
92
|
+
feature: DeviceFeature,
|
|
93
|
+
extensions: GLExtensions
|
|
94
|
+
): boolean {
|
|
95
|
+
const textureExtensions = TEXTURE_FEATURES[feature] || [];
|
|
96
|
+
return textureExtensions.every(extension => getWebGLExtension(gl, extension, extensions));
|
|
81
97
|
}
|
|
82
98
|
|
|
83
99
|
// TEXTURE FORMATS
|
|
@@ -114,8 +130,8 @@ type Format = {
|
|
|
114
130
|
attachment?: GL.DEPTH_ATTACHMENT | GL.STENCIL_ATTACHMENT | GL.DEPTH_STENCIL_ATTACHMENT;
|
|
115
131
|
/** if depthTexture is set this is a depth/stencil format that can be set to a texture */
|
|
116
132
|
depthTexture?: boolean;
|
|
117
|
-
|
|
118
|
-
|
|
133
|
+
/** @deprecated can this format be used with renderbuffers */
|
|
134
|
+
rb?: boolean;
|
|
119
135
|
};
|
|
120
136
|
|
|
121
137
|
// TABLES
|
|
@@ -126,38 +142,37 @@ type Format = {
|
|
|
126
142
|
*/
|
|
127
143
|
// prettier-ignore
|
|
128
144
|
export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
|
|
129
|
-
// Unsized formats that leave the precision up to the driver.
|
|
130
|
-
// TODO - Fix bpp constants
|
|
131
|
-
// 'r8unorm-unsized': {gl: GL.LUMINANCE, b: 4, c: 2, bpp: 4},
|
|
145
|
+
// Unsized formats that leave the precision up to the driver. TODO - Fix bpp constants
|
|
132
146
|
'rgb8unorm-unsized': {gl: GL.RGB, b: 4, c: 2, bpp: 4,
|
|
133
147
|
dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5]},
|
|
134
148
|
'rgba8unorm-unsized': {gl: GL.RGBA, b: 4, c: 2, bpp: 4,
|
|
135
149
|
dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4, GL.UNSIGNED_SHORT_5_5_5_1]},
|
|
150
|
+
// 'r8unorm-unsized': {gl: GL.LUMINANCE, b: 4, c: 2, bpp: 4},
|
|
136
151
|
// 'rgb8unorm-srgb-unsized': {gl: GL.SRGB_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
|
|
137
152
|
// 'rgba8unorm-srgb-unsized': {gl: GL.SRGB_ALPHA_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
|
|
138
153
|
|
|
139
154
|
// 8-bit formats
|
|
140
|
-
'r8unorm': {gl: GL.R8, b: 1, c: 1,
|
|
141
|
-
'r8snorm': {gl: GL.R8_SNORM, b: 1, c: 1},
|
|
142
|
-
'r8uint': {gl: GL.R8UI, b: 1, c: 1,
|
|
143
|
-
'r8sint': {gl: GL.R8I, b: 1, c: 1,
|
|
155
|
+
'r8unorm': {gl: GL.R8, b: 1, c: 1, rb: true},
|
|
156
|
+
'r8snorm': {gl: GL.R8_SNORM, b: 1, c: 1, render: snorm8_renderable},
|
|
157
|
+
'r8uint': {gl: GL.R8UI, b: 1, c: 1, rb: true},
|
|
158
|
+
'r8sint': {gl: GL.R8I, b: 1, c: 1, rb: true},
|
|
144
159
|
|
|
145
160
|
// 16-bit formats
|
|
146
|
-
'rg8unorm': {gl: GL.RG8, b: 2, c: 2,
|
|
147
|
-
'rg8snorm': {gl: GL.RG8_SNORM, b: 2, c: 2},
|
|
148
|
-
'rg8uint': {gl: GL.RG8UI, b: 2, c: 2,
|
|
149
|
-
'rg8sint': {gl: GL.RG8I, b: 2, c: 2,
|
|
161
|
+
'rg8unorm': {gl: GL.RG8, b: 2, c: 2, rb: true},
|
|
162
|
+
'rg8snorm': {gl: GL.RG8_SNORM, b: 2, c: 2, render: snorm8_renderable},
|
|
163
|
+
'rg8uint': {gl: GL.RG8UI, b: 2, c: 2, rb: true},
|
|
164
|
+
'rg8sint': {gl: GL.RG8I, b: 2, c: 2, rb: true},
|
|
150
165
|
|
|
151
|
-
'r16uint': {gl: GL.R16UI, b: 2, c: 1,
|
|
152
|
-
'r16sint': {gl: GL.R16I, b: 2, c: 1,
|
|
153
|
-
'r16float': {gl: GL.R16F, b: 2, c: 1, render:
|
|
154
|
-
'r16unorm-webgl': {gl: GL.R16_EXT, b:2, c:1, f:
|
|
155
|
-
'r16snorm-webgl': {gl: GL.R16_SNORM_EXT, b:2, c:1, f:
|
|
166
|
+
'r16uint': {gl: GL.R16UI, b: 2, c: 1, rb: true},
|
|
167
|
+
'r16sint': {gl: GL.R16I, b: 2, c: 1, rb: true},
|
|
168
|
+
'r16float': {gl: GL.R16F, b: 2, c: 1, render: float16_renderable, filter: 'float16-filterable-webgl', rb: true},
|
|
169
|
+
'r16unorm-webgl': {gl: GL.R16_EXT, b:2, c:1, f: norm16_renderable, rb: true},
|
|
170
|
+
'r16snorm-webgl': {gl: GL.R16_SNORM_EXT, b:2, c:1, f: snorm16_renderable},
|
|
156
171
|
|
|
157
172
|
// Packed 16-bit formats
|
|
158
|
-
'rgba4unorm-webgl': {gl: GL.RGBA4, b: 2, c: 4, wgpu: false,
|
|
159
|
-
'rgb565unorm-webgl': {gl: GL.RGB565, b: 2, c: 4, wgpu: false,
|
|
160
|
-
'rgb5a1unorm-webgl': {gl: GL.RGB5_A1, b: 2, c: 4, wgpu: false,
|
|
173
|
+
'rgba4unorm-webgl': {gl: GL.RGBA4, b: 2, c: 4, wgpu: false, rb: true},
|
|
174
|
+
'rgb565unorm-webgl': {gl: GL.RGB565, b: 2, c: 4, wgpu: false, rb: true},
|
|
175
|
+
'rgb5a1unorm-webgl': {gl: GL.RGB5_A1, b: 2, c: 4, wgpu: false, rb: true},
|
|
161
176
|
|
|
162
177
|
// 24-bit formats
|
|
163
178
|
'rgb8unorm-webgl': {gl: GL.RGB8, b: 3, c: 3, wgpu: false},
|
|
@@ -166,7 +181,7 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
|
|
|
166
181
|
// 32-bit formats
|
|
167
182
|
'rgba8unorm': {gl: GL.RGBA8, b: 4, c: 2, bpp: 4},
|
|
168
183
|
'rgba8unorm-srgb': {gl: GL.SRGB8_ALPHA8, b: 4, c: 4, bpp: 4},
|
|
169
|
-
'rgba8snorm': {gl: GL.RGBA8_SNORM, b: 4, c: 4},
|
|
184
|
+
'rgba8snorm': {gl: GL.RGBA8_SNORM, b: 4, c: 4, render: snorm8_renderable},
|
|
170
185
|
'rgba8uint': {gl: GL.RGBA8UI, b: 4, c: 4, bpp: 4},
|
|
171
186
|
'rgba8sint': {gl: GL.RGBA8I, b: 4, c: 4, bpp: 4},
|
|
172
187
|
// reverse colors, webgpu only
|
|
@@ -176,56 +191,62 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
|
|
|
176
191
|
'rg16uint': {gl: GL.RG16UI, b: 4, c: 1, bpp: 4},
|
|
177
192
|
'rg16sint': {gl: GL.RG16I, b: 4, c: 2, bpp: 4},
|
|
178
193
|
// When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
|
|
179
|
-
'rg16float': {gl: GL.RG16F, bpp: 4, b: 4, c: 2, render:
|
|
180
|
-
'rg16unorm-webgl': {gl: GL.RG16_EXT, b:2, c:2,
|
|
181
|
-
'rg16snorm-webgl': {gl: GL.RG16_SNORM_EXT, b:2, c:2,
|
|
194
|
+
'rg16float': {gl: GL.RG16F, bpp: 4, b: 4, c: 2, render: float16_renderable, filter: float16_filterable, rb: true},
|
|
195
|
+
'rg16unorm-webgl': {gl: GL.RG16_EXT, b:2, c:2, render: norm16_renderable},
|
|
196
|
+
'rg16snorm-webgl': {gl: GL.RG16_SNORM_EXT, b:2, c:2, render: snorm16_renderable},
|
|
182
197
|
|
|
183
|
-
'r32uint': {gl: GL.R32UI, b: 4, c: 1, bpp: 4,
|
|
184
|
-
'r32sint': {gl: GL.R32I, b: 4, c: 1, bpp: 4,
|
|
185
|
-
'r32float': {gl: GL.R32F, bpp: 4, b: 4, c: 1, render:
|
|
198
|
+
'r32uint': {gl: GL.R32UI, b: 4, c: 1, bpp: 4, rb: true},
|
|
199
|
+
'r32sint': {gl: GL.R32I, b: 4, c: 1, bpp: 4, rb: true},
|
|
200
|
+
'r32float': {gl: GL.R32F, bpp: 4, b: 4, c: 1, render: float32_renderable, filter: float32_filterable},
|
|
186
201
|
|
|
187
202
|
// Packed 32-bit formats
|
|
188
|
-
'rgb9e5ufloat': {gl: GL.RGB9_E5, b: 4, c: 3, p: 1, render:
|
|
189
|
-
'rg11b10ufloat': {gl: GL.R11F_G11F_B10F, b: 4, c: 3, p: 1,render:
|
|
190
|
-
'rgb10a2unorm': {gl: GL.RGB10_A2, b: 4, c: 4, p: 1,
|
|
191
|
-
'
|
|
203
|
+
'rgb9e5ufloat': {gl: GL.RGB9_E5, b: 4, c: 3, p: 1, render: rgb9e5ufloat_renderable}, // , filter: true},
|
|
204
|
+
'rg11b10ufloat': {gl: GL.R11F_G11F_B10F, b: 4, c: 3, p: 1,render: float32_renderable, rb: true},
|
|
205
|
+
'rgb10a2unorm': {gl: GL.RGB10_A2, b: 4, c: 4, p: 1, rb: true},
|
|
206
|
+
'rgb10a2uint-webgl': {b: 4, c: 4, gl: GL.RGB10_A2UI, p: 1, wgpu: false, bpp: 4, rb: true},
|
|
192
207
|
|
|
193
208
|
// 48-bit formats
|
|
194
|
-
'rgb16unorm-webgl': {gl: GL.RGB16_EXT, b:2, c:3, f:
|
|
195
|
-
'rgb16snorm-webgl': {gl: GL.RGB16_SNORM_EXT, b:2, c:3, f:
|
|
209
|
+
'rgb16unorm-webgl': {gl: GL.RGB16_EXT, b:2, c:3, f: norm16_renderable}, // rgb not renderable
|
|
210
|
+
'rgb16snorm-webgl': {gl: GL.RGB16_SNORM_EXT, b:2, c:3, f: norm16_renderable}, // rgb not renderable
|
|
196
211
|
|
|
197
212
|
// 64-bit formats
|
|
198
|
-
'rg32uint': {gl: GL.RG32UI, b: 8, c: 2,
|
|
199
|
-
'rg32sint': {gl: GL.RG32I, b: 8, c: 2,
|
|
200
|
-
'rg32float': {gl: GL.RG32F, b: 8, c: 2, render:
|
|
201
|
-
'rgba16uint': {gl: GL.RGBA16UI, b: 8, c: 4,
|
|
202
|
-
'rgba16sint': {gl: GL.RGBA16I, b: 8, c: 4,
|
|
203
|
-
'rgba16float': {gl: GL.RGBA16F, b: 8, c: 4, render:
|
|
204
|
-
'rgba16unorm-webgl': {gl: GL.RGBA16_EXT, b:2, c:4,
|
|
205
|
-
'rgba16snorm-webgl': {gl: GL.RGBA16_SNORM_EXT, b:2, c:4,
|
|
213
|
+
'rg32uint': {gl: GL.RG32UI, b: 8, c: 2, rb: true},
|
|
214
|
+
'rg32sint': {gl: GL.RG32I, b: 8, c: 2, rb: true},
|
|
215
|
+
'rg32float': {gl: GL.RG32F, b: 8, c: 2, render: float32_renderable, filter: float32_filterable, rb: true},
|
|
216
|
+
'rgba16uint': {gl: GL.RGBA16UI, b: 8, c: 4, rb: true},
|
|
217
|
+
'rgba16sint': {gl: GL.RGBA16I, b: 8, c: 4, rb: true},
|
|
218
|
+
'rgba16float': {gl: GL.RGBA16F, b: 8, c: 4, render: float16_renderable, filter: float16_filterable},
|
|
219
|
+
'rgba16unorm-webgl': {gl: GL.RGBA16_EXT, b:2, c:4, render: norm16_renderable, rb: true},
|
|
220
|
+
'rgba16snorm-webgl': {gl: GL.RGBA16_SNORM_EXT, b:2, c:4, render: snorm16_renderable},
|
|
206
221
|
|
|
207
222
|
// 96-bit formats (deprecated!)
|
|
208
|
-
'rgb32float-webgl': {gl: GL.RGB32F, render:
|
|
209
|
-
gl2ext:
|
|
223
|
+
'rgb32float-webgl': {gl: GL.RGB32F, render: float32_renderable, filter: float32_filterable,
|
|
224
|
+
gl2ext: EXT_color_buffer_float, dataFormat: GL.RGB, types: [GL.FLOAT]},
|
|
210
225
|
|
|
211
226
|
// 128-bit formats
|
|
212
|
-
'rgba32uint': {gl: GL.RGBA32UI, b: 16, c: 4,
|
|
213
|
-
'rgba32sint': {gl: GL.RGBA32I, b: 16, c: 4,
|
|
214
|
-
'rgba32float': {gl: GL.RGBA32F, b: 16, c: 4, render:
|
|
227
|
+
'rgba32uint': {gl: GL.RGBA32UI, b: 16, c: 4, rb: true},
|
|
228
|
+
'rgba32sint': {gl: GL.RGBA32I, b: 16, c: 4, rb: true},
|
|
229
|
+
'rgba32float': {gl: GL.RGBA32F, b: 16, c: 4, render: float32_renderable, filter: float32_filterable, rb: true},
|
|
215
230
|
|
|
216
231
|
// Depth and stencil formats
|
|
217
|
-
'stencil8': {gl: GL.STENCIL_INDEX8, b: 1, c: 1, attachment: GL.STENCIL_ATTACHMENT,
|
|
232
|
+
'stencil8': {gl: GL.STENCIL_INDEX8, b: 1, c: 1, attachment: GL.STENCIL_ATTACHMENT, rb: true}, // 8 stencil bits
|
|
218
233
|
|
|
219
|
-
'depth16unorm': {gl: GL.DEPTH_COMPONENT16, b: 2, c: 1, attachment: GL.DEPTH_ATTACHMENT,
|
|
220
|
-
|
|
221
|
-
'
|
|
234
|
+
'depth16unorm': {gl: GL.DEPTH_COMPONENT16, b: 2, c: 1, attachment: GL.DEPTH_ATTACHMENT,
|
|
235
|
+
dataFormat: GL.DEPTH_COMPONENT, types: [GL.UNSIGNED_SHORT], rb: true}, // 16 depth bits
|
|
236
|
+
'depth24plus': {gl: GL.DEPTH_COMPONENT24, b: 3, c: 1, attachment: GL.DEPTH_ATTACHMENT,
|
|
237
|
+
dataFormat: GL.DEPTH_COMPONENT, types: [GL.UNSIGNED_INT]},
|
|
238
|
+
'depth32float': {gl: GL.DEPTH_COMPONENT32F, b: 4, c: 1, attachment: GL.DEPTH_ATTACHMENT,
|
|
239
|
+
dataFormat: GL.DEPTH_COMPONENT, types: [GL.FLOAT], rb: true},
|
|
222
240
|
|
|
223
241
|
// The depth component of the "depth24plus" and "depth24plus-stencil8" formats may be implemented as either a 24-bit depth value or a "depth32float" value.
|
|
224
|
-
'depth24plus-stencil8': {gl: GL.
|
|
242
|
+
'depth24plus-stencil8': {gl: GL.DEPTH24_STENCIL8, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, rb: true, depthTexture: true,
|
|
243
|
+
dataFormat: GL.DEPTH_STENCIL, types: [GL.UNSIGNED_INT_24_8]},
|
|
225
244
|
// "depth24unorm-stencil8" feature
|
|
226
|
-
'depth24unorm-stencil8': {gl: GL.DEPTH24_STENCIL8, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT,
|
|
227
|
-
|
|
228
|
-
|
|
245
|
+
'depth24unorm-stencil8': {gl: GL.DEPTH24_STENCIL8, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT,
|
|
246
|
+
dataFormat: GL.DEPTH_STENCIL, types: [GL.UNSIGNED_INT_24_8], rb: true},
|
|
247
|
+
// "depth32float-stencil8" feature - TODO below is render buffer only?
|
|
248
|
+
'depth32float-stencil8': {gl: GL.DEPTH32F_STENCIL8, b: 5, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT,
|
|
249
|
+
dataFormat: GL.DEPTH_STENCIL, types: [GL.FLOAT_32_UNSIGNED_INT_24_8_REV], rb: true},
|
|
229
250
|
|
|
230
251
|
// BC compressed formats: check device.features.has("texture-compression-bc");
|
|
231
252
|
|
|
@@ -400,7 +421,7 @@ export const RENDERBUFFER_FORMATS: Record<string, RenderbufferFormat> = {
|
|
|
400
421
|
[GL.RG32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
|
|
401
422
|
// TODO - can't get WEBGL_color_buffer_float to work on renderbuffers
|
|
402
423
|
[GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 16},
|
|
403
|
-
// [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2
|
|
424
|
+
// [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2},
|
|
404
425
|
[GL.R11F_G11F_B10F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4}
|
|
405
426
|
};
|
|
406
427
|
*/
|
|
@@ -439,9 +460,9 @@ const TYPE_SIZES = {
|
|
|
439
460
|
/** Checks if a texture format is supported */
|
|
440
461
|
export function isTextureFormatSupported(
|
|
441
462
|
gl: WebGL2RenderingContext,
|
|
442
|
-
|
|
463
|
+
format: TextureFormat,
|
|
464
|
+
extensions: GLExtensions
|
|
443
465
|
): boolean {
|
|
444
|
-
const format = convertGLToTextureFormat(formatOrGL);
|
|
445
466
|
const info = TEXTURE_FORMATS[format];
|
|
446
467
|
if (!info) {
|
|
447
468
|
return false;
|
|
@@ -453,17 +474,18 @@ export function isTextureFormatSupported(
|
|
|
453
474
|
// Check extensions
|
|
454
475
|
const extension = info.x || info.gl2ext;
|
|
455
476
|
if (extension) {
|
|
456
|
-
return Boolean(gl
|
|
477
|
+
return Boolean(getWebGLExtension(gl, extension, extensions));
|
|
457
478
|
}
|
|
458
479
|
return true;
|
|
459
480
|
}
|
|
460
481
|
|
|
461
482
|
export function isRenderbufferFormatSupported(
|
|
462
483
|
gl: WebGL2RenderingContext,
|
|
463
|
-
format: TextureFormat
|
|
484
|
+
format: TextureFormat,
|
|
485
|
+
extensions: GLExtensions
|
|
464
486
|
): boolean {
|
|
465
487
|
// Note: Order is important since the function call initializes extensions.
|
|
466
|
-
return isTextureFormatSupported(gl, format) && TEXTURE_FORMATS[format]?.
|
|
488
|
+
return isTextureFormatSupported(gl, format, extensions) && TEXTURE_FORMATS[format]?.rb;
|
|
467
489
|
}
|
|
468
490
|
|
|
469
491
|
/**
|
|
@@ -495,7 +517,8 @@ export function convertTextureFormatToGL(format: TextureFormat): GL | undefined
|
|
|
495
517
|
/** Checks if a texture format is supported */
|
|
496
518
|
export function getTextureFormatSupport(
|
|
497
519
|
gl: WebGL2RenderingContext,
|
|
498
|
-
|
|
520
|
+
format: TextureFormat,
|
|
521
|
+
extensions: GLExtensions
|
|
499
522
|
): {
|
|
500
523
|
supported: boolean;
|
|
501
524
|
filterable?: boolean;
|
|
@@ -503,7 +526,6 @@ export function getTextureFormatSupport(
|
|
|
503
526
|
blendable?: boolean;
|
|
504
527
|
storable?: boolean;
|
|
505
528
|
} {
|
|
506
|
-
const format = convertGLToTextureFormat(formatOrGL);
|
|
507
529
|
const info = TEXTURE_FORMATS[format];
|
|
508
530
|
if (!info) {
|
|
509
531
|
return {supported: false};
|
|
@@ -515,20 +537,20 @@ export function getTextureFormatSupport(
|
|
|
515
537
|
|
|
516
538
|
// Support Check that we have a GL constant
|
|
517
539
|
let supported = info.gl === undefined;
|
|
518
|
-
supported = supported &&
|
|
540
|
+
supported = supported && checkTextureFeature(gl, info.f, extensions);
|
|
519
541
|
|
|
520
542
|
// Filtering
|
|
521
543
|
// const filterable = info.filter
|
|
522
|
-
// ?
|
|
544
|
+
// ? checkTextureFeature(gl, infofilter])
|
|
523
545
|
// : decoded && !decoded.signed;
|
|
524
546
|
// const renderable = info.filter
|
|
525
|
-
// ?
|
|
547
|
+
// ? checkTextureFeature(gl, inforender])
|
|
526
548
|
// : decoded && !decoded.signed;
|
|
527
549
|
|
|
528
550
|
return {
|
|
529
551
|
supported,
|
|
530
|
-
renderable: supported &&
|
|
531
|
-
filterable: supported &&
|
|
552
|
+
renderable: supported && checkTextureFeature(gl, info.render, extensions),
|
|
553
|
+
filterable: supported && checkTextureFeature(gl, info.filter, extensions),
|
|
532
554
|
blendable: false, // tod,
|
|
533
555
|
storable: false
|
|
534
556
|
};
|
|
@@ -537,10 +559,13 @@ export function getTextureFormatSupport(
|
|
|
537
559
|
/** Checks whether linear filtering (interpolated sampling) is available for floating point textures */
|
|
538
560
|
export function isTextureFormatFilterable(
|
|
539
561
|
gl: WebGL2RenderingContext,
|
|
540
|
-
|
|
562
|
+
format: TextureFormat,
|
|
563
|
+
extensions: GLExtensions
|
|
541
564
|
): boolean {
|
|
542
|
-
|
|
543
|
-
|
|
565
|
+
if (!isTextureFormatSupported(gl, format, extensions)) {
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
568
|
+
if (format.startsWith('depth') || format.startsWith('stencil')) {
|
|
544
569
|
return false;
|
|
545
570
|
}
|
|
546
571
|
try {
|
|
@@ -552,20 +577,20 @@ export function isTextureFormatFilterable(
|
|
|
552
577
|
return false;
|
|
553
578
|
}
|
|
554
579
|
if (format.endsWith('32float')) {
|
|
555
|
-
return Boolean(gl
|
|
580
|
+
return Boolean(getWebGLExtension(gl, 'OES_texture_float_linear, extensions', extensions));
|
|
556
581
|
}
|
|
557
582
|
if (format.endsWith('16float')) {
|
|
558
|
-
return Boolean(gl
|
|
583
|
+
return Boolean(getWebGLExtension(gl, 'OES_texture_half_float_linear, extensions', extensions));
|
|
559
584
|
}
|
|
560
585
|
return true;
|
|
561
586
|
}
|
|
562
587
|
|
|
563
588
|
export function isTextureFormatRenderable(
|
|
564
589
|
gl: WebGL2RenderingContext,
|
|
565
|
-
|
|
590
|
+
format: TextureFormat,
|
|
591
|
+
extensions: GLExtensions
|
|
566
592
|
): boolean {
|
|
567
|
-
|
|
568
|
-
if (!isTextureFormatSupported(gl, format)) {
|
|
593
|
+
if (!isTextureFormatSupported(gl, format, extensions)) {
|
|
569
594
|
return false;
|
|
570
595
|
}
|
|
571
596
|
if (typeof format === 'number') {
|
|
@@ -575,20 +600,20 @@ export function isTextureFormatRenderable(
|
|
|
575
600
|
return true;
|
|
576
601
|
}
|
|
577
602
|
|
|
578
|
-
|
|
579
|
-
|
|
603
|
+
/** Get parameters necessary to work with format in WebGL: internalFormat, dataFormat, type, compressed, */
|
|
604
|
+
export function getWebGLTextureParameters(format: TextureFormat) {
|
|
605
|
+
const formatData = TEXTURE_FORMATS[format];
|
|
580
606
|
const webglFormat = convertTextureFormatToGL(format);
|
|
581
607
|
const decoded = decodeTextureFormat(format);
|
|
582
608
|
return {
|
|
583
609
|
format: webglFormat,
|
|
584
|
-
dataFormat:
|
|
585
|
-
|
|
586
|
-
decoded.integer,
|
|
587
|
-
decoded.normalized,
|
|
588
|
-
webglFormat
|
|
589
|
-
),
|
|
610
|
+
dataFormat:
|
|
611
|
+
formatData?.dataFormat ||
|
|
612
|
+
getWebGLPixelDataFormat(decoded.format, decoded.integer, decoded.normalized, webglFormat),
|
|
590
613
|
// depth formats don't have a type
|
|
591
|
-
type: decoded.dataType
|
|
614
|
+
type: decoded.dataType
|
|
615
|
+
? getGLFromVertexType(decoded.dataType)
|
|
616
|
+
: formatData?.types?.[0] || GL.UNSIGNED_BYTE,
|
|
592
617
|
// @ts-expect-error
|
|
593
618
|
compressed: decoded.compressed
|
|
594
619
|
};
|
|
@@ -605,9 +630,8 @@ export function getDepthStencilAttachmentWebGL(
|
|
|
605
630
|
}
|
|
606
631
|
|
|
607
632
|
/** TODO - VERY roundabout legacy way of calculating bytes per pixel */
|
|
608
|
-
export function getTextureFormatBytesPerPixel(
|
|
633
|
+
export function getTextureFormatBytesPerPixel(format: TextureFormat): number {
|
|
609
634
|
// TODO remove webgl1 support
|
|
610
|
-
const format = convertGLToTextureFormat(formatOrGL);
|
|
611
635
|
const params = getWebGLTextureParameters(format);
|
|
612
636
|
// NOTE(Tarek): Default to RGBA bytes
|
|
613
637
|
const channels = DATA_FORMAT_CHANNELS[params.dataFormat] || 4;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import {GL} from '@luma.gl/constants';
|
|
5
6
|
import {VertexFormat, VertexType} from '@luma.gl/core';
|
|
6
7
|
|
|
7
|
-
type GLDataType =
|
|
8
|
+
type GLDataType =
|
|
8
9
|
| GL.UNSIGNED_BYTE
|
|
9
10
|
| GL.BYTE
|
|
10
11
|
| GL.UNSIGNED_SHORT
|
|
@@ -14,7 +15,6 @@ type GLDataType =
|
|
|
14
15
|
| GL.HALF_FLOAT
|
|
15
16
|
| GL.FLOAT;
|
|
16
17
|
|
|
17
|
-
|
|
18
18
|
/** Get vertex format from GL constants */
|
|
19
19
|
export function getVertexFormatFromGL(type: GLDataType, components: 1 | 2 | 3 | 4): VertexFormat {
|
|
20
20
|
const base = getVertexTypeFromGL(type);
|
|
@@ -1,69 +1,121 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
// Feature detection for WebGL
|
|
5
6
|
// Provides a function that enables simple checking of which WebGL features are
|
|
6
7
|
|
|
7
|
-
import {DeviceFeature} from '@luma.gl/core';
|
|
8
|
-
import {
|
|
8
|
+
import {DeviceFeature, DeviceFeatures} from '@luma.gl/core';
|
|
9
|
+
import {GLExtensions} from '@luma.gl/constants';
|
|
10
|
+
import {getWebGLExtension} from '../../context/helpers/webgl-extensions';
|
|
11
|
+
import {isTextureFeature, checkTextureFeature} from '../converters/texture-formats';
|
|
12
|
+
import {TEXTURE_FEATURES} from '../converters/texture-formats';
|
|
9
13
|
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Defines luma.gl "feature" names and semantics
|
|
16
|
+
* when value is 'string' it is the name of the extension that enables this feature
|
|
17
|
+
*/
|
|
18
|
+
const WEBGL_FEATURES: Partial<Record<DeviceFeature, boolean | string>> = {
|
|
19
|
+
// optional WebGPU features
|
|
20
|
+
'depth-clip-control': 'EXT_depth_clamp', // TODO these seem subtly different
|
|
21
|
+
// 'timestamp-query' // GPUQueryType "timestamp-query"
|
|
22
|
+
// "indirect-first-instance"
|
|
23
|
+
// Textures are handled by getTextureFeatures()
|
|
24
|
+
// 'depth24unorm-stencil8' // GPUTextureFormat 'depth24unorm-stencil8'
|
|
25
|
+
// 'depth32float-stencil8' // GPUTextureFormat 'depth32float-stencil8'
|
|
13
26
|
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
// optional WebGL features
|
|
28
|
+
'timer-query-webgl': 'EXT_disjoint_timer_query_webgl2',
|
|
29
|
+
'compilation-status-async-webgl': 'KHR_parallel_shader_compile',
|
|
30
|
+
'polygon-mode-webgl': 'WEBGL_polygon_mode',
|
|
31
|
+
'provoking-vertex-webgl': 'WEBGL_provoking_vertex',
|
|
32
|
+
'shader-clip-cull-distance-webgl': 'WEBGL_clip_cull_distance',
|
|
33
|
+
'shader-noperspective-interpolation-webgl': 'NV_shader_noperspective_interpolation',
|
|
34
|
+
'shader-conservative-depth-webgl': 'EXT_conservative_depth'
|
|
19
35
|
|
|
20
|
-
//
|
|
21
|
-
|
|
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"
|
|
36
|
+
// Textures are handled by getTextureFeatures()
|
|
37
|
+
};
|
|
26
38
|
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
/**
|
|
40
|
+
* WebGL extensions exposed as luma.gl features
|
|
41
|
+
* To minimize GL log noise and improve performance, this class ensures that
|
|
42
|
+
* - WebGL extensions are not queried until the corresponding feature is checked.
|
|
43
|
+
* - WebGL extensions are only queried once.
|
|
44
|
+
*/
|
|
45
|
+
export class WebGLDeviceFeatures extends DeviceFeatures {
|
|
46
|
+
protected gl: WebGL2RenderingContext;
|
|
47
|
+
protected extensions: GLExtensions;
|
|
48
|
+
protected testedFeatures = new Set<DeviceFeature>();
|
|
29
49
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
50
|
+
constructor(
|
|
51
|
+
gl: WebGL2RenderingContext,
|
|
52
|
+
extensions: GLExtensions,
|
|
53
|
+
disabledFeatures: Partial<Record<DeviceFeature, boolean>>
|
|
54
|
+
) {
|
|
55
|
+
super([], disabledFeatures);
|
|
56
|
+
this.gl = gl;
|
|
57
|
+
this.extensions = extensions;
|
|
58
|
+
// TODO - is this really needed?
|
|
59
|
+
// Enable EXT_float_blend first: https://developer.mozilla.org/en-US/docs/Web/API/EXT_float_blend
|
|
60
|
+
getWebGLExtension(gl, 'EXT_color_buffer_float', extensions);
|
|
61
|
+
}
|
|
34
62
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
63
|
+
*[Symbol.iterator](): IterableIterator<DeviceFeature> {
|
|
64
|
+
for (const feature of Object.keys(WEBGL_FEATURES) as DeviceFeature[]) {
|
|
65
|
+
if (this.has(feature)) {
|
|
66
|
+
yield feature;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const feature of Object.keys(TEXTURE_FEATURES) as DeviceFeature[]) {
|
|
70
|
+
if (this.has(feature)) {
|
|
71
|
+
yield feature;
|
|
72
|
+
}
|
|
39
73
|
}
|
|
74
|
+
return [];
|
|
40
75
|
}
|
|
41
|
-
return features;
|
|
42
|
-
}
|
|
43
76
|
|
|
44
|
-
|
|
45
|
-
|
|
77
|
+
override has(feature: DeviceFeature): boolean {
|
|
78
|
+
if (this.disabledFeatures[feature]) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
46
81
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
: Boolean(featureInfo);
|
|
51
|
-
}
|
|
82
|
+
// We have already tested this feature
|
|
83
|
+
if (!this.testedFeatures.has(feature)) {
|
|
84
|
+
this.testedFeatures.add(feature);
|
|
52
85
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const WEBGL_FEATURES: Partial<Record<DeviceFeature, boolean | string>> = {
|
|
58
|
-
webgl: true,
|
|
59
|
-
glsl: true,
|
|
86
|
+
// Check the feature once
|
|
87
|
+
if (isTextureFeature(feature) && checkTextureFeature(this.gl, feature, this.extensions)) {
|
|
88
|
+
this.features.add(feature);
|
|
89
|
+
}
|
|
60
90
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
91
|
+
if (this.getWebGLFeature(feature)) {
|
|
92
|
+
this.features.add(feature);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return this.features.has(feature);
|
|
96
|
+
}
|
|
64
97
|
|
|
65
|
-
|
|
66
|
-
'shader-status-async-webgl': 'KHR_parallel_shader_compile'
|
|
98
|
+
// FOR DEVICE
|
|
67
99
|
|
|
68
|
-
|
|
69
|
-
|
|
100
|
+
initializeFeatures() {
|
|
101
|
+
// @ts-expect-error
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
103
|
+
for (const feature of this) {
|
|
104
|
+
// WebGL extensions are initialized by requesting them
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// IMPLEMENTATION
|
|
109
|
+
|
|
110
|
+
/** Extract all WebGL features */
|
|
111
|
+
protected getWebGLFeature(feature: DeviceFeature): boolean {
|
|
112
|
+
const featureInfo = WEBGL_FEATURES[feature];
|
|
113
|
+
// string value requires checking the corresponding WebGL extension
|
|
114
|
+
const isSupported =
|
|
115
|
+
typeof featureInfo === 'string'
|
|
116
|
+
? Boolean(getWebGLExtension(this.gl, featureInfo, this.extensions))
|
|
117
|
+
: Boolean(featureInfo);
|
|
118
|
+
|
|
119
|
+
return isSupported;
|
|
120
|
+
}
|
|
121
|
+
}
|