@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.
Files changed (237) hide show
  1. package/dist/adapter/converters/device-parameters.js +240 -158
  2. package/dist/adapter/converters/sampler-parameters.d.ts +0 -4
  3. package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
  4. package/dist/adapter/converters/sampler-parameters.js +73 -68
  5. package/dist/adapter/converters/shader-formats.js +33 -46
  6. package/dist/adapter/converters/texture-formats.d.ts +9 -18
  7. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  8. package/dist/adapter/converters/texture-formats.js +454 -871
  9. package/dist/adapter/converters/vertex-formats.js +52 -61
  10. package/dist/adapter/device-helpers/device-features.d.ts +2 -5
  11. package/dist/adapter/device-helpers/device-features.d.ts.map +1 -1
  12. package/dist/adapter/device-helpers/device-features.js +56 -87
  13. package/dist/adapter/device-helpers/device-limits.d.ts +2 -4
  14. package/dist/adapter/device-helpers/device-limits.d.ts.map +1 -1
  15. package/dist/adapter/device-helpers/device-limits.js +88 -83
  16. package/dist/adapter/device-helpers/get-device-info.d.ts +1 -1
  17. package/dist/adapter/device-helpers/get-device-info.d.ts.map +1 -1
  18. package/dist/adapter/device-helpers/get-device-info.js +79 -63
  19. package/dist/adapter/device-helpers/webgl-device-features.d.ts +6 -0
  20. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -0
  21. package/dist/adapter/device-helpers/webgl-device-features.js +52 -0
  22. package/dist/adapter/device-helpers/webgl-device-info.d.ts +4 -0
  23. package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -0
  24. package/dist/adapter/device-helpers/webgl-device-info.js +87 -0
  25. package/dist/adapter/device-helpers/webgl-device-limits.d.ts +50 -0
  26. package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -0
  27. package/dist/adapter/device-helpers/webgl-device-limits.js +92 -0
  28. package/dist/adapter/helpers/decode-webgl-types.js +87 -76
  29. package/dist/adapter/helpers/get-shader-layout.d.ts +1 -1
  30. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  31. package/dist/adapter/helpers/get-shader-layout.js +261 -226
  32. package/dist/adapter/helpers/parse-shader-compiler-log.js +46 -37
  33. package/dist/adapter/helpers/set-uniform.d.ts +1 -1
  34. package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
  35. package/dist/adapter/helpers/set-uniform.js +67 -82
  36. package/dist/adapter/helpers/webgl-topology-utils.js +77 -93
  37. package/dist/adapter/objects/constants-to-keys.d.ts +1 -1
  38. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  39. package/dist/adapter/objects/constants-to-keys.js +18 -12
  40. package/dist/adapter/objects/webgl-renderbuffer.js +76 -80
  41. package/dist/adapter/objects/webgl-resource.d.ts +1 -1
  42. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  43. package/dist/adapter/objects/webgl-resource.js +204 -154
  44. package/dist/adapter/resources/webgl-buffer.d.ts +2 -3
  45. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  46. package/dist/adapter/resources/webgl-buffer.js +160 -119
  47. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  48. package/dist/adapter/resources/webgl-command-buffer.js +268 -171
  49. package/dist/adapter/resources/webgl-command-encoder.js +32 -40
  50. package/dist/adapter/resources/webgl-external-texture.js +92 -1
  51. package/dist/adapter/resources/webgl-framebuffer.d.ts +2 -2
  52. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  53. package/dist/adapter/resources/webgl-framebuffer.js +167 -139
  54. package/dist/adapter/resources/webgl-render-pass.js +121 -95
  55. package/dist/adapter/resources/webgl-render-pipeline.d.ts +11 -1
  56. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  57. package/dist/adapter/resources/webgl-render-pipeline.js +378 -228
  58. package/dist/adapter/resources/webgl-sampler.d.ts +0 -2
  59. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  60. package/dist/adapter/resources/webgl-sampler.js +43 -34
  61. package/dist/adapter/resources/webgl-shader.d.ts +10 -1
  62. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  63. package/dist/adapter/resources/webgl-shader.js +106 -45
  64. package/dist/adapter/resources/webgl-texture.d.ts +2 -6
  65. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  66. package/dist/adapter/resources/webgl-texture.js +614 -699
  67. package/dist/adapter/resources/webgl-transform-feedback.d.ts +1 -1
  68. package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
  69. package/dist/adapter/resources/webgl-transform-feedback.js +143 -145
  70. package/dist/adapter/resources/webgl-vertex-array.d.ts +1 -1
  71. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  72. package/dist/adapter/resources/webgl-vertex-array.js +229 -158
  73. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  74. package/dist/adapter/webgl-canvas-context.js +58 -37
  75. package/dist/adapter/webgl-device.d.ts +7 -15
  76. package/dist/adapter/webgl-device.d.ts.map +1 -1
  77. package/dist/adapter/webgl-device.js +440 -381
  78. package/dist/classic/accessor.js +132 -102
  79. package/dist/classic/clear.d.ts +2 -2
  80. package/dist/classic/clear.d.ts.map +1 -1
  81. package/dist/classic/clear.js +73 -73
  82. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  83. package/dist/classic/copy-and-blit.js +176 -177
  84. package/dist/classic/format-utils.d.ts +2 -2
  85. package/dist/classic/format-utils.js +38 -32
  86. package/dist/classic/typed-array-utils.js +95 -81
  87. package/dist/context/{polyfill → context}/context-data.d.ts +2 -1
  88. package/dist/context/context/context-data.d.ts.map +1 -0
  89. package/dist/context/context/context-data.js +33 -0
  90. package/dist/context/context/create-browser-context.d.ts +1 -6
  91. package/dist/context/context/create-browser-context.d.ts.map +1 -1
  92. package/dist/context/context/create-browser-context.js +62 -49
  93. package/dist/context/debug/spector.js +54 -50
  94. package/dist/context/debug/webgl-developer-tools.d.ts +1 -2
  95. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  96. package/dist/context/debug/webgl-developer-tools.js +102 -76
  97. package/dist/context/parameters/unified-parameter-api.d.ts +3 -3
  98. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  99. package/dist/context/parameters/unified-parameter-api.js +95 -46
  100. package/dist/context/parameters/webgl-parameter-tables.d.ts +110 -99
  101. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  102. package/dist/context/parameters/webgl-parameter-tables.js +456 -404
  103. package/dist/context/state-tracker/deep-array-equal.js +18 -14
  104. package/dist/context/state-tracker/track-context-state.d.ts +4 -4
  105. package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
  106. package/dist/context/state-tracker/track-context-state.js +190 -126
  107. package/dist/context/state-tracker/with-parameters.d.ts +1 -1
  108. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  109. package/dist/context/state-tracker/with-parameters.js +45 -29
  110. package/dist/dist.dev.js +2568 -3786
  111. package/dist/index.cjs +1346 -2464
  112. package/dist/index.cjs.map +7 -0
  113. package/dist/index.d.ts +2 -5
  114. package/dist/index.d.ts.map +1 -1
  115. package/dist/index.js +36 -26
  116. package/dist/types.js +2 -1
  117. package/dist.min.js +9 -42
  118. package/package.json +11 -15
  119. package/src/adapter/converters/device-parameters.ts +0 -1
  120. package/src/adapter/converters/sampler-parameters.ts +0 -17
  121. package/src/adapter/converters/texture-formats.ts +86 -154
  122. package/src/adapter/device-helpers/webgl-device-features.ts +69 -0
  123. package/src/adapter/device-helpers/{get-device-info.ts → webgl-device-info.ts} +3 -4
  124. package/src/adapter/device-helpers/{device-limits.ts → webgl-device-limits.ts} +25 -23
  125. package/src/adapter/helpers/get-shader-layout.ts +17 -28
  126. package/src/adapter/helpers/set-uniform.ts +1 -3
  127. package/src/adapter/objects/constants-to-keys.ts +1 -1
  128. package/src/adapter/objects/webgl-renderbuffer.ts +4 -4
  129. package/src/adapter/objects/webgl-resource.ts +3 -18
  130. package/src/adapter/resources/webgl-buffer.ts +6 -11
  131. package/src/adapter/resources/webgl-command-buffer.ts +20 -30
  132. package/src/adapter/resources/webgl-external-texture.ts +2 -3
  133. package/src/adapter/resources/webgl-framebuffer.ts +4 -5
  134. package/src/adapter/resources/webgl-render-pass.ts +7 -7
  135. package/src/adapter/resources/webgl-render-pipeline.ts +106 -31
  136. package/src/adapter/resources/webgl-sampler.ts +5 -9
  137. package/src/adapter/resources/webgl-shader.ts +57 -10
  138. package/src/adapter/resources/webgl-texture.ts +29 -103
  139. package/src/adapter/resources/webgl-transform-feedback.ts +14 -15
  140. package/src/adapter/resources/webgl-vertex-array.ts +16 -18
  141. package/src/adapter/webgl-canvas-context.ts +1 -7
  142. package/src/adapter/webgl-device.ts +18 -67
  143. package/src/classic/clear.ts +13 -14
  144. package/src/classic/copy-and-blit.ts +1 -2
  145. package/src/context/context/context-data.ts +44 -0
  146. package/src/context/context/create-browser-context.ts +7 -32
  147. package/src/context/debug/webgl-developer-tools.ts +6 -8
  148. package/src/context/parameters/unified-parameter-api.ts +3 -3
  149. package/src/context/parameters/webgl-parameter-tables.ts +66 -75
  150. package/src/context/state-tracker/track-context-state.ts +18 -17
  151. package/src/context/state-tracker/with-parameters.ts +1 -1
  152. package/src/index.ts +2 -17
  153. package/dist/adapter/converters/device-parameters.js.map +0 -1
  154. package/dist/adapter/converters/sampler-parameters.js.map +0 -1
  155. package/dist/adapter/converters/shader-formats.js.map +0 -1
  156. package/dist/adapter/converters/texture-formats.js.map +0 -1
  157. package/dist/adapter/converters/vertex-formats.js.map +0 -1
  158. package/dist/adapter/device-helpers/device-features.js.map +0 -1
  159. package/dist/adapter/device-helpers/device-limits.js.map +0 -1
  160. package/dist/adapter/device-helpers/get-device-info.js.map +0 -1
  161. package/dist/adapter/device-helpers/is-old-ie.d.ts +0 -2
  162. package/dist/adapter/device-helpers/is-old-ie.d.ts.map +0 -1
  163. package/dist/adapter/device-helpers/is-old-ie.js +0 -9
  164. package/dist/adapter/device-helpers/is-old-ie.js.map +0 -1
  165. package/dist/adapter/helpers/decode-webgl-types.js.map +0 -1
  166. package/dist/adapter/helpers/get-shader-layout.js.map +0 -1
  167. package/dist/adapter/helpers/parse-shader-compiler-log.js.map +0 -1
  168. package/dist/adapter/helpers/set-uniform.js.map +0 -1
  169. package/dist/adapter/helpers/webgl-topology-utils.js.map +0 -1
  170. package/dist/adapter/objects/constants-to-keys.js.map +0 -1
  171. package/dist/adapter/objects/webgl-renderbuffer.js.map +0 -1
  172. package/dist/adapter/objects/webgl-resource.js.map +0 -1
  173. package/dist/adapter/resources/webgl-buffer.js.map +0 -1
  174. package/dist/adapter/resources/webgl-command-buffer.js.map +0 -1
  175. package/dist/adapter/resources/webgl-command-encoder.js.map +0 -1
  176. package/dist/adapter/resources/webgl-external-texture.js.map +0 -1
  177. package/dist/adapter/resources/webgl-framebuffer.js.map +0 -1
  178. package/dist/adapter/resources/webgl-render-pass.js.map +0 -1
  179. package/dist/adapter/resources/webgl-render-pipeline.js.map +0 -1
  180. package/dist/adapter/resources/webgl-sampler.js.map +0 -1
  181. package/dist/adapter/resources/webgl-shader.js.map +0 -1
  182. package/dist/adapter/resources/webgl-texture.js.map +0 -1
  183. package/dist/adapter/resources/webgl-transform-feedback.js.map +0 -1
  184. package/dist/adapter/resources/webgl-vertex-array.js.map +0 -1
  185. package/dist/adapter/webgl-canvas-context.js.map +0 -1
  186. package/dist/adapter/webgl-device.js.map +0 -1
  187. package/dist/classic/accessor.js.map +0 -1
  188. package/dist/classic/clear.js.map +0 -1
  189. package/dist/classic/copy-and-blit.js.map +0 -1
  190. package/dist/classic/format-utils.js.map +0 -1
  191. package/dist/classic/typed-array-utils.js.map +0 -1
  192. package/dist/context/context/create-browser-context.js.map +0 -1
  193. package/dist/context/context/create-headless-context.d.ts +0 -9
  194. package/dist/context/context/create-headless-context.d.ts.map +0 -1
  195. package/dist/context/context/create-headless-context.js +0 -42
  196. package/dist/context/context/create-headless-context.js.map +0 -1
  197. package/dist/context/context/webgl-checks.d.ts +0 -13
  198. package/dist/context/context/webgl-checks.d.ts.map +0 -1
  199. package/dist/context/context/webgl-checks.js +0 -31
  200. package/dist/context/context/webgl-checks.js.map +0 -1
  201. package/dist/context/debug/spector.js.map +0 -1
  202. package/dist/context/debug/webgl-developer-tools.js.map +0 -1
  203. package/dist/context/parameters/unified-parameter-api.js.map +0 -1
  204. package/dist/context/parameters/webgl-parameter-tables.js.map +0 -1
  205. package/dist/context/polyfill/context-data.d.ts.map +0 -1
  206. package/dist/context/polyfill/context-data.js +0 -12
  207. package/dist/context/polyfill/context-data.js.map +0 -1
  208. package/dist/context/polyfill/get-parameter-polyfill.d.ts +0 -2
  209. package/dist/context/polyfill/get-parameter-polyfill.d.ts.map +0 -1
  210. package/dist/context/polyfill/get-parameter-polyfill.js +0 -85
  211. package/dist/context/polyfill/get-parameter-polyfill.js.map +0 -1
  212. package/dist/context/polyfill/polyfill-context.d.ts +0 -5
  213. package/dist/context/polyfill/polyfill-context.d.ts.map +0 -1
  214. package/dist/context/polyfill/polyfill-context.js +0 -87
  215. package/dist/context/polyfill/polyfill-context.js.map +0 -1
  216. package/dist/context/polyfill/polyfill-table.d.ts +0 -48
  217. package/dist/context/polyfill/polyfill-table.d.ts.map +0 -1
  218. package/dist/context/polyfill/polyfill-table.js +0 -137
  219. package/dist/context/polyfill/polyfill-table.js.map +0 -1
  220. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts +0 -2
  221. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts.map +0 -1
  222. package/dist/context/polyfill/polyfill-vertex-array-object.js +0 -265
  223. package/dist/context/polyfill/polyfill-vertex-array-object.js.map +0 -1
  224. package/dist/context/state-tracker/deep-array-equal.js.map +0 -1
  225. package/dist/context/state-tracker/track-context-state.js.map +0 -1
  226. package/dist/context/state-tracker/with-parameters.js.map +0 -1
  227. package/dist/index.js.map +0 -1
  228. package/dist/types.js.map +0 -1
  229. package/src/adapter/device-helpers/device-features.ts +0 -161
  230. package/src/adapter/device-helpers/is-old-ie.ts +0 -14
  231. package/src/context/context/create-headless-context.ts +0 -51
  232. package/src/context/context/webgl-checks.ts +0 -51
  233. package/src/context/polyfill/context-data.ts +0 -30
  234. package/src/context/polyfill/get-parameter-polyfill.ts +0 -122
  235. package/src/context/polyfill/polyfill-context.ts +0 -104
  236. package/src/context/polyfill/polyfill-table.ts +0 -167
  237. package/src/context/polyfill/polyfill-vertex-array-object.ts +0 -365
@@ -1,917 +1,500 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
1
3
  import { decodeTextureFormat } from '@luma.gl/core';
2
- import { isWebGL2 } from "../../context/context/webgl-checks.js";
3
- import { getGLFromVertexType } from "./vertex-formats.js";
4
+ import { GL } from '@luma.gl/constants';
5
+ import { getGLFromVertexType } from './vertex-formats';
6
+ /* eslint-disable camelcase */
7
+ // TEXTURE FEATURES
8
+ // Define local device feature strings to optimize minification
4
9
  const texture_compression_bc = 'texture-compression-bc';
5
10
  const texture_compression_astc = 'texture-compression-astc';
6
11
  const texture_compression_etc2 = 'texture-compression-etc2';
7
12
  const texture_compression_etc1_webgl = 'texture-compression-etc1-webgl';
8
13
  const texture_compression_pvrtc_webgl = 'texture-compression-pvrtc-webgl';
9
14
  const texture_compression_atc_webgl = 'texture-compression-atc-webgl';
10
- const X_S3TC = 'WEBGL_compressed_texture_s3tc';
11
- const X_S3TC_SRGB = 'WEBGL_compressed_texture_s3tc_srgb';
12
- const X_RGTC = 'EXT_texture_compression_rgtc';
13
- const X_BPTC = 'EXT_texture_compression_bptc';
14
- const X_ETC2 = 'WEBGL_compressed_texture_etc';
15
+ // const float32_renderable_webgl: DeviceFeature = 'float32-renderable-webgl';
16
+ // const float16_renderable_webgl: DeviceFeature = 'float16-renderable-webgl';
17
+ // Define local webgl extension strings to optimize minification
18
+ const X_S3TC = 'WEBGL_compressed_texture_s3tc'; // BC1, BC2, BC3
19
+ const X_S3TC_SRGB = 'WEBGL_compressed_texture_s3tc_srgb'; // BC1, BC2, BC3
20
+ const X_RGTC = 'EXT_texture_compression_rgtc'; // BC4, BC5
21
+ const X_BPTC = 'EXT_texture_compression_bptc'; // BC6, BC7
22
+ const X_ETC2 = 'WEBGL_compressed_texture_etc'; // Renamed from 'WEBGL_compressed_texture_es3'
15
23
  const X_ASTC = 'WEBGL_compressed_texture_astc';
16
24
  const X_ETC1 = 'WEBGL_compressed_texture_etc1';
17
25
  const X_PVRTC = 'WEBGL_compressed_texture_pvrtc';
18
26
  const X_ATC = 'WEBGL_compressed_texture_atc';
19
- const EXT_SRGB = 'EXT_sRGB';
27
+ // Define local webgl extension strings to optimize minification
20
28
  const EXT_TEXTURE_NORM16 = 'EXT_texture_norm16';
21
- const EXT_FLOAT_WEBGL1 = 'WEBGL_color_buffer_float';
22
29
  const EXT_FLOAT_RENDER_WEBGL2 = 'EXT_color_buffer_float';
23
- const checkExtension = (gl, extension) => gl.getExtension(extension);
24
- const checkExtensions = (gl, extensions) => extensions.every(extension => gl.getExtension(extension));
30
+ // const EXT_HALF_FLOAT_WEBGL1 = 'EXT_color_buffer_half_float';
31
+ // const DEPTH = 'WEBGL_depth_texture';
32
+ // WebGL1-only extensions
33
+ // const EXT_SRGB = 'EXT_sRGB'; // https://developer.mozilla.org/en-US/docs/Web/API/EXT_sRGB
34
+ // prettier-ignore
25
35
  const TEXTURE_FEATURE_CHECKS = {
26
- 'texture-blend-float-webgl1': gl => isWebGL2(gl) ? true : checkExtension(gl, 'EXT_float_blend'),
27
- 'texture-formats-srgb-webgl1': gl => isWebGL2(gl) ? true : checkExtension(gl, EXT_SRGB),
28
- 'texture-formats-depth-webgl1': gl => isWebGL2(gl) ? true : checkExtension(gl, 'WEBGL_depth_texture'),
29
- 'texture-formats-float32-webgl1': gl => isWebGL2(gl) ? true : checkExtension(gl, 'OES_texture_float'),
30
- 'texture-formats-float16-webgl1': gl => isWebGL2(gl) ? true : checkExtension(gl, 'OES_texture_half_float'),
31
- 'texture-formats-norm16-webgl': gl => isWebGL2(gl) ? checkExtension(gl, EXT_TEXTURE_NORM16) : false,
32
- 'texture-filter-linear-float32-webgl': gl => checkExtension(gl, 'OES_texture_float_linear'),
33
- 'texture-filter-linear-float16-webgl': gl => checkExtension(gl, 'OES_texture_half_float_linear'),
34
- 'texture-filter-anisotropic-webgl': gl => checkExtension(gl, 'EXT_texture_filter_anisotropic'),
35
- 'texture-renderable-float32-webgl': gl => checkExtension(gl, 'EXT_color_buffer_float'),
36
- 'texture-renderable-float16-webgl': gl => checkExtension(gl, 'EXT_color_buffer_half_float'),
37
- 'texture-compression-bc': gl => checkExtensions(gl, [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC]),
38
- 'texture-compression-bc5-webgl': gl => checkExtensions(gl, [X_RGTC]),
39
- 'texture-compression-etc2': gl => checkExtensions(gl, [X_ETC2]),
40
- 'texture-compression-astc': gl => checkExtensions(gl, [X_ASTC]),
41
- 'texture-compression-etc1-webgl': gl => checkExtensions(gl, [X_ETC1]),
42
- 'texture-compression-pvrtc-webgl': gl => checkExtensions(gl, [X_PVRTC]),
43
- 'texture-compression-atc-webgl': gl => checkExtensions(gl, [X_ATC])
36
+ 'float32-renderable-webgl': ['EXT_color_buffer_float'], // [false, 'EXT_color_buffer_float'],
37
+ 'float16-renderable-webgl': ['EXT_color_buffer_half_float'],
38
+ 'norm16-renderable-webgl': [EXT_TEXTURE_NORM16],
39
+ 'float32-filterable-linear-webgl': ['OES_texture_float_linear'],
40
+ 'float16-filterable-linear-webgl': ['OES_texture_half_float_linear'],
41
+ 'texture-filterable-anisotropic-webgl': ['EXT_texture_filter_anisotropic'],
42
+ 'texture-blend-float-webgl': ['EXT_float_blend'],
43
+ 'texture-compression-bc': [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC],
44
+ // 'texture-compression-bc3-srgb-webgl': [X_S3TC_SRGB],
45
+ // 'texture-compression-bc3-webgl': [X_S3TC],
46
+ 'texture-compression-bc5-webgl': [X_RGTC],
47
+ 'texture-compression-bc7-webgl': [X_BPTC],
48
+ 'texture-compression-etc2': [X_ETC2],
49
+ 'texture-compression-astc': [X_ASTC],
50
+ 'texture-compression-etc1-webgl': [X_ETC1],
51
+ 'texture-compression-pvrtc-webgl': [X_PVRTC],
52
+ 'texture-compression-atc-webgl': [X_ATC]
44
53
  };
45
- export function checkTextureFeature(gl, feature) {
46
- var _TEXTURE_FEATURE_CHEC;
47
- return ((_TEXTURE_FEATURE_CHEC = TEXTURE_FEATURE_CHECKS[feature]) === null || _TEXTURE_FEATURE_CHEC === void 0 ? void 0 : _TEXTURE_FEATURE_CHEC.call(TEXTURE_FEATURE_CHECKS, gl)) || false;
54
+ function checkTextureFeature(gl, feature) {
55
+ const extensions = TEXTURE_FEATURE_CHECKS[feature] || [];
56
+ return extensions.every(extension => gl.getExtension(extension));
48
57
  }
49
- const checkTextureFeatures = (gl, features) => features.every(feature => checkTextureFeature(gl, feature));
58
+ function checkTextureFeatures(gl, features) {
59
+ return features.every(feature => checkTextureFeature(gl, feature));
60
+ }
61
+ /** Return a list of texture feature strings (for Device.features). Mainly compressed texture support */
50
62
  export function getTextureFeatures(gl) {
51
- const textureFeatures = Object.keys(TEXTURE_FEATURE_CHECKS);
52
- return textureFeatures.filter(feature => checkTextureFeature(gl, feature));
63
+ const textureFeatures = Object.keys(TEXTURE_FEATURE_CHECKS);
64
+ return textureFeatures.filter(feature => checkTextureFeature(gl, feature));
53
65
  }
66
+ // TABLES
67
+ /**
68
+ * Texture format data -
69
+ * Exported but can change without notice
70
+ */
71
+ // prettier-ignore
54
72
  export const TEXTURE_FORMATS = {
55
- 'rgb8unorm-unsized': {
56
- gl: 6407,
57
- gl1: 6407,
58
- b: 4,
59
- c: 2,
60
- bpp: 4,
61
- dataFormat: 6407,
62
- types: [5121, 33635]
63
- },
64
- 'rgba8unorm-unsized': {
65
- gl: 6408,
66
- gl1: 6408,
67
- b: 4,
68
- c: 2,
69
- bpp: 4,
70
- dataFormat: 6408,
71
- types: [5121, 32819, 32820]
72
- },
73
- 'r8unorm': {
74
- gl: 33321,
75
- b: 1,
76
- c: 1,
77
- renderbuffer: true
78
- },
79
- 'r8snorm': {
80
- gl: 36756,
81
- b: 1,
82
- c: 1
83
- },
84
- 'r8uint': {
85
- gl: 33330,
86
- b: 1,
87
- c: 1,
88
- renderbuffer: true
89
- },
90
- 'r8sint': {
91
- gl: 33329,
92
- b: 1,
93
- c: 1,
94
- renderbuffer: true
95
- },
96
- 'rg8unorm': {
97
- gl: 33323,
98
- b: 2,
99
- c: 2,
100
- renderbuffer: true
101
- },
102
- 'rg8snorm': {
103
- gl: 36757,
104
- b: 2,
105
- c: 2
106
- },
107
- 'rg8uint': {
108
- gl: 33336,
109
- b: 2,
110
- c: 2,
111
- renderbuffer: true
112
- },
113
- 'rg8sint': {
114
- gl: 33335,
115
- b: 2,
116
- c: 2,
117
- renderbuffer: true
118
- },
119
- 'r16uint': {
120
- gl: 33332,
121
- b: 2,
122
- c: 1,
123
- renderbuffer: true
124
- },
125
- 'r16sint': {
126
- gl: 33331,
127
- b: 2,
128
- c: 1,
129
- renderbuffer: true
130
- },
131
- 'r16float': {
132
- gl: 33325,
133
- b: 2,
134
- c: 1,
135
- render: 'texture-renderable-float16-webgl',
136
- filter: 'texture-filter-linear-float16-webgl',
137
- renderbuffer: true
138
- },
139
- 'r16unorm-webgl': {
140
- gl: 33322,
141
- b: 2,
142
- c: 1,
143
- f: 'texture-formats-norm16-webgl',
144
- renderbuffer: true,
145
- x: EXT_TEXTURE_NORM16
146
- },
147
- 'r16snorm-webgl': {
148
- gl: 36760,
149
- b: 2,
150
- c: 1,
151
- f: 'texture-formats-norm16-webgl',
152
- x: EXT_TEXTURE_NORM16
153
- },
154
- 'rgba4unorm-webgl': {
155
- gl: 32854,
156
- b: 2,
157
- c: 4,
158
- wgpu: false,
159
- renderbuffer: true
160
- },
161
- 'rgb565unorm-webgl': {
162
- gl: 36194,
163
- b: 2,
164
- c: 4,
165
- wgpu: false,
166
- renderbuffer: true
167
- },
168
- 'rgb5a1unorm-webgl': {
169
- gl: 32855,
170
- b: 2,
171
- c: 4,
172
- wgpu: false,
173
- renderbuffer: true
174
- },
175
- 'rgb8unorm-webgl': {
176
- gl: 32849,
177
- b: 3,
178
- c: 3,
179
- wgpu: false
180
- },
181
- 'rgb8snorm-webgl': {
182
- gl: 36758,
183
- b: 3,
184
- c: 3,
185
- wgpu: false
186
- },
187
- 'rgba8unorm': {
188
- gl: 32856,
189
- gl1: 6408,
190
- b: 4,
191
- c: 2,
192
- bpp: 4
193
- },
194
- 'rgba8unorm-srgb': {
195
- gl: 35907,
196
- gl1: 35906,
197
- b: 4,
198
- c: 4,
199
- gl1ext: EXT_SRGB,
200
- bpp: 4
201
- },
202
- 'rgba8snorm': {
203
- gl: 36759,
204
- b: 4,
205
- c: 4
206
- },
207
- 'rgba8uint': {
208
- gl: 36220,
209
- b: 4,
210
- c: 4,
211
- bpp: 4
212
- },
213
- 'rgba8sint': {
214
- gl: 36238,
215
- b: 4,
216
- c: 4,
217
- bpp: 4
218
- },
219
- 'bgra8unorm': {
220
- b: 4,
221
- c: 4
222
- },
223
- 'bgra8unorm-srgb': {
224
- b: 4,
225
- c: 4
226
- },
227
- 'rg16uint': {
228
- gl: 33338,
229
- b: 4,
230
- c: 1,
231
- bpp: 4
232
- },
233
- 'rg16sint': {
234
- gl: 33337,
235
- b: 4,
236
- c: 2,
237
- bpp: 4
238
- },
239
- 'rg16float': {
240
- gl: 33327,
241
- bpp: 4,
242
- b: 4,
243
- c: 2,
244
- render: 'texture-renderable-float16-webgl',
245
- filter: 'texture-filter-linear-float16-webgl',
246
- renderbuffer: true
247
- },
248
- 'rg16unorm-webgl': {
249
- gl: 33324,
250
- b: 2,
251
- c: 2,
252
- f: 'texture-formats-norm16-webgl',
253
- x: EXT_TEXTURE_NORM16
254
- },
255
- 'rg16snorm-webgl': {
256
- gl: 36761,
257
- b: 2,
258
- c: 2,
259
- f: 'texture-formats-norm16-webgl',
260
- x: EXT_TEXTURE_NORM16
261
- },
262
- 'r32uint': {
263
- gl: 33334,
264
- b: 4,
265
- c: 1,
266
- bpp: 4,
267
- renderbuffer: true
268
- },
269
- 'r32sint': {
270
- gl: 33333,
271
- b: 4,
272
- c: 1,
273
- bpp: 4,
274
- renderbuffer: true
275
- },
276
- 'r32float': {
277
- gl: 33326,
278
- bpp: 4,
279
- b: 4,
280
- c: 1,
281
- render: 'texture-renderable-float32-webgl',
282
- filter: 'texture-filter-linear-float32-webgl'
283
- },
284
- 'rgb9e5ufloat': {
285
- gl: 35901,
286
- b: 4,
287
- c: 3,
288
- p: 1,
289
- render: 'texture-renderable-float16-webgl',
290
- filter: 'texture-filter-linear-float16-webgl'
291
- },
292
- 'rg11b10ufloat': {
293
- gl: 35898,
294
- b: 4,
295
- c: 3,
296
- p: 1,
297
- render: 'texture-renderable-float32-webgl',
298
- renderbuffer: true
299
- },
300
- 'rgb10a2unorm': {
301
- gl: 32857,
302
- b: 4,
303
- c: 4,
304
- p: 1,
305
- renderbuffer: true
306
- },
307
- 'rgb10a2unorm-webgl': {
308
- b: 4,
309
- c: 4,
310
- gl: 36975,
311
- p: 1,
312
- wgpu: false,
313
- bpp: 4,
314
- renderbuffer: true
315
- },
316
- 'rgb16unorm-webgl': {
317
- gl: 32852,
318
- b: 2,
319
- c: 3,
320
- f: 'texture-formats-norm16-webgl',
321
- x: EXT_TEXTURE_NORM16
322
- },
323
- 'rgb16snorm-webgl': {
324
- gl: 36762,
325
- b: 2,
326
- c: 3,
327
- f: 'texture-formats-norm16-webgl',
328
- x: EXT_TEXTURE_NORM16
329
- },
330
- 'rg32uint': {
331
- gl: 33340,
332
- b: 8,
333
- c: 2,
334
- renderbuffer: true
335
- },
336
- 'rg32sint': {
337
- gl: 33339,
338
- b: 8,
339
- c: 2,
340
- renderbuffer: true
341
- },
342
- 'rg32float': {
343
- gl: 33328,
344
- b: 8,
345
- c: 2,
346
- render: 'texture-renderable-float32-webgl',
347
- filter: 'texture-filter-linear-float32-webgl',
348
- renderbuffer: true
349
- },
350
- 'rgba16uint': {
351
- gl: 36214,
352
- b: 8,
353
- c: 4,
354
- renderbuffer: true
355
- },
356
- 'rgba16sint': {
357
- gl: 36232,
358
- b: 8,
359
- c: 4,
360
- renderbuffer: true
361
- },
362
- 'rgba16float': {
363
- gl: 34842,
364
- gl1: 6408,
365
- b: 8,
366
- c: 4,
367
- render: 'texture-renderable-float16-webgl',
368
- filter: 'texture-filter-linear-float16-webgl'
369
- },
370
- 'rgba16unorm-webgl': {
371
- gl: 32859,
372
- b: 2,
373
- c: 4,
374
- f: 'texture-formats-norm16-webgl',
375
- renderbuffer: true,
376
- x: EXT_TEXTURE_NORM16
377
- },
378
- 'rgba16snorm-webgl': {
379
- gl: 36763,
380
- b: 2,
381
- c: 4,
382
- f: 'texture-formats-norm16-webgl',
383
- x: EXT_TEXTURE_NORM16
384
- },
385
- 'rgb32float-webgl': {
386
- gl: 34837,
387
- gl1: 6407,
388
- render: 'texture-renderable-float32-webgl',
389
- filter: 'texture-filter-linear-float32-webgl',
390
- gl2ext: EXT_FLOAT_RENDER_WEBGL2,
391
- gl1ext: EXT_FLOAT_WEBGL1,
392
- dataFormat: 6407,
393
- types: [5126]
394
- },
395
- 'rgba32uint': {
396
- gl: 36208,
397
- b: 16,
398
- c: 4,
399
- renderbuffer: true
400
- },
401
- 'rgba32sint': {
402
- gl: 36226,
403
- b: 16,
404
- c: 4,
405
- renderbuffer: true
406
- },
407
- 'rgba32float': {
408
- gl: 34836,
409
- b: 16,
410
- c: 4,
411
- render: 'texture-renderable-float32-webgl',
412
- filter: 'texture-filter-linear-float32-webgl',
413
- renderbuffer: true
414
- },
415
- 'stencil8': {
416
- gl: 36168,
417
- gl1: 36168,
418
- b: 1,
419
- c: 1,
420
- attachment: 36128,
421
- renderbuffer: true
422
- },
423
- 'depth16unorm': {
424
- gl: 33189,
425
- gl1: 33189,
426
- b: 2,
427
- c: 1,
428
- attachment: 36096,
429
- renderbuffer: true
430
- },
431
- 'depth24plus': {
432
- gl: 33190,
433
- b: 3,
434
- c: 1,
435
- attachment: 36096
436
- },
437
- 'depth32float': {
438
- gl: 36012,
439
- b: 4,
440
- c: 1,
441
- attachment: 36096,
442
- renderbuffer: true
443
- },
444
- 'depth24plus-stencil8': {
445
- gl: 34041,
446
- gl1: 34041,
447
- b: 4,
448
- c: 2,
449
- p: 1,
450
- attachment: 33306,
451
- renderbuffer: true,
452
- depthTexture: true
453
- },
454
- 'depth24unorm-stencil8': {
455
- gl: 35056,
456
- b: 4,
457
- c: 2,
458
- p: 1,
459
- attachment: 33306,
460
- renderbuffer: true
461
- },
462
- 'depth32float-stencil8': {
463
- gl: 36013,
464
- b: 5,
465
- c: 2,
466
- p: 1,
467
- attachment: 33306,
468
- renderbuffer: true
469
- },
470
- 'bc1-rgb-unorm-webgl': {
471
- gl: 33776,
472
- x: X_S3TC,
473
- f: texture_compression_bc
474
- },
475
- 'bc1-rgb-unorm-srgb-webgl': {
476
- gl: 35916,
477
- x: X_S3TC_SRGB,
478
- f: texture_compression_bc
479
- },
480
- 'bc1-rgba-unorm': {
481
- gl: 33777,
482
- x: X_S3TC,
483
- f: texture_compression_bc
484
- },
485
- 'bc1-rgba-unorm-srgb': {
486
- gl: 35916,
487
- x: X_S3TC_SRGB,
488
- f: texture_compression_bc
489
- },
490
- 'bc2-rgba-unorm': {
491
- gl: 33778,
492
- x: X_S3TC,
493
- f: texture_compression_bc
494
- },
495
- 'bc2-rgba-unorm-srgb': {
496
- gl: 35918,
497
- x: X_S3TC_SRGB,
498
- f: texture_compression_bc
499
- },
500
- 'bc3-rgba-unorm': {
501
- gl: 33779,
502
- x: X_S3TC,
503
- f: texture_compression_bc
504
- },
505
- 'bc3-rgba-unorm-srgb': {
506
- gl: 35919,
507
- x: X_S3TC_SRGB,
508
- f: texture_compression_bc
509
- },
510
- 'bc4-r-unorm': {
511
- gl: 36283,
512
- x: X_RGTC,
513
- f: texture_compression_bc
514
- },
515
- 'bc4-r-snorm': {
516
- gl: 36284,
517
- x: X_RGTC,
518
- f: texture_compression_bc
519
- },
520
- 'bc5-rg-unorm': {
521
- gl: 36285,
522
- x: X_RGTC,
523
- f: texture_compression_bc
524
- },
525
- 'bc5-rg-snorm': {
526
- gl: 36286,
527
- x: X_RGTC,
528
- f: texture_compression_bc
529
- },
530
- 'bc6h-rgb-ufloat': {
531
- gl: 36495,
532
- x: X_BPTC,
533
- f: texture_compression_bc
534
- },
535
- 'bc6h-rgb-float': {
536
- gl: 36494,
537
- x: X_BPTC,
538
- f: texture_compression_bc
539
- },
540
- 'bc7-rgba-unorm': {
541
- gl: 36492,
542
- x: X_BPTC,
543
- f: texture_compression_bc
544
- },
545
- 'bc7-rgba-unorm-srgb': {
546
- gl: 36493,
547
- x: X_BPTC,
548
- f: texture_compression_bc
549
- },
550
- 'etc2-rgb8unorm': {
551
- gl: 37492,
552
- f: texture_compression_etc2
553
- },
554
- 'etc2-rgb8unorm-srgb': {
555
- gl: 37494,
556
- f: texture_compression_etc2
557
- },
558
- 'etc2-rgb8a1unorm': {
559
- gl: 37496,
560
- f: texture_compression_etc2
561
- },
562
- 'etc2-rgb8a1unorm-srgb': {
563
- gl: 37497,
564
- f: texture_compression_etc2
565
- },
566
- 'etc2-rgba8unorm': {
567
- gl: 37493,
568
- f: texture_compression_etc2
569
- },
570
- 'etc2-rgba8unorm-srgb': {
571
- gl: 37495,
572
- f: texture_compression_etc2
573
- },
574
- 'eac-r11unorm': {
575
- gl: 37488,
576
- f: texture_compression_etc2
577
- },
578
- 'eac-r11snorm': {
579
- gl: 37489,
580
- f: texture_compression_etc2
581
- },
582
- 'eac-rg11unorm': {
583
- gl: 37490,
584
- f: texture_compression_etc2
585
- },
586
- 'eac-rg11snorm': {
587
- gl: 37491,
588
- f: texture_compression_etc2
589
- },
590
- 'astc-4x4-unorm': {
591
- gl: 37808,
592
- f: texture_compression_astc
593
- },
594
- 'astc-4x4-unorm-srgb': {
595
- gl: 37840,
596
- f: texture_compression_astc
597
- },
598
- 'astc-5x4-unorm': {
599
- gl: 37809,
600
- f: texture_compression_astc
601
- },
602
- 'astc-5x4-unorm-srgb': {
603
- gl: 37841,
604
- f: texture_compression_astc
605
- },
606
- 'astc-5x5-unorm': {
607
- gl: 37810,
608
- f: texture_compression_astc
609
- },
610
- 'astc-5x5-unorm-srgb': {
611
- gl: 37842,
612
- f: texture_compression_astc
613
- },
614
- 'astc-6x5-unorm': {
615
- gl: 37811,
616
- f: texture_compression_astc
617
- },
618
- 'astc-6x5-unorm-srgb': {
619
- gl: 37843,
620
- f: texture_compression_astc
621
- },
622
- 'astc-6x6-unorm': {
623
- gl: 37812,
624
- f: texture_compression_astc
625
- },
626
- 'astc-6x6-unorm-srgb': {
627
- gl: 37844,
628
- f: texture_compression_astc
629
- },
630
- 'astc-8x5-unorm': {
631
- gl: 37813,
632
- f: texture_compression_astc
633
- },
634
- 'astc-8x5-unorm-srgb': {
635
- gl: 37845,
636
- f: texture_compression_astc
637
- },
638
- 'astc-8x6-unorm': {
639
- gl: 37814,
640
- f: texture_compression_astc
641
- },
642
- 'astc-8x6-unorm-srgb': {
643
- gl: 37846,
644
- f: texture_compression_astc
645
- },
646
- 'astc-8x8-unorm': {
647
- gl: 37815,
648
- f: texture_compression_astc
649
- },
650
- 'astc-8x8-unorm-srgb': {
651
- gl: 37847,
652
- f: texture_compression_astc
653
- },
654
- 'astc-10x5-unorm': {
655
- gl: 37819,
656
- f: texture_compression_astc
657
- },
658
- 'astc-10x5-unorm-srgb': {
659
- gl: 37851,
660
- f: texture_compression_astc
661
- },
662
- 'astc-10x6-unorm': {
663
- gl: 37817,
664
- f: texture_compression_astc
665
- },
666
- 'astc-10x6-unorm-srgb': {
667
- gl: 37849,
668
- f: texture_compression_astc
669
- },
670
- 'astc-10x8-unorm': {
671
- gl: 37818,
672
- f: texture_compression_astc
673
- },
674
- 'astc-10x8-unorm-srgb': {
675
- gl: 37850,
676
- f: texture_compression_astc
677
- },
678
- 'astc-10x10-unorm': {
679
- gl: 37819,
680
- f: texture_compression_astc
681
- },
682
- 'astc-10x10-unorm-srgb': {
683
- gl: 37851,
684
- f: texture_compression_astc
685
- },
686
- 'astc-12x10-unorm': {
687
- gl: 37820,
688
- f: texture_compression_astc
689
- },
690
- 'astc-12x10-unorm-srgb': {
691
- gl: 37852,
692
- f: texture_compression_astc
693
- },
694
- 'astc-12x12-unorm': {
695
- gl: 37821,
696
- f: texture_compression_astc
697
- },
698
- 'astc-12x12-unorm-srgb': {
699
- gl: 37853,
700
- f: texture_compression_astc
701
- },
702
- 'pvrtc-rgb4unorm-webgl': {
703
- gl: 35840,
704
- f: texture_compression_pvrtc_webgl
705
- },
706
- 'pvrtc-rgba4unorm-webgl': {
707
- gl: 35842,
708
- f: texture_compression_pvrtc_webgl
709
- },
710
- 'pvrtc-rbg2unorm-webgl': {
711
- gl: 35841,
712
- f: texture_compression_pvrtc_webgl
713
- },
714
- 'pvrtc-rgba2unorm-webgl': {
715
- gl: 35843,
716
- f: texture_compression_pvrtc_webgl
717
- },
718
- 'etc1-rbg-unorm-webgl': {
719
- gl: 36196,
720
- f: texture_compression_etc1_webgl
721
- },
722
- 'atc-rgb-unorm-webgl': {
723
- gl: 35986,
724
- f: texture_compression_atc_webgl
725
- },
726
- 'atc-rgba-unorm-webgl': {
727
- gl: 35986,
728
- f: texture_compression_atc_webgl
729
- },
730
- 'atc-rgbai-unorm-webgl': {
731
- gl: 34798,
732
- f: texture_compression_atc_webgl
733
- }
73
+ // Unsized formats that leave the precision up to the driver.
74
+ // TODO - Fix bpp constants
75
+ // 'r8unorm-unsized': {gl: GL.LUMINANCE, b: 4, c: 2, bpp: 4},
76
+ 'rgb8unorm-unsized': { gl: GL.RGB, b: 4, c: 2, bpp: 4,
77
+ dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5] },
78
+ 'rgba8unorm-unsized': { gl: GL.RGBA, b: 4, c: 2, bpp: 4,
79
+ dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4, GL.UNSIGNED_SHORT_5_5_5_1] },
80
+ // 'rgb8unorm-srgb-unsized': {gl: GL.SRGB_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
81
+ // 'rgba8unorm-srgb-unsized': {gl: GL.SRGB_ALPHA_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
82
+ // 8-bit formats
83
+ 'r8unorm': { gl: GL.R8, b: 1, c: 1, renderbuffer: true },
84
+ 'r8snorm': { gl: GL.R8_SNORM, b: 1, c: 1 },
85
+ 'r8uint': { gl: GL.R8UI, b: 1, c: 1, renderbuffer: true },
86
+ 'r8sint': { gl: GL.R8I, b: 1, c: 1, renderbuffer: true },
87
+ // 16-bit formats
88
+ 'rg8unorm': { gl: GL.RG8, b: 2, c: 2, renderbuffer: true },
89
+ 'rg8snorm': { gl: GL.RG8_SNORM, b: 2, c: 2 },
90
+ 'rg8uint': { gl: GL.RG8UI, b: 2, c: 2, renderbuffer: true },
91
+ 'rg8sint': { gl: GL.RG8I, b: 2, c: 2, renderbuffer: true },
92
+ 'r16uint': { gl: GL.R16UI, b: 2, c: 1, renderbuffer: true },
93
+ 'r16sint': { gl: GL.R16I, b: 2, c: 1, renderbuffer: true },
94
+ 'r16float': { gl: GL.R16F, b: 2, c: 1, render: 'float16-renderable-webgl', filter: 'float16-filterable-linear-webgl', renderbuffer: true },
95
+ 'r16unorm-webgl': { gl: GL.R16_EXT, b: 2, c: 1, f: 'norm16-renderable-webgl', renderbuffer: true, x: EXT_TEXTURE_NORM16 },
96
+ 'r16snorm-webgl': { gl: GL.R16_SNORM_EXT, b: 2, c: 1, f: 'norm16-renderable-webgl', x: EXT_TEXTURE_NORM16 },
97
+ // Packed 16-bit formats
98
+ 'rgba4unorm-webgl': { gl: GL.RGBA4, b: 2, c: 4, wgpu: false, renderbuffer: true },
99
+ 'rgb565unorm-webgl': { gl: GL.RGB565, b: 2, c: 4, wgpu: false, renderbuffer: true },
100
+ 'rgb5a1unorm-webgl': { gl: GL.RGB5_A1, b: 2, c: 4, wgpu: false, renderbuffer: true },
101
+ // 24-bit formats
102
+ 'rgb8unorm-webgl': { gl: GL.RGB8, b: 3, c: 3, wgpu: false },
103
+ 'rgb8snorm-webgl': { gl: GL.RGB8_SNORM, b: 3, c: 3, wgpu: false },
104
+ // 32-bit formats
105
+ 'rgba8unorm': { gl: GL.RGBA8, b: 4, c: 2, bpp: 4 },
106
+ 'rgba8unorm-srgb': { gl: GL.SRGB8_ALPHA8, b: 4, c: 4, bpp: 4 },
107
+ 'rgba8snorm': { gl: GL.RGBA8_SNORM, b: 4, c: 4 },
108
+ 'rgba8uint': { gl: GL.RGBA8UI, b: 4, c: 4, bpp: 4 },
109
+ 'rgba8sint': { gl: GL.RGBA8I, b: 4, c: 4, bpp: 4 },
110
+ // reverse colors, webgpu only
111
+ 'bgra8unorm': { b: 4, c: 4 },
112
+ 'bgra8unorm-srgb': { b: 4, c: 4 },
113
+ 'rg16uint': { gl: GL.RG16UI, b: 4, c: 1, bpp: 4 },
114
+ 'rg16sint': { gl: GL.RG16I, b: 4, c: 2, bpp: 4 },
115
+ // When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
116
+ 'rg16float': { gl: GL.RG16F, bpp: 4, b: 4, c: 2, render: 'float16-renderable-webgl', filter: 'float16-filterable-linear-webgl', renderbuffer: true },
117
+ 'rg16unorm-webgl': { gl: GL.RG16_EXT, b: 2, c: 2, f: 'norm16-renderable-webgl', x: EXT_TEXTURE_NORM16 },
118
+ 'rg16snorm-webgl': { gl: GL.RG16_SNORM_EXT, b: 2, c: 2, f: 'norm16-renderable-webgl', x: EXT_TEXTURE_NORM16 },
119
+ 'r32uint': { gl: GL.R32UI, b: 4, c: 1, bpp: 4, renderbuffer: true },
120
+ 'r32sint': { gl: GL.R32I, b: 4, c: 1, bpp: 4, renderbuffer: true },
121
+ 'r32float': { gl: GL.R32F, bpp: 4, b: 4, c: 1, render: 'float32-renderable-webgl', filter: 'float32-filterable-linear-webgl' },
122
+ // Packed 32-bit formats
123
+ 'rgb9e5ufloat': { gl: GL.RGB9_E5, b: 4, c: 3, p: 1, render: 'float16-renderable-webgl', filter: 'float16-filterable-linear-webgl' },
124
+ 'rg11b10ufloat': { gl: GL.R11F_G11F_B10F, b: 4, c: 3, p: 1, render: 'float32-renderable-webgl', renderbuffer: true },
125
+ 'rgb10a2unorm': { gl: GL.RGB10_A2, b: 4, c: 4, p: 1, renderbuffer: true },
126
+ 'rgb10a2unorm-webgl': { b: 4, c: 4, gl: GL.RGB10_A2UI, p: 1, wgpu: false, bpp: 4, renderbuffer: true },
127
+ // 48-bit formats
128
+ 'rgb16unorm-webgl': { gl: GL.RGB16_EXT, b: 2, c: 3, f: 'norm16-renderable-webgl', x: EXT_TEXTURE_NORM16 },
129
+ 'rgb16snorm-webgl': { gl: GL.RGB16_SNORM_EXT, b: 2, c: 3, f: 'norm16-renderable-webgl', x: EXT_TEXTURE_NORM16 },
130
+ // 64-bit formats
131
+ 'rg32uint': { gl: GL.RG32UI, b: 8, c: 2, renderbuffer: true },
132
+ 'rg32sint': { gl: GL.RG32I, b: 8, c: 2, renderbuffer: true },
133
+ 'rg32float': { gl: GL.RG32F, b: 8, c: 2, render: 'float32-renderable-webgl', filter: 'float32-filterable-linear-webgl', renderbuffer: true },
134
+ 'rgba16uint': { gl: GL.RGBA16UI, b: 8, c: 4, renderbuffer: true },
135
+ 'rgba16sint': { gl: GL.RGBA16I, b: 8, c: 4, renderbuffer: true },
136
+ 'rgba16float': { gl: GL.RGBA16F, b: 8, c: 4, render: 'float16-renderable-webgl', filter: 'float16-filterable-linear-webgl' },
137
+ 'rgba16unorm-webgl': { gl: GL.RGBA16_EXT, b: 2, c: 4, f: 'norm16-renderable-webgl', renderbuffer: true, x: EXT_TEXTURE_NORM16 },
138
+ 'rgba16snorm-webgl': { gl: GL.RGBA16_SNORM_EXT, b: 2, c: 4, f: 'norm16-renderable-webgl', x: EXT_TEXTURE_NORM16 },
139
+ // 96-bit formats (deprecated!)
140
+ 'rgb32float-webgl': { gl: GL.RGB32F, render: 'float32-renderable-webgl', filter: 'float32-filterable-linear-webgl',
141
+ gl2ext: EXT_FLOAT_RENDER_WEBGL2, dataFormat: GL.RGB, types: [GL.FLOAT] },
142
+ // 128-bit formats
143
+ 'rgba32uint': { gl: GL.RGBA32UI, b: 16, c: 4, renderbuffer: true },
144
+ 'rgba32sint': { gl: GL.RGBA32I, b: 16, c: 4, renderbuffer: true },
145
+ 'rgba32float': { gl: GL.RGBA32F, b: 16, c: 4, render: 'float32-renderable-webgl', filter: 'float32-filterable-linear-webgl', renderbuffer: true },
146
+ // Depth and stencil formats
147
+ 'stencil8': { gl: GL.STENCIL_INDEX8, b: 1, c: 1, attachment: GL.STENCIL_ATTACHMENT, renderbuffer: true }, // 8 stencil bits
148
+ 'depth16unorm': { gl: GL.DEPTH_COMPONENT16, b: 2, c: 1, attachment: GL.DEPTH_ATTACHMENT, renderbuffer: true }, // 16 depth bits
149
+ 'depth24plus': { gl: GL.DEPTH_COMPONENT24, b: 3, c: 1, attachment: GL.DEPTH_ATTACHMENT },
150
+ 'depth32float': { gl: GL.DEPTH_COMPONENT32F, b: 4, c: 1, attachment: GL.DEPTH_ATTACHMENT, renderbuffer: true },
151
+ // The depth component of the "depth24plus" and "depth24plus-stencil8" formats may be implemented as either a 24-bit depth value or a "depth32float" value.
152
+ 'depth24plus-stencil8': { gl: GL.DEPTH_STENCIL, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, renderbuffer: true, depthTexture: true },
153
+ // "depth24unorm-stencil8" feature
154
+ 'depth24unorm-stencil8': { gl: GL.DEPTH24_STENCIL8, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, renderbuffer: true },
155
+ // "depth32float-stencil8" feature
156
+ 'depth32float-stencil8': { gl: GL.DEPTH32F_STENCIL8, b: 5, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, renderbuffer: true },
157
+ // BC compressed formats: check device.features.has("texture-compression-bc");
158
+ 'bc1-rgb-unorm-webgl': { gl: GL.COMPRESSED_RGB_S3TC_DXT1_EXT, x: X_S3TC, f: texture_compression_bc },
159
+ 'bc1-rgb-unorm-srgb-webgl': { gl: GL.COMPRESSED_SRGB_S3TC_DXT1_EXT, x: X_S3TC_SRGB, f: texture_compression_bc },
160
+ 'bc1-rgba-unorm': { gl: GL.COMPRESSED_RGBA_S3TC_DXT1_EXT, x: X_S3TC, f: texture_compression_bc },
161
+ 'bc1-rgba-unorm-srgb': { gl: GL.COMPRESSED_SRGB_S3TC_DXT1_EXT, x: X_S3TC_SRGB, f: texture_compression_bc },
162
+ 'bc2-rgba-unorm': { gl: GL.COMPRESSED_RGBA_S3TC_DXT3_EXT, x: X_S3TC, f: texture_compression_bc },
163
+ 'bc2-rgba-unorm-srgb': { gl: GL.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, x: X_S3TC_SRGB, f: texture_compression_bc },
164
+ 'bc3-rgba-unorm': { gl: GL.COMPRESSED_RGBA_S3TC_DXT5_EXT, x: X_S3TC, f: texture_compression_bc },
165
+ 'bc3-rgba-unorm-srgb': { gl: GL.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, x: X_S3TC_SRGB, f: texture_compression_bc },
166
+ 'bc4-r-unorm': { gl: GL.COMPRESSED_RED_RGTC1_EXT, x: X_RGTC, f: texture_compression_bc },
167
+ 'bc4-r-snorm': { gl: GL.COMPRESSED_SIGNED_RED_RGTC1_EXT, x: X_RGTC, f: texture_compression_bc },
168
+ 'bc5-rg-unorm': { gl: GL.COMPRESSED_RED_GREEN_RGTC2_EXT, x: X_RGTC, f: texture_compression_bc },
169
+ 'bc5-rg-snorm': { gl: GL.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, x: X_RGTC, f: texture_compression_bc },
170
+ 'bc6h-rgb-ufloat': { gl: GL.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, x: X_BPTC, f: texture_compression_bc },
171
+ 'bc6h-rgb-float': { gl: GL.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, x: X_BPTC, f: texture_compression_bc },
172
+ 'bc7-rgba-unorm': { gl: GL.COMPRESSED_RGBA_BPTC_UNORM_EXT, x: X_BPTC, f: texture_compression_bc },
173
+ 'bc7-rgba-unorm-srgb': { gl: GL.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, x: X_BPTC, f: texture_compression_bc },
174
+ // WEBGL_compressed_texture_etc: device.features.has("texture-compression-etc2")
175
+ // Note: Supposedly guaranteed availability compressed formats in WebGL2, but through CPU decompression
176
+ 'etc2-rgb8unorm': { gl: GL.COMPRESSED_RGB8_ETC2, f: texture_compression_etc2 },
177
+ 'etc2-rgb8unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ETC2, f: texture_compression_etc2 },
178
+ 'etc2-rgb8a1unorm': { gl: GL.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, f: texture_compression_etc2 },
179
+ 'etc2-rgb8a1unorm-srgb': { gl: GL.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, f: texture_compression_etc2 },
180
+ 'etc2-rgba8unorm': { gl: GL.COMPRESSED_RGBA8_ETC2_EAC, f: texture_compression_etc2 },
181
+ 'etc2-rgba8unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, f: texture_compression_etc2 },
182
+ 'eac-r11unorm': { gl: GL.COMPRESSED_R11_EAC, f: texture_compression_etc2 },
183
+ 'eac-r11snorm': { gl: GL.COMPRESSED_SIGNED_R11_EAC, f: texture_compression_etc2 },
184
+ 'eac-rg11unorm': { gl: GL.COMPRESSED_RG11_EAC, f: texture_compression_etc2 },
185
+ 'eac-rg11snorm': { gl: GL.COMPRESSED_SIGNED_RG11_EAC, f: texture_compression_etc2 },
186
+ // X_ASTC compressed formats: device.features.has("texture-compression-astc")
187
+ 'astc-4x4-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_4x4_KHR, f: texture_compression_astc },
188
+ 'astc-4x4-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, f: texture_compression_astc },
189
+ 'astc-5x4-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_5x4_KHR, f: texture_compression_astc },
190
+ 'astc-5x4-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, f: texture_compression_astc },
191
+ 'astc-5x5-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_5x5_KHR, f: texture_compression_astc },
192
+ 'astc-5x5-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, f: texture_compression_astc },
193
+ 'astc-6x5-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_6x5_KHR, f: texture_compression_astc },
194
+ 'astc-6x5-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, f: texture_compression_astc },
195
+ 'astc-6x6-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_6x6_KHR, f: texture_compression_astc },
196
+ 'astc-6x6-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, f: texture_compression_astc },
197
+ 'astc-8x5-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_8x5_KHR, f: texture_compression_astc },
198
+ 'astc-8x5-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, f: texture_compression_astc },
199
+ 'astc-8x6-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_8x6_KHR, f: texture_compression_astc },
200
+ 'astc-8x6-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, f: texture_compression_astc },
201
+ 'astc-8x8-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_8x8_KHR, f: texture_compression_astc },
202
+ 'astc-8x8-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, f: texture_compression_astc },
203
+ 'astc-10x5-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_10x10_KHR, f: texture_compression_astc },
204
+ 'astc-10x5-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, f: texture_compression_astc },
205
+ 'astc-10x6-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_10x6_KHR, f: texture_compression_astc },
206
+ 'astc-10x6-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, f: texture_compression_astc },
207
+ 'astc-10x8-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_10x8_KHR, f: texture_compression_astc },
208
+ 'astc-10x8-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, f: texture_compression_astc },
209
+ 'astc-10x10-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_10x10_KHR, f: texture_compression_astc },
210
+ 'astc-10x10-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, f: texture_compression_astc },
211
+ 'astc-12x10-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_12x10_KHR, f: texture_compression_astc },
212
+ 'astc-12x10-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, f: texture_compression_astc },
213
+ 'astc-12x12-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_12x12_KHR, f: texture_compression_astc },
214
+ 'astc-12x12-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, f: texture_compression_astc },
215
+ // WEBGL_compressed_texture_pvrtc
216
+ 'pvrtc-rgb4unorm-webgl': { gl: GL.COMPRESSED_RGB_PVRTC_4BPPV1_IMG, f: texture_compression_pvrtc_webgl },
217
+ 'pvrtc-rgba4unorm-webgl': { gl: GL.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, f: texture_compression_pvrtc_webgl },
218
+ 'pvrtc-rbg2unorm-webgl': { gl: GL.COMPRESSED_RGB_PVRTC_2BPPV1_IMG, f: texture_compression_pvrtc_webgl },
219
+ 'pvrtc-rgba2unorm-webgl': { gl: GL.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, f: texture_compression_pvrtc_webgl },
220
+ // WEBGL_compressed_texture_etc1
221
+ 'etc1-rbg-unorm-webgl': { gl: GL.COMPRESSED_RGB_ETC1_WEBGL, f: texture_compression_etc1_webgl },
222
+ // WEBGL_compressed_texture_atc
223
+ 'atc-rgb-unorm-webgl': { gl: GL.COMPRESSED_RGB_ATC_WEBGL, f: texture_compression_atc_webgl },
224
+ 'atc-rgba-unorm-webgl': { gl: GL.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL, f: texture_compression_atc_webgl },
225
+ 'atc-rgbai-unorm-webgl': { gl: GL.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL, f: texture_compression_atc_webgl }
226
+ };
227
+ /** Legal combinations for internalFormat, format and type *
228
+ // [GL.DEPTH_COMPONENT]: {types: [GL.UNSIGNED_SHORT, GL.UNSIGNED_INT, GL.UNSIGNED_INT_24_8]},
229
+ // [GL.DEPTH_STENCIL]: ,
230
+ // Sized texture format
231
+ // R
232
+ [GL.R8]: {dataFormat: GL.RED, types: [GL.UNSIGNED_BYTE], gl2: true},
233
+ [GL.R16F]: {dataFormat: GL.RED, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
234
+ [GL.R8UI]: {dataFormat: GL.RED_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
235
+ // // RG
236
+ [GL.RG8]: {dataFormat: GL.RG, types: [GL.UNSIGNED_BYTE], gl2: true},
237
+ [GL.RG16F]: {dataFormat: GL.RG, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
238
+ [GL.RG8UI]: {dataFormat: GL.RG_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
239
+ // // RGB
240
+ [GL.RGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
241
+ [GL.SRGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
242
+ [GL.RGB16F]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
243
+ [GL.RGB8UI]: {dataFormat: GL.RGB_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
244
+ // // RGBA
245
+
246
+ [GL.RGB565]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5], gl2: true},
247
+ [GL.R11F_G11F_B10F]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_INT_10F_11F_11F_REV, GL.HALF_FLOAT, GL.FLOAT], gl2: true},
248
+ [GL.RGB9_E5]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
249
+ [GL.RGBA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true},
250
+ [GL.SRGB8_ALPHA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true, gl1ext: EXT_SRGB},
251
+ [GL.RGB5_A1]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_5_5_1], gl2: true},
252
+ [GL.RGBA4]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4], gl2: true},
253
+ [GL.RGBA16F]: {dataFormat: GL.RGBA, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
254
+ [GL.RGBA8UI]: {dataFormat: GL.RGBA_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true}
255
+ */
256
+ /* This table is now baked into the above table
257
+ type RenderbufferFormat = {
258
+ bpp: number;
259
+ gl2?: boolean;
260
+ ext?: string;
261
+ };
262
+
263
+ export const RENDERBUFFER_FORMATS: Record<string, RenderbufferFormat> = {
264
+ [GL.DEPTH_COMPONENT16]: {bpp: 2}, // 16 depth bits.
265
+ // TODO - Not clear which webgpu value to map this to.
266
+ // [GL.DEPTH_COMPONENT24]: {gl2: true, bpp: 3},
267
+ [GL.DEPTH_COMPONENT32F]: {gl2: true, bpp: 4},
268
+
269
+ [GL.STENCIL_INDEX8]: {bpp: 1}, // 8 stencil bits.
270
+
271
+ [GL.DEPTH_STENCIL]: {bpp: 4},
272
+ [GL.DEPTH24_STENCIL8]: {gl2: true, bpp: 4},
273
+ [GL.DEPTH32F_STENCIL8]: {gl2: true, bpp: 5},
274
+
275
+ // When using a WebGL 1 context, color renderbuffer formats are limited
276
+ [GL.RGBA4]: {gl2: true, bpp: 2},
277
+ [GL.RGB565]: {gl2: true, bpp: 2},
278
+ [GL.RGB5_A1]: {gl2: true, bpp: 2},
279
+
280
+ // When using a WebGL 2 context, the following values are available additionally:
281
+ [GL.R8]: {gl2: true, bpp: 1},
282
+ [GL.R8UI]: {gl2: true, bpp: 1},
283
+ [GL.R8I]: {gl2: true, bpp: 1},
284
+ [GL.R16UI]: {gl2: true, bpp: 2},
285
+ [GL.R16I]: {gl2: true, bpp: 2},
286
+ [GL.R32UI]: {gl2: true, bpp: 4},
287
+ [GL.R32I]: {gl2: true, bpp: 4},
288
+ [GL.RG8]: {gl2: true, bpp: 2},
289
+ [GL.RG8UI]: {gl2: true, bpp: 2},
290
+ [GL.RG8I]: {gl2: true, bpp: 2},
291
+ [GL.RG16UI]: {gl2: true, bpp: 4},
292
+ [GL.RG16I]: {gl2: true, bpp: 4},
293
+ [GL.RG32UI]: {gl2: true, bpp: 8},
294
+ [GL.RG32I]: {gl2: true, bpp: 8},
295
+ [GL.RGB8]: {gl2: true, bpp: 3},
296
+ [GL.RGBA8]: {gl2: true, bpp: 4},
297
+ // [GL.SRGB8_ALPHA8]: {gl2: true, gl1: SRGB}, // When using the EXT_sRGB WebGL1 extension
298
+ [GL.RGB10_A2]: {gl2: true, bpp: 4},
299
+ [GL.RGBA8UI]: {gl2: true, bpp: 4},
300
+ [GL.RGBA8I]: {gl2: true, bpp: 4},
301
+ [GL.RGB10_A2UI]: {gl2: true, bpp: 4},
302
+ [GL.RGBA16UI]: {gl2: true, bpp: 8},
303
+ [GL.RGBA16I]: {gl2: true, bpp: 8},
304
+ [GL.RGBA32I]: {gl2: true, bpp: 16},
305
+ [GL.RGBA32UI]: {gl2: true, bpp: 16},
306
+
307
+ // When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
308
+ [GL.R16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 2},
309
+ [GL.RG16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4},
310
+ [GL.RGBA16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
311
+ [GL.R32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4},
312
+ [GL.RG32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
313
+ // TODO - can't get WEBGL_color_buffer_float to work on renderbuffers
314
+ [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 16},
315
+ // [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2, gl1: EXT_FLOAT_WEBGL1},
316
+ [GL.R11F_G11F_B10F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4}
734
317
  };
318
+ */
319
+ /** @deprecated should be removed */
735
320
  const DATA_FORMAT_CHANNELS = {
736
- [6403]: 1,
737
- [36244]: 1,
738
- [33319]: 2,
739
- [33320]: 2,
740
- [6407]: 3,
741
- [36248]: 3,
742
- [6408]: 4,
743
- [36249]: 4,
744
- [6402]: 1,
745
- [34041]: 1,
746
- [6406]: 1,
747
- [6409]: 1,
748
- [6410]: 2
321
+ [GL.RED]: 1,
322
+ [GL.RED_INTEGER]: 1,
323
+ [GL.RG]: 2,
324
+ [GL.RG_INTEGER]: 2,
325
+ [GL.RGB]: 3,
326
+ [GL.RGB_INTEGER]: 3,
327
+ [GL.RGBA]: 4,
328
+ [GL.RGBA_INTEGER]: 4,
329
+ [GL.DEPTH_COMPONENT]: 1,
330
+ [GL.DEPTH_STENCIL]: 1,
331
+ [GL.ALPHA]: 1,
332
+ [GL.LUMINANCE]: 1,
333
+ [GL.LUMINANCE_ALPHA]: 2
749
334
  };
335
+ /** @deprecated should be removed */
750
336
  const TYPE_SIZES = {
751
- [5126]: 4,
752
- [5125]: 4,
753
- [5124]: 4,
754
- [5123]: 2,
755
- [5122]: 2,
756
- [5131]: 2,
757
- [5120]: 1,
758
- [5121]: 1
337
+ [GL.FLOAT]: 4,
338
+ [GL.UNSIGNED_INT]: 4,
339
+ [GL.INT]: 4,
340
+ [GL.UNSIGNED_SHORT]: 2,
341
+ [GL.SHORT]: 2,
342
+ [GL.HALF_FLOAT]: 2,
343
+ [GL.BYTE]: 1,
344
+ [GL.UNSIGNED_BYTE]: 1
759
345
  };
346
+ // FUNCTIONS
347
+ /** Checks if a texture format is supported */
760
348
  export function isTextureFormatSupported(gl, formatOrGL) {
761
- const format = convertGLToTextureFormat(formatOrGL);
762
- const info = TEXTURE_FORMATS[format];
763
- if (!info) {
764
- return false;
765
- }
766
- if (isWebGL2(gl) ? info.gl === undefined : info.gl1 === undefined) {
767
- return false;
768
- }
769
- const extension = info.x || (isWebGL2(gl) ? info.gl2ext || info.gl1ext : info.gl1ext);
770
- if (extension) {
771
- return Boolean(gl.getExtension(extension));
772
- }
773
- return true;
349
+ const format = convertGLToTextureFormat(formatOrGL);
350
+ const info = TEXTURE_FORMATS[format];
351
+ if (!info) {
352
+ return false;
353
+ }
354
+ // Check that we have a GL constant
355
+ if (info.gl === undefined) {
356
+ return false;
357
+ }
358
+ // Check extensions
359
+ const extension = info.x || info.gl2ext;
360
+ if (extension) {
361
+ return Boolean(gl.getExtension(extension));
362
+ }
363
+ return true;
774
364
  }
775
365
  export function isRenderbufferFormatSupported(gl, format) {
776
- var _TEXTURE_FORMATS$form;
777
- return isTextureFormatSupported(gl, format) && ((_TEXTURE_FORMATS$form = TEXTURE_FORMATS[format]) === null || _TEXTURE_FORMATS$form === void 0 ? void 0 : _TEXTURE_FORMATS$form.renderbuffer);
366
+ // Note: Order is important since the function call initializes extensions.
367
+ return isTextureFormatSupported(gl, format) && TEXTURE_FORMATS[format]?.renderbuffer;
778
368
  }
369
+ /**
370
+ * Map WebGL texture formats (GL constants) to WebGPU-style TextureFormat strings
371
+ */
779
372
  export function convertGLToTextureFormat(format) {
780
- if (typeof format === 'string') {
781
- return format;
782
- }
783
- const entry = Object.entries(TEXTURE_FORMATS).find(_ref => {
784
- let [, entry] = _ref;
785
- return entry.gl === format || entry.gl1 === format;
786
- });
787
- if (!entry) {
788
- throw new Error(`Unknown texture format ${format}`);
789
- }
790
- return entry[0];
373
+ if (typeof format === 'string') {
374
+ return format;
375
+ }
376
+ const entry = Object.entries(TEXTURE_FORMATS).find(([, entry]) => entry.gl === format);
377
+ if (!entry) {
378
+ throw new Error(`Unknown texture format ${format}`);
379
+ }
380
+ return entry[0];
791
381
  }
792
- export function convertTextureFormatToGL(format, isWebGL2) {
793
- const formatInfo = TEXTURE_FORMATS[format];
794
- const webglFormat = isWebGL2 ? formatInfo === null || formatInfo === void 0 ? void 0 : formatInfo.gl : formatInfo === null || formatInfo === void 0 ? void 0 : formatInfo.gl1;
795
- if (webglFormat === undefined) {
796
- throw new Error(`Unsupported texture format ${format}`);
797
- }
798
- return webglFormat;
382
+ /**
383
+ * Map WebGPU style texture format strings to GL constants
384
+ */
385
+ export function convertTextureFormatToGL(format) {
386
+ const formatInfo = TEXTURE_FORMATS[format];
387
+ const webglFormat = formatInfo?.gl;
388
+ if (webglFormat === undefined) {
389
+ throw new Error(`Unsupported texture format ${format}`);
390
+ }
391
+ return webglFormat;
799
392
  }
393
+ /** Checks if a texture format is supported */
800
394
  export function getTextureFormatSupport(gl, formatOrGL) {
801
- const format = convertGLToTextureFormat(formatOrGL);
802
- const info = TEXTURE_FORMATS[format];
803
- if (!info) {
395
+ const format = convertGLToTextureFormat(formatOrGL);
396
+ const info = TEXTURE_FORMATS[format];
397
+ if (!info) {
398
+ return { supported: false };
399
+ }
400
+ // let decoded;
401
+ // try {
402
+ // decoded = decodeTextureFormat(format);
403
+ // } catch {}
404
+ // Support Check that we have a GL constant
405
+ let supported = info.gl === undefined;
406
+ supported = supported && checkTextureFeatures(gl, [info.f]);
407
+ // Filtering
408
+ // const filterable = info.filter
409
+ // ? checkTextureFeatures(gl, [info.filter])
410
+ // : decoded && !decoded.signed;
411
+ // const renderable = info.filter
412
+ // ? checkTextureFeatures(gl, [info.render])
413
+ // : decoded && !decoded.signed;
804
414
  return {
805
- supported: false
415
+ supported,
416
+ renderable: supported && checkTextureFeatures(gl, [info.render]),
417
+ filterable: supported && checkTextureFeatures(gl, [info.filter]),
418
+ blendable: false, // tod,
419
+ storable: false
806
420
  };
807
- }
808
- let supported = isWebGL2(gl) ? info.gl === undefined : info.gl1 === undefined;
809
- supported = supported && checkTextureFeatures(gl, [info.f]);
810
- return {
811
- supported,
812
- renderable: supported && checkTextureFeatures(gl, [info.render]),
813
- filterable: supported && checkTextureFeatures(gl, [info.filter]),
814
- blendable: false,
815
- storable: false
816
- };
817
421
  }
422
+ /** Checks whether linear filtering (interpolated sampling) is available for floating point textures */
818
423
  export function isTextureFormatFilterable(gl, formatOrGL) {
819
- const format = convertGLToTextureFormat(formatOrGL);
820
- if (!isTextureFormatSupported(gl, format)) {
821
- return false;
822
- }
823
- try {
824
- const decoded = decodeTextureFormat(format);
825
- if (decoded.signed) {
826
- return false;
424
+ const format = convertGLToTextureFormat(formatOrGL);
425
+ if (!isTextureFormatSupported(gl, format)) {
426
+ return false;
427
+ }
428
+ try {
429
+ const decoded = decodeTextureFormat(format);
430
+ if (decoded.signed) {
431
+ return false;
432
+ }
827
433
  }
828
- } catch {
829
- return false;
830
- }
831
- if (format.endsWith('32float')) {
832
- return Boolean(gl.getExtension('OES_texture_float_linear'));
833
- }
834
- if (format.endsWith('16float')) {
835
- return Boolean(gl.getExtension('OES_texture_half_float_linear'));
836
- }
837
- return true;
434
+ catch {
435
+ return false;
436
+ }
437
+ if (format.endsWith('32float')) {
438
+ return Boolean(gl.getExtension('OES_texture_float_linear'));
439
+ }
440
+ if (format.endsWith('16float')) {
441
+ return Boolean(gl.getExtension('OES_texture_half_float_linear'));
442
+ }
443
+ return true;
838
444
  }
839
445
  export function isTextureFormatRenderable(gl, formatOrGL) {
840
- const format = convertGLToTextureFormat(formatOrGL);
841
- if (!isTextureFormatSupported(gl, format)) {
842
- return false;
843
- }
844
- if (typeof format === 'number') {
845
- return false;
846
- }
847
- return true;
446
+ const format = convertGLToTextureFormat(formatOrGL);
447
+ if (!isTextureFormatSupported(gl, format)) {
448
+ return false;
449
+ }
450
+ if (typeof format === 'number') {
451
+ return false; // isTextureFormatFilterableWebGL(gl, format);
452
+ }
453
+ // TODO depends on device...
454
+ return true;
848
455
  }
849
- export function getWebGLTextureParameters(formatOrGL, isWebGL2) {
850
- const format = convertGLToTextureFormat(formatOrGL);
851
- const webglFormat = convertTextureFormatToGL(format, isWebGL2);
852
- const decoded = decodeTextureFormat(format);
853
- return {
854
- format: webglFormat,
855
- dataFormat: getWebGLPixelDataFormat(decoded.format, decoded.integer, decoded.normalized, webglFormat),
856
- type: decoded.dataType ? getGLFromVertexType(decoded.dataType) : 5121,
857
- compressed: decoded.compressed
858
- };
456
+ export function getWebGLTextureParameters(formatOrGL) {
457
+ const format = convertGLToTextureFormat(formatOrGL);
458
+ const webglFormat = convertTextureFormatToGL(format);
459
+ const decoded = decodeTextureFormat(format);
460
+ return {
461
+ format: webglFormat,
462
+ dataFormat: getWebGLPixelDataFormat(decoded.format, decoded.integer, decoded.normalized, webglFormat),
463
+ // depth formats don't have a type
464
+ type: decoded.dataType ? getGLFromVertexType(decoded.dataType) : GL.UNSIGNED_BYTE,
465
+ // @ts-expect-error
466
+ compressed: decoded.compressed
467
+ };
859
468
  }
860
469
  export function getDepthStencilAttachmentWebGL(format) {
861
- const info = TEXTURE_FORMATS[format];
862
- if (!(info !== null && info !== void 0 && info.attachment)) {
863
- throw new Error(`${format} is not a depth stencil format`);
864
- }
865
- return info.attachment;
866
- }
867
- export function _checkFloat32ColorAttachment(gl) {
868
- let internalFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6408;
869
- let srcFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 6408;
870
- let srcType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 5121;
871
- let texture = null;
872
- let framebuffer = null;
873
- try {
874
- texture = gl.createTexture();
875
- gl.bindTexture(3553, texture);
876
- const level = 0;
877
- const width = 1;
878
- const height = 1;
879
- const border = 0;
880
- const pixel = new Uint8Array([0, 0, 255, 255]);
881
- gl.texImage2D(3553, level, internalFormat, width, height, border, srcFormat, srcType, pixel);
882
- framebuffer = gl.createFramebuffer();
883
- gl.bindFramebuffer(36160, framebuffer);
884
- gl.framebufferTexture2D(36160, 36064, 3553, texture, 0);
885
- const status = gl.checkFramebufferStatus(36160) === 36053;
886
- gl.bindTexture(3553, null);
887
- return status;
888
- } finally {
889
- gl.deleteTexture(texture);
890
- gl.deleteFramebuffer(framebuffer);
891
- }
470
+ const info = TEXTURE_FORMATS[format];
471
+ if (!info?.attachment) {
472
+ throw new Error(`${format} is not a depth stencil format`);
473
+ }
474
+ return info.attachment;
892
475
  }
893
- export function getTextureFormatBytesPerPixel(formatOrGL, isWebGL2) {
894
- const format = convertGLToTextureFormat(formatOrGL);
895
- const params = getWebGLTextureParameters(format, isWebGL2);
896
- const channels = DATA_FORMAT_CHANNELS[params.dataFormat] || 4;
897
- const channelSize = TYPE_SIZES[params.type] || 1;
898
- return channels * channelSize;
476
+ /** TODO - VERY roundabout legacy way of calculating bytes per pixel */
477
+ export function getTextureFormatBytesPerPixel(formatOrGL) {
478
+ // TODO remove webgl1 support
479
+ const format = convertGLToTextureFormat(formatOrGL);
480
+ const params = getWebGLTextureParameters(format);
481
+ // NOTE(Tarek): Default to RGBA bytes
482
+ const channels = DATA_FORMAT_CHANNELS[params.dataFormat] || 4;
483
+ const channelSize = TYPE_SIZES[params.type] || 1;
484
+ return channels * channelSize;
899
485
  }
486
+ // DATA TYPE HELPERS
900
487
  function getWebGLPixelDataFormat(dataFormat, integer, normalized, format) {
901
- if (format === 6408 || format === 6407) {
902
- return format;
903
- }
904
- switch (dataFormat) {
905
- case 'r':
906
- return integer && !normalized ? 36244 : 6403;
907
- case 'rg':
908
- return integer && !normalized ? 33320 : 33319;
909
- case 'rgb':
910
- return integer && !normalized ? 36248 : 6407;
911
- case 'rgba':
912
- return integer && !normalized ? 36249 : 6408;
913
- default:
914
- return 6408;
915
- }
488
+ // WebGL1 formats use same internalFormat
489
+ if (format === GL.RGBA || format === GL.RGB) {
490
+ return format;
491
+ }
492
+ // prettier-ignore
493
+ switch (dataFormat) {
494
+ case 'r': return integer && !normalized ? GL.RED_INTEGER : GL.RED;
495
+ case 'rg': return integer && !normalized ? GL.RG_INTEGER : GL.RG;
496
+ case 'rgb': return integer && !normalized ? GL.RGB_INTEGER : GL.RGB;
497
+ case 'rgba': return integer && !normalized ? GL.RGBA_INTEGER : GL.RGBA;
498
+ default: return GL.RGBA;
499
+ }
916
500
  }
917
- //# sourceMappingURL=texture-formats.js.map