@luma.gl/webgl 9.0.0-beta.4 → 9.0.0-beta.6

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 (288) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  2. package/dist/adapter/converters/device-parameters.js +297 -155
  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 +13 -19
  9. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  10. package/dist/adapter/converters/texture-formats.js +474 -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/device-features.d.ts +2 -5
  14. package/dist/adapter/device-helpers/device-features.d.ts.map +1 -1
  15. package/dist/adapter/device-helpers/device-features.js +56 -87
  16. package/dist/adapter/device-helpers/device-limits.d.ts +2 -4
  17. package/dist/adapter/device-helpers/device-limits.d.ts.map +1 -1
  18. package/dist/adapter/device-helpers/device-limits.js +88 -83
  19. package/dist/adapter/device-helpers/get-device-info.d.ts +1 -1
  20. package/dist/adapter/device-helpers/get-device-info.d.ts.map +1 -1
  21. package/dist/adapter/device-helpers/get-device-info.js +79 -63
  22. package/dist/adapter/device-helpers/webgl-device-features.d.ts +19 -0
  23. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -0
  24. package/dist/adapter/device-helpers/webgl-device-features.js +86 -0
  25. package/dist/adapter/device-helpers/webgl-device-info.d.ts +5 -0
  26. package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -0
  27. package/dist/adapter/device-helpers/webgl-device-info.js +90 -0
  28. package/dist/adapter/device-helpers/webgl-device-limits.d.ts +35 -0
  29. package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -0
  30. package/dist/adapter/device-helpers/webgl-device-limits.js +47 -0
  31. package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -1
  32. package/dist/adapter/helpers/decode-webgl-types.js +88 -76
  33. package/dist/adapter/helpers/get-shader-layout.d.ts +1 -1
  34. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  35. package/dist/adapter/helpers/get-shader-layout.js +261 -225
  36. package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
  37. package/dist/adapter/helpers/parse-shader-compiler-log.js +47 -37
  38. package/dist/adapter/helpers/set-uniform.d.ts +1 -1
  39. package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
  40. package/dist/adapter/helpers/set-uniform.js +68 -82
  41. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
  42. package/dist/adapter/helpers/webgl-topology-utils.js +78 -93
  43. package/dist/adapter/objects/constants-to-keys.d.ts +1 -1
  44. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  45. package/dist/adapter/objects/constants-to-keys.js +19 -12
  46. package/dist/adapter/objects/webgl-renderbuffer.d.ts +2 -2
  47. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
  48. package/dist/adapter/objects/webgl-renderbuffer.js +86 -77
  49. package/dist/adapter/objects/webgl-resource.d.ts +3 -25
  50. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  51. package/dist/adapter/objects/webgl-resource.js +102 -146
  52. package/dist/adapter/resources/webgl-buffer.d.ts +3 -4
  53. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  54. package/dist/adapter/resources/webgl-buffer.js +161 -119
  55. package/dist/adapter/resources/webgl-command-buffer.d.ts +1 -1
  56. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  57. package/dist/adapter/resources/webgl-command-buffer.js +266 -168
  58. package/dist/adapter/resources/webgl-command-encoder.d.ts +8 -3
  59. package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
  60. package/dist/adapter/resources/webgl-command-encoder.js +33 -39
  61. package/dist/adapter/resources/webgl-external-texture.js +93 -1
  62. package/dist/adapter/resources/webgl-framebuffer.d.ts +8 -10
  63. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  64. package/dist/adapter/resources/webgl-framebuffer.js +167 -137
  65. package/dist/adapter/resources/webgl-query-set.d.ts +44 -0
  66. package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -0
  67. package/dist/adapter/resources/webgl-query-set.js +136 -0
  68. package/dist/adapter/resources/webgl-render-pass.d.ts +3 -1
  69. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  70. package/dist/adapter/resources/webgl-render-pass.js +124 -90
  71. package/dist/adapter/resources/webgl-render-pipeline.d.ts +15 -6
  72. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  73. package/dist/adapter/resources/webgl-render-pipeline.js +356 -221
  74. package/dist/adapter/resources/webgl-sampler.d.ts +1 -3
  75. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  76. package/dist/adapter/resources/webgl-sampler.js +43 -33
  77. package/dist/adapter/resources/webgl-shader.d.ts +12 -2
  78. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  79. package/dist/adapter/resources/webgl-shader.js +114 -47
  80. package/dist/adapter/resources/webgl-texture-view.d.ts +14 -0
  81. package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -0
  82. package/dist/adapter/resources/webgl-texture-view.js +18 -0
  83. package/dist/adapter/resources/webgl-texture.d.ts +6 -9
  84. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  85. package/dist/adapter/resources/webgl-texture.js +615 -695
  86. package/dist/adapter/resources/webgl-transform-feedback.d.ts +2 -2
  87. package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
  88. package/dist/adapter/resources/webgl-transform-feedback.js +141 -143
  89. package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -3
  90. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  91. package/dist/adapter/resources/webgl-vertex-array.js +229 -157
  92. package/dist/adapter/webgl-canvas-context.d.ts +2 -2
  93. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  94. package/dist/adapter/webgl-canvas-context.js +58 -36
  95. package/dist/adapter/webgl-device.d.ts +34 -40
  96. package/dist/adapter/webgl-device.d.ts.map +1 -1
  97. package/dist/adapter/webgl-device.js +418 -363
  98. package/dist/classic/accessor.d.ts.map +1 -1
  99. package/dist/classic/accessor.js +132 -101
  100. package/dist/classic/clear.d.ts +2 -2
  101. package/dist/classic/clear.d.ts.map +1 -1
  102. package/dist/classic/clear.js +73 -72
  103. package/dist/classic/copy-and-blit.d.ts +1 -1
  104. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  105. package/dist/classic/copy-and-blit.js +175 -175
  106. package/dist/classic/format-utils.d.ts +2 -2
  107. package/dist/classic/format-utils.d.ts.map +1 -1
  108. package/dist/classic/format-utils.js +39 -32
  109. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  110. package/dist/classic/typed-array-utils.js +96 -81
  111. package/dist/context/context/context-data.d.ts +14 -0
  112. package/dist/context/context/context-data.d.ts.map +1 -0
  113. package/dist/context/context/context-data.js +33 -0
  114. package/dist/context/context/create-browser-context.d.ts +1 -6
  115. package/dist/context/context/create-browser-context.d.ts.map +1 -1
  116. package/dist/context/context/create-browser-context.js +62 -49
  117. package/dist/context/debug/spector.d.ts.map +1 -1
  118. package/dist/context/debug/spector.js +55 -50
  119. package/dist/context/debug/webgl-developer-tools.d.ts +1 -2
  120. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  121. package/dist/context/debug/webgl-developer-tools.js +104 -77
  122. package/dist/context/helpers/create-browser-context.d.ts +35 -0
  123. package/dist/context/helpers/create-browser-context.d.ts.map +1 -0
  124. package/dist/context/helpers/create-browser-context.js +67 -0
  125. package/dist/context/{polyfill/context-data.d.ts → helpers/webgl-context-data.d.ts} +2 -2
  126. package/dist/context/helpers/webgl-context-data.d.ts.map +1 -0
  127. package/dist/context/helpers/webgl-context-data.js +21 -0
  128. package/dist/context/helpers/webgl-extensions.d.ts +4 -0
  129. package/dist/context/helpers/webgl-extensions.d.ts.map +1 -0
  130. package/dist/context/helpers/webgl-extensions.js +10 -0
  131. package/dist/context/parameters/unified-parameter-api.d.ts +3 -3
  132. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  133. package/dist/context/parameters/unified-parameter-api.js +94 -44
  134. package/dist/context/parameters/webgl-parameter-tables.d.ts +120 -99
  135. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  136. package/dist/context/parameters/webgl-parameter-tables.js +469 -404
  137. package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
  138. package/dist/context/state-tracker/deep-array-equal.js +19 -14
  139. package/dist/context/state-tracker/track-context-state.d.ts +4 -4
  140. package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
  141. package/dist/context/state-tracker/track-context-state.js +188 -123
  142. package/dist/context/state-tracker/with-parameters.d.ts +2 -2
  143. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  144. package/dist/context/state-tracker/with-parameters.js +43 -26
  145. package/dist/dist.dev.js +3135 -4142
  146. package/dist/index.cjs +1766 -2717
  147. package/dist/index.cjs.map +7 -0
  148. package/dist/index.d.ts +25 -28
  149. package/dist/index.d.ts.map +1 -1
  150. package/dist/index.js +16 -5
  151. package/dist/types.d.ts.map +1 -1
  152. package/dist/types.js +3 -1
  153. package/dist.min.js +9 -42
  154. package/package.json +11 -15
  155. package/src/adapter/converters/device-parameters.ts +105 -17
  156. package/src/adapter/converters/sampler-parameters.ts +12 -20
  157. package/src/adapter/converters/shader-formats.ts +47 -22
  158. package/src/adapter/converters/texture-formats.ts +138 -185
  159. package/src/adapter/converters/vertex-formats.ts +3 -3
  160. package/src/adapter/device-helpers/webgl-device-features.ts +101 -0
  161. package/src/adapter/device-helpers/{get-device-info.ts → webgl-device-info.ts} +30 -22
  162. package/src/adapter/device-helpers/webgl-device-limits.ts +53 -0
  163. package/src/adapter/helpers/decode-webgl-types.ts +13 -7
  164. package/src/adapter/helpers/get-shader-layout.ts +21 -31
  165. package/src/adapter/helpers/parse-shader-compiler-log.ts +10 -6
  166. package/src/adapter/helpers/set-uniform.ts +3 -4
  167. package/src/adapter/helpers/webgl-topology-utils.ts +10 -3
  168. package/src/adapter/objects/constants-to-keys.ts +3 -2
  169. package/src/adapter/objects/webgl-renderbuffer.ts +38 -16
  170. package/src/adapter/objects/webgl-resource.ts +7 -140
  171. package/src/adapter/resources/webgl-buffer.ts +10 -14
  172. package/src/adapter/resources/webgl-command-buffer.ts +24 -34
  173. package/src/adapter/resources/webgl-command-encoder.ts +14 -11
  174. package/src/adapter/resources/webgl-external-texture.ts +5 -5
  175. package/src/adapter/resources/webgl-framebuffer.ts +38 -34
  176. package/src/adapter/resources/webgl-query-set.ts +171 -0
  177. package/src/adapter/resources/webgl-render-pass.ts +24 -15
  178. package/src/adapter/resources/webgl-render-pipeline.ts +138 -70
  179. package/src/adapter/resources/webgl-sampler.ts +7 -10
  180. package/src/adapter/resources/webgl-shader.ts +65 -11
  181. package/src/adapter/resources/webgl-texture-view.ts +28 -0
  182. package/src/adapter/resources/webgl-texture.ts +38 -105
  183. package/src/adapter/resources/webgl-transform-feedback.ts +16 -22
  184. package/src/adapter/resources/webgl-vertex-array.ts +20 -21
  185. package/src/adapter/webgl-canvas-context.ts +7 -11
  186. package/src/adapter/webgl-device.ts +106 -151
  187. package/src/classic/accessor.ts +5 -4
  188. package/src/classic/clear.ts +25 -20
  189. package/src/classic/copy-and-blit.ts +12 -6
  190. package/src/classic/format-utils.ts +2 -1
  191. package/src/classic/typed-array-utils.ts +3 -7
  192. package/src/context/debug/spector.ts +9 -6
  193. package/src/context/debug/webgl-developer-tools.ts +31 -20
  194. package/src/context/{context → helpers}/create-browser-context.ts +9 -33
  195. package/src/context/{polyfill/context-data.ts → helpers/webgl-context-data.ts} +3 -2
  196. package/src/context/helpers/webgl-extensions.ts +17 -0
  197. package/src/context/parameters/unified-parameter-api.ts +5 -4
  198. package/src/context/parameters/webgl-parameter-tables.ts +118 -90
  199. package/src/context/state-tracker/deep-array-equal.ts +2 -1
  200. package/src/context/state-tracker/track-context-state.ts +29 -23
  201. package/src/context/state-tracker/with-parameters.ts +7 -2
  202. package/src/index.ts +4 -18
  203. package/src/types.ts +2 -1
  204. package/dist/adapter/converters/device-parameters.js.map +0 -1
  205. package/dist/adapter/converters/sampler-parameters.js.map +0 -1
  206. package/dist/adapter/converters/shader-formats.js.map +0 -1
  207. package/dist/adapter/converters/texture-formats.js.map +0 -1
  208. package/dist/adapter/converters/vertex-formats.js.map +0 -1
  209. package/dist/adapter/device-helpers/device-features.js.map +0 -1
  210. package/dist/adapter/device-helpers/device-limits.js.map +0 -1
  211. package/dist/adapter/device-helpers/get-device-info.js.map +0 -1
  212. package/dist/adapter/device-helpers/is-old-ie.d.ts +0 -2
  213. package/dist/adapter/device-helpers/is-old-ie.d.ts.map +0 -1
  214. package/dist/adapter/device-helpers/is-old-ie.js +0 -9
  215. package/dist/adapter/device-helpers/is-old-ie.js.map +0 -1
  216. package/dist/adapter/helpers/decode-webgl-types.js.map +0 -1
  217. package/dist/adapter/helpers/get-shader-layout.js.map +0 -1
  218. package/dist/adapter/helpers/parse-shader-compiler-log.js.map +0 -1
  219. package/dist/adapter/helpers/set-uniform.js.map +0 -1
  220. package/dist/adapter/helpers/webgl-topology-utils.js.map +0 -1
  221. package/dist/adapter/objects/constants-to-keys.js.map +0 -1
  222. package/dist/adapter/objects/webgl-renderbuffer.js.map +0 -1
  223. package/dist/adapter/objects/webgl-resource.js.map +0 -1
  224. package/dist/adapter/resources/webgl-buffer.js.map +0 -1
  225. package/dist/adapter/resources/webgl-command-buffer.js.map +0 -1
  226. package/dist/adapter/resources/webgl-command-encoder.js.map +0 -1
  227. package/dist/adapter/resources/webgl-external-texture.js.map +0 -1
  228. package/dist/adapter/resources/webgl-framebuffer.js.map +0 -1
  229. package/dist/adapter/resources/webgl-render-pass.js.map +0 -1
  230. package/dist/adapter/resources/webgl-render-pipeline.js.map +0 -1
  231. package/dist/adapter/resources/webgl-sampler.js.map +0 -1
  232. package/dist/adapter/resources/webgl-shader.js.map +0 -1
  233. package/dist/adapter/resources/webgl-texture.js.map +0 -1
  234. package/dist/adapter/resources/webgl-transform-feedback.js.map +0 -1
  235. package/dist/adapter/resources/webgl-vertex-array.js.map +0 -1
  236. package/dist/adapter/webgl-canvas-context.js.map +0 -1
  237. package/dist/adapter/webgl-device.js.map +0 -1
  238. package/dist/classic/accessor.js.map +0 -1
  239. package/dist/classic/clear.js.map +0 -1
  240. package/dist/classic/copy-and-blit.js.map +0 -1
  241. package/dist/classic/format-utils.js.map +0 -1
  242. package/dist/classic/typed-array-utils.js.map +0 -1
  243. package/dist/context/context/create-browser-context.js.map +0 -1
  244. package/dist/context/context/create-headless-context.d.ts +0 -9
  245. package/dist/context/context/create-headless-context.d.ts.map +0 -1
  246. package/dist/context/context/create-headless-context.js +0 -42
  247. package/dist/context/context/create-headless-context.js.map +0 -1
  248. package/dist/context/context/webgl-checks.d.ts +0 -13
  249. package/dist/context/context/webgl-checks.d.ts.map +0 -1
  250. package/dist/context/context/webgl-checks.js +0 -31
  251. package/dist/context/context/webgl-checks.js.map +0 -1
  252. package/dist/context/debug/spector.js.map +0 -1
  253. package/dist/context/debug/webgl-developer-tools.js.map +0 -1
  254. package/dist/context/parameters/unified-parameter-api.js.map +0 -1
  255. package/dist/context/parameters/webgl-parameter-tables.js.map +0 -1
  256. package/dist/context/polyfill/context-data.d.ts.map +0 -1
  257. package/dist/context/polyfill/context-data.js +0 -12
  258. package/dist/context/polyfill/context-data.js.map +0 -1
  259. package/dist/context/polyfill/get-parameter-polyfill.d.ts +0 -2
  260. package/dist/context/polyfill/get-parameter-polyfill.d.ts.map +0 -1
  261. package/dist/context/polyfill/get-parameter-polyfill.js +0 -85
  262. package/dist/context/polyfill/get-parameter-polyfill.js.map +0 -1
  263. package/dist/context/polyfill/polyfill-context.d.ts +0 -5
  264. package/dist/context/polyfill/polyfill-context.d.ts.map +0 -1
  265. package/dist/context/polyfill/polyfill-context.js +0 -87
  266. package/dist/context/polyfill/polyfill-context.js.map +0 -1
  267. package/dist/context/polyfill/polyfill-table.d.ts +0 -48
  268. package/dist/context/polyfill/polyfill-table.d.ts.map +0 -1
  269. package/dist/context/polyfill/polyfill-table.js +0 -137
  270. package/dist/context/polyfill/polyfill-table.js.map +0 -1
  271. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts +0 -2
  272. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts.map +0 -1
  273. package/dist/context/polyfill/polyfill-vertex-array-object.js +0 -265
  274. package/dist/context/polyfill/polyfill-vertex-array-object.js.map +0 -1
  275. package/dist/context/state-tracker/deep-array-equal.js.map +0 -1
  276. package/dist/context/state-tracker/track-context-state.js.map +0 -1
  277. package/dist/context/state-tracker/with-parameters.js.map +0 -1
  278. package/dist/index.js.map +0 -1
  279. package/dist/types.js.map +0 -1
  280. package/src/adapter/device-helpers/device-features.ts +0 -161
  281. package/src/adapter/device-helpers/device-limits.ts +0 -155
  282. package/src/adapter/device-helpers/is-old-ie.ts +0 -14
  283. package/src/context/context/create-headless-context.ts +0 -51
  284. package/src/context/context/webgl-checks.ts +0 -51
  285. package/src/context/polyfill/get-parameter-polyfill.ts +0 -122
  286. package/src/context/polyfill/polyfill-context.ts +0 -104
  287. package/src/context/polyfill/polyfill-table.ts +0 -167
  288. package/src/context/polyfill/polyfill-vertex-array-object.ts +0 -365
@@ -1,917 +1,512 @@
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.
86
+ // TODO - Fix bpp constants
87
+ // 'r8unorm-unsized': {gl: GL.LUMINANCE, b: 4, c: 2, bpp: 4},
88
+ 'rgb8unorm-unsized': { gl: GL.RGB, b: 4, c: 2, bpp: 4,
89
+ dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5] },
90
+ 'rgba8unorm-unsized': { gl: GL.RGBA, b: 4, c: 2, bpp: 4,
91
+ dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4, GL.UNSIGNED_SHORT_5_5_5_1] },
92
+ // 'rgb8unorm-srgb-unsized': {gl: GL.SRGB_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
93
+ // 'rgba8unorm-srgb-unsized': {gl: GL.SRGB_ALPHA_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
94
+ // 8-bit formats
95
+ 'r8unorm': { gl: GL.R8, b: 1, c: 1, renderbuffer: true },
96
+ 'r8snorm': { gl: GL.R8_SNORM, b: 1, c: 1, render: snorm8_renderable },
97
+ 'r8uint': { gl: GL.R8UI, b: 1, c: 1, renderbuffer: true },
98
+ 'r8sint': { gl: GL.R8I, b: 1, c: 1, renderbuffer: true },
99
+ // 16-bit formats
100
+ 'rg8unorm': { gl: GL.RG8, b: 2, c: 2, renderbuffer: true },
101
+ 'rg8snorm': { gl: GL.RG8_SNORM, b: 2, c: 2, render: snorm8_renderable },
102
+ 'rg8uint': { gl: GL.RG8UI, b: 2, c: 2, renderbuffer: true },
103
+ 'rg8sint': { gl: GL.RG8I, b: 2, c: 2, renderbuffer: true },
104
+ 'r16uint': { gl: GL.R16UI, b: 2, c: 1, renderbuffer: true },
105
+ 'r16sint': { gl: GL.R16I, b: 2, c: 1, renderbuffer: true },
106
+ 'r16float': { gl: GL.R16F, b: 2, c: 1, render: float16_renderable, filter: 'float16-filterable-webgl', renderbuffer: true },
107
+ 'r16unorm-webgl': { gl: GL.R16_EXT, b: 2, c: 1, f: norm16_renderable, renderbuffer: true },
108
+ 'r16snorm-webgl': { gl: GL.R16_SNORM_EXT, b: 2, c: 1, f: snorm16_renderable },
109
+ // Packed 16-bit formats
110
+ 'rgba4unorm-webgl': { gl: GL.RGBA4, b: 2, c: 4, wgpu: false, renderbuffer: true },
111
+ 'rgb565unorm-webgl': { gl: GL.RGB565, b: 2, c: 4, wgpu: false, renderbuffer: true },
112
+ 'rgb5a1unorm-webgl': { gl: GL.RGB5_A1, b: 2, c: 4, wgpu: false, renderbuffer: true },
113
+ // 24-bit formats
114
+ 'rgb8unorm-webgl': { gl: GL.RGB8, b: 3, c: 3, wgpu: false },
115
+ 'rgb8snorm-webgl': { gl: GL.RGB8_SNORM, b: 3, c: 3, wgpu: false },
116
+ // 32-bit formats
117
+ 'rgba8unorm': { gl: GL.RGBA8, b: 4, c: 2, bpp: 4 },
118
+ 'rgba8unorm-srgb': { gl: GL.SRGB8_ALPHA8, b: 4, c: 4, bpp: 4 },
119
+ 'rgba8snorm': { gl: GL.RGBA8_SNORM, b: 4, c: 4, render: snorm8_renderable },
120
+ 'rgba8uint': { gl: GL.RGBA8UI, b: 4, c: 4, bpp: 4 },
121
+ 'rgba8sint': { gl: GL.RGBA8I, b: 4, c: 4, bpp: 4 },
122
+ // reverse colors, webgpu only
123
+ 'bgra8unorm': { b: 4, c: 4 },
124
+ 'bgra8unorm-srgb': { b: 4, c: 4 },
125
+ 'rg16uint': { gl: GL.RG16UI, b: 4, c: 1, bpp: 4 },
126
+ 'rg16sint': { gl: GL.RG16I, b: 4, c: 2, bpp: 4 },
127
+ // When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
128
+ 'rg16float': { gl: GL.RG16F, bpp: 4, b: 4, c: 2, render: float16_renderable, filter: float16_filterable, renderbuffer: true },
129
+ 'rg16unorm-webgl': { gl: GL.RG16_EXT, b: 2, c: 2, render: norm16_renderable },
130
+ 'rg16snorm-webgl': { gl: GL.RG16_SNORM_EXT, b: 2, c: 2, render: snorm16_renderable },
131
+ 'r32uint': { gl: GL.R32UI, b: 4, c: 1, bpp: 4, renderbuffer: true },
132
+ 'r32sint': { gl: GL.R32I, b: 4, c: 1, bpp: 4, renderbuffer: true },
133
+ 'r32float': { gl: GL.R32F, bpp: 4, b: 4, c: 1, render: float32_renderable, filter: float32_filterable },
134
+ // Packed 32-bit formats
135
+ 'rgb9e5ufloat': { gl: GL.RGB9_E5, b: 4, c: 3, p: 1, render: rgb9e5ufloat_renderable }, // , filter: true},
136
+ 'rg11b10ufloat': { gl: GL.R11F_G11F_B10F, b: 4, c: 3, p: 1, render: float32_renderable, renderbuffer: true },
137
+ 'rgb10a2unorm': { gl: GL.RGB10_A2, b: 4, c: 4, p: 1, renderbuffer: true },
138
+ 'rgb10a2uint-webgl': { b: 4, c: 4, gl: GL.RGB10_A2UI, p: 1, wgpu: false, bpp: 4, renderbuffer: true },
139
+ // 48-bit formats
140
+ 'rgb16unorm-webgl': { gl: GL.RGB16_EXT, b: 2, c: 3, f: norm16_renderable }, // rgb not renderable
141
+ 'rgb16snorm-webgl': { gl: GL.RGB16_SNORM_EXT, b: 2, c: 3, f: norm16_renderable }, // rgb not renderable
142
+ // 64-bit formats
143
+ 'rg32uint': { gl: GL.RG32UI, b: 8, c: 2, renderbuffer: true },
144
+ 'rg32sint': { gl: GL.RG32I, b: 8, c: 2, renderbuffer: true },
145
+ 'rg32float': { gl: GL.RG32F, b: 8, c: 2, render: float32_renderable, filter: float32_filterable, renderbuffer: true },
146
+ 'rgba16uint': { gl: GL.RGBA16UI, b: 8, c: 4, renderbuffer: true },
147
+ 'rgba16sint': { gl: GL.RGBA16I, b: 8, c: 4, renderbuffer: true },
148
+ 'rgba16float': { gl: GL.RGBA16F, b: 8, c: 4, render: float16_renderable, filter: float16_filterable },
149
+ 'rgba16unorm-webgl': { gl: GL.RGBA16_EXT, b: 2, c: 4, render: norm16_renderable, renderbuffer: true },
150
+ 'rgba16snorm-webgl': { gl: GL.RGBA16_SNORM_EXT, b: 2, c: 4, render: snorm16_renderable },
151
+ // 96-bit formats (deprecated!)
152
+ 'rgb32float-webgl': { gl: GL.RGB32F, render: float32_renderable, filter: float32_filterable,
153
+ gl2ext: EXT_color_buffer_float, dataFormat: GL.RGB, types: [GL.FLOAT] },
154
+ // 128-bit formats
155
+ 'rgba32uint': { gl: GL.RGBA32UI, b: 16, c: 4, renderbuffer: true },
156
+ 'rgba32sint': { gl: GL.RGBA32I, b: 16, c: 4, renderbuffer: true },
157
+ 'rgba32float': { gl: GL.RGBA32F, b: 16, c: 4, render: float32_renderable, filter: float32_filterable, renderbuffer: true },
158
+ // Depth and stencil formats
159
+ 'stencil8': { gl: GL.STENCIL_INDEX8, b: 1, c: 1, attachment: GL.STENCIL_ATTACHMENT, renderbuffer: true }, // 8 stencil bits
160
+ 'depth16unorm': { gl: GL.DEPTH_COMPONENT16, b: 2, c: 1, attachment: GL.DEPTH_ATTACHMENT, renderbuffer: true }, // 16 depth bits
161
+ 'depth24plus': { gl: GL.DEPTH_COMPONENT24, b: 3, c: 1, attachment: GL.DEPTH_ATTACHMENT },
162
+ 'depth32float': { gl: GL.DEPTH_COMPONENT32F, b: 4, c: 1, attachment: GL.DEPTH_ATTACHMENT, renderbuffer: true },
163
+ // The depth component of the "depth24plus" and "depth24plus-stencil8" formats may be implemented as either a 24-bit depth value or a "depth32float" value.
164
+ 'depth24plus-stencil8': { gl: GL.DEPTH_STENCIL, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, renderbuffer: true, depthTexture: true },
165
+ // "depth24unorm-stencil8" feature
166
+ 'depth24unorm-stencil8': { gl: GL.DEPTH24_STENCIL8, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, renderbuffer: true },
167
+ // "depth32float-stencil8" feature
168
+ 'depth32float-stencil8': { gl: GL.DEPTH32F_STENCIL8, b: 5, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, renderbuffer: true },
169
+ // BC compressed formats: check device.features.has("texture-compression-bc");
170
+ 'bc1-rgb-unorm-webgl': { gl: GL.COMPRESSED_RGB_S3TC_DXT1_EXT, x: X_S3TC, f: texture_compression_bc },
171
+ 'bc1-rgb-unorm-srgb-webgl': { gl: GL.COMPRESSED_SRGB_S3TC_DXT1_EXT, x: X_S3TC_SRGB, f: texture_compression_bc },
172
+ 'bc1-rgba-unorm': { gl: GL.COMPRESSED_RGBA_S3TC_DXT1_EXT, x: X_S3TC, f: texture_compression_bc },
173
+ 'bc1-rgba-unorm-srgb': { gl: GL.COMPRESSED_SRGB_S3TC_DXT1_EXT, x: X_S3TC_SRGB, f: texture_compression_bc },
174
+ 'bc2-rgba-unorm': { gl: GL.COMPRESSED_RGBA_S3TC_DXT3_EXT, x: X_S3TC, f: texture_compression_bc },
175
+ 'bc2-rgba-unorm-srgb': { gl: GL.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, x: X_S3TC_SRGB, f: texture_compression_bc },
176
+ 'bc3-rgba-unorm': { gl: GL.COMPRESSED_RGBA_S3TC_DXT5_EXT, x: X_S3TC, f: texture_compression_bc },
177
+ 'bc3-rgba-unorm-srgb': { gl: GL.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, x: X_S3TC_SRGB, f: texture_compression_bc },
178
+ 'bc4-r-unorm': { gl: GL.COMPRESSED_RED_RGTC1_EXT, x: X_RGTC, f: texture_compression_bc },
179
+ 'bc4-r-snorm': { gl: GL.COMPRESSED_SIGNED_RED_RGTC1_EXT, x: X_RGTC, f: texture_compression_bc },
180
+ 'bc5-rg-unorm': { gl: GL.COMPRESSED_RED_GREEN_RGTC2_EXT, x: X_RGTC, f: texture_compression_bc },
181
+ 'bc5-rg-snorm': { gl: GL.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, x: X_RGTC, f: texture_compression_bc },
182
+ 'bc6h-rgb-ufloat': { gl: GL.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, x: X_BPTC, f: texture_compression_bc },
183
+ 'bc6h-rgb-float': { gl: GL.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, x: X_BPTC, f: texture_compression_bc },
184
+ 'bc7-rgba-unorm': { gl: GL.COMPRESSED_RGBA_BPTC_UNORM_EXT, x: X_BPTC, f: texture_compression_bc },
185
+ 'bc7-rgba-unorm-srgb': { gl: GL.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, x: X_BPTC, f: texture_compression_bc },
186
+ // WEBGL_compressed_texture_etc: device.features.has("texture-compression-etc2")
187
+ // Note: Supposedly guaranteed availability compressed formats in WebGL2, but through CPU decompression
188
+ 'etc2-rgb8unorm': { gl: GL.COMPRESSED_RGB8_ETC2, f: texture_compression_etc2 },
189
+ 'etc2-rgb8unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ETC2, f: texture_compression_etc2 },
190
+ 'etc2-rgb8a1unorm': { gl: GL.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, f: texture_compression_etc2 },
191
+ 'etc2-rgb8a1unorm-srgb': { gl: GL.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, f: texture_compression_etc2 },
192
+ 'etc2-rgba8unorm': { gl: GL.COMPRESSED_RGBA8_ETC2_EAC, f: texture_compression_etc2 },
193
+ 'etc2-rgba8unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, f: texture_compression_etc2 },
194
+ 'eac-r11unorm': { gl: GL.COMPRESSED_R11_EAC, f: texture_compression_etc2 },
195
+ 'eac-r11snorm': { gl: GL.COMPRESSED_SIGNED_R11_EAC, f: texture_compression_etc2 },
196
+ 'eac-rg11unorm': { gl: GL.COMPRESSED_RG11_EAC, f: texture_compression_etc2 },
197
+ 'eac-rg11snorm': { gl: GL.COMPRESSED_SIGNED_RG11_EAC, f: texture_compression_etc2 },
198
+ // X_ASTC compressed formats: device.features.has("texture-compression-astc")
199
+ 'astc-4x4-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_4x4_KHR, f: texture_compression_astc },
200
+ 'astc-4x4-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, f: texture_compression_astc },
201
+ 'astc-5x4-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_5x4_KHR, f: texture_compression_astc },
202
+ 'astc-5x4-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, f: texture_compression_astc },
203
+ 'astc-5x5-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_5x5_KHR, f: texture_compression_astc },
204
+ 'astc-5x5-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, f: texture_compression_astc },
205
+ 'astc-6x5-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_6x5_KHR, f: texture_compression_astc },
206
+ 'astc-6x5-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, f: texture_compression_astc },
207
+ 'astc-6x6-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_6x6_KHR, f: texture_compression_astc },
208
+ 'astc-6x6-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, f: texture_compression_astc },
209
+ 'astc-8x5-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_8x5_KHR, f: texture_compression_astc },
210
+ 'astc-8x5-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, f: texture_compression_astc },
211
+ 'astc-8x6-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_8x6_KHR, f: texture_compression_astc },
212
+ 'astc-8x6-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, f: texture_compression_astc },
213
+ 'astc-8x8-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_8x8_KHR, f: texture_compression_astc },
214
+ 'astc-8x8-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, f: texture_compression_astc },
215
+ 'astc-10x5-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_10x10_KHR, f: texture_compression_astc },
216
+ 'astc-10x5-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, f: texture_compression_astc },
217
+ 'astc-10x6-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_10x6_KHR, f: texture_compression_astc },
218
+ 'astc-10x6-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, f: texture_compression_astc },
219
+ 'astc-10x8-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_10x8_KHR, f: texture_compression_astc },
220
+ 'astc-10x8-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, f: texture_compression_astc },
221
+ 'astc-10x10-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_10x10_KHR, f: texture_compression_astc },
222
+ 'astc-10x10-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, f: texture_compression_astc },
223
+ 'astc-12x10-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_12x10_KHR, f: texture_compression_astc },
224
+ 'astc-12x10-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, f: texture_compression_astc },
225
+ 'astc-12x12-unorm': { gl: GL.COMPRESSED_RGBA_ASTC_12x12_KHR, f: texture_compression_astc },
226
+ 'astc-12x12-unorm-srgb': { gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, f: texture_compression_astc },
227
+ // WEBGL_compressed_texture_pvrtc
228
+ 'pvrtc-rgb4unorm-webgl': { gl: GL.COMPRESSED_RGB_PVRTC_4BPPV1_IMG, f: texture_compression_pvrtc_webgl },
229
+ 'pvrtc-rgba4unorm-webgl': { gl: GL.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, f: texture_compression_pvrtc_webgl },
230
+ 'pvrtc-rbg2unorm-webgl': { gl: GL.COMPRESSED_RGB_PVRTC_2BPPV1_IMG, f: texture_compression_pvrtc_webgl },
231
+ 'pvrtc-rgba2unorm-webgl': { gl: GL.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, f: texture_compression_pvrtc_webgl },
232
+ // WEBGL_compressed_texture_etc1
233
+ 'etc1-rbg-unorm-webgl': { gl: GL.COMPRESSED_RGB_ETC1_WEBGL, f: texture_compression_etc1_webgl },
234
+ // WEBGL_compressed_texture_atc
235
+ 'atc-rgb-unorm-webgl': { gl: GL.COMPRESSED_RGB_ATC_WEBGL, f: texture_compression_atc_webgl },
236
+ 'atc-rgba-unorm-webgl': { gl: GL.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL, f: texture_compression_atc_webgl },
237
+ 'atc-rgbai-unorm-webgl': { gl: GL.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL, f: texture_compression_atc_webgl }
734
238
  };
239
+ /** Legal combinations for internalFormat, format and type *
240
+ // [GL.DEPTH_COMPONENT]: {types: [GL.UNSIGNED_SHORT, GL.UNSIGNED_INT, GL.UNSIGNED_INT_24_8]},
241
+ // [GL.DEPTH_STENCIL]: ,
242
+ // Sized texture format
243
+ // R
244
+ [GL.R8]: {dataFormat: GL.RED, types: [GL.UNSIGNED_BYTE], gl2: true},
245
+ [GL.R16F]: {dataFormat: GL.RED, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
246
+ [GL.R8UI]: {dataFormat: GL.RED_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
247
+ // // RG
248
+ [GL.RG8]: {dataFormat: GL.RG, types: [GL.UNSIGNED_BYTE], gl2: true},
249
+ [GL.RG16F]: {dataFormat: GL.RG, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
250
+ [GL.RG8UI]: {dataFormat: GL.RG_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
251
+ // // RGB
252
+ [GL.RGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
253
+ [GL.SRGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
254
+ [GL.RGB16F]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
255
+ [GL.RGB8UI]: {dataFormat: GL.RGB_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
256
+ // // RGBA
257
+
258
+ [GL.RGB565]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5], gl2: true},
259
+ [GL.R11F_G11F_B10F]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_INT_10F_11F_11F_REV, GL.HALF_FLOAT, GL.FLOAT], gl2: true},
260
+ [GL.RGB9_E5]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
261
+ [GL.RGBA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true},
262
+ [GL.SRGB8_ALPHA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true, gl1ext: EXT_SRGB},
263
+ [GL.RGB5_A1]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_5_5_1], gl2: true},
264
+ [GL.RGBA4]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4], gl2: true},
265
+ [GL.RGBA16F]: {dataFormat: GL.RGBA, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
266
+ [GL.RGBA8UI]: {dataFormat: GL.RGBA_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true}
267
+ */
268
+ /* This table is now baked into the above table
269
+ type RenderbufferFormat = {
270
+ bpp: number;
271
+ gl2?: boolean;
272
+ ext?: string;
273
+ };
274
+
275
+ export const RENDERBUFFER_FORMATS: Record<string, RenderbufferFormat> = {
276
+ [GL.DEPTH_COMPONENT16]: {bpp: 2}, // 16 depth bits.
277
+ // TODO - Not clear which webgpu value to map this to.
278
+ // [GL.DEPTH_COMPONENT24]: {gl2: true, bpp: 3},
279
+ [GL.DEPTH_COMPONENT32F]: {gl2: true, bpp: 4},
280
+
281
+ [GL.STENCIL_INDEX8]: {bpp: 1}, // 8 stencil bits.
282
+
283
+ [GL.DEPTH_STENCIL]: {bpp: 4},
284
+ [GL.DEPTH24_STENCIL8]: {gl2: true, bpp: 4},
285
+ [GL.DEPTH32F_STENCIL8]: {gl2: true, bpp: 5},
286
+
287
+ // When using a WebGL 1 context, color renderbuffer formats are limited
288
+ [GL.RGBA4]: {gl2: true, bpp: 2},
289
+ [GL.RGB565]: {gl2: true, bpp: 2},
290
+ [GL.RGB5_A1]: {gl2: true, bpp: 2},
291
+
292
+ // When using a WebGL 2 context, the following values are available additionally:
293
+ [GL.R8]: {gl2: true, bpp: 1},
294
+ [GL.R8UI]: {gl2: true, bpp: 1},
295
+ [GL.R8I]: {gl2: true, bpp: 1},
296
+ [GL.R16UI]: {gl2: true, bpp: 2},
297
+ [GL.R16I]: {gl2: true, bpp: 2},
298
+ [GL.R32UI]: {gl2: true, bpp: 4},
299
+ [GL.R32I]: {gl2: true, bpp: 4},
300
+ [GL.RG8]: {gl2: true, bpp: 2},
301
+ [GL.RG8UI]: {gl2: true, bpp: 2},
302
+ [GL.RG8I]: {gl2: true, bpp: 2},
303
+ [GL.RG16UI]: {gl2: true, bpp: 4},
304
+ [GL.RG16I]: {gl2: true, bpp: 4},
305
+ [GL.RG32UI]: {gl2: true, bpp: 8},
306
+ [GL.RG32I]: {gl2: true, bpp: 8},
307
+ [GL.RGB8]: {gl2: true, bpp: 3},
308
+ [GL.RGBA8]: {gl2: true, bpp: 4},
309
+ // [GL.SRGB8_ALPHA8]: {gl2: true, gl1: SRGB}, // When using the EXT_sRGB WebGL1 extension
310
+ [GL.RGB10_A2]: {gl2: true, bpp: 4},
311
+ [GL.RGBA8UI]: {gl2: true, bpp: 4},
312
+ [GL.RGBA8I]: {gl2: true, bpp: 4},
313
+ [GL.RGB10_A2UI]: {gl2: true, bpp: 4},
314
+ [GL.RGBA16UI]: {gl2: true, bpp: 8},
315
+ [GL.RGBA16I]: {gl2: true, bpp: 8},
316
+ [GL.RGBA32I]: {gl2: true, bpp: 16},
317
+ [GL.RGBA32UI]: {gl2: true, bpp: 16},
318
+
319
+ // When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
320
+ [GL.R16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 2},
321
+ [GL.RG16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4},
322
+ [GL.RGBA16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
323
+ [GL.R32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4},
324
+ [GL.RG32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
325
+ // TODO - can't get WEBGL_color_buffer_float to work on renderbuffers
326
+ [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 16},
327
+ // [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2},
328
+ [GL.R11F_G11F_B10F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4}
329
+ };
330
+ */
331
+ /** @deprecated should be removed */
735
332
  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
333
+ [GL.RED]: 1,
334
+ [GL.RED_INTEGER]: 1,
335
+ [GL.RG]: 2,
336
+ [GL.RG_INTEGER]: 2,
337
+ [GL.RGB]: 3,
338
+ [GL.RGB_INTEGER]: 3,
339
+ [GL.RGBA]: 4,
340
+ [GL.RGBA_INTEGER]: 4,
341
+ [GL.DEPTH_COMPONENT]: 1,
342
+ [GL.DEPTH_STENCIL]: 1,
343
+ [GL.ALPHA]: 1,
344
+ [GL.LUMINANCE]: 1,
345
+ [GL.LUMINANCE_ALPHA]: 2
749
346
  };
347
+ /** @deprecated should be removed */
750
348
  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
349
+ [GL.FLOAT]: 4,
350
+ [GL.UNSIGNED_INT]: 4,
351
+ [GL.INT]: 4,
352
+ [GL.UNSIGNED_SHORT]: 2,
353
+ [GL.SHORT]: 2,
354
+ [GL.HALF_FLOAT]: 2,
355
+ [GL.BYTE]: 1,
356
+ [GL.UNSIGNED_BYTE]: 1
759
357
  };
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;
358
+ // FUNCTIONS
359
+ /** Checks if a texture format is supported */
360
+ export function isTextureFormatSupported(gl, formatOrGL, extensions) {
361
+ const format = convertGLToTextureFormat(formatOrGL);
362
+ const info = TEXTURE_FORMATS[format];
363
+ if (!info) {
364
+ return false;
365
+ }
366
+ // Check that we have a GL constant
367
+ if (info.gl === undefined) {
368
+ return false;
369
+ }
370
+ // Check extensions
371
+ const extension = info.x || info.gl2ext;
372
+ if (extension) {
373
+ return Boolean(getWebGLExtension(gl, extension, extensions));
374
+ }
375
+ return true;
774
376
  }
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);
377
+ export function isRenderbufferFormatSupported(gl, format, extensions) {
378
+ // Note: Order is important since the function call initializes extensions.
379
+ return isTextureFormatSupported(gl, format, extensions) && TEXTURE_FORMATS[format]?.renderbuffer;
778
380
  }
381
+ /**
382
+ * Map WebGL texture formats (GL constants) to WebGPU-style TextureFormat strings
383
+ */
779
384
  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];
385
+ if (typeof format === 'string') {
386
+ return format;
387
+ }
388
+ const entry = Object.entries(TEXTURE_FORMATS).find(([, entry]) => entry.gl === format);
389
+ if (!entry) {
390
+ throw new Error(`Unknown texture format ${format}`);
391
+ }
392
+ return entry[0];
791
393
  }
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;
394
+ /**
395
+ * Map WebGPU style texture format strings to GL constants
396
+ */
397
+ export function convertTextureFormatToGL(format) {
398
+ const formatInfo = TEXTURE_FORMATS[format];
399
+ const webglFormat = formatInfo?.gl;
400
+ if (webglFormat === undefined) {
401
+ throw new Error(`Unsupported texture format ${format}`);
402
+ }
403
+ return webglFormat;
799
404
  }
800
- export function getTextureFormatSupport(gl, formatOrGL) {
801
- const format = convertGLToTextureFormat(formatOrGL);
802
- const info = TEXTURE_FORMATS[format];
803
- if (!info) {
405
+ /** Checks if a texture format is supported */
406
+ export function getTextureFormatSupport(gl, formatOrGL, extensions) {
407
+ const format = convertGLToTextureFormat(formatOrGL);
408
+ const info = TEXTURE_FORMATS[format];
409
+ if (!info) {
410
+ return { supported: false };
411
+ }
412
+ // let decoded;
413
+ // try {
414
+ // decoded = decodeTextureFormat(format);
415
+ // } catch {}
416
+ // Support Check that we have a GL constant
417
+ let supported = info.gl === undefined;
418
+ supported = supported && checkTextureFeature(gl, info.f, extensions);
419
+ // Filtering
420
+ // const filterable = info.filter
421
+ // ? checkTextureFeature(gl, infofilter])
422
+ // : decoded && !decoded.signed;
423
+ // const renderable = info.filter
424
+ // ? checkTextureFeature(gl, inforender])
425
+ // : decoded && !decoded.signed;
804
426
  return {
805
- supported: false
427
+ supported,
428
+ renderable: supported && checkTextureFeature(gl, info.render, extensions),
429
+ filterable: supported && checkTextureFeature(gl, info.filter, extensions),
430
+ blendable: false, // tod,
431
+ storable: false
806
432
  };
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
433
  }
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;
434
+ /** Checks whether linear filtering (interpolated sampling) is available for floating point textures */
435
+ export function isTextureFormatFilterable(gl, formatOrGL, extensions) {
436
+ const format = convertGLToTextureFormat(formatOrGL);
437
+ if (!isTextureFormatSupported(gl, format, extensions)) {
438
+ return false;
439
+ }
440
+ try {
441
+ const decoded = decodeTextureFormat(format);
442
+ if (decoded.signed) {
443
+ return false;
444
+ }
445
+ }
446
+ catch {
447
+ return false;
827
448
  }
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;
449
+ if (format.endsWith('32float')) {
450
+ return Boolean(getWebGLExtension(gl, 'OES_texture_float_linear, extensions', extensions));
451
+ }
452
+ if (format.endsWith('16float')) {
453
+ return Boolean(getWebGLExtension(gl, 'OES_texture_half_float_linear, extensions', extensions));
454
+ }
455
+ return true;
838
456
  }
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;
457
+ export function isTextureFormatRenderable(gl, formatOrGL, extensions) {
458
+ const format = convertGLToTextureFormat(formatOrGL);
459
+ if (!isTextureFormatSupported(gl, format, extensions)) {
460
+ return false;
461
+ }
462
+ if (typeof format === 'number') {
463
+ return false; // isTextureFormatFilterableWebGL(gl, format);
464
+ }
465
+ // TODO depends on device...
466
+ return true;
848
467
  }
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
- };
468
+ export function getWebGLTextureParameters(formatOrGL) {
469
+ const format = convertGLToTextureFormat(formatOrGL);
470
+ const webglFormat = convertTextureFormatToGL(format);
471
+ const decoded = decodeTextureFormat(format);
472
+ return {
473
+ format: webglFormat,
474
+ dataFormat: getWebGLPixelDataFormat(decoded.format, decoded.integer, decoded.normalized, webglFormat),
475
+ // depth formats don't have a type
476
+ type: decoded.dataType ? getGLFromVertexType(decoded.dataType) : GL.UNSIGNED_BYTE,
477
+ // @ts-expect-error
478
+ compressed: decoded.compressed
479
+ };
859
480
  }
860
481
  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
- }
482
+ const info = TEXTURE_FORMATS[format];
483
+ if (!info?.attachment) {
484
+ throw new Error(`${format} is not a depth stencil format`);
485
+ }
486
+ return info.attachment;
892
487
  }
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;
488
+ /** TODO - VERY roundabout legacy way of calculating bytes per pixel */
489
+ export function getTextureFormatBytesPerPixel(formatOrGL) {
490
+ // TODO remove webgl1 support
491
+ const format = convertGLToTextureFormat(formatOrGL);
492
+ const params = getWebGLTextureParameters(format);
493
+ // NOTE(Tarek): Default to RGBA bytes
494
+ const channels = DATA_FORMAT_CHANNELS[params.dataFormat] || 4;
495
+ const channelSize = TYPE_SIZES[params.type] || 1;
496
+ return channels * channelSize;
899
497
  }
498
+ // DATA TYPE HELPERS
900
499
  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
- }
500
+ // WebGL1 formats use same internalFormat
501
+ if (format === GL.RGBA || format === GL.RGB) {
502
+ return format;
503
+ }
504
+ // prettier-ignore
505
+ switch (dataFormat) {
506
+ case 'r': return integer && !normalized ? GL.RED_INTEGER : GL.RED;
507
+ case 'rg': return integer && !normalized ? GL.RG_INTEGER : GL.RG;
508
+ case 'rgb': return integer && !normalized ? GL.RGB_INTEGER : GL.RGB;
509
+ case 'rgba': return integer && !normalized ? GL.RGBA_INTEGER : GL.RGBA;
510
+ default: return GL.RGBA;
511
+ }
916
512
  }
917
- //# sourceMappingURL=texture-formats.js.map