@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.
Files changed (192) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  2. package/dist/adapter/converters/device-parameters.js +128 -71
  3. package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
  4. package/dist/adapter/converters/sampler-parameters.js +20 -19
  5. package/dist/adapter/converters/shader-formats.d.ts.map +1 -1
  6. package/dist/adapter/converters/shader-formats.js +40 -20
  7. package/dist/adapter/converters/texture-formats.d.ts +16 -11
  8. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  9. package/dist/adapter/converters/texture-formats.js +224 -205
  10. package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
  11. package/dist/adapter/converters/vertex-formats.js +22 -21
  12. package/dist/adapter/device-helpers/webgl-device-features.d.ts +19 -5
  13. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
  14. package/dist/adapter/device-helpers/webgl-device-features.js +89 -43
  15. package/dist/adapter/device-helpers/webgl-device-info.d.ts +2 -1
  16. package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -1
  17. package/dist/adapter/device-helpers/webgl-device-info.js +22 -19
  18. package/dist/adapter/device-helpers/webgl-device-limits.d.ts +33 -48
  19. package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -1
  20. package/dist/adapter/device-helpers/webgl-device-limits.js +42 -87
  21. package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -1
  22. package/dist/adapter/helpers/decode-webgl-types.js +47 -46
  23. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  24. package/dist/adapter/helpers/get-shader-layout.js +35 -34
  25. package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
  26. package/dist/adapter/helpers/parse-shader-compiler-log.js +3 -2
  27. package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
  28. package/dist/adapter/helpers/set-uniform.js +42 -41
  29. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
  30. package/dist/adapter/helpers/webgl-topology-utils.js +40 -39
  31. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  32. package/dist/adapter/objects/constants-to-keys.js +2 -1
  33. package/dist/adapter/objects/webgl-renderbuffer.d.ts +2 -2
  34. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
  35. package/dist/adapter/objects/webgl-renderbuffer.js +30 -17
  36. package/dist/adapter/objects/webgl-resource.d.ts +2 -24
  37. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  38. package/dist/adapter/objects/webgl-resource.js +6 -101
  39. package/dist/adapter/resources/webgl-buffer.d.ts +1 -1
  40. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  41. package/dist/adapter/resources/webgl-buffer.js +16 -15
  42. package/dist/adapter/resources/webgl-command-buffer.d.ts +1 -1
  43. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  44. package/dist/adapter/resources/webgl-command-buffer.js +32 -31
  45. package/dist/adapter/resources/webgl-command-encoder.d.ts +8 -3
  46. package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
  47. package/dist/adapter/resources/webgl-command-encoder.js +4 -2
  48. package/dist/adapter/resources/webgl-external-texture.js +6 -5
  49. package/dist/adapter/resources/webgl-framebuffer.d.ts +6 -10
  50. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  51. package/dist/adapter/resources/webgl-framebuffer.js +60 -53
  52. package/dist/adapter/resources/webgl-query-set.d.ts +44 -0
  53. package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -0
  54. package/dist/adapter/resources/webgl-query-set.js +136 -0
  55. package/dist/adapter/resources/webgl-render-pass.d.ts +3 -1
  56. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  57. package/dist/adapter/resources/webgl-render-pass.js +20 -12
  58. package/dist/adapter/resources/webgl-render-pipeline.d.ts +4 -5
  59. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  60. package/dist/adapter/resources/webgl-render-pipeline.js +52 -61
  61. package/dist/adapter/resources/webgl-sampler.d.ts +1 -1
  62. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  63. package/dist/adapter/resources/webgl-sampler.js +5 -4
  64. package/dist/adapter/resources/webgl-shader.d.ts +3 -2
  65. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  66. package/dist/adapter/resources/webgl-shader.js +15 -9
  67. package/dist/adapter/resources/webgl-texture-view.d.ts +14 -0
  68. package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -0
  69. package/dist/adapter/resources/webgl-texture-view.js +18 -0
  70. package/dist/adapter/resources/webgl-texture.d.ts +6 -4
  71. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  72. package/dist/adapter/resources/webgl-texture.js +39 -32
  73. package/dist/adapter/resources/webgl-transform-feedback.d.ts +1 -1
  74. package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
  75. package/dist/adapter/resources/webgl-transform-feedback.js +10 -10
  76. package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -3
  77. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  78. package/dist/adapter/resources/webgl-vertex-array.js +10 -9
  79. package/dist/adapter/webgl-canvas-context.d.ts +2 -2
  80. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  81. package/dist/adapter/webgl-canvas-context.js +3 -2
  82. package/dist/adapter/webgl-device.d.ts +35 -30
  83. package/dist/adapter/webgl-device.d.ts.map +1 -1
  84. package/dist/adapter/webgl-device.js +110 -109
  85. package/dist/classic/accessor.d.ts.map +1 -1
  86. package/dist/classic/accessor.js +8 -7
  87. package/dist/classic/clear.d.ts.map +1 -1
  88. package/dist/classic/clear.js +5 -4
  89. package/dist/classic/copy-and-blit.d.ts +1 -1
  90. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  91. package/dist/classic/copy-and-blit.js +19 -19
  92. package/dist/classic/format-utils.d.ts.map +1 -1
  93. package/dist/classic/format-utils.js +16 -15
  94. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  95. package/dist/classic/typed-array-utils.js +20 -19
  96. package/dist/context/debug/spector.d.ts.map +1 -1
  97. package/dist/context/debug/spector.js +2 -1
  98. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  99. package/dist/context/debug/webgl-developer-tools.js +7 -6
  100. package/dist/context/{context → helpers}/create-browser-context.d.ts.map +1 -1
  101. package/dist/context/{context → helpers}/create-browser-context.js +2 -1
  102. package/dist/context/{context/context-data.d.ts → helpers/webgl-context-data.d.ts} +2 -3
  103. package/dist/context/helpers/webgl-context-data.d.ts.map +1 -0
  104. package/dist/context/helpers/webgl-context-data.js +21 -0
  105. package/dist/context/helpers/webgl-extensions.d.ts +4 -0
  106. package/dist/context/helpers/webgl-extensions.d.ts.map +1 -0
  107. package/dist/context/helpers/webgl-extensions.js +10 -0
  108. package/dist/context/parameters/unified-parameter-api.d.ts +3 -4
  109. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  110. package/dist/context/parameters/unified-parameter-api.js +7 -11
  111. package/dist/context/parameters/webgl-parameter-tables.d.ts +12 -13
  112. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  113. package/dist/context/parameters/webgl-parameter-tables.js +302 -295
  114. package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
  115. package/dist/context/state-tracker/deep-array-equal.js +2 -1
  116. package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
  117. package/dist/context/state-tracker/track-context-state.js +5 -4
  118. package/dist/context/state-tracker/with-parameters.d.ts +2 -3
  119. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  120. package/dist/context/state-tracker/with-parameters.js +6 -8
  121. package/dist/dist.dev.js +1635 -1387
  122. package/dist/index.cjs +1766 -1534
  123. package/dist/index.cjs.map +4 -4
  124. package/dist/index.d.ts +25 -25
  125. package/dist/index.d.ts.map +1 -1
  126. package/dist/index.js +24 -23
  127. package/dist/types.d.ts.map +1 -1
  128. package/dist/types.js +2 -1
  129. package/dist.min.js +6 -6
  130. package/package.json +4 -4
  131. package/src/adapter/converters/device-parameters.ts +114 -27
  132. package/src/adapter/converters/sampler-parameters.ts +12 -3
  133. package/src/adapter/converters/shader-formats.ts +47 -22
  134. package/src/adapter/converters/texture-formats.ts +138 -114
  135. package/src/adapter/converters/vertex-formats.ts +3 -3
  136. package/src/adapter/device-helpers/webgl-device-features.ts +102 -50
  137. package/src/adapter/device-helpers/webgl-device-info.ts +28 -19
  138. package/src/adapter/device-helpers/webgl-device-limits.ts +46 -150
  139. package/src/adapter/helpers/decode-webgl-types.ts +13 -7
  140. package/src/adapter/helpers/get-shader-layout.ts +4 -3
  141. package/src/adapter/helpers/parse-shader-compiler-log.ts +10 -6
  142. package/src/adapter/helpers/set-uniform.ts +2 -1
  143. package/src/adapter/helpers/webgl-topology-utils.ts +10 -3
  144. package/src/adapter/objects/constants-to-keys.ts +2 -1
  145. package/src/adapter/objects/webgl-renderbuffer.ts +36 -14
  146. package/src/adapter/objects/webgl-resource.ts +7 -125
  147. package/src/adapter/resources/webgl-buffer.ts +4 -3
  148. package/src/adapter/resources/webgl-command-buffer.ts +5 -5
  149. package/src/adapter/resources/webgl-command-encoder.ts +14 -11
  150. package/src/adapter/resources/webgl-external-texture.ts +6 -5
  151. package/src/adapter/resources/webgl-framebuffer.ts +61 -53
  152. package/src/adapter/resources/webgl-query-set.ts +171 -0
  153. package/src/adapter/resources/webgl-render-pass.ts +20 -11
  154. package/src/adapter/resources/webgl-render-pipeline.ts +54 -54
  155. package/src/adapter/resources/webgl-sampler.ts +2 -1
  156. package/src/adapter/resources/webgl-shader.ts +12 -5
  157. package/src/adapter/resources/webgl-texture-view.ts +28 -0
  158. package/src/adapter/resources/webgl-texture.ts +14 -3
  159. package/src/adapter/resources/webgl-transform-feedback.ts +2 -7
  160. package/src/adapter/resources/webgl-vertex-array.ts +4 -3
  161. package/src/adapter/webgl-canvas-context.ts +6 -4
  162. package/src/adapter/webgl-device.ts +116 -107
  163. package/src/classic/accessor.ts +5 -4
  164. package/src/classic/clear.ts +14 -8
  165. package/src/classic/copy-and-blit.ts +11 -4
  166. package/src/classic/format-utils.ts +2 -1
  167. package/src/classic/typed-array-utils.ts +3 -7
  168. package/src/context/debug/spector.ts +9 -6
  169. package/src/context/debug/webgl-developer-tools.ts +27 -14
  170. package/src/context/{context → helpers}/create-browser-context.ts +3 -2
  171. package/src/context/helpers/webgl-context-data.ts +31 -0
  172. package/src/context/helpers/webgl-extensions.ts +17 -0
  173. package/src/context/parameters/unified-parameter-api.ts +6 -17
  174. package/src/context/parameters/webgl-parameter-tables.ts +69 -32
  175. package/src/context/state-tracker/deep-array-equal.ts +2 -1
  176. package/src/context/state-tracker/track-context-state.ts +11 -6
  177. package/src/context/state-tracker/with-parameters.ts +8 -8
  178. package/src/index.ts +7 -6
  179. package/src/types.ts +2 -1
  180. package/dist/adapter/device-helpers/device-features.d.ts +0 -6
  181. package/dist/adapter/device-helpers/device-features.d.ts.map +0 -1
  182. package/dist/adapter/device-helpers/device-features.js +0 -65
  183. package/dist/adapter/device-helpers/device-limits.d.ts +0 -50
  184. package/dist/adapter/device-helpers/device-limits.d.ts.map +0 -1
  185. package/dist/adapter/device-helpers/device-limits.js +0 -92
  186. package/dist/adapter/device-helpers/get-device-info.d.ts +0 -4
  187. package/dist/adapter/device-helpers/get-device-info.d.ts.map +0 -1
  188. package/dist/adapter/device-helpers/get-device-info.js +0 -87
  189. package/dist/context/context/context-data.d.ts.map +0 -1
  190. package/dist/context/context/context-data.js +0 -33
  191. package/src/context/context/context-data.ts +0 -44
  192. /package/dist/context/{context → helpers}/create-browser-context.d.ts +0 -0
@@ -1,9 +1,11 @@
1
- // luma.gl, MIT license
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
- // const float32_renderable_webgl: DeviceFeature = 'float32-renderable-webgl';
22
- // const float16_renderable_webgl: DeviceFeature = 'float16-renderable-webgl';
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 EXT_TEXTURE_NORM16 = 'EXT_texture_norm16';
37
- const EXT_FLOAT_RENDER_WEBGL2 = 'EXT_color_buffer_float';
38
- // const EXT_HALF_FLOAT_WEBGL1 = 'EXT_color_buffer_half_float';
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 TEXTURE_FEATURE_CHECKS: Partial<Record<DeviceFeature, string[]>> = {
46
- 'float32-renderable-webgl': ['EXT_color_buffer_float'], // [false, '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
- 'norm16-renderable-webgl': [EXT_TEXTURE_NORM16],
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-linear-webgl': ['OES_texture_float_linear'],
51
- 'float16-filterable-linear-webgl': ['OES_texture_half_float_linear'],
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
- function checkTextureFeature(gl: WebGL2RenderingContext, feature: DeviceFeature): boolean {
69
- const extensions = TEXTURE_FEATURE_CHECKS[feature] || [];
70
- return extensions.every(extension => gl.getExtension(extension));
71
- }
72
-
73
- function checkTextureFeatures(gl: WebGL2RenderingContext, features: DeviceFeature[]): boolean {
74
- return features.every(feature => checkTextureFeature(gl, feature));
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
- /** Return a list of texture feature strings (for Device.features). Mainly compressed texture support */
78
- export function getTextureFeatures(gl: WebGL2RenderingContext): DeviceFeature[] {
79
- const textureFeatures = Object.keys(TEXTURE_FEATURE_CHECKS) as DeviceFeature[];
80
- return textureFeatures.filter(feature => checkTextureFeature(gl, feature));
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
- renderbuffer?: boolean;
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, renderbuffer: true},
141
- 'r8snorm': {gl: GL.R8_SNORM, b: 1, c: 1},
142
- 'r8uint': {gl: GL.R8UI, b: 1, c: 1, renderbuffer: true},
143
- 'r8sint': {gl: GL.R8I, b: 1, c: 1, renderbuffer: true},
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, renderbuffer: true},
147
- 'rg8snorm': {gl: GL.RG8_SNORM, b: 2, c: 2},
148
- 'rg8uint': {gl: GL.RG8UI, b: 2, c: 2, renderbuffer: true},
149
- 'rg8sint': {gl: GL.RG8I, b: 2, c: 2, renderbuffer: true},
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, renderbuffer: true},
152
- 'r16sint': {gl: GL.R16I, b: 2, c: 1, renderbuffer: true},
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},
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, renderbuffer: true},
159
- 'rgb565unorm-webgl': {gl: GL.RGB565, b: 2, c: 4, wgpu: false, renderbuffer: true},
160
- 'rgb5a1unorm-webgl': {gl: GL.RGB5_A1, b: 2, c: 4, wgpu: false, renderbuffer: true},
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: '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},
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, renderbuffer: true},
184
- 'r32sint': {gl: GL.R32I, b: 4, c: 1, bpp: 4, renderbuffer: true},
185
- 'r32float': {gl: GL.R32F, bpp: 4, b: 4, c: 1, render: 'float32-renderable-webgl', filter: 'float32-filterable-linear-webgl'},
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: '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},
190
- 'rgb10a2unorm': {gl: GL.RGB10_A2, b: 4, c: 4, p: 1, renderbuffer: true},
191
- 'rgb10a2unorm-webgl': {b: 4, c: 4, gl: GL.RGB10_A2UI, p: 1, wgpu: false, bpp: 4, renderbuffer: true},
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: '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},
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, renderbuffer: true},
199
- 'rg32sint': {gl: GL.RG32I, b: 8, c: 2, renderbuffer: true},
200
- 'rg32float': {gl: GL.RG32F, b: 8, c: 2, render: 'float32-renderable-webgl', filter: 'float32-filterable-linear-webgl', renderbuffer: true},
201
- 'rgba16uint': {gl: GL.RGBA16UI, b: 8, c: 4, renderbuffer: true},
202
- 'rgba16sint': {gl: GL.RGBA16I, b: 8, c: 4, renderbuffer: true},
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},
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: 'float32-renderable-webgl', filter: 'float32-filterable-linear-webgl',
209
- gl2ext: EXT_FLOAT_RENDER_WEBGL2, dataFormat: GL.RGB, types: [GL.FLOAT]},
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, renderbuffer: true},
213
- 'rgba32sint': {gl: GL.RGBA32I, b: 16, c: 4, renderbuffer: true},
214
- 'rgba32float': {gl: GL.RGBA32F, b: 16, c: 4, render: 'float32-renderable-webgl', filter: 'float32-filterable-linear-webgl', renderbuffer: true},
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, renderbuffer: true}, // 8 stencil bits
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, renderbuffer: true}, // 16 depth bits
220
- 'depth24plus': {gl: GL.DEPTH_COMPONENT24, b: 3, c: 1, attachment: GL.DEPTH_ATTACHMENT},
221
- 'depth32float': {gl: GL.DEPTH_COMPONENT32F, b: 4, c: 1, attachment: GL.DEPTH_ATTACHMENT, renderbuffer: true},
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.DEPTH_STENCIL, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, renderbuffer: true, depthTexture: true},
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, renderbuffer: true},
227
- // "depth32float-stencil8" feature
228
- 'depth32float-stencil8': {gl: GL.DEPTH32F_STENCIL8, b: 5, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, renderbuffer: true},
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, gl1: EXT_FLOAT_WEBGL1},
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
- formatOrGL: TextureFormat | GL
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.getExtension(extension));
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]?.renderbuffer;
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
- formatOrGL: TextureFormat | GL
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 && checkTextureFeatures(gl, [info.f]);
540
+ supported = supported && checkTextureFeature(gl, info.f, extensions);
519
541
 
520
542
  // Filtering
521
543
  // const filterable = info.filter
522
- // ? checkTextureFeatures(gl, [info.filter])
544
+ // ? checkTextureFeature(gl, infofilter])
523
545
  // : decoded && !decoded.signed;
524
546
  // const renderable = info.filter
525
- // ? checkTextureFeatures(gl, [info.render])
547
+ // ? checkTextureFeature(gl, inforender])
526
548
  // : decoded && !decoded.signed;
527
549
 
528
550
  return {
529
551
  supported,
530
- renderable: supported && checkTextureFeatures(gl, [info.render]),
531
- filterable: supported && checkTextureFeatures(gl, [info.filter]),
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
- formatOrGL: TextureFormat | GL
562
+ format: TextureFormat,
563
+ extensions: GLExtensions
541
564
  ): boolean {
542
- const format = convertGLToTextureFormat(formatOrGL);
543
- if (!isTextureFormatSupported(gl, format)) {
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.getExtension('OES_texture_float_linear'));
580
+ return Boolean(getWebGLExtension(gl, 'OES_texture_float_linear, extensions', extensions));
556
581
  }
557
582
  if (format.endsWith('16float')) {
558
- return Boolean(gl.getExtension('OES_texture_half_float_linear'));
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
- formatOrGL: TextureFormat | GL
590
+ format: TextureFormat,
591
+ extensions: GLExtensions
566
592
  ): boolean {
567
- const format = convertGLToTextureFormat(formatOrGL);
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
- export function getWebGLTextureParameters(formatOrGL: TextureFormat | GL) {
579
- const format = convertGLToTextureFormat(formatOrGL);
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: getWebGLPixelDataFormat(
585
- decoded.format,
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 ? getGLFromVertexType(decoded.dataType) : GL.UNSIGNED_BYTE,
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(formatOrGL: TextureFormat | GL): number {
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, MIT license
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, MIT license
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 {getTextureFeatures} from '../converters/texture-formats';
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
- /** Get WebGPU style feature strings */
11
- export function getDeviceFeatures(gl: WebGL2RenderingContext): Set<DeviceFeature> {
12
- const features = getWebGLFeatures(gl);
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
- // texture features
15
- // features.add('texture-compression-bc');
16
- for (const textureFeature of getTextureFeatures(gl)) {
17
- features.add(textureFeature);
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
- // 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"
36
+ // Textures are handled by getTextureFeatures()
37
+ };
26
38
 
27
- return features;
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
- /** 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');
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
- 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);
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
- function isFeatureSupported(gl: WebGL2RenderingContext, feature: DeviceFeature): boolean {
45
- const featureInfo = WEBGL_FEATURES[feature];
77
+ override has(feature: DeviceFeature): boolean {
78
+ if (this.disabledFeatures[feature]) {
79
+ return false;
80
+ }
46
81
 
47
- // string value requires checking the corresponding WebGL extension
48
- return typeof featureInfo === 'string'
49
- ? Boolean(gl.getExtension(featureInfo))
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
- * 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,
86
+ // Check the feature once
87
+ if (isTextureFeature(feature) && checkTextureFeature(this.gl, feature, this.extensions)) {
88
+ this.features.add(feature);
89
+ }
60
90
 
61
- 'uniforms-webgl': true,
62
- 'transform-feedback-webgl': true,
63
- 'constant-attributes-webgl': true,
91
+ if (this.getWebGLFeature(feature)) {
92
+ this.features.add(feature);
93
+ }
94
+ }
95
+ return this.features.has(feature);
96
+ }
64
97
 
65
- 'timer-query-webgl': 'EXT_disjoint_timer_query_webgl2',
66
- 'shader-status-async-webgl': 'KHR_parallel_shader_compile'
98
+ // FOR DEVICE
67
99
 
68
- // Textures are handled by getTextureFeatures()
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
+ }