@loaders.gl/textures 3.1.0-alpha.4 → 3.1.0-beta.3

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 (271) hide show
  1. package/dist/basis-loader.d.ts +50 -0
  2. package/dist/basis-loader.d.ts.map +1 -0
  3. package/dist/basis-loader.js +40 -0
  4. package/dist/basis-worker.js +675 -2
  5. package/dist/bundle.d.ts +2 -0
  6. package/dist/bundle.d.ts.map +1 -0
  7. package/dist/bundle.js +2107 -0
  8. package/dist/compressed-texture-loader.d.ts +63 -0
  9. package/dist/compressed-texture-loader.d.ts.map +1 -0
  10. package/dist/compressed-texture-loader.js +64 -0
  11. package/dist/compressed-texture-worker.js +1179 -2
  12. package/dist/compressed-texture-writer.d.ts +25 -0
  13. package/dist/compressed-texture-writer.d.ts.map +1 -0
  14. package/dist/compressed-texture-writer.js +28 -0
  15. package/dist/crunch-loader.d.ts +21 -0
  16. package/dist/crunch-loader.d.ts.map +1 -0
  17. package/dist/crunch-loader.js +25 -0
  18. package/dist/crunch-worker.js +486 -2
  19. package/dist/es5/basis-loader.js +5 -13
  20. package/dist/es5/basis-loader.js.map +1 -1
  21. package/dist/es5/bundle.js +1 -1
  22. package/dist/es5/bundle.js.map +1 -1
  23. package/dist/es5/compressed-texture-loader.js +20 -59
  24. package/dist/es5/compressed-texture-loader.js.map +1 -1
  25. package/dist/es5/compressed-texture-writer.js +2 -2
  26. package/dist/es5/compressed-texture-writer.js.map +1 -1
  27. package/dist/es5/crunch-loader.js +2 -2
  28. package/dist/es5/crunch-loader.js.map +1 -1
  29. package/dist/es5/index.js +26 -18
  30. package/dist/es5/index.js.map +1 -1
  31. package/dist/es5/ktx2-basis-universal-texture-writer.js +29 -0
  32. package/dist/es5/ktx2-basis-universal-texture-writer.js.map +1 -0
  33. package/dist/es5/lib/encoders/encode-ktx.js +1 -1
  34. package/dist/es5/lib/encoders/encode-ktx.js.map +1 -1
  35. package/dist/es5/lib/encoders/encode-ktx2-basis-texture.js +43 -0
  36. package/dist/es5/lib/encoders/encode-ktx2-basis-texture.js.map +1 -0
  37. package/dist/es5/lib/encoders/encode-texture.js +13 -41
  38. package/dist/es5/lib/encoders/encode-texture.js.map +1 -1
  39. package/dist/es5/lib/{gl-constants.js → gl-extensions.js} +4 -4
  40. package/dist/es5/lib/gl-extensions.js.map +1 -0
  41. package/dist/es5/lib/parsers/basis-module-loader.js +51 -190
  42. package/dist/es5/lib/parsers/basis-module-loader.js.map +1 -1
  43. package/dist/es5/lib/parsers/crunch-module-loader.js +15 -71
  44. package/dist/es5/lib/parsers/crunch-module-loader.js.map +1 -1
  45. package/dist/es5/lib/parsers/parse-basis.js +86 -138
  46. package/dist/es5/lib/parsers/parse-basis.js.map +1 -1
  47. package/dist/es5/lib/parsers/parse-crunch.js +59 -80
  48. package/dist/es5/lib/parsers/parse-crunch.js.map +1 -1
  49. package/dist/es5/lib/parsers/parse-dds.js +39 -39
  50. package/dist/es5/lib/parsers/parse-dds.js.map +1 -1
  51. package/dist/es5/lib/parsers/parse-ktx.js +14 -16
  52. package/dist/es5/lib/parsers/parse-ktx.js.map +1 -1
  53. package/dist/es5/lib/parsers/parse-npy.js +27 -28
  54. package/dist/es5/lib/parsers/parse-npy.js.map +1 -1
  55. package/dist/es5/lib/parsers/parse-pvr.js +49 -49
  56. package/dist/es5/lib/parsers/parse-pvr.js.map +1 -1
  57. package/dist/es5/lib/texture-api/async-deep-map.js +27 -156
  58. package/dist/es5/lib/texture-api/async-deep-map.js.map +1 -1
  59. package/dist/es5/lib/texture-api/deep-load.js +6 -67
  60. package/dist/es5/lib/texture-api/deep-load.js.map +1 -1
  61. package/dist/es5/lib/texture-api/generate-url.js +4 -16
  62. package/dist/es5/lib/texture-api/generate-url.js.map +1 -1
  63. package/dist/es5/lib/texture-api/load-image-array.js +12 -76
  64. package/dist/es5/lib/texture-api/load-image-array.js.map +1 -1
  65. package/dist/es5/lib/texture-api/load-image-cube.js +27 -96
  66. package/dist/es5/lib/texture-api/load-image-cube.js.map +1 -1
  67. package/dist/es5/lib/texture-api/load-image.js +37 -146
  68. package/dist/es5/lib/texture-api/load-image.js.map +1 -1
  69. package/dist/es5/lib/texture-api/texture-api-types.js +2 -0
  70. package/dist/es5/lib/texture-api/texture-api-types.js.map +1 -0
  71. package/dist/es5/lib/utils/extract-mipmap-images.js +9 -9
  72. package/dist/es5/lib/utils/extract-mipmap-images.js.map +1 -1
  73. package/dist/es5/lib/utils/ktx-format-helper.js +68 -68
  74. package/dist/es5/lib/utils/ktx-format-helper.js.map +1 -1
  75. package/dist/es5/lib/utils/texture-formats.js +9 -27
  76. package/dist/es5/lib/utils/texture-formats.js.map +1 -1
  77. package/dist/es5/lib/utils/version.js +1 -1
  78. package/dist/es5/lib/utils/version.js.map +1 -1
  79. package/dist/es5/libs/README.md +2 -2
  80. package/dist/es5/libs/basis_encoder.js +1 -1
  81. package/dist/es5/libs/basis_transcoder.js +1 -1
  82. package/dist/es5/libs/crunch.js +1 -0
  83. package/dist/es5/npy-loader.js +7 -42
  84. package/dist/es5/npy-loader.js.map +1 -1
  85. package/dist/es5/workers/crunch-worker.js +2 -11
  86. package/dist/es5/workers/crunch-worker.js.map +1 -1
  87. package/dist/esm/index.js +2 -1
  88. package/dist/esm/index.js.map +1 -1
  89. package/dist/esm/ktx2-basis-universal-texture-writer.js +18 -0
  90. package/dist/esm/ktx2-basis-universal-texture-writer.js.map +1 -0
  91. package/dist/esm/lib/encoders/encode-ktx2-basis-texture.js +35 -0
  92. package/dist/esm/lib/encoders/encode-ktx2-basis-texture.js.map +1 -0
  93. package/dist/esm/lib/encoders/encode-texture.js +1 -1
  94. package/dist/esm/lib/encoders/encode-texture.js.map +1 -1
  95. package/dist/esm/lib/{gl-constants.js → gl-extensions.js} +2 -2
  96. package/dist/esm/lib/gl-extensions.js.map +1 -0
  97. package/dist/esm/lib/parsers/basis-module-loader.js +8 -3
  98. package/dist/esm/lib/parsers/basis-module-loader.js.map +1 -1
  99. package/dist/esm/lib/parsers/crunch-module-loader.js.map +1 -1
  100. package/dist/esm/lib/parsers/parse-basis.js +8 -8
  101. package/dist/esm/lib/parsers/parse-basis.js.map +1 -1
  102. package/dist/esm/lib/parsers/parse-crunch.js +4 -4
  103. package/dist/esm/lib/parsers/parse-crunch.js.map +1 -1
  104. package/dist/esm/lib/parsers/parse-dds.js +24 -24
  105. package/dist/esm/lib/parsers/parse-dds.js.map +1 -1
  106. package/dist/esm/lib/parsers/parse-ktx.js +2 -2
  107. package/dist/esm/lib/parsers/parse-ktx.js.map +1 -1
  108. package/dist/esm/lib/parsers/parse-npy.js +4 -2
  109. package/dist/esm/lib/parsers/parse-npy.js.map +1 -1
  110. package/dist/esm/lib/parsers/parse-pvr.js +28 -28
  111. package/dist/esm/lib/parsers/parse-pvr.js.map +1 -1
  112. package/dist/esm/lib/texture-api/async-deep-map.js.map +1 -1
  113. package/dist/esm/lib/texture-api/deep-load.js.map +1 -1
  114. package/dist/esm/lib/texture-api/generate-url.js +6 -14
  115. package/dist/esm/lib/texture-api/generate-url.js.map +1 -1
  116. package/dist/esm/lib/texture-api/load-image-array.js.map +1 -1
  117. package/dist/esm/lib/texture-api/load-image-cube.js.map +1 -1
  118. package/dist/esm/lib/texture-api/load-image.js +2 -5
  119. package/dist/esm/lib/texture-api/load-image.js.map +1 -1
  120. package/dist/esm/lib/texture-api/texture-api-types.js +2 -0
  121. package/dist/esm/lib/texture-api/texture-api-types.js.map +1 -0
  122. package/dist/esm/lib/utils/extract-mipmap-images.js.map +1 -1
  123. package/dist/esm/lib/utils/ktx-format-helper.js +67 -67
  124. package/dist/esm/lib/utils/ktx-format-helper.js.map +1 -1
  125. package/dist/esm/lib/utils/texture-formats.js +1 -1
  126. package/dist/esm/lib/utils/texture-formats.js.map +1 -1
  127. package/dist/esm/lib/utils/version.js +1 -1
  128. package/dist/esm/lib/utils/version.js.map +1 -1
  129. package/dist/esm/libs/README.md +2 -2
  130. package/dist/esm/libs/basis_encoder.js +1 -1
  131. package/dist/esm/libs/basis_transcoder.js +1 -1
  132. package/dist/esm/libs/crunch.js +1 -0
  133. package/dist/esm/npy-loader.js.map +1 -1
  134. package/dist/index.d.ts +16 -0
  135. package/dist/index.d.ts.map +1 -0
  136. package/dist/index.js +37 -0
  137. package/dist/ktx2-basis-universal-texture-writer.d.ts +22 -0
  138. package/dist/ktx2-basis-universal-texture-writer.d.ts.map +1 -0
  139. package/dist/ktx2-basis-universal-texture-writer.js +25 -0
  140. package/dist/lib/encoders/encode-ktx.d.ts +2 -0
  141. package/dist/lib/encoders/encode-ktx.d.ts.map +1 -0
  142. package/dist/lib/encoders/encode-ktx.js +10 -0
  143. package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts +10 -0
  144. package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts.map +1 -0
  145. package/dist/lib/encoders/encode-ktx2-basis-texture.js +41 -0
  146. package/dist/lib/encoders/encode-texture.d.ts +2 -0
  147. package/dist/lib/encoders/encode-texture.d.ts.map +1 -0
  148. package/dist/lib/encoders/encode-texture.js +30 -0
  149. package/dist/lib/gl-extensions.d.ts +61 -0
  150. package/dist/lib/gl-extensions.d.ts.map +1 -0
  151. package/dist/lib/gl-extensions.js +72 -0
  152. package/dist/lib/parsers/basis-module-loader.d.ts +13 -0
  153. package/dist/lib/parsers/basis-module-loader.d.ts.map +1 -0
  154. package/dist/lib/parsers/basis-module-loader.js +114 -0
  155. package/dist/lib/parsers/crunch-module-loader.d.ts +7 -0
  156. package/dist/lib/parsers/crunch-module-loader.d.ts.map +1 -0
  157. package/dist/lib/parsers/crunch-module-loader.js +35 -0
  158. package/dist/lib/parsers/parse-basis.d.ts +30 -0
  159. package/dist/lib/parsers/parse-basis.d.ts.map +1 -0
  160. package/dist/lib/parsers/parse-basis.js +245 -0
  161. package/dist/lib/parsers/parse-compressed-texture.d.ts +8 -0
  162. package/dist/lib/parsers/parse-compressed-texture.d.ts.map +1 -0
  163. package/dist/lib/parsers/parse-compressed-texture.js +26 -0
  164. package/dist/lib/parsers/parse-crunch.d.ts +9 -0
  165. package/dist/lib/parsers/parse-crunch.d.ts.map +1 -0
  166. package/dist/lib/parsers/parse-crunch.js +105 -0
  167. package/dist/lib/parsers/parse-dds.d.ts +28 -0
  168. package/dist/lib/parsers/parse-dds.d.ts.map +1 -0
  169. package/dist/lib/parsers/parse-dds.js +108 -0
  170. package/dist/lib/parsers/parse-ktx.d.ts +3 -0
  171. package/dist/lib/parsers/parse-ktx.d.ts.map +1 -0
  172. package/dist/lib/parsers/parse-ktx.js +46 -0
  173. package/dist/lib/parsers/parse-npy.d.ts +10 -0
  174. package/dist/lib/parsers/parse-npy.d.ts.map +1 -0
  175. package/dist/lib/parsers/parse-npy.js +85 -0
  176. package/dist/lib/parsers/parse-pvr.d.ts +15 -0
  177. package/dist/lib/parsers/parse-pvr.d.ts.map +1 -0
  178. package/dist/lib/parsers/parse-pvr.js +250 -0
  179. package/dist/lib/texture-api/async-deep-map.d.ts +5 -0
  180. package/dist/lib/texture-api/async-deep-map.d.ts.map +1 -0
  181. package/dist/lib/texture-api/async-deep-map.js +41 -0
  182. package/dist/lib/texture-api/deep-load.d.ts +5 -0
  183. package/dist/lib/texture-api/deep-load.d.ts.map +1 -0
  184. package/dist/lib/texture-api/deep-load.js +16 -0
  185. package/dist/lib/texture-api/generate-url.d.ts +3 -0
  186. package/dist/lib/texture-api/generate-url.d.ts.map +1 -0
  187. package/dist/lib/texture-api/generate-url.js +17 -0
  188. package/dist/lib/texture-api/load-image-array.d.ts +4 -0
  189. package/dist/lib/texture-api/load-image-array.d.ts.map +1 -0
  190. package/dist/lib/texture-api/load-image-array.js +21 -0
  191. package/dist/lib/texture-api/load-image-cube.d.ts +12 -0
  192. package/dist/lib/texture-api/load-image-cube.d.ts.map +1 -0
  193. package/dist/lib/texture-api/load-image-cube.js +47 -0
  194. package/dist/lib/texture-api/load-image.d.ts +8 -0
  195. package/dist/lib/texture-api/load-image.d.ts.map +1 -0
  196. package/dist/lib/texture-api/load-image.js +43 -0
  197. package/dist/lib/texture-api/texture-api-types.d.ts +10 -0
  198. package/dist/lib/texture-api/texture-api-types.d.ts.map +1 -0
  199. package/dist/lib/texture-api/texture-api-types.js +3 -0
  200. package/dist/lib/utils/extract-mipmap-images.d.ts +13 -0
  201. package/dist/lib/utils/extract-mipmap-images.d.ts.map +1 -0
  202. package/dist/lib/utils/extract-mipmap-images.js +50 -0
  203. package/dist/lib/utils/ktx-format-helper.d.ts +9 -0
  204. package/dist/lib/utils/ktx-format-helper.d.ts.map +1 -0
  205. package/dist/lib/utils/ktx-format-helper.js +125 -0
  206. package/dist/lib/utils/texture-formats.d.ts +8 -0
  207. package/dist/lib/utils/texture-formats.d.ts.map +1 -0
  208. package/dist/lib/utils/texture-formats.js +51 -0
  209. package/dist/lib/utils/version.d.ts +2 -0
  210. package/dist/lib/utils/version.d.ts.map +1 -0
  211. package/dist/lib/utils/version.js +8 -0
  212. package/dist/libs/README.md +2 -2
  213. package/dist/libs/basis_encoder.js +1 -1
  214. package/dist/libs/basis_transcoder.js +1 -1
  215. package/dist/libs/crunch.js +1 -0
  216. package/dist/npy-loader.d.ts +45 -0
  217. package/dist/npy-loader.d.ts.map +1 -0
  218. package/dist/npy-loader.js +34 -0
  219. package/dist/npy-worker.js +240 -2
  220. package/dist/types.d.ts +21 -0
  221. package/dist/types.d.ts.map +1 -0
  222. package/dist/types.js +2 -0
  223. package/dist/workers/basis-worker.d.ts +2 -0
  224. package/dist/workers/basis-worker.d.ts.map +1 -0
  225. package/dist/workers/basis-worker.js +5 -0
  226. package/dist/workers/compressed-texture-worker.d.ts +2 -0
  227. package/dist/workers/compressed-texture-worker.d.ts.map +1 -0
  228. package/dist/workers/compressed-texture-worker.js +5 -0
  229. package/dist/workers/crunch-worker.d.ts +21 -0
  230. package/dist/workers/crunch-worker.d.ts.map +1 -0
  231. package/dist/workers/crunch-worker.js +14 -0
  232. package/dist/workers/npy-worker.d.ts +2 -0
  233. package/dist/workers/npy-worker.d.ts.map +1 -0
  234. package/dist/workers/npy-worker.js +5 -0
  235. package/package.json +11 -11
  236. package/src/index.ts +2 -1
  237. package/src/ktx2-basis-universal-texture-writer.ts +27 -0
  238. package/src/lib/encoders/encode-ktx2-basis-texture.ts +44 -0
  239. package/src/lib/{gl-constants.ts → gl-extensions.ts} +1 -1
  240. package/src/lib/parsers/basis-module-loader.ts +12 -4
  241. package/src/lib/parsers/crunch-module-loader.ts +1 -0
  242. package/src/lib/parsers/parse-basis.js +32 -8
  243. package/src/lib/parsers/parse-crunch.ts +4 -4
  244. package/src/lib/parsers/parse-dds.ts +29 -26
  245. package/src/lib/parsers/parse-ktx.js +3 -6
  246. package/src/lib/parsers/parse-ktx.ts +47 -0
  247. package/src/lib/parsers/parse-npy.js +3 -17
  248. package/src/lib/parsers/parse-npy.ts +98 -0
  249. package/src/lib/parsers/parse-pvr.ts +90 -48
  250. package/src/lib/texture-api/async-deep-map.ts +15 -8
  251. package/src/lib/texture-api/deep-load.ts +7 -3
  252. package/src/lib/texture-api/generate-url.ts +10 -8
  253. package/src/lib/texture-api/load-image-array.ts +8 -2
  254. package/src/lib/texture-api/load-image-cube.ts +18 -4
  255. package/src/lib/texture-api/load-image.ts +15 -5
  256. package/src/lib/texture-api/texture-api-types.ts +12 -0
  257. package/src/lib/utils/extract-mipmap-images.ts +16 -3
  258. package/src/lib/utils/ktx-format-helper.ts +71 -71
  259. package/src/libs/README.md +2 -2
  260. package/src/libs/basis_encoder.js +1 -1
  261. package/src/libs/basis_transcoder.js +1 -1
  262. package/src/libs/crunch.js +1 -0
  263. package/src/npy-loader.ts +2 -2
  264. package/dist/basis-worker.js.map +0 -1
  265. package/dist/compressed-texture-worker.js.map +0 -1
  266. package/dist/crunch-worker.js.map +0 -1
  267. package/dist/dist.min.js +0 -2
  268. package/dist/dist.min.js.map +0 -1
  269. package/dist/es5/lib/gl-constants.js.map +0 -1
  270. package/dist/esm/lib/gl-constants.js.map +0 -1
  271. package/dist/npy-worker.js.map +0 -1
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  import {loadLibrary} from '@loaders.gl/worker-utils';
2
3
 
3
4
  /**
@@ -1,20 +1,44 @@
1
1
  import {loadBasisEncoderModule, loadBasisTrascoderModule} from './basis-module-loader';
2
- import {GL} from '../gl-constants';
3
- import {getSupportedGPUTextureFormats} from '../..';
2
+ import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
3
+ import {getSupportedGPUTextureFormats} from '../utils/texture-formats';
4
4
  import {isKTX} from './parse-ktx';
5
5
 
6
6
  const OutputFormat = {
7
- etc1: {basisFormat: 0, compressed: true, format: GL.COMPRESSED_RGB_ETC1_WEBGL},
7
+ etc1: {
8
+ basisFormat: 0,
9
+ compressed: true,
10
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL
11
+ },
8
12
  etc2: {basisFormat: 1, compressed: true},
9
- bc1: {basisFormat: 2, compressed: true, format: GL.COMPRESSED_RGB_S3TC_DXT1_EXT},
10
- bc3: {basisFormat: 3, compressed: true, format: GL.COMPRESSED_RGBA_S3TC_DXT5_EXT},
13
+ bc1: {
14
+ basisFormat: 2,
15
+ compressed: true,
16
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT
17
+ },
18
+ bc3: {
19
+ basisFormat: 3,
20
+ compressed: true,
21
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT
22
+ },
11
23
  bc4: {basisFormat: 4, compressed: true},
12
24
  bc5: {basisFormat: 5, compressed: true},
13
25
  'bc7-m6-opaque-only': {basisFormat: 6, compressed: true},
14
26
  'bc7-m5': {basisFormat: 7, compressed: true},
15
- 'pvrtc1-4-rgb': {basisFormat: 8, compressed: true, format: GL.COMPRESSED_RGB_PVRTC_4BPPV1_IMG},
16
- 'pvrtc1-4-rgba': {basisFormat: 9, compressed: true, format: GL.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG},
17
- 'astc-4x4': {basisFormat: 10, compressed: true, format: GL.COMPRESSED_RGBA_ASTC_4X4_KHR},
27
+ 'pvrtc1-4-rgb': {
28
+ basisFormat: 8,
29
+ compressed: true,
30
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
31
+ },
32
+ 'pvrtc1-4-rgba': {
33
+ basisFormat: 9,
34
+ compressed: true,
35
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
36
+ },
37
+ 'astc-4x4': {
38
+ basisFormat: 10,
39
+ compressed: true,
40
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR
41
+ },
18
42
  'atc-rgb': {basisFormat: 11, compressed: true},
19
43
  'atc-rgba-interpolated-alpha': {basisFormat: 12, compressed: true},
20
44
  rgba32: {basisFormat: 13, compressed: false},
@@ -1,6 +1,6 @@
1
1
  import type {TextureLevel} from '../../types';
2
2
  import {loadCrunchModule} from './crunch-module-loader';
3
- import {GL} from '../gl-constants';
3
+ import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
4
4
  import {assert} from '@loaders.gl/loader-utils';
5
5
  import {getDxt1LevelSize, getDxtXLevelSize} from './parse-dds';
6
6
  import {extractMipmapImages} from '../utils/extract-mipmap-images';
@@ -20,15 +20,15 @@ const CRN_FORMAT = {
20
20
  // Mapping of Crunch formats to DXT formats.
21
21
  const DXT_FORMAT_MAP = {};
22
22
  DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT1] = {
23
- pixelFormat: GL.COMPRESSED_RGB_S3TC_DXT1_EXT,
23
+ pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
24
24
  sizeFunction: getDxt1LevelSize
25
25
  };
26
26
  DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT3] = {
27
- pixelFormat: GL.COMPRESSED_RGBA_S3TC_DXT3_EXT,
27
+ pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
28
28
  sizeFunction: getDxtXLevelSize
29
29
  };
30
30
  DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT5] = {
31
- pixelFormat: GL.COMPRESSED_RGBA_S3TC_DXT5_EXT,
31
+ pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
32
32
  sizeFunction: getDxtXLevelSize
33
33
  };
34
34
 
@@ -1,11 +1,8 @@
1
1
  import type {TextureLevel} from '../../types';
2
2
  import {assert} from '@loaders.gl/loader-utils';
3
- import {GL} from '../gl-constants';
3
+ import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
4
4
  import {extractMipmapImages} from '../utils/extract-mipmap-images';
5
5
 
6
- const getATCLevelSize = getDxt1LevelSize;
7
- const getATCALevelSize = getDxtXLevelSize;
8
- const getATCILevelSize = getDxtXLevelSize;
9
6
  const DDS_CONSTANTS = {
10
7
  MAGIC_NUMBER: 0x20534444,
11
8
  HEADER_LENGTH: 31,
@@ -18,23 +15,29 @@ const DDS_CONSTANTS = {
18
15
  HEADER_PF_FLAGS_INDEX: 20,
19
16
  HEADER_PF_FOURCC_INDEX: 21,
20
17
  DDSD_MIPMAPCOUNT: 0x20000,
21
- DDPF_FOURCC: 0x4,
22
- PIXEL_FORMATS: {
23
- DXT1: GL.COMPRESSED_RGB_S3TC_DXT1_EXT,
24
- DXT3: GL.COMPRESSED_RGBA_S3TC_DXT3_EXT,
25
- DXT5: GL.COMPRESSED_RGBA_S3TC_DXT5_EXT,
26
- 'ATC ': GL.COMPRESSED_RGB_ATC_WEBGL,
27
- ATCA: GL.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL,
28
- ATCI: GL.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL
29
- },
30
- SIZE_FUNCTIONS: {
31
- DXT1: getDxt1LevelSize,
32
- DXT3: getDxtXLevelSize,
33
- DXT5: getDxtXLevelSize,
34
- 'ATC ': getATCLevelSize,
35
- ATCA: getATCALevelSize,
36
- ATCI: getATCILevelSize
37
- }
18
+ DDPF_FOURCC: 0x4
19
+ };
20
+
21
+ const DDS_PIXEL_FORMATS: Record<string, number> = {
22
+ DXT1: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
23
+ DXT3: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
24
+ DXT5: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
25
+ 'ATC ': GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ATC_WEBGL,
26
+ ATCA: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL,
27
+ ATCI: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL
28
+ };
29
+
30
+ const getATCLevelSize = getDxt1LevelSize;
31
+ const getATCALevelSize = getDxtXLevelSize;
32
+ const getATCILevelSize = getDxtXLevelSize;
33
+
34
+ const DDS_SIZE_FUNCTIONS: Record<string, (width: number, height: number) => number> = {
35
+ DXT1: getDxt1LevelSize,
36
+ DXT3: getDxtXLevelSize,
37
+ DXT5: getDxtXLevelSize,
38
+ 'ATC ': getATCLevelSize,
39
+ ATCA: getATCALevelSize,
40
+ ATCI: getATCILevelSize
38
41
  };
39
42
 
40
43
  /**
@@ -61,8 +64,8 @@ export function parseDDS(data: ArrayBuffer): TextureLevel[] {
61
64
  'DDS: Unsupported format, must contain a FourCC code'
62
65
  );
63
66
  const fourCC = int32ToFourCC(pixelFormatNumber);
64
- const internalFormat = DDS_CONSTANTS.PIXEL_FORMATS[fourCC];
65
- const sizeFunction = DDS_CONSTANTS.SIZE_FUNCTIONS[fourCC];
67
+ const internalFormat = DDS_PIXEL_FORMATS[fourCC];
68
+ const sizeFunction = DDS_SIZE_FUNCTIONS[fourCC];
66
69
  assert(internalFormat && sizeFunction, `DDS: Unknown pixel format ${pixelFormatNumber}`);
67
70
 
68
71
  let mipMapLevels = 1;
@@ -105,10 +108,10 @@ export function getDxtXLevelSize(width: number, height: number): number {
105
108
 
106
109
  /**
107
110
  * Convert every byte of Int32 value to char
108
- * @param {number} value - Int32 number
109
- * @returns {string} string of 4 characters
111
+ * @param value - Int32 number
112
+ * @returns string of 4 characters
110
113
  */
111
- function int32ToFourCC(value) {
114
+ function int32ToFourCC(value: number): string {
112
115
  return String.fromCharCode(
113
116
  value & 0xff,
114
117
  (value >> 8) & 0xff,
@@ -1,16 +1,16 @@
1
1
  import {read} from 'ktx-parse';
2
2
  import {extractMipmapImages} from '../utils/extract-mipmap-images';
3
3
  import {mapVkFormatToWebGL} from '../utils/ktx-format-helper';
4
-
5
4
  const KTX2_ID = [
6
5
  // '´', 'K', 'T', 'X', '2', '0', 'ª', '\r', '\n', '\x1A', '\n'
7
6
  0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a
8
7
  ];
9
-
10
8
  // eslint-disable-next-line complexity
11
9
  export function isKTX(data) {
12
- const id = new Uint8Array(data.buffer || data, data.byteOffset || 0, KTX2_ID.length);
10
+ // const id = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
11
+ const id = new Uint8Array(data);
13
12
  const notKTX =
13
+ id.byteLength < KTX2_ID.length ||
14
14
  id[0] !== KTX2_ID[0] || // '´'
15
15
  id[1] !== KTX2_ID[1] || // 'K'
16
16
  id[2] !== KTX2_ID[2] || // 'T'
@@ -23,10 +23,8 @@ export function isKTX(data) {
23
23
  id[9] !== KTX2_ID[9] || // '\n'
24
24
  id[10] !== KTX2_ID[10] || // '\x1A'
25
25
  id[11] !== KTX2_ID[11]; // '\n'
26
-
27
26
  return !notKTX;
28
27
  }
29
-
30
28
  export function parseKTX(arrayBuffer) {
31
29
  const uint8Array = new Uint8Array(arrayBuffer);
32
30
  const ktx = read(uint8Array);
@@ -34,7 +32,6 @@ export function parseKTX(arrayBuffer) {
34
32
  const width = ktx.pixelWidth;
35
33
  const height = ktx.pixelHeight;
36
34
  const internalFormat = mapVkFormatToWebGL(ktx.vkFormat);
37
-
38
35
  return extractMipmapImages(ktx.levels, {
39
36
  mipMapLevels,
40
37
  width,
@@ -0,0 +1,47 @@
1
+ import {read} from 'ktx-parse';
2
+ import {extractMipmapImages} from '../utils/extract-mipmap-images';
3
+ import {mapVkFormatToWebGL} from '../utils/ktx-format-helper';
4
+
5
+ const KTX2_ID = [
6
+ // '´', 'K', 'T', 'X', '2', '0', 'ª', '\r', '\n', '\x1A', '\n'
7
+ 0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a
8
+ ];
9
+
10
+ // eslint-disable-next-line complexity
11
+ export function isKTX(data: ArrayBuffer) {
12
+ // const id = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
13
+ const id = new Uint8Array(data);
14
+ const notKTX =
15
+ id.byteLength < KTX2_ID.length ||
16
+ id[0] !== KTX2_ID[0] || // '´'
17
+ id[1] !== KTX2_ID[1] || // 'K'
18
+ id[2] !== KTX2_ID[2] || // 'T'
19
+ id[3] !== KTX2_ID[3] || // 'X'
20
+ id[4] !== KTX2_ID[4] || // ' '
21
+ id[5] !== KTX2_ID[5] || // '2'
22
+ id[6] !== KTX2_ID[6] || // '0'
23
+ id[7] !== KTX2_ID[7] || // 'ª'
24
+ id[8] !== KTX2_ID[8] || // '\r'
25
+ id[9] !== KTX2_ID[9] || // '\n'
26
+ id[10] !== KTX2_ID[10] || // '\x1A'
27
+ id[11] !== KTX2_ID[11]; // '\n'
28
+
29
+ return !notKTX;
30
+ }
31
+
32
+ export function parseKTX(arrayBuffer: ArrayBuffer) {
33
+ const uint8Array = new Uint8Array(arrayBuffer);
34
+ const ktx = read(uint8Array);
35
+ const mipMapLevels = Math.max(1, ktx.levels.length);
36
+ const width = ktx.pixelWidth;
37
+ const height = ktx.pixelHeight;
38
+ const internalFormat = mapVkFormatToWebGL(ktx.vkFormat);
39
+
40
+ return extractMipmapImages(ktx.levels, {
41
+ mipMapLevels,
42
+ width,
43
+ height,
44
+ sizeFunction: (level: any): number => level.uncompressedByteLength,
45
+ internalFormat
46
+ });
47
+ }
@@ -3,9 +3,7 @@ function systemIsLittleEndian() {
3
3
  const b = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
4
4
  return !(b[0] === 0x12);
5
5
  }
6
-
7
6
  const LITTLE_ENDIAN_OS = systemIsLittleEndian();
8
-
9
7
  // The basic string format consists of 3 characters:
10
8
  // 1. a character describing the byteorder of the data (<: little-endian, >: big-endian, |: not-relevant)
11
9
  // 2. a character code giving the basic type of the array
@@ -24,15 +22,12 @@ const DTYPES = {
24
22
  f4: Float32Array,
25
23
  f8: Float64Array
26
24
  };
27
-
28
25
  export function parseNPY(arrayBuffer, options) {
29
26
  if (!arrayBuffer) {
30
27
  return null;
31
28
  }
32
-
33
29
  const view = new DataView(arrayBuffer);
34
30
  const {header, headerEndOffset} = parseHeader(view);
35
-
36
31
  const numpyType = header.descr;
37
32
  const ArrayType = DTYPES[numpyType.slice(1, 3)];
38
33
  if (!ArrayType) {
@@ -40,34 +35,28 @@ export function parseNPY(arrayBuffer, options) {
40
35
  console.warn(`Decoding of npy dtype not implemented: ${numpyType}`);
41
36
  return null;
42
37
  }
43
-
44
- const nArrayElements = header.shape.reduce((a, b) => a * b);
38
+ const nArrayElements = header.shape?.reduce((a, b) => a * b);
45
39
  const arrayByteLength = nArrayElements * ArrayType.BYTES_PER_ELEMENT;
46
-
47
40
  const data = new ArrayType(arrayBuffer.slice(headerEndOffset, headerEndOffset + arrayByteLength));
48
-
49
41
  // Swap endianness if needed
50
42
  if ((numpyType[0] === '>' && LITTLE_ENDIAN_OS) || (numpyType[0] === '<' && !LITTLE_ENDIAN_OS)) {
51
43
  // eslint-disable-next-line no-console, no-undef
52
44
  console.warn('Data is wrong endianness, byte swapping not yet implemented.');
53
45
  }
54
-
55
46
  return {
56
47
  data,
57
48
  header
58
49
  };
59
50
  }
60
-
61
51
  /**
62
52
  * Parse NPY header
63
53
  *
64
- * @param {DataView} view
65
- * @return {Object}
54
+ * @param view
55
+ * @return
66
56
  */
67
57
  function parseHeader(view) {
68
58
  const majorVersion = view.getUint8(6);
69
59
  // const minorVersion = view.getUint8(7);
70
-
71
60
  let offset = 8;
72
61
  let headerLength;
73
62
  if (majorVersion >= 2) {
@@ -77,13 +66,11 @@ function parseHeader(view) {
77
66
  headerLength = view.getUint16(8, true);
78
67
  offset += 2;
79
68
  }
80
-
81
69
  const encoding = majorVersion <= 2 ? 'latin1' : 'utf-8';
82
70
  const decoder = new TextDecoder(encoding);
83
71
  const headerArray = new Uint8Array(view.buffer, offset, headerLength);
84
72
  const headerText = decoder.decode(headerArray);
85
73
  offset += headerLength;
86
-
87
74
  const header = JSON.parse(
88
75
  headerText
89
76
  .replace(/'/g, '"')
@@ -91,6 +78,5 @@ function parseHeader(view) {
91
78
  .replace('(', '[')
92
79
  .replace(/,*\),*/g, ']')
93
80
  );
94
-
95
81
  return {header, headerEndOffset: offset};
96
82
  }
@@ -0,0 +1,98 @@
1
+ type NumpyHeader = {descr: string; shape: number[]};
2
+
3
+ function systemIsLittleEndian() {
4
+ const a = new Uint32Array([0x12345678]);
5
+ const b = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
6
+ return !(b[0] === 0x12);
7
+ }
8
+
9
+ const LITTLE_ENDIAN_OS = systemIsLittleEndian();
10
+
11
+ // The basic string format consists of 3 characters:
12
+ // 1. a character describing the byteorder of the data (<: little-endian, >: big-endian, |: not-relevant)
13
+ // 2. a character code giving the basic type of the array
14
+ // 3. an integer providing the number of bytes the type uses.
15
+ // https://numpy.org/doc/stable/reference/arrays.interface.html
16
+ //
17
+ // Here I only include the second and third characters, and check endianness
18
+ // separately
19
+ const DTYPES: Record<string, any> = {
20
+ u1: Uint8Array,
21
+ i1: Int8Array,
22
+ u2: Uint16Array,
23
+ i2: Int16Array,
24
+ u4: Uint32Array,
25
+ i4: Int32Array,
26
+ f4: Float32Array,
27
+ f8: Float64Array
28
+ };
29
+
30
+ export function parseNPY(arrayBuffer: ArrayBuffer, options?: unknown) {
31
+ if (!arrayBuffer) {
32
+ return null;
33
+ }
34
+
35
+ const view = new DataView(arrayBuffer);
36
+ const {header, headerEndOffset} = parseHeader(view);
37
+
38
+ const numpyType = header.descr;
39
+ const ArrayType = DTYPES[numpyType.slice(1, 3)];
40
+ if (!ArrayType) {
41
+ // eslint-disable-next-line no-console, no-undef
42
+ console.warn(`Decoding of npy dtype not implemented: ${numpyType}`);
43
+ return null;
44
+ }
45
+
46
+ const nArrayElements = header.shape?.reduce((a: number, b: number): number => a * b);
47
+ const arrayByteLength = nArrayElements * ArrayType.BYTES_PER_ELEMENT;
48
+
49
+ const data = new ArrayType(arrayBuffer.slice(headerEndOffset, headerEndOffset + arrayByteLength));
50
+
51
+ // Swap endianness if needed
52
+ if ((numpyType[0] === '>' && LITTLE_ENDIAN_OS) || (numpyType[0] === '<' && !LITTLE_ENDIAN_OS)) {
53
+ // eslint-disable-next-line no-console, no-undef
54
+ console.warn('Data is wrong endianness, byte swapping not yet implemented.');
55
+ }
56
+
57
+ return {
58
+ data,
59
+ header
60
+ };
61
+ }
62
+
63
+ /**
64
+ * Parse NPY header
65
+ *
66
+ * @param view
67
+ * @return
68
+ */
69
+ function parseHeader(view: DataView): {header: NumpyHeader; headerEndOffset: number} {
70
+ const majorVersion = view.getUint8(6);
71
+ // const minorVersion = view.getUint8(7);
72
+
73
+ let offset = 8;
74
+ let headerLength;
75
+ if (majorVersion >= 2) {
76
+ headerLength = view.getUint32(8, true);
77
+ offset += 4;
78
+ } else {
79
+ headerLength = view.getUint16(8, true);
80
+ offset += 2;
81
+ }
82
+
83
+ const encoding = majorVersion <= 2 ? 'latin1' : 'utf-8';
84
+ const decoder = new TextDecoder(encoding);
85
+ const headerArray = new Uint8Array(view.buffer, offset, headerLength);
86
+ const headerText = decoder.decode(headerArray);
87
+ offset += headerLength;
88
+
89
+ const header = JSON.parse(
90
+ headerText
91
+ .replace(/'/g, '"')
92
+ .replace('False', 'false')
93
+ .replace('(', '[')
94
+ .replace(/,*\),*/g, ']')
95
+ );
96
+
97
+ return {header, headerEndOffset: offset};
98
+ }
@@ -2,10 +2,10 @@ import {TextureLevel} from '../../types';
2
2
  /* eslint-disable camelcase */
3
3
  // Forked from PicoGL: https://github.com/tsherif/picogl.js/blob/master/examples/utils/utils.js
4
4
  // Copyright (c) 2017 Tarek Sherif, The MIT License (MIT)
5
- import {GL} from '../gl-constants';
5
+ import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
6
6
  import {extractMipmapImages} from '../utils/extract-mipmap-images';
7
7
 
8
- const PVR_CONSTANTS = {
8
+ const PVR_CONSTANTS: Record<string, number> = {
9
9
  MAGIC_NUMBER: 0x03525650,
10
10
  MAGIC_NUMBER_EXTRA: 0x50565203,
11
11
  HEADER_LENGTH: 13,
@@ -19,37 +19,79 @@ const PVR_CONSTANTS = {
19
19
  METADATA_SIZE_INDEX: 12
20
20
  };
21
21
 
22
- const PVR_PIXEL_FORMATS = {
23
- 0: [GL.COMPRESSED_RGB_PVRTC_2BPPV1_IMG],
24
- 1: [GL.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG],
25
- 2: [GL.COMPRESSED_RGB_PVRTC_4BPPV1_IMG],
26
- 3: [GL.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG],
27
- 6: [GL.COMPRESSED_RGB_ETC1_WEBGL],
28
- 7: [GL.COMPRESSED_RGB_S3TC_DXT1_EXT],
29
- 9: [GL.COMPRESSED_RGBA_S3TC_DXT3_EXT],
30
- 11: [GL.COMPRESSED_RGBA_S3TC_DXT5_EXT],
31
- 22: [GL.COMPRESSED_RGB8_ETC2],
32
- 23: [GL.COMPRESSED_RGBA8_ETC2_EAC],
33
- 24: [GL.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2],
34
- 25: [GL.COMPRESSED_R11_EAC],
35
- 26: [GL.COMPRESSED_RG11_EAC],
36
- 27: [GL.COMPRESSED_RGBA_ASTC_4X4_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR],
37
- 28: [GL.COMPRESSED_RGBA_ASTC_5X4_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR],
38
- 29: [GL.COMPRESSED_RGBA_ASTC_5X5_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR],
39
- 30: [GL.COMPRESSED_RGBA_ASTC_6X5_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR],
40
- 31: [GL.COMPRESSED_RGBA_ASTC_6X6_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR],
41
- 32: [GL.COMPRESSED_RGBA_ASTC_8X5_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR],
42
- 33: [GL.COMPRESSED_RGBA_ASTC_8X6_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR],
43
- 34: [GL.COMPRESSED_RGBA_ASTC_8X8_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR],
44
- 35: [GL.COMPRESSED_RGBA_ASTC_10X5_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR],
45
- 36: [GL.COMPRESSED_RGBA_ASTC_10X6_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR],
46
- 37: [GL.COMPRESSED_RGBA_ASTC_10X8_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR],
47
- 38: [GL.COMPRESSED_RGBA_ASTC_10X10_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR],
48
- 39: [GL.COMPRESSED_RGBA_ASTC_12X10_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR],
49
- 40: [GL.COMPRESSED_RGBA_ASTC_12X12_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR]
22
+ const PVR_PIXEL_FORMATS: Record<number, number[]> = {
23
+ 0: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG],
24
+ 1: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG],
25
+ 2: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG],
26
+ 3: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG],
27
+ 6: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL],
28
+ 7: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT],
29
+ 9: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT],
30
+ 11: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT],
31
+ 22: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_ETC2],
32
+ 23: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA8_ETC2_EAC],
33
+ 24: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2],
34
+ 25: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_R11_EAC],
35
+ 26: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RG11_EAC],
36
+ 27: [
37
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR,
38
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR
39
+ ],
40
+ 28: [
41
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X4_KHR,
42
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR
43
+ ],
44
+ 29: [
45
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X5_KHR,
46
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR
47
+ ],
48
+ 30: [
49
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X5_KHR,
50
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR
51
+ ],
52
+ 31: [
53
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X6_KHR,
54
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR
55
+ ],
56
+ 32: [
57
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X5_KHR,
58
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR
59
+ ],
60
+ 33: [
61
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X6_KHR,
62
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR
63
+ ],
64
+ 34: [
65
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X8_KHR,
66
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR
67
+ ],
68
+ 35: [
69
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X5_KHR,
70
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR
71
+ ],
72
+ 36: [
73
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X6_KHR,
74
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR
75
+ ],
76
+ 37: [
77
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X8_KHR,
78
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR
79
+ ],
80
+ 38: [
81
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X10_KHR,
82
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR
83
+ ],
84
+ 39: [
85
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X10_KHR,
86
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR
87
+ ],
88
+ 40: [
89
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X12_KHR,
90
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR
91
+ ]
50
92
  };
51
93
 
52
- const PVR_SIZE_FUNCTIONS = {
94
+ const PVR_SIZE_FUNCTIONS: Record<number, (width: number, height: number) => number> = {
53
95
  0: pvrtc2bppSize,
54
96
  1: pvrtc2bppSize,
55
97
  2: pvrtc4bppSize,
@@ -126,7 +168,7 @@ export function parsePVR(data: ArrayBuffer): TextureLevel[] {
126
168
  }
127
169
 
128
170
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_pvrtc/
129
- function pvrtc2bppSize(width, height) {
171
+ function pvrtc2bppSize(width: number, height: number): number {
130
172
  width = Math.max(width, 16);
131
173
  height = Math.max(height, 8);
132
174
 
@@ -134,7 +176,7 @@ function pvrtc2bppSize(width, height) {
134
176
  }
135
177
 
136
178
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_pvrtc/
137
- function pvrtc4bppSize(width, height) {
179
+ function pvrtc4bppSize(width: number, height: number): number {
138
180
  width = Math.max(width, 8);
139
181
  height = Math.max(height, 8);
140
182
 
@@ -151,7 +193,7 @@ function pvrtc4bppSize(width, height) {
151
193
  // COMPRESSED_SRGB8_ETC2
152
194
  // COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
153
195
  // COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
154
- function dxtEtcSmallSize(width, height) {
196
+ function dxtEtcSmallSize(width: number, height: number): number {
155
197
  return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8;
156
198
  }
157
199
 
@@ -166,71 +208,71 @@ function dxtEtcSmallSize(width, height) {
166
208
  // COMPRESSED_RGBA8_ETC2_EAC
167
209
  // COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
168
210
  // COMPRESSED_RGBA_ASTC_4x4_KHR
169
- function dxtEtcAstcBigSize(width, height) {
211
+ function dxtEtcAstcBigSize(width: number, height: number): number {
170
212
  return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;
171
213
  }
172
214
 
173
215
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
174
- function atc5x4Size(width, height) {
216
+ function atc5x4Size(width: number, height: number): number {
175
217
  return Math.floor((width + 4) / 5) * Math.floor((height + 3) / 4) * 16;
176
218
  }
177
219
 
178
220
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
179
- function atc5x5Size(width, height) {
221
+ function atc5x5Size(width: number, height: number): number {
180
222
  return Math.floor((width + 4) / 5) * Math.floor((height + 4) / 5) * 16;
181
223
  }
182
224
 
183
225
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
184
- function atc6x5Size(width, height) {
226
+ function atc6x5Size(width: number, height: number): number {
185
227
  return Math.floor((width + 5) / 6) * Math.floor((height + 4) / 5) * 16;
186
228
  }
187
229
 
188
230
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
189
- function atc6x6Size(width, height) {
231
+ function atc6x6Size(width: number, height: number): number {
190
232
  return Math.floor((width + 5) / 6) * Math.floor((height + 5) / 6) * 16;
191
233
  }
192
234
 
193
235
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
194
- function atc8x5Size(width, height) {
236
+ function atc8x5Size(width: number, height: number): number {
195
237
  return Math.floor((width + 7) / 8) * Math.floor((height + 4) / 5) * 16;
196
238
  }
197
239
 
198
240
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
199
- function atc8x6Size(width, height) {
241
+ function atc8x6Size(width: number, height: number): number {
200
242
  return Math.floor((width + 7) / 8) * Math.floor((height + 5) / 6) * 16;
201
243
  }
202
244
 
203
245
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
204
- function atc8x8Size(width, height) {
246
+ function atc8x8Size(width: number, height: number): number {
205
247
  return Math.floor((width + 7) / 8) * Math.floor((height + 7) / 8) * 16;
206
248
  }
207
249
 
208
250
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
209
- function atc10x5Size(width, height) {
251
+ function atc10x5Size(width: number, height: number): number {
210
252
  return Math.floor((width + 9) / 10) * Math.floor((height + 4) / 5) * 16;
211
253
  }
212
254
 
213
255
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
214
- function atc10x6Size(width, height) {
256
+ function atc10x6Size(width: number, height: number): number {
215
257
  return Math.floor((width + 9) / 10) * Math.floor((height + 5) / 6) * 16;
216
258
  }
217
259
 
218
260
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
219
- function atc10x8Size(width, height) {
261
+ function atc10x8Size(width: number, height: number): number {
220
262
  return Math.floor((width + 9) / 10) * Math.floor((height + 7) / 8) * 16;
221
263
  }
222
264
 
223
265
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
224
- function atc10x10Size(width, height) {
266
+ function atc10x10Size(width: number, height: number): number {
225
267
  return Math.floor((width + 9) / 10) * Math.floor((height + 9) / 10) * 16;
226
268
  }
227
269
 
228
270
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
229
- function atc12x10Size(width, height) {
271
+ function atc12x10Size(width: number, height: number): number {
230
272
  return Math.floor((width + 11) / 12) * Math.floor((height + 9) / 10) * 16;
231
273
  }
232
274
 
233
275
  // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
234
- function atc12x12Size(width, height) {
276
+ function atc12x12Size(width: number, height: number): number {
235
277
  return Math.floor((width + 11) / 12) * Math.floor((height + 11) / 12) * 16;
236
278
  }