@luma.gl/webgl 9.0.0-beta.1 → 9.0.0-beta.10

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 (285) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  2. package/dist/adapter/converters/device-parameters.js +295 -156
  3. package/dist/adapter/converters/sampler-parameters.d.ts +0 -4
  4. package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
  5. package/dist/adapter/converters/sampler-parameters.js +73 -67
  6. package/dist/adapter/converters/shader-formats.d.ts.map +1 -1
  7. package/dist/adapter/converters/shader-formats.js +53 -46
  8. package/dist/adapter/converters/texture-formats.d.ts +17 -21
  9. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  10. package/dist/adapter/converters/texture-formats.js +481 -879
  11. package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
  12. package/dist/adapter/converters/vertex-formats.js +53 -61
  13. package/dist/adapter/device-helpers/webgl-device-features.d.ts +20 -0
  14. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -0
  15. package/dist/adapter/device-helpers/webgl-device-features.js +98 -0
  16. package/dist/adapter/device-helpers/webgl-device-info.d.ts +5 -0
  17. package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -0
  18. package/dist/adapter/device-helpers/webgl-device-info.js +90 -0
  19. package/dist/adapter/device-helpers/webgl-device-limits.d.ts +35 -0
  20. package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -0
  21. package/dist/adapter/device-helpers/webgl-device-limits.js +47 -0
  22. package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -1
  23. package/dist/adapter/helpers/decode-webgl-types.js +88 -76
  24. package/dist/adapter/helpers/get-shader-layout.d.ts +1 -1
  25. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  26. package/dist/adapter/helpers/get-shader-layout.js +261 -225
  27. package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
  28. package/dist/adapter/helpers/parse-shader-compiler-log.js +47 -37
  29. package/dist/adapter/helpers/set-uniform.d.ts +1 -1
  30. package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
  31. package/dist/adapter/helpers/set-uniform.js +68 -82
  32. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
  33. package/dist/adapter/helpers/webgl-topology-utils.js +78 -93
  34. package/dist/adapter/objects/constants-to-keys.d.ts +1 -1
  35. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  36. package/dist/adapter/objects/constants-to-keys.js +19 -12
  37. package/dist/adapter/objects/webgl-renderbuffer.d.ts +2 -2
  38. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
  39. package/dist/adapter/objects/webgl-renderbuffer.js +86 -77
  40. package/dist/adapter/objects/webgl-resource.d.ts +3 -25
  41. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  42. package/dist/adapter/objects/webgl-resource.js +102 -147
  43. package/dist/adapter/resources/webgl-buffer.d.ts +3 -4
  44. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  45. package/dist/adapter/resources/webgl-buffer.js +159 -117
  46. package/dist/adapter/resources/webgl-command-buffer.d.ts +1 -1
  47. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  48. package/dist/adapter/resources/webgl-command-buffer.js +266 -168
  49. package/dist/adapter/resources/webgl-command-encoder.d.ts +8 -3
  50. package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
  51. package/dist/adapter/resources/webgl-command-encoder.js +33 -39
  52. package/dist/adapter/resources/webgl-external-texture.js +93 -1
  53. package/dist/adapter/resources/webgl-framebuffer.d.ts +8 -12
  54. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  55. package/dist/adapter/resources/webgl-framebuffer.js +174 -139
  56. package/dist/adapter/resources/webgl-query-set.d.ts +44 -0
  57. package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -0
  58. package/dist/adapter/resources/webgl-query-set.js +136 -0
  59. package/dist/adapter/resources/webgl-render-pass.d.ts +3 -1
  60. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  61. package/dist/adapter/resources/webgl-render-pass.js +124 -90
  62. package/dist/adapter/resources/webgl-render-pipeline.d.ts +15 -6
  63. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  64. package/dist/adapter/resources/webgl-render-pipeline.js +362 -221
  65. package/dist/adapter/resources/webgl-sampler.d.ts +1 -3
  66. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  67. package/dist/adapter/resources/webgl-sampler.js +43 -33
  68. package/dist/adapter/resources/webgl-shader.d.ts +12 -2
  69. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  70. package/dist/adapter/resources/webgl-shader.js +114 -47
  71. package/dist/adapter/resources/webgl-texture-view.d.ts +14 -0
  72. package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -0
  73. package/dist/adapter/resources/webgl-texture-view.js +18 -0
  74. package/dist/adapter/resources/webgl-texture.d.ts +8 -10
  75. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  76. package/dist/adapter/resources/webgl-texture.js +616 -694
  77. package/dist/adapter/resources/webgl-transform-feedback.d.ts +2 -2
  78. package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
  79. package/dist/adapter/resources/webgl-transform-feedback.js +141 -143
  80. package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -3
  81. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  82. package/dist/adapter/resources/webgl-vertex-array.js +229 -157
  83. package/dist/adapter/webgl-canvas-context.d.ts +2 -2
  84. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  85. package/dist/adapter/webgl-canvas-context.js +58 -36
  86. package/dist/adapter/webgl-device.d.ts +50 -44
  87. package/dist/adapter/webgl-device.d.ts.map +1 -1
  88. package/dist/adapter/webgl-device.js +427 -352
  89. package/dist/classic/accessor.d.ts.map +1 -1
  90. package/dist/classic/accessor.js +132 -101
  91. package/dist/classic/clear.d.ts +2 -2
  92. package/dist/classic/clear.d.ts.map +1 -1
  93. package/dist/classic/clear.js +73 -72
  94. package/dist/classic/copy-and-blit.d.ts +1 -1
  95. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  96. package/dist/classic/copy-and-blit.js +174 -175
  97. package/dist/classic/format-utils.d.ts +2 -2
  98. package/dist/classic/format-utils.d.ts.map +1 -1
  99. package/dist/classic/format-utils.js +39 -32
  100. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  101. package/dist/classic/typed-array-utils.js +96 -81
  102. package/dist/context/debug/spector.d.ts.map +1 -1
  103. package/dist/context/debug/spector.js +55 -50
  104. package/dist/context/debug/webgl-developer-tools.d.ts +1 -2
  105. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  106. package/dist/context/debug/webgl-developer-tools.js +104 -77
  107. package/dist/context/{context → helpers}/create-browser-context.d.ts +1 -6
  108. package/dist/context/helpers/create-browser-context.d.ts.map +1 -0
  109. package/dist/context/helpers/create-browser-context.js +67 -0
  110. package/dist/context/{polyfill/context-data.d.ts → helpers/webgl-context-data.d.ts} +2 -2
  111. package/dist/context/helpers/webgl-context-data.d.ts.map +1 -0
  112. package/dist/context/helpers/webgl-context-data.js +21 -0
  113. package/dist/context/helpers/webgl-extensions.d.ts +4 -0
  114. package/dist/context/helpers/webgl-extensions.d.ts.map +1 -0
  115. package/dist/context/helpers/webgl-extensions.js +10 -0
  116. package/dist/context/parameters/unified-parameter-api.d.ts +3 -4
  117. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  118. package/dist/context/parameters/unified-parameter-api.js +92 -47
  119. package/dist/context/parameters/webgl-parameter-tables.d.ts +109 -99
  120. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  121. package/dist/context/parameters/webgl-parameter-tables.js +463 -404
  122. package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
  123. package/dist/context/state-tracker/deep-array-equal.js +19 -14
  124. package/dist/context/state-tracker/track-context-state.d.ts +4 -4
  125. package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
  126. package/dist/context/state-tracker/track-context-state.js +188 -123
  127. package/dist/context/state-tracker/with-parameters.d.ts +2 -3
  128. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  129. package/dist/context/state-tracker/with-parameters.js +42 -28
  130. package/dist/dist.dev.js +4465 -7235
  131. package/dist/dist.min.js +10 -0
  132. package/dist/index.cjs +2146 -3116
  133. package/dist/index.cjs.map +7 -0
  134. package/dist/index.d.ts +25 -31
  135. package/dist/index.d.ts.map +1 -1
  136. package/dist/index.js +19 -10
  137. package/dist/types.d.ts.map +1 -1
  138. package/dist/types.js +3 -1
  139. package/dist.min.js +9 -42
  140. package/package.json +10 -15
  141. package/src/adapter/converters/device-parameters.ts +114 -28
  142. package/src/adapter/converters/sampler-parameters.ts +12 -20
  143. package/src/adapter/converters/shader-formats.ts +47 -22
  144. package/src/adapter/converters/texture-formats.ts +183 -227
  145. package/src/adapter/converters/vertex-formats.ts +3 -3
  146. package/src/adapter/device-helpers/webgl-device-features.ts +121 -0
  147. package/src/adapter/device-helpers/{get-device-info.ts → webgl-device-info.ts} +30 -22
  148. package/src/adapter/device-helpers/webgl-device-limits.ts +53 -0
  149. package/src/adapter/helpers/decode-webgl-types.ts +13 -7
  150. package/src/adapter/helpers/get-shader-layout.ts +21 -31
  151. package/src/adapter/helpers/parse-shader-compiler-log.ts +10 -6
  152. package/src/adapter/helpers/set-uniform.ts +3 -4
  153. package/src/adapter/helpers/webgl-topology-utils.ts +10 -3
  154. package/src/adapter/objects/constants-to-keys.ts +3 -2
  155. package/src/adapter/objects/webgl-renderbuffer.ts +38 -16
  156. package/src/adapter/objects/webgl-resource.ts +8 -141
  157. package/src/adapter/resources/webgl-buffer.ts +10 -14
  158. package/src/adapter/resources/webgl-command-buffer.ts +24 -34
  159. package/src/adapter/resources/webgl-command-encoder.ts +14 -11
  160. package/src/adapter/resources/webgl-external-texture.ts +7 -7
  161. package/src/adapter/resources/webgl-framebuffer.ts +65 -58
  162. package/src/adapter/resources/webgl-query-set.ts +171 -0
  163. package/src/adapter/resources/webgl-render-pass.ts +27 -18
  164. package/src/adapter/resources/webgl-render-pipeline.ts +148 -73
  165. package/src/adapter/resources/webgl-sampler.ts +7 -10
  166. package/src/adapter/resources/webgl-shader.ts +65 -11
  167. package/src/adapter/resources/webgl-texture-view.ts +28 -0
  168. package/src/adapter/resources/webgl-texture.ts +43 -106
  169. package/src/adapter/resources/webgl-transform-feedback.ts +16 -22
  170. package/src/adapter/resources/webgl-vertex-array.ts +20 -21
  171. package/src/adapter/webgl-canvas-context.ts +7 -11
  172. package/src/adapter/webgl-device.ts +142 -162
  173. package/src/classic/accessor.ts +5 -4
  174. package/src/classic/clear.ts +25 -20
  175. package/src/classic/copy-and-blit.ts +12 -6
  176. package/src/classic/format-utils.ts +2 -1
  177. package/src/classic/typed-array-utils.ts +3 -7
  178. package/src/context/debug/spector.ts +9 -6
  179. package/src/context/debug/webgl-developer-tools.ts +31 -20
  180. package/src/context/{context → helpers}/create-browser-context.ts +9 -33
  181. package/src/context/{polyfill/context-data.ts → helpers/webgl-context-data.ts} +3 -2
  182. package/src/context/helpers/webgl-extensions.ts +17 -0
  183. package/src/context/parameters/unified-parameter-api.ts +6 -17
  184. package/src/context/parameters/webgl-parameter-tables.ts +118 -90
  185. package/src/context/state-tracker/deep-array-equal.ts +2 -1
  186. package/src/context/state-tracker/track-context-state.ts +29 -23
  187. package/src/context/state-tracker/with-parameters.ts +8 -8
  188. package/src/index.ts +16 -56
  189. package/src/types.ts +2 -1
  190. package/dist/adapter/converters/device-parameters.js.map +0 -1
  191. package/dist/adapter/converters/sampler-parameters.js.map +0 -1
  192. package/dist/adapter/converters/shader-formats.js.map +0 -1
  193. package/dist/adapter/converters/texture-formats.js.map +0 -1
  194. package/dist/adapter/converters/vertex-formats.js.map +0 -1
  195. package/dist/adapter/device-helpers/device-features.d.ts +0 -9
  196. package/dist/adapter/device-helpers/device-features.d.ts.map +0 -1
  197. package/dist/adapter/device-helpers/device-features.js +0 -96
  198. package/dist/adapter/device-helpers/device-features.js.map +0 -1
  199. package/dist/adapter/device-helpers/device-limits.d.ts +0 -52
  200. package/dist/adapter/device-helpers/device-limits.d.ts.map +0 -1
  201. package/dist/adapter/device-helpers/device-limits.js +0 -87
  202. package/dist/adapter/device-helpers/device-limits.js.map +0 -1
  203. package/dist/adapter/device-helpers/get-device-info.d.ts +0 -4
  204. package/dist/adapter/device-helpers/get-device-info.d.ts.map +0 -1
  205. package/dist/adapter/device-helpers/get-device-info.js +0 -71
  206. package/dist/adapter/device-helpers/get-device-info.js.map +0 -1
  207. package/dist/adapter/device-helpers/is-old-ie.d.ts +0 -2
  208. package/dist/adapter/device-helpers/is-old-ie.d.ts.map +0 -1
  209. package/dist/adapter/device-helpers/is-old-ie.js +0 -9
  210. package/dist/adapter/device-helpers/is-old-ie.js.map +0 -1
  211. package/dist/adapter/helpers/decode-webgl-types.js.map +0 -1
  212. package/dist/adapter/helpers/get-shader-layout.js.map +0 -1
  213. package/dist/adapter/helpers/parse-shader-compiler-log.js.map +0 -1
  214. package/dist/adapter/helpers/set-uniform.js.map +0 -1
  215. package/dist/adapter/helpers/webgl-topology-utils.js.map +0 -1
  216. package/dist/adapter/objects/constants-to-keys.js.map +0 -1
  217. package/dist/adapter/objects/webgl-renderbuffer.js.map +0 -1
  218. package/dist/adapter/objects/webgl-resource.js.map +0 -1
  219. package/dist/adapter/resources/webgl-buffer.js.map +0 -1
  220. package/dist/adapter/resources/webgl-command-buffer.js.map +0 -1
  221. package/dist/adapter/resources/webgl-command-encoder.js.map +0 -1
  222. package/dist/adapter/resources/webgl-external-texture.js.map +0 -1
  223. package/dist/adapter/resources/webgl-framebuffer.js.map +0 -1
  224. package/dist/adapter/resources/webgl-render-pass.js.map +0 -1
  225. package/dist/adapter/resources/webgl-render-pipeline.js.map +0 -1
  226. package/dist/adapter/resources/webgl-sampler.js.map +0 -1
  227. package/dist/adapter/resources/webgl-shader.js.map +0 -1
  228. package/dist/adapter/resources/webgl-texture.js.map +0 -1
  229. package/dist/adapter/resources/webgl-transform-feedback.js.map +0 -1
  230. package/dist/adapter/resources/webgl-vertex-array.js.map +0 -1
  231. package/dist/adapter/webgl-canvas-context.js.map +0 -1
  232. package/dist/adapter/webgl-device.js.map +0 -1
  233. package/dist/classic/accessor.js.map +0 -1
  234. package/dist/classic/clear.js.map +0 -1
  235. package/dist/classic/copy-and-blit.js.map +0 -1
  236. package/dist/classic/format-utils.js.map +0 -1
  237. package/dist/classic/typed-array-utils.js.map +0 -1
  238. package/dist/context/context/create-browser-context.d.ts.map +0 -1
  239. package/dist/context/context/create-browser-context.js +0 -53
  240. package/dist/context/context/create-browser-context.js.map +0 -1
  241. package/dist/context/context/create-headless-context.d.ts +0 -9
  242. package/dist/context/context/create-headless-context.d.ts.map +0 -1
  243. package/dist/context/context/create-headless-context.js +0 -42
  244. package/dist/context/context/create-headless-context.js.map +0 -1
  245. package/dist/context/context/webgl-checks.d.ts +0 -13
  246. package/dist/context/context/webgl-checks.d.ts.map +0 -1
  247. package/dist/context/context/webgl-checks.js +0 -31
  248. package/dist/context/context/webgl-checks.js.map +0 -1
  249. package/dist/context/debug/spector.js.map +0 -1
  250. package/dist/context/debug/webgl-developer-tools.js.map +0 -1
  251. package/dist/context/parameters/unified-parameter-api.js.map +0 -1
  252. package/dist/context/parameters/webgl-parameter-tables.js.map +0 -1
  253. package/dist/context/polyfill/context-data.d.ts.map +0 -1
  254. package/dist/context/polyfill/context-data.js +0 -12
  255. package/dist/context/polyfill/context-data.js.map +0 -1
  256. package/dist/context/polyfill/get-parameter-polyfill.d.ts +0 -2
  257. package/dist/context/polyfill/get-parameter-polyfill.d.ts.map +0 -1
  258. package/dist/context/polyfill/get-parameter-polyfill.js +0 -85
  259. package/dist/context/polyfill/get-parameter-polyfill.js.map +0 -1
  260. package/dist/context/polyfill/polyfill-context.d.ts +0 -5
  261. package/dist/context/polyfill/polyfill-context.d.ts.map +0 -1
  262. package/dist/context/polyfill/polyfill-context.js +0 -87
  263. package/dist/context/polyfill/polyfill-context.js.map +0 -1
  264. package/dist/context/polyfill/polyfill-table.d.ts +0 -48
  265. package/dist/context/polyfill/polyfill-table.d.ts.map +0 -1
  266. package/dist/context/polyfill/polyfill-table.js +0 -137
  267. package/dist/context/polyfill/polyfill-table.js.map +0 -1
  268. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts +0 -2
  269. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts.map +0 -1
  270. package/dist/context/polyfill/polyfill-vertex-array-object.js +0 -265
  271. package/dist/context/polyfill/polyfill-vertex-array-object.js.map +0 -1
  272. package/dist/context/state-tracker/deep-array-equal.js.map +0 -1
  273. package/dist/context/state-tracker/track-context-state.js.map +0 -1
  274. package/dist/context/state-tracker/with-parameters.js.map +0 -1
  275. package/dist/index.js.map +0 -1
  276. package/dist/types.js.map +0 -1
  277. package/src/adapter/device-helpers/device-features.ts +0 -161
  278. package/src/adapter/device-helpers/device-limits.ts +0 -155
  279. package/src/adapter/device-helpers/is-old-ie.ts +0 -14
  280. package/src/context/context/create-headless-context.ts +0 -51
  281. package/src/context/context/webgl-checks.ts +0 -51
  282. package/src/context/polyfill/get-parameter-polyfill.ts +0 -122
  283. package/src/context/polyfill/polyfill-context.ts +0 -104
  284. package/src/context/polyfill/polyfill-table.ts +0 -167
  285. package/src/context/polyfill/polyfill-vertex-array-object.ts +0 -365
@@ -1,917 +1,519 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { decodeTextureFormat } from '@luma.gl/core';
2
- import { isWebGL2 } from "../../context/context/webgl-checks.js";
5
+ import { GL } from '@luma.gl/constants';
6
+ import { getWebGLExtension } from "../../context/helpers/webgl-extensions.js";
3
7
  import { getGLFromVertexType } from "./vertex-formats.js";
8
+ /* eslint-disable camelcase */
9
+ // TEXTURE FEATURES
10
+ // Define local device feature strings to optimize minification
4
11
  const texture_compression_bc = 'texture-compression-bc';
5
12
  const texture_compression_astc = 'texture-compression-astc';
6
13
  const texture_compression_etc2 = 'texture-compression-etc2';
7
14
  const texture_compression_etc1_webgl = 'texture-compression-etc1-webgl';
8
15
  const texture_compression_pvrtc_webgl = 'texture-compression-pvrtc-webgl';
9
16
  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';
17
+ const float32_renderable = 'float32-renderable-webgl';
18
+ const float16_renderable = 'float16-renderable-webgl';
19
+ const rgb9e5ufloat_renderable = 'rgb9e5ufloat_renderable-webgl';
20
+ const snorm8_renderable = 'snorm8-renderable-webgl';
21
+ const norm16_renderable = 'norm16-renderable-webgl';
22
+ const snorm16_renderable = 'snorm16-renderable-webgl';
23
+ const float32_filterable = 'float32-filterable';
24
+ const float16_filterable = 'float16-filterable-webgl';
25
+ // Define local webgl extension strings to optimize minification
26
+ const X_S3TC = 'WEBGL_compressed_texture_s3tc'; // BC1, BC2, BC3
27
+ const X_S3TC_SRGB = 'WEBGL_compressed_texture_s3tc_srgb'; // BC1, BC2, BC3
28
+ const X_RGTC = 'EXT_texture_compression_rgtc'; // BC4, BC5
29
+ const X_BPTC = 'EXT_texture_compression_bptc'; // BC6, BC7
30
+ const X_ETC2 = 'WEBGL_compressed_texture_etc'; // Renamed from 'WEBGL_compressed_texture_es3'
15
31
  const X_ASTC = 'WEBGL_compressed_texture_astc';
16
32
  const X_ETC1 = 'WEBGL_compressed_texture_etc1';
17
33
  const X_PVRTC = 'WEBGL_compressed_texture_pvrtc';
18
34
  const X_ATC = 'WEBGL_compressed_texture_atc';
19
- const EXT_SRGB = 'EXT_sRGB';
20
- const EXT_TEXTURE_NORM16 = 'EXT_texture_norm16';
21
- const EXT_FLOAT_WEBGL1 = 'WEBGL_color_buffer_float';
22
- 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));
25
- 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])
35
+ // Define local webgl extension strings to optimize minification
36
+ const EXT_texture_norm16 = 'EXT_texture_norm16';
37
+ const EXT_render_snorm = 'EXT_render_snorm';
38
+ const EXT_color_buffer_float = 'EXT_color_buffer_float';
39
+ // prettier-ignore
40
+ export const TEXTURE_FEATURES = {
41
+ 'float32-renderable-webgl': ['EXT_color_buffer_float'],
42
+ 'float16-renderable-webgl': ['EXT_color_buffer_half_float'],
43
+ 'rgb9e5ufloat_renderable-webgl': ['WEBGL_render_shared_exponent'],
44
+ 'snorm8-renderable-webgl': [EXT_render_snorm],
45
+ 'norm16-renderable-webgl': [EXT_texture_norm16],
46
+ 'snorm16-renderable-webgl': [EXT_texture_norm16, EXT_render_snorm],
47
+ 'float32-filterable': ['OES_texture_float_linear'],
48
+ 'float16-filterable-webgl': ['OES_texture_half_float_linear'],
49
+ 'texture-filterable-anisotropic-webgl': ['EXT_texture_filter_anisotropic'],
50
+ 'texture-blend-float-webgl': ['EXT_float_blend'],
51
+ 'texture-compression-bc': [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC],
52
+ // 'texture-compression-bc3-srgb-webgl': [X_S3TC_SRGB],
53
+ // 'texture-compression-bc3-webgl': [X_S3TC],
54
+ 'texture-compression-bc5-webgl': [X_RGTC],
55
+ 'texture-compression-bc7-webgl': [X_BPTC],
56
+ 'texture-compression-etc2': [X_ETC2],
57
+ 'texture-compression-astc': [X_ASTC],
58
+ 'texture-compression-etc1-webgl': [X_ETC1],
59
+ 'texture-compression-pvrtc-webgl': [X_PVRTC],
60
+ 'texture-compression-atc-webgl': [X_ATC]
44
61
  };
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;
62
+ /** Return a list of texture feature strings (for Device.features). Mainly compressed texture support */
63
+ // export function getTextureFeatures(
64
+ // gl: WebGL2RenderingContext,
65
+ // extensions: GLExtensions
66
+ // ): DeviceFeature[] {
67
+ // const textureFeatures = Object.keys(TEXTURE_FEATURES) as DeviceFeature[];
68
+ // return textureFeatures.filter(feature => checkTextureFeature(gl, feature, extensions));
69
+ // }
70
+ export function isTextureFeature(feature) {
71
+ return feature in TEXTURE_FEATURES;
48
72
  }
49
- const checkTextureFeatures = (gl, features) => features.every(feature => checkTextureFeature(gl, feature));
50
- export function getTextureFeatures(gl) {
51
- const textureFeatures = Object.keys(TEXTURE_FEATURE_CHECKS);
52
- return textureFeatures.filter(feature => checkTextureFeature(gl, feature));
73
+ /** Checks a texture feature (for Device.features). Mainly compressed texture support */
74
+ export function checkTextureFeature(gl, feature, extensions) {
75
+ const textureExtensions = TEXTURE_FEATURES[feature] || [];
76
+ return textureExtensions.every(extension => getWebGLExtension(gl, extension, extensions));
53
77
  }
78
+ // TABLES
79
+ /**
80
+ * Texture format data -
81
+ * Exported but can change without notice
82
+ */
83
+ // prettier-ignore
54
84
  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
- }
85
+ // Unsized formats that leave the precision up to the driver. TODO - Fix bpp constants
86
+ 'rgb8unorm-unsized': { gl: 6407, b: 4, c: 2, bpp: 4,
87
+ dataFormat: 6407, types: [5121, 33635] },
88
+ 'rgba8unorm-unsized': { gl: 6408, b: 4, c: 2, bpp: 4,
89
+ dataFormat: 6408, types: [5121, 32819, 32820] },
90
+ // 'r8unorm-unsized': {gl: GL.LUMINANCE, b: 4, c: 2, bpp: 4},
91
+ // 'rgb8unorm-srgb-unsized': {gl: GL.SRGB_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
92
+ // 'rgba8unorm-srgb-unsized': {gl: GL.SRGB_ALPHA_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
93
+ // 8-bit formats
94
+ 'r8unorm': { gl: 33321, b: 1, c: 1, rb: true },
95
+ 'r8snorm': { gl: 36756, b: 1, c: 1, render: snorm8_renderable },
96
+ 'r8uint': { gl: 33330, b: 1, c: 1, rb: true },
97
+ 'r8sint': { gl: 33329, b: 1, c: 1, rb: true },
98
+ // 16-bit formats
99
+ 'rg8unorm': { gl: 33323, b: 2, c: 2, rb: true },
100
+ 'rg8snorm': { gl: 36757, b: 2, c: 2, render: snorm8_renderable },
101
+ 'rg8uint': { gl: 33336, b: 2, c: 2, rb: true },
102
+ 'rg8sint': { gl: 33335, b: 2, c: 2, rb: true },
103
+ 'r16uint': { gl: 33332, b: 2, c: 1, rb: true },
104
+ 'r16sint': { gl: 33331, b: 2, c: 1, rb: true },
105
+ 'r16float': { gl: 33325, b: 2, c: 1, render: float16_renderable, filter: 'float16-filterable-webgl', rb: true },
106
+ 'r16unorm-webgl': { gl: 33322, b: 2, c: 1, f: norm16_renderable, rb: true },
107
+ 'r16snorm-webgl': { gl: 36760, b: 2, c: 1, f: snorm16_renderable },
108
+ // Packed 16-bit formats
109
+ 'rgba4unorm-webgl': { gl: 32854, b: 2, c: 4, wgpu: false, rb: true },
110
+ 'rgb565unorm-webgl': { gl: 36194, b: 2, c: 4, wgpu: false, rb: true },
111
+ 'rgb5a1unorm-webgl': { gl: 32855, b: 2, c: 4, wgpu: false, rb: true },
112
+ // 24-bit formats
113
+ 'rgb8unorm-webgl': { gl: 32849, b: 3, c: 3, wgpu: false },
114
+ 'rgb8snorm-webgl': { gl: 36758, b: 3, c: 3, wgpu: false },
115
+ // 32-bit formats
116
+ 'rgba8unorm': { gl: 32856, b: 4, c: 2, bpp: 4 },
117
+ 'rgba8unorm-srgb': { gl: 35907, b: 4, c: 4, bpp: 4 },
118
+ 'rgba8snorm': { gl: 36759, b: 4, c: 4, render: snorm8_renderable },
119
+ 'rgba8uint': { gl: 36220, b: 4, c: 4, bpp: 4 },
120
+ 'rgba8sint': { gl: 36238, b: 4, c: 4, bpp: 4 },
121
+ // reverse colors, webgpu only
122
+ 'bgra8unorm': { b: 4, c: 4 },
123
+ 'bgra8unorm-srgb': { b: 4, c: 4 },
124
+ 'rg16uint': { gl: 33338, b: 4, c: 1, bpp: 4 },
125
+ 'rg16sint': { gl: 33337, b: 4, c: 2, bpp: 4 },
126
+ // When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
127
+ 'rg16float': { gl: 33327, bpp: 4, b: 4, c: 2, render: float16_renderable, filter: float16_filterable, rb: true },
128
+ 'rg16unorm-webgl': { gl: 33324, b: 2, c: 2, render: norm16_renderable },
129
+ 'rg16snorm-webgl': { gl: 36761, b: 2, c: 2, render: snorm16_renderable },
130
+ 'r32uint': { gl: 33334, b: 4, c: 1, bpp: 4, rb: true },
131
+ 'r32sint': { gl: 33333, b: 4, c: 1, bpp: 4, rb: true },
132
+ 'r32float': { gl: 33326, bpp: 4, b: 4, c: 1, render: float32_renderable, filter: float32_filterable },
133
+ // Packed 32-bit formats
134
+ 'rgb9e5ufloat': { gl: 35901, b: 4, c: 3, p: 1, render: rgb9e5ufloat_renderable }, // , filter: true},
135
+ 'rg11b10ufloat': { gl: 35898, b: 4, c: 3, p: 1, render: float32_renderable, rb: true },
136
+ 'rgb10a2unorm': { gl: 32857, b: 4, c: 4, p: 1, rb: true },
137
+ 'rgb10a2uint-webgl': { b: 4, c: 4, gl: 36975, p: 1, wgpu: false, bpp: 4, rb: true },
138
+ // 48-bit formats
139
+ 'rgb16unorm-webgl': { gl: 32852, b: 2, c: 3, f: norm16_renderable }, // rgb not renderable
140
+ 'rgb16snorm-webgl': { gl: 36762, b: 2, c: 3, f: norm16_renderable }, // rgb not renderable
141
+ // 64-bit formats
142
+ 'rg32uint': { gl: 33340, b: 8, c: 2, rb: true },
143
+ 'rg32sint': { gl: 33339, b: 8, c: 2, rb: true },
144
+ 'rg32float': { gl: 33328, b: 8, c: 2, render: float32_renderable, filter: float32_filterable, rb: true },
145
+ 'rgba16uint': { gl: 36214, b: 8, c: 4, rb: true },
146
+ 'rgba16sint': { gl: 36232, b: 8, c: 4, rb: true },
147
+ 'rgba16float': { gl: 34842, b: 8, c: 4, render: float16_renderable, filter: float16_filterable },
148
+ 'rgba16unorm-webgl': { gl: 32859, b: 2, c: 4, render: norm16_renderable, rb: true },
149
+ 'rgba16snorm-webgl': { gl: 36763, b: 2, c: 4, render: snorm16_renderable },
150
+ // 96-bit formats (deprecated!)
151
+ 'rgb32float-webgl': { gl: 34837, render: float32_renderable, filter: float32_filterable,
152
+ gl2ext: EXT_color_buffer_float, dataFormat: 6407, types: [5126] },
153
+ // 128-bit formats
154
+ 'rgba32uint': { gl: 36208, b: 16, c: 4, rb: true },
155
+ 'rgba32sint': { gl: 36226, b: 16, c: 4, rb: true },
156
+ 'rgba32float': { gl: 34836, b: 16, c: 4, render: float32_renderable, filter: float32_filterable, rb: true },
157
+ // Depth and stencil formats
158
+ 'stencil8': { gl: 36168, b: 1, c: 1, attachment: 36128, rb: true }, // 8 stencil bits
159
+ 'depth16unorm': { gl: 33189, b: 2, c: 1, attachment: 36096,
160
+ dataFormat: 6402, types: [5123], rb: true }, // 16 depth bits
161
+ 'depth24plus': { gl: 33190, b: 3, c: 1, attachment: 36096,
162
+ dataFormat: 6402, types: [5125] },
163
+ 'depth32float': { gl: 36012, b: 4, c: 1, attachment: 36096,
164
+ dataFormat: 6402, types: [5126], rb: true },
165
+ // The depth component of the "depth24plus" and "depth24plus-stencil8" formats may be implemented as either a 24-bit depth value or a "depth32float" value.
166
+ 'depth24plus-stencil8': { gl: 35056, b: 4, c: 2, p: 1, attachment: 33306, rb: true, depthTexture: true,
167
+ dataFormat: 34041, types: [34042] },
168
+ // "depth24unorm-stencil8" feature
169
+ 'depth24unorm-stencil8': { gl: 35056, b: 4, c: 2, p: 1, attachment: 33306,
170
+ dataFormat: 34041, types: [34042], rb: true },
171
+ // "depth32float-stencil8" feature - TODO below is render buffer only?
172
+ 'depth32float-stencil8': { gl: 36013, b: 5, c: 2, p: 1, attachment: 33306,
173
+ dataFormat: 34041, types: [36269], rb: true },
174
+ // BC compressed formats: check device.features.has("texture-compression-bc");
175
+ 'bc1-rgb-unorm-webgl': { gl: 33776, x: X_S3TC, f: texture_compression_bc },
176
+ 'bc1-rgb-unorm-srgb-webgl': { gl: 35916, x: X_S3TC_SRGB, f: texture_compression_bc },
177
+ 'bc1-rgba-unorm': { gl: 33777, x: X_S3TC, f: texture_compression_bc },
178
+ 'bc1-rgba-unorm-srgb': { gl: 35916, x: X_S3TC_SRGB, f: texture_compression_bc },
179
+ 'bc2-rgba-unorm': { gl: 33778, x: X_S3TC, f: texture_compression_bc },
180
+ 'bc2-rgba-unorm-srgb': { gl: 35918, x: X_S3TC_SRGB, f: texture_compression_bc },
181
+ 'bc3-rgba-unorm': { gl: 33779, x: X_S3TC, f: texture_compression_bc },
182
+ 'bc3-rgba-unorm-srgb': { gl: 35919, x: X_S3TC_SRGB, f: texture_compression_bc },
183
+ 'bc4-r-unorm': { gl: 36283, x: X_RGTC, f: texture_compression_bc },
184
+ 'bc4-r-snorm': { gl: 36284, x: X_RGTC, f: texture_compression_bc },
185
+ 'bc5-rg-unorm': { gl: 36285, x: X_RGTC, f: texture_compression_bc },
186
+ 'bc5-rg-snorm': { gl: 36286, x: X_RGTC, f: texture_compression_bc },
187
+ 'bc6h-rgb-ufloat': { gl: 36495, x: X_BPTC, f: texture_compression_bc },
188
+ 'bc6h-rgb-float': { gl: 36494, x: X_BPTC, f: texture_compression_bc },
189
+ 'bc7-rgba-unorm': { gl: 36492, x: X_BPTC, f: texture_compression_bc },
190
+ 'bc7-rgba-unorm-srgb': { gl: 36493, x: X_BPTC, f: texture_compression_bc },
191
+ // WEBGL_compressed_texture_etc: device.features.has("texture-compression-etc2")
192
+ // Note: Supposedly guaranteed availability compressed formats in WebGL2, but through CPU decompression
193
+ 'etc2-rgb8unorm': { gl: 37492, f: texture_compression_etc2 },
194
+ 'etc2-rgb8unorm-srgb': { gl: 37494, f: texture_compression_etc2 },
195
+ 'etc2-rgb8a1unorm': { gl: 37496, f: texture_compression_etc2 },
196
+ 'etc2-rgb8a1unorm-srgb': { gl: 37497, f: texture_compression_etc2 },
197
+ 'etc2-rgba8unorm': { gl: 37493, f: texture_compression_etc2 },
198
+ 'etc2-rgba8unorm-srgb': { gl: 37495, f: texture_compression_etc2 },
199
+ 'eac-r11unorm': { gl: 37488, f: texture_compression_etc2 },
200
+ 'eac-r11snorm': { gl: 37489, f: texture_compression_etc2 },
201
+ 'eac-rg11unorm': { gl: 37490, f: texture_compression_etc2 },
202
+ 'eac-rg11snorm': { gl: 37491, f: texture_compression_etc2 },
203
+ // X_ASTC compressed formats: device.features.has("texture-compression-astc")
204
+ 'astc-4x4-unorm': { gl: 37808, f: texture_compression_astc },
205
+ 'astc-4x4-unorm-srgb': { gl: 37840, f: texture_compression_astc },
206
+ 'astc-5x4-unorm': { gl: 37809, f: texture_compression_astc },
207
+ 'astc-5x4-unorm-srgb': { gl: 37841, f: texture_compression_astc },
208
+ 'astc-5x5-unorm': { gl: 37810, f: texture_compression_astc },
209
+ 'astc-5x5-unorm-srgb': { gl: 37842, f: texture_compression_astc },
210
+ 'astc-6x5-unorm': { gl: 37811, f: texture_compression_astc },
211
+ 'astc-6x5-unorm-srgb': { gl: 37843, f: texture_compression_astc },
212
+ 'astc-6x6-unorm': { gl: 37812, f: texture_compression_astc },
213
+ 'astc-6x6-unorm-srgb': { gl: 37844, f: texture_compression_astc },
214
+ 'astc-8x5-unorm': { gl: 37813, f: texture_compression_astc },
215
+ 'astc-8x5-unorm-srgb': { gl: 37845, f: texture_compression_astc },
216
+ 'astc-8x6-unorm': { gl: 37814, f: texture_compression_astc },
217
+ 'astc-8x6-unorm-srgb': { gl: 37846, f: texture_compression_astc },
218
+ 'astc-8x8-unorm': { gl: 37815, f: texture_compression_astc },
219
+ 'astc-8x8-unorm-srgb': { gl: 37847, f: texture_compression_astc },
220
+ 'astc-10x5-unorm': { gl: 37819, f: texture_compression_astc },
221
+ 'astc-10x5-unorm-srgb': { gl: 37851, f: texture_compression_astc },
222
+ 'astc-10x6-unorm': { gl: 37817, f: texture_compression_astc },
223
+ 'astc-10x6-unorm-srgb': { gl: 37849, f: texture_compression_astc },
224
+ 'astc-10x8-unorm': { gl: 37818, f: texture_compression_astc },
225
+ 'astc-10x8-unorm-srgb': { gl: 37850, f: texture_compression_astc },
226
+ 'astc-10x10-unorm': { gl: 37819, f: texture_compression_astc },
227
+ 'astc-10x10-unorm-srgb': { gl: 37851, f: texture_compression_astc },
228
+ 'astc-12x10-unorm': { gl: 37820, f: texture_compression_astc },
229
+ 'astc-12x10-unorm-srgb': { gl: 37852, f: texture_compression_astc },
230
+ 'astc-12x12-unorm': { gl: 37821, f: texture_compression_astc },
231
+ 'astc-12x12-unorm-srgb': { gl: 37853, f: texture_compression_astc },
232
+ // WEBGL_compressed_texture_pvrtc
233
+ 'pvrtc-rgb4unorm-webgl': { gl: 35840, f: texture_compression_pvrtc_webgl },
234
+ 'pvrtc-rgba4unorm-webgl': { gl: 35842, f: texture_compression_pvrtc_webgl },
235
+ 'pvrtc-rbg2unorm-webgl': { gl: 35841, f: texture_compression_pvrtc_webgl },
236
+ 'pvrtc-rgba2unorm-webgl': { gl: 35843, f: texture_compression_pvrtc_webgl },
237
+ // WEBGL_compressed_texture_etc1
238
+ 'etc1-rbg-unorm-webgl': { gl: 36196, f: texture_compression_etc1_webgl },
239
+ // WEBGL_compressed_texture_atc
240
+ 'atc-rgb-unorm-webgl': { gl: 35986, f: texture_compression_atc_webgl },
241
+ 'atc-rgba-unorm-webgl': { gl: 35986, f: texture_compression_atc_webgl },
242
+ 'atc-rgbai-unorm-webgl': { gl: 34798, f: texture_compression_atc_webgl }
734
243
  };
244
+ /** Legal combinations for internalFormat, format and type *
245
+ // [GL.DEPTH_COMPONENT]: {types: [GL.UNSIGNED_SHORT, GL.UNSIGNED_INT, GL.UNSIGNED_INT_24_8]},
246
+ // [GL.DEPTH_STENCIL]: ,
247
+ // Sized texture format
248
+ // R
249
+ [GL.R8]: {dataFormat: GL.RED, types: [GL.UNSIGNED_BYTE], gl2: true},
250
+ [GL.R16F]: {dataFormat: GL.RED, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
251
+ [GL.R8UI]: {dataFormat: GL.RED_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
252
+ // // RG
253
+ [GL.RG8]: {dataFormat: GL.RG, types: [GL.UNSIGNED_BYTE], gl2: true},
254
+ [GL.RG16F]: {dataFormat: GL.RG, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
255
+ [GL.RG8UI]: {dataFormat: GL.RG_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
256
+ // // RGB
257
+ [GL.RGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
258
+ [GL.SRGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
259
+ [GL.RGB16F]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
260
+ [GL.RGB8UI]: {dataFormat: GL.RGB_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
261
+ // // RGBA
262
+
263
+ [GL.RGB565]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5], gl2: true},
264
+ [GL.R11F_G11F_B10F]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_INT_10F_11F_11F_REV, GL.HALF_FLOAT, GL.FLOAT], gl2: true},
265
+ [GL.RGB9_E5]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
266
+ [GL.RGBA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true},
267
+ [GL.SRGB8_ALPHA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true, gl1ext: EXT_SRGB},
268
+ [GL.RGB5_A1]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_5_5_1], gl2: true},
269
+ [GL.RGBA4]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4], gl2: true},
270
+ [GL.RGBA16F]: {dataFormat: GL.RGBA, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
271
+ [GL.RGBA8UI]: {dataFormat: GL.RGBA_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true}
272
+ */
273
+ /* This table is now baked into the above table
274
+ type RenderbufferFormat = {
275
+ bpp: number;
276
+ gl2?: boolean;
277
+ ext?: string;
278
+ };
279
+
280
+ export const RENDERBUFFER_FORMATS: Record<string, RenderbufferFormat> = {
281
+ [GL.DEPTH_COMPONENT16]: {bpp: 2}, // 16 depth bits.
282
+ // TODO - Not clear which webgpu value to map this to.
283
+ // [GL.DEPTH_COMPONENT24]: {gl2: true, bpp: 3},
284
+ [GL.DEPTH_COMPONENT32F]: {gl2: true, bpp: 4},
285
+
286
+ [GL.STENCIL_INDEX8]: {bpp: 1}, // 8 stencil bits.
287
+
288
+ [GL.DEPTH_STENCIL]: {bpp: 4},
289
+ [GL.DEPTH24_STENCIL8]: {gl2: true, bpp: 4},
290
+ [GL.DEPTH32F_STENCIL8]: {gl2: true, bpp: 5},
291
+
292
+ // When using a WebGL 1 context, color renderbuffer formats are limited
293
+ [GL.RGBA4]: {gl2: true, bpp: 2},
294
+ [GL.RGB565]: {gl2: true, bpp: 2},
295
+ [GL.RGB5_A1]: {gl2: true, bpp: 2},
296
+
297
+ // When using a WebGL 2 context, the following values are available additionally:
298
+ [GL.R8]: {gl2: true, bpp: 1},
299
+ [GL.R8UI]: {gl2: true, bpp: 1},
300
+ [GL.R8I]: {gl2: true, bpp: 1},
301
+ [GL.R16UI]: {gl2: true, bpp: 2},
302
+ [GL.R16I]: {gl2: true, bpp: 2},
303
+ [GL.R32UI]: {gl2: true, bpp: 4},
304
+ [GL.R32I]: {gl2: true, bpp: 4},
305
+ [GL.RG8]: {gl2: true, bpp: 2},
306
+ [GL.RG8UI]: {gl2: true, bpp: 2},
307
+ [GL.RG8I]: {gl2: true, bpp: 2},
308
+ [GL.RG16UI]: {gl2: true, bpp: 4},
309
+ [GL.RG16I]: {gl2: true, bpp: 4},
310
+ [GL.RG32UI]: {gl2: true, bpp: 8},
311
+ [GL.RG32I]: {gl2: true, bpp: 8},
312
+ [GL.RGB8]: {gl2: true, bpp: 3},
313
+ [GL.RGBA8]: {gl2: true, bpp: 4},
314
+ // [GL.SRGB8_ALPHA8]: {gl2: true, gl1: SRGB}, // When using the EXT_sRGB WebGL1 extension
315
+ [GL.RGB10_A2]: {gl2: true, bpp: 4},
316
+ [GL.RGBA8UI]: {gl2: true, bpp: 4},
317
+ [GL.RGBA8I]: {gl2: true, bpp: 4},
318
+ [GL.RGB10_A2UI]: {gl2: true, bpp: 4},
319
+ [GL.RGBA16UI]: {gl2: true, bpp: 8},
320
+ [GL.RGBA16I]: {gl2: true, bpp: 8},
321
+ [GL.RGBA32I]: {gl2: true, bpp: 16},
322
+ [GL.RGBA32UI]: {gl2: true, bpp: 16},
323
+
324
+ // When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
325
+ [GL.R16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 2},
326
+ [GL.RG16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4},
327
+ [GL.RGBA16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
328
+ [GL.R32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4},
329
+ [GL.RG32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
330
+ // TODO - can't get WEBGL_color_buffer_float to work on renderbuffers
331
+ [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 16},
332
+ // [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2},
333
+ [GL.R11F_G11F_B10F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4}
334
+ };
335
+ */
336
+ /** @deprecated should be removed */
735
337
  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
338
+ [6403]: 1,
339
+ [36244]: 1,
340
+ [33319]: 2,
341
+ [33320]: 2,
342
+ [6407]: 3,
343
+ [36248]: 3,
344
+ [6408]: 4,
345
+ [36249]: 4,
346
+ [6402]: 1,
347
+ [34041]: 1,
348
+ [6406]: 1,
349
+ [6409]: 1,
350
+ [6410]: 2
749
351
  };
352
+ /** @deprecated should be removed */
750
353
  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
354
+ [5126]: 4,
355
+ [5125]: 4,
356
+ [5124]: 4,
357
+ [5123]: 2,
358
+ [5122]: 2,
359
+ [5131]: 2,
360
+ [5120]: 1,
361
+ [5121]: 1
759
362
  };
760
- 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;
363
+ // FUNCTIONS
364
+ /** Checks if a texture format is supported */
365
+ export function isTextureFormatSupported(gl, format, extensions) {
366
+ const info = TEXTURE_FORMATS[format];
367
+ if (!info) {
368
+ return false;
369
+ }
370
+ // Check that we have a GL constant
371
+ if (info.gl === undefined) {
372
+ return false;
373
+ }
374
+ // Check extensions
375
+ const extension = info.x || info.gl2ext;
376
+ if (extension) {
377
+ return Boolean(getWebGLExtension(gl, extension, extensions));
378
+ }
379
+ return true;
774
380
  }
775
- 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);
381
+ export function isRenderbufferFormatSupported(gl, format, extensions) {
382
+ // Note: Order is important since the function call initializes extensions.
383
+ return isTextureFormatSupported(gl, format, extensions) && TEXTURE_FORMATS[format]?.rb;
778
384
  }
385
+ /**
386
+ * Map WebGL texture formats (GL constants) to WebGPU-style TextureFormat strings
387
+ */
779
388
  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];
389
+ if (typeof format === 'string') {
390
+ return format;
391
+ }
392
+ const entry = Object.entries(TEXTURE_FORMATS).find(([, entry]) => entry.gl === format);
393
+ if (!entry) {
394
+ throw new Error(`Unknown texture format ${format}`);
395
+ }
396
+ return entry[0];
791
397
  }
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;
398
+ /**
399
+ * Map WebGPU style texture format strings to GL constants
400
+ */
401
+ export function convertTextureFormatToGL(format) {
402
+ const formatInfo = TEXTURE_FORMATS[format];
403
+ const webglFormat = formatInfo?.gl;
404
+ if (webglFormat === undefined) {
405
+ throw new Error(`Unsupported texture format ${format}`);
406
+ }
407
+ return webglFormat;
799
408
  }
800
- export function getTextureFormatSupport(gl, formatOrGL) {
801
- const format = convertGLToTextureFormat(formatOrGL);
802
- const info = TEXTURE_FORMATS[format];
803
- if (!info) {
409
+ /** Checks if a texture format is supported */
410
+ export function getTextureFormatSupport(gl, format, extensions) {
411
+ const info = TEXTURE_FORMATS[format];
412
+ if (!info) {
413
+ return { supported: false };
414
+ }
415
+ // let decoded;
416
+ // try {
417
+ // decoded = decodeTextureFormat(format);
418
+ // } catch {}
419
+ // Support Check that we have a GL constant
420
+ let supported = info.gl === undefined;
421
+ supported = supported && checkTextureFeature(gl, info.f, extensions);
422
+ // Filtering
423
+ // const filterable = info.filter
424
+ // ? checkTextureFeature(gl, infofilter])
425
+ // : decoded && !decoded.signed;
426
+ // const renderable = info.filter
427
+ // ? checkTextureFeature(gl, inforender])
428
+ // : decoded && !decoded.signed;
804
429
  return {
805
- supported: false
430
+ supported,
431
+ renderable: supported && checkTextureFeature(gl, info.render, extensions),
432
+ filterable: supported && checkTextureFeature(gl, info.filter, extensions),
433
+ blendable: false, // tod,
434
+ storable: false
806
435
  };
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
436
  }
818
- 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;
437
+ /** Checks whether linear filtering (interpolated sampling) is available for floating point textures */
438
+ export function isTextureFormatFilterable(gl, format, extensions) {
439
+ if (!isTextureFormatSupported(gl, format, extensions)) {
440
+ return false;
441
+ }
442
+ if (format.startsWith('depth') || format.startsWith('stencil')) {
443
+ return false;
444
+ }
445
+ try {
446
+ const decoded = decodeTextureFormat(format);
447
+ if (decoded.signed) {
448
+ return false;
449
+ }
827
450
  }
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;
451
+ catch {
452
+ return false;
453
+ }
454
+ if (format.endsWith('32float')) {
455
+ return Boolean(getWebGLExtension(gl, 'OES_texture_float_linear, extensions', extensions));
456
+ }
457
+ if (format.endsWith('16float')) {
458
+ return Boolean(getWebGLExtension(gl, 'OES_texture_half_float_linear, extensions', extensions));
459
+ }
460
+ return true;
838
461
  }
839
- 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;
462
+ export function isTextureFormatRenderable(gl, format, extensions) {
463
+ if (!isTextureFormatSupported(gl, format, extensions)) {
464
+ return false;
465
+ }
466
+ if (typeof format === 'number') {
467
+ return false; // isTextureFormatFilterableWebGL(gl, format);
468
+ }
469
+ // TODO depends on device...
470
+ return true;
848
471
  }
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
- };
472
+ /** Get parameters necessary to work with format in WebGL: internalFormat, dataFormat, type, compressed, */
473
+ export function getWebGLTextureParameters(format) {
474
+ const formatData = TEXTURE_FORMATS[format];
475
+ const webglFormat = convertTextureFormatToGL(format);
476
+ const decoded = decodeTextureFormat(format);
477
+ return {
478
+ format: webglFormat,
479
+ dataFormat: formatData?.dataFormat ||
480
+ getWebGLPixelDataFormat(decoded.format, decoded.integer, decoded.normalized, webglFormat),
481
+ // depth formats don't have a type
482
+ type: decoded.dataType
483
+ ? getGLFromVertexType(decoded.dataType)
484
+ : formatData?.types?.[0] || 5121,
485
+ // @ts-expect-error
486
+ compressed: decoded.compressed
487
+ };
859
488
  }
860
489
  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
- }
490
+ const info = TEXTURE_FORMATS[format];
491
+ if (!info?.attachment) {
492
+ throw new Error(`${format} is not a depth stencil format`);
493
+ }
494
+ return info.attachment;
892
495
  }
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;
496
+ /** TODO - VERY roundabout legacy way of calculating bytes per pixel */
497
+ export function getTextureFormatBytesPerPixel(format) {
498
+ // TODO remove webgl1 support
499
+ const params = getWebGLTextureParameters(format);
500
+ // NOTE(Tarek): Default to RGBA bytes
501
+ const channels = DATA_FORMAT_CHANNELS[params.dataFormat] || 4;
502
+ const channelSize = TYPE_SIZES[params.type] || 1;
503
+ return channels * channelSize;
899
504
  }
505
+ // DATA TYPE HELPERS
900
506
  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
- }
507
+ // WebGL1 formats use same internalFormat
508
+ if (format === 6408 || format === 6407) {
509
+ return format;
510
+ }
511
+ // prettier-ignore
512
+ switch (dataFormat) {
513
+ case 'r': return integer && !normalized ? 36244 : 6403;
514
+ case 'rg': return integer && !normalized ? 33320 : 33319;
515
+ case 'rgb': return integer && !normalized ? 36248 : 6407;
516
+ case 'rgba': return integer && !normalized ? 36249 : 6408;
517
+ default: return 6408;
518
+ }
916
519
  }
917
- //# sourceMappingURL=texture-formats.js.map