@loaders.gl/textures 4.4.0-alpha.2 → 4.4.0

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 (234) hide show
  1. package/README.md +197 -1
  2. package/dist/basis-loader.d.ts +15 -10
  3. package/dist/basis-loader.d.ts.map +1 -1
  4. package/dist/basis-loader.js +1 -1
  5. package/dist/basis-loader.js.map +1 -0
  6. package/dist/basis-worker-node.js +932 -10040
  7. package/dist/basis-worker.d.ts +2 -0
  8. package/dist/basis-worker.d.ts.map +1 -0
  9. package/dist/basis-worker.js +337 -151
  10. package/dist/basis-worker.js.map +1 -0
  11. package/dist/compressed-texture-loader.d.ts +2 -5
  12. package/dist/compressed-texture-loader.d.ts.map +1 -1
  13. package/dist/compressed-texture-loader.js +2 -3
  14. package/dist/compressed-texture-loader.js.map +1 -0
  15. package/dist/compressed-texture-worker.d.ts +2 -0
  16. package/dist/compressed-texture-worker.d.ts.map +1 -0
  17. package/dist/compressed-texture-worker.js +1148 -365
  18. package/dist/compressed-texture-worker.js.map +1 -0
  19. package/dist/compressed-texture-writer.js +1 -0
  20. package/dist/compressed-texture-writer.js.map +1 -0
  21. package/dist/crunch-loader.d.ts +1 -5
  22. package/dist/crunch-loader.d.ts.map +1 -1
  23. package/dist/crunch-loader.js +2 -3
  24. package/dist/crunch-loader.js.map +1 -0
  25. package/dist/crunch-worker.d.ts +2 -0
  26. package/dist/crunch-worker.d.ts.map +1 -0
  27. package/dist/crunch-worker.js +204 -92
  28. package/dist/crunch-worker.js.map +1 -0
  29. package/dist/dist.dev.js +2687 -677
  30. package/dist/dist.min.js +1 -2
  31. package/dist/index.cjs +1644 -428
  32. package/dist/index.cjs.map +4 -4
  33. package/dist/index.d.ts +13 -4
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +7 -3
  36. package/dist/index.js.map +1 -0
  37. package/dist/ktx2-basis-writer-worker-node.js +574 -9832
  38. package/dist/ktx2-basis-writer-worker.d.ts +2 -0
  39. package/dist/ktx2-basis-writer-worker.d.ts.map +1 -0
  40. package/dist/ktx2-basis-writer-worker.js +45 -7
  41. package/dist/ktx2-basis-writer-worker.js.map +1 -0
  42. package/dist/ktx2-basis-writer.js +1 -0
  43. package/dist/ktx2-basis-writer.js.map +1 -0
  44. package/dist/lib/composite-image/image-texture-cube.d.ts +47 -0
  45. package/dist/lib/composite-image/image-texture-cube.d.ts.map +1 -0
  46. package/dist/lib/composite-image/image-texture-cube.js +42 -0
  47. package/dist/lib/composite-image/image-texture-cube.js.map +1 -0
  48. package/dist/lib/composite-image/parse-composite-image.d.ts +43 -0
  49. package/dist/lib/composite-image/parse-composite-image.d.ts.map +1 -0
  50. package/dist/lib/composite-image/parse-composite-image.js +437 -0
  51. package/dist/lib/composite-image/parse-composite-image.js.map +1 -0
  52. package/dist/lib/encoders/encode-ktx.d.ts +1 -1
  53. package/dist/lib/encoders/encode-ktx.d.ts.map +1 -1
  54. package/dist/lib/encoders/encode-ktx.js +1 -0
  55. package/dist/lib/encoders/encode-ktx.js.map +1 -0
  56. package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts +2 -1
  57. package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts.map +1 -1
  58. package/dist/lib/encoders/encode-ktx2-basis-texture.js +3 -1
  59. package/dist/lib/encoders/encode-ktx2-basis-texture.js.map +1 -0
  60. package/dist/lib/encoders/encode-texture.js +1 -0
  61. package/dist/lib/encoders/encode-texture.js.map +1 -0
  62. package/dist/lib/gl-extensions.d.ts +166 -58
  63. package/dist/lib/gl-extensions.d.ts.map +1 -1
  64. package/dist/lib/gl-extensions.js +178 -66
  65. package/dist/lib/gl-extensions.js.map +1 -0
  66. package/dist/lib/gl-types.d.ts +4 -0
  67. package/dist/lib/gl-types.d.ts.map +1 -0
  68. package/dist/lib/gl-types.js +5 -0
  69. package/dist/lib/gl-types.js.map +1 -0
  70. package/dist/lib/parsers/basis-module-loader.d.ts +3 -2
  71. package/dist/lib/parsers/basis-module-loader.d.ts.map +1 -1
  72. package/dist/lib/parsers/basis-module-loader.js +1 -0
  73. package/dist/lib/parsers/basis-module-loader.js.map +1 -0
  74. package/dist/lib/parsers/crunch-module-loader.d.ts +2 -2
  75. package/dist/lib/parsers/crunch-module-loader.d.ts.map +1 -1
  76. package/dist/lib/parsers/crunch-module-loader.js +1 -0
  77. package/dist/lib/parsers/crunch-module-loader.js.map +1 -0
  78. package/dist/lib/parsers/parse-basis.d.ts +34 -2
  79. package/dist/lib/parsers/parse-basis.d.ts.map +1 -1
  80. package/dist/lib/parsers/parse-basis.js +265 -64
  81. package/dist/lib/parsers/parse-basis.js.map +1 -0
  82. package/dist/lib/parsers/parse-compressed-texture.js +1 -0
  83. package/dist/lib/parsers/parse-compressed-texture.js.map +1 -0
  84. package/dist/lib/parsers/parse-crunch.d.ts.map +1 -1
  85. package/dist/lib/parsers/parse-crunch.js +7 -6
  86. package/dist/lib/parsers/parse-crunch.js.map +1 -0
  87. package/dist/lib/parsers/parse-dds.d.ts.map +1 -1
  88. package/dist/lib/parsers/parse-dds.js +11 -11
  89. package/dist/lib/parsers/parse-dds.js.map +1 -0
  90. package/dist/lib/parsers/parse-hdr.d.ts +21 -0
  91. package/dist/lib/parsers/parse-hdr.d.ts.map +1 -0
  92. package/dist/lib/parsers/parse-hdr.js +305 -0
  93. package/dist/lib/parsers/parse-hdr.js.map +1 -0
  94. package/dist/lib/parsers/parse-ktx.d.ts.map +1 -1
  95. package/dist/lib/parsers/parse-ktx.js +11 -3
  96. package/dist/lib/parsers/parse-ktx.js.map +1 -0
  97. package/dist/lib/parsers/parse-npy.js +1 -0
  98. package/dist/lib/parsers/parse-npy.js.map +1 -0
  99. package/dist/lib/parsers/parse-pvr.d.ts.map +1 -1
  100. package/dist/lib/parsers/parse-pvr.js +32 -74
  101. package/dist/lib/parsers/parse-pvr.js.map +1 -0
  102. package/dist/lib/texture-api/async-deep-map.js +1 -0
  103. package/dist/lib/texture-api/async-deep-map.js.map +1 -0
  104. package/dist/lib/texture-api/deep-load.js +1 -0
  105. package/dist/lib/texture-api/deep-load.js.map +1 -0
  106. package/dist/lib/texture-api/generate-url.d.ts.map +1 -1
  107. package/dist/lib/texture-api/generate-url.js +3 -10
  108. package/dist/lib/texture-api/generate-url.js.map +1 -0
  109. package/dist/lib/texture-api/load-image-array.d.ts +6 -3
  110. package/dist/lib/texture-api/load-image-array.d.ts.map +1 -1
  111. package/dist/lib/texture-api/load-image-array.js +6 -3
  112. package/dist/lib/texture-api/load-image-array.js.map +1 -0
  113. package/dist/lib/texture-api/load-image-cube.d.ts +7 -11
  114. package/dist/lib/texture-api/load-image-cube.d.ts.map +1 -1
  115. package/dist/lib/texture-api/load-image-cube.js +9 -20
  116. package/dist/lib/texture-api/load-image-cube.js.map +1 -0
  117. package/dist/lib/texture-api/load-image.d.ts +6 -3
  118. package/dist/lib/texture-api/load-image.d.ts.map +1 -1
  119. package/dist/lib/texture-api/load-image.js +9 -4
  120. package/dist/lib/texture-api/load-image.js.map +1 -0
  121. package/dist/lib/texture-api/texture-api-types.d.ts +13 -0
  122. package/dist/lib/texture-api/texture-api-types.d.ts.map +1 -1
  123. package/dist/lib/texture-api/texture-api-types.js +1 -0
  124. package/dist/lib/texture-api/texture-api-types.js.map +1 -0
  125. package/dist/lib/utils/detect-supported-texture-formats.d.ts +14 -0
  126. package/dist/lib/utils/detect-supported-texture-formats.d.ts.map +1 -0
  127. package/dist/lib/utils/detect-supported-texture-formats.js +197 -0
  128. package/dist/lib/utils/detect-supported-texture-formats.js.map +1 -0
  129. package/dist/lib/utils/extract-mipmap-images.d.ts +6 -2
  130. package/dist/lib/utils/extract-mipmap-images.d.ts.map +1 -1
  131. package/dist/lib/utils/extract-mipmap-images.js +14 -2
  132. package/dist/lib/utils/extract-mipmap-images.js.map +1 -0
  133. package/dist/lib/utils/ktx-format-helper.d.ts +9 -1
  134. package/dist/lib/utils/ktx-format-helper.d.ts.map +1 -1
  135. package/dist/lib/utils/ktx-format-helper.js +77 -109
  136. package/dist/lib/utils/ktx-format-helper.js.map +1 -0
  137. package/dist/lib/utils/texture-format-map.d.ts +10 -0
  138. package/dist/lib/utils/texture-format-map.d.ts.map +1 -0
  139. package/dist/lib/utils/texture-format-map.js +87 -0
  140. package/dist/lib/utils/texture-format-map.js.map +1 -0
  141. package/dist/lib/utils/version.js +2 -1
  142. package/dist/lib/utils/version.js.map +1 -0
  143. package/dist/libs/libs/README.md +9 -0
  144. package/dist/libs/libs/basis_encoder.js +21 -0
  145. package/dist/libs/libs/basis_encoder.wasm +0 -0
  146. package/dist/libs/libs/basis_transcoder.js +22 -0
  147. package/dist/libs/libs/basis_transcoder.wasm +0 -0
  148. package/dist/libs/libs/crunch.js +136 -0
  149. package/dist/npy-loader.d.ts +2 -2
  150. package/dist/npy-loader.js +1 -0
  151. package/dist/npy-loader.js.map +1 -0
  152. package/dist/npy-worker.d.ts +2 -0
  153. package/dist/npy-worker.d.ts.map +1 -0
  154. package/dist/npy-worker.js +5 -2
  155. package/dist/npy-worker.js.map +1 -0
  156. package/dist/radiance-hdr-loader.d.ts +25 -0
  157. package/dist/radiance-hdr-loader.d.ts.map +1 -0
  158. package/dist/radiance-hdr-loader.js +23 -0
  159. package/dist/radiance-hdr-loader.js.map +1 -0
  160. package/dist/texture-array-loader.d.ts +25 -0
  161. package/dist/texture-array-loader.d.ts.map +1 -0
  162. package/dist/texture-array-loader.js +24 -0
  163. package/dist/texture-array-loader.js.map +1 -0
  164. package/dist/texture-cube-array-loader.d.ts +25 -0
  165. package/dist/texture-cube-array-loader.d.ts.map +1 -0
  166. package/dist/texture-cube-array-loader.js +24 -0
  167. package/dist/texture-cube-array-loader.js.map +1 -0
  168. package/dist/texture-cube-loader.d.ts +25 -0
  169. package/dist/texture-cube-loader.d.ts.map +1 -0
  170. package/dist/texture-cube-loader.js +24 -0
  171. package/dist/texture-cube-loader.js.map +1 -0
  172. package/dist/texture-loader.d.ts +25 -0
  173. package/dist/texture-loader.d.ts.map +1 -0
  174. package/dist/texture-loader.js +24 -0
  175. package/dist/texture-loader.js.map +1 -0
  176. package/dist/workers/basis-worker-node.js +1 -0
  177. package/dist/workers/basis-worker-node.js.map +1 -0
  178. package/dist/workers/basis-worker.js +1 -0
  179. package/dist/workers/basis-worker.js.map +1 -0
  180. package/dist/workers/compressed-texture-worker.js +1 -1
  181. package/dist/workers/compressed-texture-worker.js.map +1 -0
  182. package/dist/workers/crunch-worker.d.ts +1 -3
  183. package/dist/workers/crunch-worker.d.ts.map +1 -1
  184. package/dist/workers/crunch-worker.js +1 -0
  185. package/dist/workers/crunch-worker.js.map +1 -0
  186. package/dist/workers/ktx2-basis-writer-worker-node.js +1 -0
  187. package/dist/workers/ktx2-basis-writer-worker-node.js.map +1 -0
  188. package/dist/workers/ktx2-basis-writer-worker.js +1 -0
  189. package/dist/workers/ktx2-basis-writer-worker.js.map +1 -0
  190. package/dist/workers/npy-worker.js +1 -0
  191. package/dist/workers/npy-worker.js.map +1 -0
  192. package/package.json +27 -6
  193. package/src/basis-loader.ts +19 -9
  194. package/src/basis-worker.ts +7 -0
  195. package/src/compressed-texture-loader.ts +3 -7
  196. package/src/compressed-texture-worker.ts +6 -0
  197. package/src/crunch-loader.ts +1 -5
  198. package/src/crunch-worker.ts +6 -0
  199. package/src/index.ts +21 -4
  200. package/src/ktx2-basis-writer-worker.ts +6 -0
  201. package/src/lib/composite-image/image-texture-cube.ts +49 -0
  202. package/src/lib/composite-image/parse-composite-image.ts +699 -0
  203. package/src/lib/encoders/encode-ktx.ts +1 -1
  204. package/src/lib/encoders/encode-ktx2-basis-texture.ts +4 -2
  205. package/src/lib/gl-extensions.ts +188 -81
  206. package/src/lib/gl-types.ts +136 -0
  207. package/src/lib/parsers/basis-module-loader.ts +5 -5
  208. package/src/lib/parsers/crunch-module-loader.ts +4 -4
  209. package/src/lib/parsers/parse-basis.ts +358 -66
  210. package/src/lib/parsers/parse-crunch.ts +11 -8
  211. package/src/lib/parsers/parse-dds.ts +11 -12
  212. package/src/lib/parsers/parse-hdr.ts +426 -0
  213. package/src/lib/parsers/parse-ktx.ts +13 -3
  214. package/src/lib/parsers/parse-pvr.ts +33 -75
  215. package/src/lib/texture-api/generate-url.ts +2 -12
  216. package/src/lib/texture-api/load-image-array.ts +15 -6
  217. package/src/lib/texture-api/load-image-cube.ts +20 -34
  218. package/src/lib/texture-api/load-image.ts +19 -8
  219. package/src/lib/texture-api/texture-api-types.ts +15 -0
  220. package/src/lib/utils/detect-supported-texture-formats.ts +210 -0
  221. package/src/lib/utils/extract-mipmap-images.ts +23 -4
  222. package/src/lib/utils/ktx-format-helper.ts +135 -111
  223. package/src/lib/utils/texture-format-map.ts +162 -0
  224. package/src/npy-worker.ts +6 -0
  225. package/src/radiance-hdr-loader.ts +36 -0
  226. package/src/texture-array-loader.ts +46 -0
  227. package/src/texture-cube-array-loader.ts +49 -0
  228. package/src/texture-cube-loader.ts +46 -0
  229. package/src/texture-loader.ts +49 -0
  230. package/src/workers/compressed-texture-worker.ts +0 -1
  231. package/dist/lib/utils/texture-formats.d.ts +0 -8
  232. package/dist/lib/utils/texture-formats.d.ts.map +0 -1
  233. package/dist/lib/utils/texture-formats.js +0 -50
  234. package/src/lib/utils/texture-formats.ts +0 -59
@@ -7,6 +7,541 @@
7
7
  }
8
8
  }
9
9
 
10
+ // ../../node_modules/@probe.gl/env/dist/lib/globals.js
11
+ var window_ = globalThis;
12
+ var document_ = globalThis.document || {};
13
+ var process_ = globalThis.process || {};
14
+ var console_ = globalThis.console;
15
+ var navigator_ = globalThis.navigator || {};
16
+
17
+ // ../../node_modules/@probe.gl/env/dist/lib/is-electron.js
18
+ function isElectron(mockUserAgent) {
19
+ if (typeof window !== "undefined" && window.process?.type === "renderer") {
20
+ return true;
21
+ }
22
+ if (typeof process !== "undefined" && Boolean(process.versions?.["electron"])) {
23
+ return true;
24
+ }
25
+ const realUserAgent = typeof navigator !== "undefined" && navigator.userAgent;
26
+ const userAgent = mockUserAgent || realUserAgent;
27
+ return Boolean(userAgent && userAgent.indexOf("Electron") >= 0);
28
+ }
29
+
30
+ // ../../node_modules/@probe.gl/env/dist/lib/is-browser.js
31
+ function isBrowser() {
32
+ const isNode = (
33
+ // @ts-expect-error
34
+ typeof process === "object" && String(process) === "[object process]" && !process?.browser
35
+ );
36
+ return !isNode || isElectron();
37
+ }
38
+
39
+ // ../../node_modules/@probe.gl/env/dist/index.js
40
+ var VERSION = true ? "4.1.1" : "untranspiled source";
41
+
42
+ // ../../node_modules/@probe.gl/log/dist/utils/assert.js
43
+ function assert2(condition, message) {
44
+ if (!condition) {
45
+ throw new Error(message || "Assertion failed");
46
+ }
47
+ }
48
+
49
+ // ../../node_modules/@probe.gl/log/dist/loggers/log-utils.js
50
+ function normalizeLogLevel(logLevel) {
51
+ if (!logLevel) {
52
+ return 0;
53
+ }
54
+ let resolvedLevel;
55
+ switch (typeof logLevel) {
56
+ case "number":
57
+ resolvedLevel = logLevel;
58
+ break;
59
+ case "object":
60
+ resolvedLevel = logLevel.logLevel || logLevel.priority || 0;
61
+ break;
62
+ default:
63
+ return 0;
64
+ }
65
+ assert2(Number.isFinite(resolvedLevel) && resolvedLevel >= 0);
66
+ return resolvedLevel;
67
+ }
68
+ function normalizeArguments(opts) {
69
+ const { logLevel, message } = opts;
70
+ opts.logLevel = normalizeLogLevel(logLevel);
71
+ const args = opts.args ? Array.from(opts.args) : [];
72
+ while (args.length && args.shift() !== message) {
73
+ }
74
+ switch (typeof logLevel) {
75
+ case "string":
76
+ case "function":
77
+ if (message !== void 0) {
78
+ args.unshift(message);
79
+ }
80
+ opts.message = logLevel;
81
+ break;
82
+ case "object":
83
+ Object.assign(opts, logLevel);
84
+ break;
85
+ default:
86
+ }
87
+ if (typeof opts.message === "function") {
88
+ opts.message = opts.message();
89
+ }
90
+ const messageType = typeof opts.message;
91
+ assert2(messageType === "string" || messageType === "object");
92
+ return Object.assign(opts, { args }, opts.opts);
93
+ }
94
+
95
+ // ../../node_modules/@probe.gl/log/dist/loggers/base-log.js
96
+ var noop = () => {
97
+ };
98
+ var BaseLog = class {
99
+ constructor({ level = 0 } = {}) {
100
+ this.userData = {};
101
+ this._onceCache = /* @__PURE__ */ new Set();
102
+ this._level = level;
103
+ }
104
+ set level(newLevel) {
105
+ this.setLevel(newLevel);
106
+ }
107
+ get level() {
108
+ return this.getLevel();
109
+ }
110
+ setLevel(level) {
111
+ this._level = level;
112
+ return this;
113
+ }
114
+ getLevel() {
115
+ return this._level;
116
+ }
117
+ // Unconditional logging
118
+ warn(message, ...args) {
119
+ return this._log("warn", 0, message, args, { once: true });
120
+ }
121
+ error(message, ...args) {
122
+ return this._log("error", 0, message, args);
123
+ }
124
+ // Conditional logging
125
+ log(logLevel, message, ...args) {
126
+ return this._log("log", logLevel, message, args);
127
+ }
128
+ info(logLevel, message, ...args) {
129
+ return this._log("info", logLevel, message, args);
130
+ }
131
+ once(logLevel, message, ...args) {
132
+ return this._log("once", logLevel, message, args, { once: true });
133
+ }
134
+ _log(type, logLevel, message, args, options = {}) {
135
+ const normalized = normalizeArguments({
136
+ logLevel,
137
+ message,
138
+ args: this._buildArgs(logLevel, message, args),
139
+ opts: options
140
+ });
141
+ return this._createLogFunction(type, normalized, options);
142
+ }
143
+ _buildArgs(logLevel, message, args) {
144
+ return [logLevel, message, ...args];
145
+ }
146
+ _createLogFunction(type, normalized, options) {
147
+ if (!this._shouldLog(normalized.logLevel)) {
148
+ return noop;
149
+ }
150
+ const tag = this._getOnceTag(options.tag ?? normalized.tag ?? normalized.message);
151
+ if ((options.once || normalized.once) && tag !== void 0) {
152
+ if (this._onceCache.has(tag)) {
153
+ return noop;
154
+ }
155
+ this._onceCache.add(tag);
156
+ }
157
+ return this._emit(type, normalized);
158
+ }
159
+ _shouldLog(logLevel) {
160
+ return this.getLevel() >= normalizeLogLevel(logLevel);
161
+ }
162
+ _getOnceTag(tag) {
163
+ if (tag === void 0) {
164
+ return void 0;
165
+ }
166
+ try {
167
+ return typeof tag === "string" ? tag : String(tag);
168
+ } catch {
169
+ return void 0;
170
+ }
171
+ }
172
+ };
173
+
174
+ // ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
175
+ function getStorage(type) {
176
+ try {
177
+ const storage = window[type];
178
+ const x = "__storage_test__";
179
+ storage.setItem(x, x);
180
+ storage.removeItem(x);
181
+ return storage;
182
+ } catch (e) {
183
+ return null;
184
+ }
185
+ }
186
+ var LocalStorage = class {
187
+ constructor(id, defaultConfig, type = "sessionStorage") {
188
+ this.storage = getStorage(type);
189
+ this.id = id;
190
+ this.config = defaultConfig;
191
+ this._loadConfiguration();
192
+ }
193
+ getConfiguration() {
194
+ return this.config;
195
+ }
196
+ setConfiguration(configuration) {
197
+ Object.assign(this.config, configuration);
198
+ if (this.storage) {
199
+ const serialized = JSON.stringify(this.config);
200
+ this.storage.setItem(this.id, serialized);
201
+ }
202
+ }
203
+ // Get config from persistent store, if available
204
+ _loadConfiguration() {
205
+ let configuration = {};
206
+ if (this.storage) {
207
+ const serializedConfiguration = this.storage.getItem(this.id);
208
+ configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {};
209
+ }
210
+ Object.assign(this.config, configuration);
211
+ return this;
212
+ }
213
+ };
214
+
215
+ // ../../node_modules/@probe.gl/log/dist/utils/formatters.js
216
+ function formatTime(ms) {
217
+ let formatted;
218
+ if (ms < 10) {
219
+ formatted = `${ms.toFixed(2)}ms`;
220
+ } else if (ms < 100) {
221
+ formatted = `${ms.toFixed(1)}ms`;
222
+ } else if (ms < 1e3) {
223
+ formatted = `${ms.toFixed(0)}ms`;
224
+ } else {
225
+ formatted = `${(ms / 1e3).toFixed(2)}s`;
226
+ }
227
+ return formatted;
228
+ }
229
+ function leftPad(string, length = 8) {
230
+ const padLength = Math.max(length - string.length, 0);
231
+ return `${" ".repeat(padLength)}${string}`;
232
+ }
233
+
234
+ // ../../node_modules/@probe.gl/log/dist/utils/color.js
235
+ var COLOR;
236
+ (function(COLOR2) {
237
+ COLOR2[COLOR2["BLACK"] = 30] = "BLACK";
238
+ COLOR2[COLOR2["RED"] = 31] = "RED";
239
+ COLOR2[COLOR2["GREEN"] = 32] = "GREEN";
240
+ COLOR2[COLOR2["YELLOW"] = 33] = "YELLOW";
241
+ COLOR2[COLOR2["BLUE"] = 34] = "BLUE";
242
+ COLOR2[COLOR2["MAGENTA"] = 35] = "MAGENTA";
243
+ COLOR2[COLOR2["CYAN"] = 36] = "CYAN";
244
+ COLOR2[COLOR2["WHITE"] = 37] = "WHITE";
245
+ COLOR2[COLOR2["BRIGHT_BLACK"] = 90] = "BRIGHT_BLACK";
246
+ COLOR2[COLOR2["BRIGHT_RED"] = 91] = "BRIGHT_RED";
247
+ COLOR2[COLOR2["BRIGHT_GREEN"] = 92] = "BRIGHT_GREEN";
248
+ COLOR2[COLOR2["BRIGHT_YELLOW"] = 93] = "BRIGHT_YELLOW";
249
+ COLOR2[COLOR2["BRIGHT_BLUE"] = 94] = "BRIGHT_BLUE";
250
+ COLOR2[COLOR2["BRIGHT_MAGENTA"] = 95] = "BRIGHT_MAGENTA";
251
+ COLOR2[COLOR2["BRIGHT_CYAN"] = 96] = "BRIGHT_CYAN";
252
+ COLOR2[COLOR2["BRIGHT_WHITE"] = 97] = "BRIGHT_WHITE";
253
+ })(COLOR || (COLOR = {}));
254
+ var BACKGROUND_INCREMENT = 10;
255
+ function getColor(color) {
256
+ if (typeof color !== "string") {
257
+ return color;
258
+ }
259
+ color = color.toUpperCase();
260
+ return COLOR[color] || COLOR.WHITE;
261
+ }
262
+ function addColor(string, color, background) {
263
+ if (!isBrowser && typeof string === "string") {
264
+ if (color) {
265
+ const colorCode = getColor(color);
266
+ string = `\x1B[${colorCode}m${string}\x1B[39m`;
267
+ }
268
+ if (background) {
269
+ const colorCode = getColor(background);
270
+ string = `\x1B[${colorCode + BACKGROUND_INCREMENT}m${string}\x1B[49m`;
271
+ }
272
+ }
273
+ return string;
274
+ }
275
+
276
+ // ../../node_modules/@probe.gl/log/dist/utils/autobind.js
277
+ function autobind(obj, predefined = ["constructor"]) {
278
+ const proto = Object.getPrototypeOf(obj);
279
+ const propNames = Object.getOwnPropertyNames(proto);
280
+ const object = obj;
281
+ for (const key of propNames) {
282
+ const value = object[key];
283
+ if (typeof value === "function") {
284
+ if (!predefined.find((name) => key === name)) {
285
+ object[key] = value.bind(obj);
286
+ }
287
+ }
288
+ }
289
+ }
290
+
291
+ // ../../node_modules/@probe.gl/log/dist/utils/hi-res-timestamp.js
292
+ function getHiResTimestamp() {
293
+ let timestamp;
294
+ if (isBrowser() && window_.performance) {
295
+ timestamp = window_?.performance?.now?.();
296
+ } else if ("hrtime" in process_) {
297
+ const timeParts = process_?.hrtime?.();
298
+ timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
299
+ } else {
300
+ timestamp = Date.now();
301
+ }
302
+ return timestamp;
303
+ }
304
+
305
+ // ../../node_modules/@probe.gl/log/dist/loggers/probe-log.js
306
+ var originalConsole = {
307
+ debug: isBrowser() ? console.debug || console.log : console.log,
308
+ log: console.log,
309
+ info: console.info,
310
+ warn: console.warn,
311
+ error: console.error
312
+ };
313
+ var DEFAULT_LOG_CONFIGURATION = {
314
+ enabled: true,
315
+ level: 0
316
+ };
317
+ var ProbeLog = class extends BaseLog {
318
+ constructor({ id } = { id: "" }) {
319
+ super({ level: 0 });
320
+ this.VERSION = VERSION;
321
+ this._startTs = getHiResTimestamp();
322
+ this._deltaTs = getHiResTimestamp();
323
+ this.userData = {};
324
+ this.LOG_THROTTLE_TIMEOUT = 0;
325
+ this.id = id;
326
+ this.userData = {};
327
+ this._storage = new LocalStorage(`__probe-${this.id}__`, { [this.id]: DEFAULT_LOG_CONFIGURATION });
328
+ this.timeStamp(`${this.id} started`);
329
+ autobind(this);
330
+ Object.seal(this);
331
+ }
332
+ isEnabled() {
333
+ return this._getConfiguration().enabled;
334
+ }
335
+ getLevel() {
336
+ return this._getConfiguration().level;
337
+ }
338
+ /** @return milliseconds, with fractions */
339
+ getTotal() {
340
+ return Number((getHiResTimestamp() - this._startTs).toPrecision(10));
341
+ }
342
+ /** @return milliseconds, with fractions */
343
+ getDelta() {
344
+ return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10));
345
+ }
346
+ /** @deprecated use logLevel */
347
+ set priority(newPriority) {
348
+ this.level = newPriority;
349
+ }
350
+ /** @deprecated use logLevel */
351
+ get priority() {
352
+ return this.level;
353
+ }
354
+ /** @deprecated use logLevel */
355
+ getPriority() {
356
+ return this.level;
357
+ }
358
+ // Configure
359
+ enable(enabled = true) {
360
+ this._updateConfiguration({ enabled });
361
+ return this;
362
+ }
363
+ setLevel(level) {
364
+ this._updateConfiguration({ level });
365
+ return this;
366
+ }
367
+ /** return the current status of the setting */
368
+ get(setting) {
369
+ return this._getConfiguration()[setting];
370
+ }
371
+ // update the status of the setting
372
+ set(setting, value) {
373
+ this._updateConfiguration({ [setting]: value });
374
+ }
375
+ /** Logs the current settings as a table */
376
+ settings() {
377
+ if (console.table) {
378
+ console.table(this._storage.config);
379
+ } else {
380
+ console.log(this._storage.config);
381
+ }
382
+ }
383
+ // Unconditional logging
384
+ assert(condition, message) {
385
+ if (!condition) {
386
+ throw new Error(message || "Assertion failed");
387
+ }
388
+ }
389
+ warn(message, ...args) {
390
+ return this._log("warn", 0, message, args, {
391
+ method: originalConsole.warn,
392
+ once: true
393
+ });
394
+ }
395
+ error(message, ...args) {
396
+ return this._log("error", 0, message, args, {
397
+ method: originalConsole.error
398
+ });
399
+ }
400
+ /** Print a deprecation warning */
401
+ deprecated(oldUsage, newUsage) {
402
+ return this.warn(`\`${oldUsage}\` is deprecated and will be removed in a later version. Use \`${newUsage}\` instead`);
403
+ }
404
+ /** Print a removal warning */
405
+ removed(oldUsage, newUsage) {
406
+ return this.error(`\`${oldUsage}\` has been removed. Use \`${newUsage}\` instead`);
407
+ }
408
+ probe(logLevel, message, ...args) {
409
+ return this._log("log", logLevel, message, args, {
410
+ method: originalConsole.log,
411
+ time: true,
412
+ once: true
413
+ });
414
+ }
415
+ log(logLevel, message, ...args) {
416
+ return this._log("log", logLevel, message, args, {
417
+ method: originalConsole.debug
418
+ });
419
+ }
420
+ info(logLevel, message, ...args) {
421
+ return this._log("info", logLevel, message, args, { method: console.info });
422
+ }
423
+ once(logLevel, message, ...args) {
424
+ return this._log("once", logLevel, message, args, {
425
+ method: originalConsole.debug || originalConsole.info,
426
+ once: true
427
+ });
428
+ }
429
+ /** Logs an object as a table */
430
+ table(logLevel, table, columns) {
431
+ if (table) {
432
+ return this._log("table", logLevel, table, columns && [columns] || [], {
433
+ method: console.table || noop,
434
+ tag: getTableHeader(table)
435
+ });
436
+ }
437
+ return noop;
438
+ }
439
+ time(logLevel, message) {
440
+ return this._log("time", logLevel, message, [], {
441
+ method: console.time ? console.time : console.info
442
+ });
443
+ }
444
+ timeEnd(logLevel, message) {
445
+ return this._log("time", logLevel, message, [], {
446
+ method: console.timeEnd ? console.timeEnd : console.info
447
+ });
448
+ }
449
+ timeStamp(logLevel, message) {
450
+ return this._log("time", logLevel, message, [], {
451
+ method: console.timeStamp || noop
452
+ });
453
+ }
454
+ group(logLevel, message, opts = { collapsed: false }) {
455
+ const method = (opts.collapsed ? console.groupCollapsed : console.group) || console.info;
456
+ return this._log("group", logLevel, message, [], { method });
457
+ }
458
+ groupCollapsed(logLevel, message, opts = {}) {
459
+ return this.group(logLevel, message, Object.assign({}, opts, { collapsed: true }));
460
+ }
461
+ groupEnd(logLevel) {
462
+ return this._log("groupEnd", logLevel, "", [], {
463
+ method: console.groupEnd || noop
464
+ });
465
+ }
466
+ // EXPERIMENTAL
467
+ withGroup(logLevel, message, func) {
468
+ this.group(logLevel, message)();
469
+ try {
470
+ func();
471
+ } finally {
472
+ this.groupEnd(logLevel)();
473
+ }
474
+ }
475
+ trace() {
476
+ if (console.trace) {
477
+ console.trace();
478
+ }
479
+ }
480
+ _shouldLog(logLevel) {
481
+ return this.isEnabled() && super._shouldLog(logLevel);
482
+ }
483
+ _emit(_type, normalized) {
484
+ const method = normalized.method;
485
+ assert2(method);
486
+ normalized.total = this.getTotal();
487
+ normalized.delta = this.getDelta();
488
+ this._deltaTs = getHiResTimestamp();
489
+ const message = decorateMessage(this.id, normalized.message, normalized);
490
+ return method.bind(console, message, ...normalized.args);
491
+ }
492
+ _getConfiguration() {
493
+ if (!this._storage.config[this.id]) {
494
+ this._updateConfiguration(DEFAULT_LOG_CONFIGURATION);
495
+ }
496
+ return this._storage.config[this.id];
497
+ }
498
+ _updateConfiguration(configuration) {
499
+ const currentConfiguration = this._storage.config[this.id] || {
500
+ ...DEFAULT_LOG_CONFIGURATION
501
+ };
502
+ this._storage.setConfiguration({
503
+ [this.id]: { ...currentConfiguration, ...configuration }
504
+ });
505
+ }
506
+ };
507
+ ProbeLog.VERSION = VERSION;
508
+ function decorateMessage(id, message, opts) {
509
+ if (typeof message === "string") {
510
+ const time = opts.time ? leftPad(formatTime(opts.total)) : "";
511
+ message = opts.time ? `${id}: ${time} ${message}` : `${id}: ${message}`;
512
+ message = addColor(message, opts.color, opts.background);
513
+ }
514
+ return message;
515
+ }
516
+ function getTableHeader(table) {
517
+ for (const key in table) {
518
+ for (const title in table[key]) {
519
+ return title || "untitled";
520
+ }
521
+ }
522
+ return "empty";
523
+ }
524
+
525
+ // ../../node_modules/@probe.gl/log/dist/init.js
526
+ globalThis.probe = {};
527
+
528
+ // ../../node_modules/@probe.gl/log/dist/index.js
529
+ var dist_default = new ProbeLog({ id: "@probe.gl/log" });
530
+
531
+ // ../loader-utils/src/lib/log-utils/log.ts
532
+ var VERSION2 = true ? "4.4.0" : "latest";
533
+ var version = VERSION2[0] >= "0" && VERSION2[0] <= "9" ? `v${VERSION2}` : "";
534
+ function createLog() {
535
+ const log2 = new ProbeLog({ id: "loaders.gl" });
536
+ globalThis.loaders ||= {};
537
+ globalThis.loaders.log = log2;
538
+ globalThis.loaders.version = version;
539
+ globalThis.probe ||= {};
540
+ globalThis.probe.loaders = log2;
541
+ return log2;
542
+ }
543
+ var log = createLog();
544
+
10
545
  // ../loader-utils/src/lib/module-utils/js-module-utils.ts
11
546
  function registerJSModules(modules) {
12
547
  globalThis.loaders ||= {};
@@ -27,16 +562,17 @@
27
562
  "loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN."
28
563
  );
29
564
  globalThis._loadersgl_.version = NPM_TAG;
565
+ warningIssued = true;
30
566
  } else {
31
- globalThis._loadersgl_.version = "4.4.0-alpha.1";
567
+ globalThis._loadersgl_.version = "4.4.0";
32
568
  }
33
569
  }
34
570
  return globalThis._loadersgl_.version;
35
571
  }
36
- var VERSION = getVersion();
572
+ var VERSION3 = getVersion();
37
573
 
38
574
  // ../worker-utils/src/lib/env-utils/assert.ts
39
- function assert2(condition, message) {
575
+ function assert3(condition, message) {
40
576
  if (!condition) {
41
577
  throw new Error(message || "loaders.gl assertion failed.");
42
578
  }
@@ -50,10 +586,10 @@
50
586
  document: typeof document !== "undefined" && document
51
587
  };
52
588
  var self_ = globals.self || globals.window || globals.global || {};
53
- var window_ = globals.window || globals.self || globals.global || {};
54
- var global_ = globals.global || globals.self || globals.window || {};
55
- var document_ = globals.document || {};
56
- var isBrowser = (
589
+ var window_2 = globals.window || globals.self || globals.global || {};
590
+ var global_2 = globals.global || globals.self || globals.window || {};
591
+ var document_2 = globals.document || {};
592
+ var isBrowser2 = (
57
593
  // @ts-ignore process.browser
58
594
  typeof process !== "object" || String(process) !== "[object process]" || process.browser
59
595
  );
@@ -182,6 +718,16 @@
182
718
 
183
719
  // ../worker-utils/src/lib/library-utils/library-utils.ts
184
720
  var loadLibraryPromises = {};
721
+ function extractLoadLibraryOptions(options = {}) {
722
+ const useLocalLibraries = options.useLocalLibraries ?? options.core?.useLocalLibraries;
723
+ const CDN = options.CDN ?? options.core?.CDN;
724
+ const modules = options.modules;
725
+ return {
726
+ ...useLocalLibraries !== void 0 ? { useLocalLibraries } : {},
727
+ ...CDN !== void 0 ? { CDN } : {},
728
+ ...modules !== void 0 ? { modules } : {}
729
+ };
730
+ }
185
731
  async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null) {
186
732
  if (moduleName) {
187
733
  libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
@@ -191,6 +737,9 @@
191
737
  return await loadLibraryPromises[libraryUrl];
192
738
  }
193
739
  function getLibraryUrl(library, moduleName, options = {}, libraryName = null) {
740
+ if (options?.core) {
741
+ throw new Error("loadLibrary: options.core must be pre-normalized");
742
+ }
194
743
  if (!options.useLocalLibraries && library.startsWith("http")) {
195
744
  return library;
196
745
  }
@@ -199,12 +748,12 @@
199
748
  if (modules[libraryName]) {
200
749
  return modules[libraryName];
201
750
  }
202
- if (!isBrowser) {
751
+ if (!isBrowser2) {
203
752
  return `modules/${moduleName}/dist/libs/${libraryName}`;
204
753
  }
205
754
  if (options.CDN) {
206
- assert2(options.CDN.startsWith("http"));
207
- return `${options.CDN}/${moduleName}@${VERSION}/dist/libs/${libraryName}`;
755
+ assert3(options.CDN.startsWith("http"));
756
+ return `${options.CDN}/${moduleName}@${VERSION3}/dist/libs/${libraryName}`;
208
757
  }
209
758
  if (isWorker) {
210
759
  return `../src/libs/${libraryName}`;
@@ -215,11 +764,21 @@
215
764
  if (libraryUrl.endsWith("wasm")) {
216
765
  return await loadAsArrayBuffer(libraryUrl);
217
766
  }
218
- if (!isBrowser) {
767
+ if (!isBrowser2) {
768
+ const { requireFromFile } = globalThis.loaders || {};
219
769
  try {
220
- const { requireFromFile } = globalThis.loaders || {};
221
- return await requireFromFile?.(libraryUrl);
770
+ const result = await requireFromFile?.(libraryUrl);
771
+ if (result || !libraryUrl.includes("/dist/libs/")) {
772
+ return result;
773
+ }
774
+ return await requireFromFile?.(libraryUrl.replace("/dist/libs/", "/src/libs/"));
222
775
  } catch (error) {
776
+ if (libraryUrl.includes("/dist/libs/")) {
777
+ try {
778
+ return await requireFromFile?.(libraryUrl.replace("/dist/libs/", "/src/libs/"));
779
+ } catch {
780
+ }
781
+ }
223
782
  console.error(error);
224
783
  return null;
225
784
  }
@@ -231,7 +790,7 @@
231
790
  return loadLibraryFromString(scriptSource, libraryUrl);
232
791
  }
233
792
  function loadLibraryFromString(scriptSource, id) {
234
- if (!isBrowser) {
793
+ if (!isBrowser2) {
235
794
  const { requireFromString } = globalThis.loaders || {};
236
795
  return requireFromString?.(scriptSource, id);
237
796
  }
@@ -251,19 +810,33 @@
251
810
  }
252
811
  async function loadAsArrayBuffer(url) {
253
812
  const { readFileAsArrayBuffer } = globalThis.loaders || {};
254
- if (isBrowser || !readFileAsArrayBuffer || url.startsWith("http")) {
813
+ if (isBrowser2 || !readFileAsArrayBuffer || url.startsWith("http")) {
255
814
  const response = await fetch(url);
256
815
  return await response.arrayBuffer();
257
816
  }
258
- return await readFileAsArrayBuffer(url);
817
+ try {
818
+ return await readFileAsArrayBuffer(url);
819
+ } catch {
820
+ if (url.includes("/dist/libs/")) {
821
+ return await readFileAsArrayBuffer(url.replace("/dist/libs/", "/src/libs/"));
822
+ }
823
+ throw new Error(`Failed to load ArrayBuffer from ${url}`);
824
+ }
259
825
  }
260
826
  async function loadAsText(url) {
261
827
  const { readFileAsText } = globalThis.loaders || {};
262
- if (isBrowser || !readFileAsText || url.startsWith("http")) {
828
+ if (isBrowser2 || !readFileAsText || url.startsWith("http")) {
263
829
  const response = await fetch(url);
264
830
  return await response.text();
265
831
  }
266
- return await readFileAsText(url);
832
+ try {
833
+ return await readFileAsText(url);
834
+ } catch {
835
+ if (url.includes("/dist/libs/")) {
836
+ return await readFileAsText(url.replace("/dist/libs/", "/src/libs/"));
837
+ }
838
+ throw new Error(`Failed to load text from ${url}`);
839
+ }
267
840
  }
268
841
 
269
842
  // ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
@@ -342,13 +915,16 @@
342
915
  options = {
343
916
  ...options,
344
917
  modules: loader && loader.options && loader.options.modules || {},
345
- worker: false
918
+ core: {
919
+ ...options.core,
920
+ worker: false
921
+ }
346
922
  };
347
923
  return await parser(data, { ...options }, context, loader);
348
924
  }
349
925
 
350
926
  // src/lib/utils/version.ts
351
- var VERSION2 = true ? "4.4.0-alpha.1" : "latest";
927
+ var VERSION4 = true ? "4.4.0" : "latest";
352
928
 
353
929
  // ../../node_modules/ktx-parse/dist/ktx-parse.modern.js
354
930
  var KHR_SUPERCOMPRESSION_NONE = 0;
@@ -599,23 +1175,178 @@
599
1175
  return container;
600
1176
  }
601
1177
 
1178
+ // src/lib/gl-extensions.ts
1179
+ var GL_RGBA4 = 32854;
1180
+ var GL_RGBA8 = 32856;
1181
+ var GL_RGB565 = 36194;
1182
+ var GL_RGBA32F = 34836;
1183
+ var GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 33776;
1184
+ var GL_COMPRESSED_RGBA_S3TC_DXT1_EXT = 33777;
1185
+ var GL_COMPRESSED_RGBA_S3TC_DXT3_EXT = 33778;
1186
+ var GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 33779;
1187
+ var GL_COMPRESSED_R11_EAC = 37488;
1188
+ var GL_COMPRESSED_SIGNED_R11_EAC = 37489;
1189
+ var GL_COMPRESSED_RG11_EAC = 37490;
1190
+ var GL_COMPRESSED_SIGNED_RG11_EAC = 37491;
1191
+ var GL_COMPRESSED_RGB8_ETC2 = 37492;
1192
+ var GL_COMPRESSED_RGBA8_ETC2_EAC = 37493;
1193
+ var GL_COMPRESSED_SRGB8_ETC2 = 37494;
1194
+ var GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 37495;
1195
+ var GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 37496;
1196
+ var GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 37497;
1197
+ var GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 35840;
1198
+ var GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 35841;
1199
+ var GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 35842;
1200
+ var GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 35843;
1201
+ var GL_COMPRESSED_RGB_ETC1_WEBGL = 36196;
1202
+ var GL_COMPRESSED_RGB_ATC_WEBGL = 35986;
1203
+ var GL_COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL = 35987;
1204
+ var GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL = 34798;
1205
+ var GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 37808;
1206
+ var GL_COMPRESSED_RGBA_ASTC_5x4_KHR = 37809;
1207
+ var GL_COMPRESSED_RGBA_ASTC_5x5_KHR = 37810;
1208
+ var GL_COMPRESSED_RGBA_ASTC_6x5_KHR = 37811;
1209
+ var GL_COMPRESSED_RGBA_ASTC_6x6_KHR = 37812;
1210
+ var GL_COMPRESSED_RGBA_ASTC_8x5_KHR = 37813;
1211
+ var GL_COMPRESSED_RGBA_ASTC_8x6_KHR = 37814;
1212
+ var GL_COMPRESSED_RGBA_ASTC_8x8_KHR = 37815;
1213
+ var GL_COMPRESSED_RGBA_ASTC_10x5_KHR = 37816;
1214
+ var GL_COMPRESSED_RGBA_ASTC_10x6_KHR = 37817;
1215
+ var GL_COMPRESSED_RGBA_ASTC_10x8_KHR = 37818;
1216
+ var GL_COMPRESSED_RGBA_ASTC_10x10_KHR = 37819;
1217
+ var GL_COMPRESSED_RGBA_ASTC_12x10_KHR = 37820;
1218
+ var GL_COMPRESSED_RGBA_ASTC_12x12_KHR = 37821;
1219
+ var GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = 37840;
1220
+ var GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR = 37841;
1221
+ var GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR = 37842;
1222
+ var GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR = 37843;
1223
+ var GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR = 37844;
1224
+ var GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR = 37845;
1225
+ var GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR = 37846;
1226
+ var GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR = 37847;
1227
+ var GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR = 37848;
1228
+ var GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR = 37849;
1229
+ var GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR = 37850;
1230
+ var GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR = 37851;
1231
+ var GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR = 37852;
1232
+ var GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR = 37853;
1233
+ var GL_COMPRESSED_RED_RGTC1_EXT = 36283;
1234
+ var GL_COMPRESSED_SIGNED_RED_RGTC1_EXT = 36284;
1235
+ var GL_COMPRESSED_RED_GREEN_RGTC2_EXT = 36285;
1236
+ var GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT = 36286;
1237
+ var GL_COMPRESSED_RGBA_BPTC_UNORM_EXT = 36492;
1238
+ var GL_COMPRESSED_SRGB_S3TC_DXT1_EXT = 35916;
1239
+ var GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 35917;
1240
+ var GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 35918;
1241
+ var GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 35919;
1242
+
1243
+ // src/lib/utils/texture-format-map.ts
1244
+ var WEBGL_TO_TEXTURE_FORMAT = {
1245
+ [GL_RGBA32F]: "rgba32float",
1246
+ [GL_COMPRESSED_RGB_S3TC_DXT1_EXT]: "bc1-rgb-unorm-webgl",
1247
+ [GL_COMPRESSED_SRGB_S3TC_DXT1_EXT]: "bc1-rgb-unorm-srgb-webgl",
1248
+ [GL_COMPRESSED_RGBA_S3TC_DXT1_EXT]: "bc1-rgba-unorm",
1249
+ [GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT]: "bc1-rgba-unorm-srgb",
1250
+ [GL_COMPRESSED_RGBA_S3TC_DXT3_EXT]: "bc2-rgba-unorm",
1251
+ [GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT]: "bc2-rgba-unorm-srgb",
1252
+ [GL_COMPRESSED_RGBA_S3TC_DXT5_EXT]: "bc3-rgba-unorm",
1253
+ [GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT]: "bc3-rgba-unorm-srgb",
1254
+ [GL_COMPRESSED_RED_RGTC1_EXT]: "bc4-r-unorm",
1255
+ [GL_COMPRESSED_SIGNED_RED_RGTC1_EXT]: "bc4-r-snorm",
1256
+ [GL_COMPRESSED_RED_GREEN_RGTC2_EXT]: "bc5-rg-unorm",
1257
+ [GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT]: "bc5-rg-snorm",
1258
+ [GL_COMPRESSED_RGB8_ETC2]: "etc2-rgb8unorm",
1259
+ [GL_COMPRESSED_SRGB8_ETC2]: "etc2-rgb8unorm-srgb",
1260
+ [GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2]: "etc2-rgb8a1unorm",
1261
+ [GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2]: "etc2-rgb8a1unorm-srgb",
1262
+ [GL_COMPRESSED_RGBA8_ETC2_EAC]: "etc2-rgba8unorm",
1263
+ [GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC]: "etc2-rgba8unorm-srgb",
1264
+ [GL_COMPRESSED_R11_EAC]: "eac-r11unorm",
1265
+ [GL_COMPRESSED_SIGNED_R11_EAC]: "eac-r11snorm",
1266
+ [GL_COMPRESSED_RG11_EAC]: "eac-rg11unorm",
1267
+ [GL_COMPRESSED_SIGNED_RG11_EAC]: "eac-rg11snorm",
1268
+ [GL_COMPRESSED_RGBA_ASTC_4x4_KHR]: "astc-4x4-unorm",
1269
+ [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR]: "astc-4x4-unorm-srgb",
1270
+ [GL_COMPRESSED_RGBA_ASTC_5x4_KHR]: "astc-5x4-unorm",
1271
+ [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR]: "astc-5x4-unorm-srgb",
1272
+ [GL_COMPRESSED_RGBA_ASTC_5x5_KHR]: "astc-5x5-unorm",
1273
+ [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR]: "astc-5x5-unorm-srgb",
1274
+ [GL_COMPRESSED_RGBA_ASTC_6x5_KHR]: "astc-6x5-unorm",
1275
+ [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR]: "astc-6x5-unorm-srgb",
1276
+ [GL_COMPRESSED_RGBA_ASTC_6x6_KHR]: "astc-6x6-unorm",
1277
+ [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR]: "astc-6x6-unorm-srgb",
1278
+ [GL_COMPRESSED_RGBA_ASTC_8x5_KHR]: "astc-8x5-unorm",
1279
+ [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR]: "astc-8x5-unorm-srgb",
1280
+ [GL_COMPRESSED_RGBA_ASTC_8x6_KHR]: "astc-8x6-unorm",
1281
+ [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR]: "astc-8x6-unorm-srgb",
1282
+ [GL_COMPRESSED_RGBA_ASTC_8x8_KHR]: "astc-8x8-unorm",
1283
+ [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR]: "astc-8x8-unorm-srgb",
1284
+ [GL_COMPRESSED_RGBA_ASTC_10x5_KHR]: "astc-10x5-unorm",
1285
+ [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR]: "astc-10x5-unorm-srgb",
1286
+ [GL_COMPRESSED_RGBA_ASTC_10x6_KHR]: "astc-10x6-unorm",
1287
+ [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR]: "astc-10x6-unorm-srgb",
1288
+ [GL_COMPRESSED_RGBA_ASTC_10x8_KHR]: "astc-10x8-unorm",
1289
+ [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR]: "astc-10x8-unorm-srgb",
1290
+ [GL_COMPRESSED_RGBA_ASTC_10x10_KHR]: "astc-10x10-unorm",
1291
+ [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR]: "astc-10x10-unorm-srgb",
1292
+ [GL_COMPRESSED_RGBA_ASTC_12x10_KHR]: "astc-12x10-unorm",
1293
+ [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR]: "astc-12x10-unorm-srgb",
1294
+ [GL_COMPRESSED_RGBA_ASTC_12x12_KHR]: "astc-12x12-unorm",
1295
+ [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR]: "astc-12x12-unorm-srgb",
1296
+ [GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG]: "pvrtc-rgb4unorm-webgl",
1297
+ [GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG]: "pvrtc-rgba4unorm-webgl",
1298
+ [GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG]: "pvrtc-rgb2unorm-webgl",
1299
+ [GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG]: "pvrtc-rgba2unorm-webgl",
1300
+ [GL_COMPRESSED_RGB_ETC1_WEBGL]: "etc1-rgb-unorm-webgl",
1301
+ [GL_COMPRESSED_RGB_ATC_WEBGL]: "atc-rgb-unorm-webgl",
1302
+ [GL_COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL]: "atc-rgba-unorm-webgl",
1303
+ [GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL]: "atc-rgbai-unorm-webgl"
1304
+ };
1305
+ var TEXTURE_FORMAT_TO_WEBGL = Object.fromEntries(
1306
+ Object.entries(WEBGL_TO_TEXTURE_FORMAT).map(([format, textureFormat]) => [
1307
+ textureFormat,
1308
+ Number(format)
1309
+ ])
1310
+ );
1311
+ function getTextureFormatFromWebGLFormat(format) {
1312
+ if (format === void 0) {
1313
+ return void 0;
1314
+ }
1315
+ return WEBGL_TO_TEXTURE_FORMAT[format];
1316
+ }
1317
+ function getWebGLFormatFromTextureFormat(textureFormat) {
1318
+ if (textureFormat === void 0) {
1319
+ return void 0;
1320
+ }
1321
+ return TEXTURE_FORMAT_TO_WEBGL[textureFormat];
1322
+ }
1323
+
602
1324
  // src/lib/utils/extract-mipmap-images.ts
603
1325
  function extractMipmapImages(data, options) {
604
1326
  const images = new Array(options.mipMapLevels);
1327
+ const textureFormat = options.textureFormat || getTextureFormatFromWebGLFormat(options.internalFormat);
1328
+ const format = options.internalFormat || getWebGLFormatFromTextureFormat(options.textureFormat);
605
1329
  let levelWidth = options.width;
606
1330
  let levelHeight = options.height;
607
1331
  let offset = 0;
608
1332
  for (let i = 0; i < options.mipMapLevels; ++i) {
609
1333
  const levelSize = getLevelSize(options, levelWidth, levelHeight, data, i);
610
1334
  const levelData = getLevelData(data, i, offset, levelSize);
611
- images[i] = {
1335
+ const image = {
1336
+ shape: "texture-level",
612
1337
  compressed: true,
613
- format: options.internalFormat,
614
1338
  data: levelData,
615
1339
  width: levelWidth,
616
1340
  height: levelHeight,
617
1341
  levelSize
618
1342
  };
1343
+ if (format !== void 0) {
1344
+ image.format = format;
1345
+ }
1346
+ if (textureFormat) {
1347
+ image.textureFormat = textureFormat;
1348
+ }
1349
+ images[i] = image;
619
1350
  levelWidth = Math.max(1, levelWidth >> 1);
620
1351
  levelHeight = Math.max(1, levelHeight >> 1);
621
1352
  offset += levelSize;
@@ -635,190 +1366,81 @@
635
1366
  return options.sizeFunction(data[index]);
636
1367
  }
637
1368
 
638
- // src/lib/gl-extensions.ts
639
- var GL_EXTENSIONS_CONSTANTS = {
640
- // WEBGL_compressed_texture_s3tc
641
- COMPRESSED_RGB_S3TC_DXT1_EXT: 33776,
642
- COMPRESSED_RGBA_S3TC_DXT1_EXT: 33777,
643
- COMPRESSED_RGBA_S3TC_DXT3_EXT: 33778,
644
- COMPRESSED_RGBA_S3TC_DXT5_EXT: 33779,
645
- // WEBGL_compressed_texture_es3
646
- COMPRESSED_R11_EAC: 37488,
647
- COMPRESSED_SIGNED_R11_EAC: 37489,
648
- COMPRESSED_RG11_EAC: 37490,
649
- COMPRESSED_SIGNED_RG11_EAC: 37491,
650
- COMPRESSED_RGB8_ETC2: 37492,
651
- COMPRESSED_RGBA8_ETC2_EAC: 37493,
652
- COMPRESSED_SRGB8_ETC2: 37494,
653
- COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 37495,
654
- COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37496,
655
- COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37497,
656
- // WEBGL_compressed_texture_pvrtc
657
- COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 35840,
658
- COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 35842,
659
- COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 35841,
660
- COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 35843,
661
- // WEBGL_compressed_texture_etc1
662
- COMPRESSED_RGB_ETC1_WEBGL: 36196,
663
- // WEBGL_compressed_texture_atc
664
- COMPRESSED_RGB_ATC_WEBGL: 35986,
665
- COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: 35987,
666
- COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: 34798,
667
- // WEBGL_compressed_texture_astc
668
- COMPRESSED_RGBA_ASTC_4X4_KHR: 37808,
669
- COMPRESSED_RGBA_ASTC_5X4_KHR: 37809,
670
- COMPRESSED_RGBA_ASTC_5X5_KHR: 37810,
671
- COMPRESSED_RGBA_ASTC_6X5_KHR: 37811,
672
- COMPRESSED_RGBA_ASTC_6X6_KHR: 37812,
673
- COMPRESSED_RGBA_ASTC_8X5_KHR: 37813,
674
- COMPRESSED_RGBA_ASTC_8X6_KHR: 37814,
675
- COMPRESSED_RGBA_ASTC_8X8_KHR: 37815,
676
- COMPRESSED_RGBA_ASTC_10X5_KHR: 37816,
677
- COMPRESSED_RGBA_ASTC_10X6_KHR: 37817,
678
- COMPRESSED_RGBA_ASTC_10X8_KHR: 37818,
679
- COMPRESSED_RGBA_ASTC_10X10_KHR: 37819,
680
- COMPRESSED_RGBA_ASTC_12X10_KHR: 37820,
681
- COMPRESSED_RGBA_ASTC_12X12_KHR: 37821,
682
- COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR: 37840,
683
- COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR: 37841,
684
- COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR: 37842,
685
- COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR: 37843,
686
- COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR: 37844,
687
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR: 37845,
688
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR: 37846,
689
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR: 37847,
690
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR: 37848,
691
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR: 37849,
692
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR: 37850,
693
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR: 37851,
694
- COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR: 37852,
695
- COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR: 37853,
696
- // EXT_texture_compression_rgtc
697
- COMPRESSED_RED_RGTC1_EXT: 36283,
698
- COMPRESSED_SIGNED_RED_RGTC1_EXT: 36284,
699
- COMPRESSED_RED_GREEN_RGTC2_EXT: 36285,
700
- COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: 36286,
701
- // WEBGL_compressed_texture_s3tc_srgb
702
- COMPRESSED_SRGB_S3TC_DXT1_EXT: 35916,
703
- COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 35917,
704
- COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 35918,
705
- COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 35919
706
- };
707
-
708
1369
  // src/lib/utils/ktx-format-helper.ts
709
1370
  var VULKAN_TO_WEBGL_FORMAT_MAP = {
710
- 131: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
711
- 132: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_S3TC_DXT1_EXT,
712
- 133: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT1_EXT,
713
- 134: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
714
- 135: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
715
- 136: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
716
- 137: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
717
- 138: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,
718
- 139: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RED_RGTC1_EXT,
719
- 140: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_RED_RGTC1_EXT,
720
- 141: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RED_GREEN_RGTC2_EXT,
721
- 142: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT,
722
- 147: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_ETC2,
723
- 148: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ETC2,
724
- 149: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
725
- 150: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
726
- 151: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA8_ETC2_EAC,
727
- 152: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
728
- 153: GL_EXTENSIONS_CONSTANTS.COMPRESSED_R11_EAC,
729
- 154: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_R11_EAC,
730
- 155: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RG11_EAC,
731
- 156: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_RG11_EAC,
732
- // @ts-ignore
733
- 157: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4x4_KHR,
734
- // @ts-ignore
735
- 158: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
736
- // @ts-ignore
737
- 159: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x4_KHR,
738
- // @ts-ignore
739
- 160: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR,
740
- // @ts-ignore
741
- 161: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x5_KHR,
742
- // @ts-ignore
743
- 162: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
744
- // @ts-ignore
745
- 163: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x5_KHR,
746
- // @ts-ignore
747
- 164: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
748
- // @ts-ignore
749
- 165: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x6_KHR,
750
- // @ts-ignore
751
- 166: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
752
- // @ts-ignore
753
- 167: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x5_KHR,
754
- // @ts-ignore
755
- 168: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
756
- // @ts-ignore
757
- 169: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x6_KHR,
758
- // @ts-ignore
759
- 170: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
760
- // @ts-ignore
761
- 171: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x8_KHR,
762
- // @ts-ignore
763
- 172: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
764
- // @ts-ignore
765
- 173: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x5_KHR,
766
- // @ts-ignore
767
- 174: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
768
- // @ts-ignore
769
- 175: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x6_KHR,
770
- // @ts-ignore
771
- 176: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
772
- // @ts-ignore
773
- 177: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x8_KHR,
774
- // @ts-ignore
775
- 178: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
776
- // @ts-ignore
777
- 179: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x10_KHR,
778
- // @ts-ignore
779
- 180: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
780
- // @ts-ignore
781
- 181: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x10_KHR,
782
- // @ts-ignore
783
- 182: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
784
- // @ts-ignore
785
- 183: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x12_KHR,
786
- // @ts-ignore
787
- 184: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
788
- 1000054e3: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,
789
- 1000054001: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
790
- // @ts-ignore
791
- 1000066e3: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4x4_KHR,
792
- // @ts-ignore
793
- 1000066001: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x4_KHR,
794
- // @ts-ignore
795
- 1000066002: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x5_KHR,
796
- // @ts-ignore
797
- 1000066003: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x5_KHR,
798
- // @ts-ignore
799
- 1000066004: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x6_KHR,
800
- // @ts-ignore
801
- 1000066005: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x5_KHR,
802
- // @ts-ignore
803
- 1000066006: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x6_KHR,
804
- // @ts-ignore
805
- 1000066007: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x8_KHR,
806
- // @ts-ignore
807
- 1000066008: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x5_KHR,
808
- // @ts-ignore
809
- 1000066009: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x6_KHR,
810
- // @ts-ignore
811
- 1000066010: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x8_KHR,
812
- // @ts-ignore
813
- 1000066011: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x10_KHR,
814
- // @ts-ignore
815
- 1000066012: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x10_KHR,
816
- // @ts-ignore
817
- 1000066013: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x12_KHR
1371
+ 131: GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1372
+ 132: GL_COMPRESSED_SRGB_S3TC_DXT1_EXT,
1373
+ 133: GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
1374
+ 134: GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
1375
+ 135: GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
1376
+ 136: GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
1377
+ 137: GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
1378
+ 138: GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,
1379
+ 139: GL_COMPRESSED_RED_RGTC1_EXT,
1380
+ 140: GL_COMPRESSED_SIGNED_RED_RGTC1_EXT,
1381
+ 141: GL_COMPRESSED_RED_GREEN_RGTC2_EXT,
1382
+ 142: GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT,
1383
+ 147: GL_COMPRESSED_RGB8_ETC2,
1384
+ 148: GL_COMPRESSED_SRGB8_ETC2,
1385
+ 149: GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
1386
+ 150: GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
1387
+ 151: GL_COMPRESSED_RGBA8_ETC2_EAC,
1388
+ 152: GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
1389
+ 153: GL_COMPRESSED_R11_EAC,
1390
+ 154: GL_COMPRESSED_SIGNED_R11_EAC,
1391
+ 155: GL_COMPRESSED_RG11_EAC,
1392
+ 156: GL_COMPRESSED_SIGNED_RG11_EAC,
1393
+ 157: GL_COMPRESSED_RGBA_ASTC_4x4_KHR,
1394
+ 158: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
1395
+ 159: GL_COMPRESSED_RGBA_ASTC_5x4_KHR,
1396
+ 160: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
1397
+ 161: GL_COMPRESSED_RGBA_ASTC_5x5_KHR,
1398
+ 162: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
1399
+ 163: GL_COMPRESSED_RGBA_ASTC_6x5_KHR,
1400
+ 164: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
1401
+ 165: GL_COMPRESSED_RGBA_ASTC_6x6_KHR,
1402
+ 166: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
1403
+ 167: GL_COMPRESSED_RGBA_ASTC_8x5_KHR,
1404
+ 168: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
1405
+ 169: GL_COMPRESSED_RGBA_ASTC_8x6_KHR,
1406
+ 170: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
1407
+ 171: GL_COMPRESSED_RGBA_ASTC_8x8_KHR,
1408
+ 172: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
1409
+ 173: GL_COMPRESSED_RGBA_ASTC_10x5_KHR,
1410
+ 174: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
1411
+ 175: GL_COMPRESSED_RGBA_ASTC_10x6_KHR,
1412
+ 176: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
1413
+ 177: GL_COMPRESSED_RGBA_ASTC_10x8_KHR,
1414
+ 178: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
1415
+ 179: GL_COMPRESSED_RGBA_ASTC_10x10_KHR,
1416
+ 180: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
1417
+ 181: GL_COMPRESSED_RGBA_ASTC_12x10_KHR,
1418
+ 182: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
1419
+ 183: GL_COMPRESSED_RGBA_ASTC_12x12_KHR,
1420
+ 184: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
1421
+ 1000054e3: GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,
1422
+ 1000054001: GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
1423
+ 1000066e3: GL_COMPRESSED_RGBA_ASTC_4x4_KHR,
1424
+ 1000066001: GL_COMPRESSED_RGBA_ASTC_5x4_KHR,
1425
+ 1000066002: GL_COMPRESSED_RGBA_ASTC_5x5_KHR,
1426
+ 1000066003: GL_COMPRESSED_RGBA_ASTC_6x5_KHR,
1427
+ 1000066004: GL_COMPRESSED_RGBA_ASTC_6x6_KHR,
1428
+ 1000066005: GL_COMPRESSED_RGBA_ASTC_8x5_KHR,
1429
+ 1000066006: GL_COMPRESSED_RGBA_ASTC_8x6_KHR,
1430
+ 1000066007: GL_COMPRESSED_RGBA_ASTC_8x8_KHR,
1431
+ 1000066008: GL_COMPRESSED_RGBA_ASTC_10x5_KHR,
1432
+ 1000066009: GL_COMPRESSED_RGBA_ASTC_10x6_KHR,
1433
+ 1000066010: GL_COMPRESSED_RGBA_ASTC_10x8_KHR,
1434
+ 1000066011: GL_COMPRESSED_RGBA_ASTC_10x10_KHR,
1435
+ 1000066012: GL_COMPRESSED_RGBA_ASTC_12x10_KHR,
1436
+ 1000066013: GL_COMPRESSED_RGBA_ASTC_12x12_KHR
818
1437
  };
819
1438
  function mapVkFormatToWebGL(vkFormat) {
820
1439
  return VULKAN_TO_WEBGL_FORMAT_MAP[vkFormat];
821
1440
  }
1441
+ function mapVkFormatToTextureFormat(vkFormat) {
1442
+ return getTextureFormatFromWebGLFormat(mapVkFormatToWebGL(vkFormat));
1443
+ }
822
1444
 
823
1445
  // src/lib/parsers/parse-ktx.ts
824
1446
  var KTX2_ID2 = [
@@ -858,13 +1480,18 @@
858
1480
  const mipMapLevels = Math.max(1, ktx.levels.length);
859
1481
  const width = ktx.pixelWidth;
860
1482
  const height = ktx.pixelHeight;
861
- const internalFormat = mapVkFormatToWebGL(ktx.vkFormat);
1483
+ const textureFormat = mapVkFormatToTextureFormat(ktx.vkFormat);
1484
+ if (textureFormat === void 0) {
1485
+ log.warn(
1486
+ `KTX2 container vkFormat ${ktx.vkFormat} does not map to a known texture format; returning texture levels without format metadata.`
1487
+ )();
1488
+ }
862
1489
  return extractMipmapImages(ktx.levels, {
863
1490
  mipMapLevels,
864
1491
  width,
865
1492
  height,
866
1493
  sizeFunction: (level) => level.uncompressedByteLength,
867
- internalFormat
1494
+ textureFormat
868
1495
  });
869
1496
  }
870
1497
 
@@ -883,13 +1510,13 @@
883
1510
  DDSD_MIPMAPCOUNT: 131072,
884
1511
  DDPF_FOURCC: 4
885
1512
  };
886
- var DDS_PIXEL_FORMATS = {
887
- DXT1: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
888
- DXT3: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
889
- DXT5: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
890
- "ATC ": GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ATC_WEBGL,
891
- ATCA: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL,
892
- ATCI: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL
1513
+ var DDS_TEXTURE_FORMATS = {
1514
+ DXT1: "bc1-rgb-unorm-webgl",
1515
+ DXT3: "bc2-rgba-unorm",
1516
+ DXT5: "bc3-rgba-unorm",
1517
+ "ATC ": "atc-rgb-unorm-webgl",
1518
+ ATCA: "atc-rgba-unorm-webgl",
1519
+ ATCI: "atc-rgbai-unorm-webgl"
893
1520
  };
894
1521
  var getATCLevelSize = getDxt1LevelSize;
895
1522
  var getATCALevelSize = getDxtXLevelSize;
@@ -915,9 +1542,9 @@
915
1542
  "DDS: Unsupported format, must contain a FourCC code"
916
1543
  );
917
1544
  const fourCC = int32ToFourCC(pixelFormatNumber);
918
- const internalFormat = DDS_PIXEL_FORMATS[fourCC];
1545
+ const textureFormat = DDS_TEXTURE_FORMATS[fourCC];
919
1546
  const sizeFunction = DDS_SIZE_FUNCTIONS[fourCC];
920
- assert(internalFormat && sizeFunction, `DDS: Unknown pixel format ${pixelFormatNumber}`);
1547
+ assert(textureFormat && sizeFunction, `DDS: Unknown pixel format ${pixelFormatNumber}`);
921
1548
  let mipMapLevels = 1;
922
1549
  if (header[DDS_CONSTANTS.HEADER_FLAGS_INDEX] & DDS_CONSTANTS.DDSD_MIPMAPCOUNT) {
923
1550
  mipMapLevels = Math.max(1, header[DDS_CONSTANTS.MIPMAPCOUNT_INDEX]);
@@ -931,7 +1558,7 @@
931
1558
  width,
932
1559
  height,
933
1560
  sizeFunction,
934
- internalFormat
1561
+ textureFormat
935
1562
  });
936
1563
  }
937
1564
  function getDxt1LevelSize(width, height) {
@@ -963,76 +1590,34 @@
963
1590
  MIPMAPCOUNT_INDEX: 11,
964
1591
  METADATA_SIZE_INDEX: 12
965
1592
  };
966
- var PVR_PIXEL_FORMATS = {
967
- 0: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG],
968
- 1: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG],
969
- 2: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG],
970
- 3: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG],
971
- 6: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL],
972
- 7: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT],
973
- 9: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT],
974
- 11: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT],
975
- 22: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_ETC2],
976
- 23: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA8_ETC2_EAC],
977
- 24: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2],
978
- 25: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_R11_EAC],
979
- 26: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RG11_EAC],
980
- 27: [
981
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR,
982
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR
983
- ],
984
- 28: [
985
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X4_KHR,
986
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR
987
- ],
988
- 29: [
989
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X5_KHR,
990
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR
991
- ],
992
- 30: [
993
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X5_KHR,
994
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR
995
- ],
996
- 31: [
997
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X6_KHR,
998
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR
999
- ],
1000
- 32: [
1001
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X5_KHR,
1002
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR
1003
- ],
1004
- 33: [
1005
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X6_KHR,
1006
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR
1007
- ],
1008
- 34: [
1009
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X8_KHR,
1010
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR
1011
- ],
1012
- 35: [
1013
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X5_KHR,
1014
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR
1015
- ],
1016
- 36: [
1017
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X6_KHR,
1018
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR
1019
- ],
1020
- 37: [
1021
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X8_KHR,
1022
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR
1023
- ],
1024
- 38: [
1025
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X10_KHR,
1026
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR
1027
- ],
1028
- 39: [
1029
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X10_KHR,
1030
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR
1031
- ],
1032
- 40: [
1033
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X12_KHR,
1034
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR
1035
- ]
1593
+ var PVR_TEXTURE_FORMATS = {
1594
+ 0: ["pvrtc-rgb2unorm-webgl"],
1595
+ 1: ["pvrtc-rgba2unorm-webgl"],
1596
+ 2: ["pvrtc-rgb4unorm-webgl"],
1597
+ 3: ["pvrtc-rgba4unorm-webgl"],
1598
+ 6: ["etc1-rgb-unorm-webgl"],
1599
+ 7: ["bc1-rgb-unorm-webgl"],
1600
+ 9: ["bc2-rgba-unorm"],
1601
+ 11: ["bc3-rgba-unorm"],
1602
+ 22: ["etc2-rgb8unorm"],
1603
+ 23: ["etc2-rgba8unorm"],
1604
+ 24: ["etc2-rgb8a1unorm"],
1605
+ 25: ["eac-r11unorm"],
1606
+ 26: ["eac-rg11unorm"],
1607
+ 27: ["astc-4x4-unorm", "astc-4x4-unorm-srgb"],
1608
+ 28: ["astc-5x4-unorm", "astc-5x4-unorm-srgb"],
1609
+ 29: ["astc-5x5-unorm", "astc-5x5-unorm-srgb"],
1610
+ 30: ["astc-6x5-unorm", "astc-6x5-unorm-srgb"],
1611
+ 31: ["astc-6x6-unorm", "astc-6x6-unorm-srgb"],
1612
+ 32: ["astc-8x5-unorm", "astc-8x5-unorm-srgb"],
1613
+ 33: ["astc-8x6-unorm", "astc-8x6-unorm-srgb"],
1614
+ 34: ["astc-8x8-unorm", "astc-8x8-unorm-srgb"],
1615
+ 35: ["astc-10x5-unorm", "astc-10x5-unorm-srgb"],
1616
+ 36: ["astc-10x6-unorm", "astc-10x6-unorm-srgb"],
1617
+ 37: ["astc-10x8-unorm", "astc-10x8-unorm-srgb"],
1618
+ 38: ["astc-10x10-unorm", "astc-10x10-unorm-srgb"],
1619
+ 39: ["astc-12x10-unorm", "astc-12x10-unorm-srgb"],
1620
+ 40: ["astc-12x12-unorm", "astc-12x12-unorm-srgb"]
1036
1621
  };
1037
1622
  var PVR_SIZE_FUNCTIONS = {
1038
1623
  0: pvrtc2bppSize,
@@ -1065,15 +1650,15 @@
1065
1650
  };
1066
1651
  function isPVR(data) {
1067
1652
  const header = new Uint32Array(data, 0, PVR_CONSTANTS.HEADER_LENGTH);
1068
- const version = header[PVR_CONSTANTS.MAGIC_NUMBER_INDEX];
1069
- return version === PVR_CONSTANTS.MAGIC_NUMBER || version === PVR_CONSTANTS.MAGIC_NUMBER_EXTRA;
1653
+ const version2 = header[PVR_CONSTANTS.MAGIC_NUMBER_INDEX];
1654
+ return version2 === PVR_CONSTANTS.MAGIC_NUMBER || version2 === PVR_CONSTANTS.MAGIC_NUMBER_EXTRA;
1070
1655
  }
1071
1656
  function parsePVR(data) {
1072
1657
  const header = new Uint32Array(data, 0, PVR_CONSTANTS.HEADER_LENGTH);
1073
1658
  const pvrFormat = header[PVR_CONSTANTS.PIXEL_FORMAT_INDEX];
1074
1659
  const colourSpace = header[PVR_CONSTANTS.COLOUR_SPACE_INDEX];
1075
- const pixelFormats = PVR_PIXEL_FORMATS[pvrFormat] || [];
1076
- const internalFormat = pixelFormats.length > 1 && colourSpace ? pixelFormats[1] : pixelFormats[0];
1660
+ const textureFormats2 = PVR_TEXTURE_FORMATS[pvrFormat] || [];
1661
+ const textureFormat = textureFormats2.length > 1 && colourSpace ? textureFormats2[1] : textureFormats2[0];
1077
1662
  const sizeFunction = PVR_SIZE_FUNCTIONS[pvrFormat];
1078
1663
  const mipMapLevels = header[PVR_CONSTANTS.MIPMAPCOUNT_INDEX];
1079
1664
  const width = header[PVR_CONSTANTS.WIDTH_INDEX];
@@ -1085,7 +1670,7 @@
1085
1670
  width,
1086
1671
  height,
1087
1672
  sizeFunction,
1088
- internalFormat
1673
+ textureFormat
1089
1674
  });
1090
1675
  }
1091
1676
  function pvrtc2bppSize(width, height) {
@@ -1235,35 +1820,101 @@
1235
1820
  });
1236
1821
  }
1237
1822
 
1238
- // src/lib/utils/texture-formats.ts
1823
+ // src/lib/utils/detect-supported-texture-formats.ts
1239
1824
  var BROWSER_PREFIXES = ["", "WEBKIT_", "MOZ_"];
1240
- var WEBGL_EXTENSIONS = {
1825
+ var WEBGL_TEXTURE_FORMATS = {
1241
1826
  /* eslint-disable camelcase */
1242
- WEBGL_compressed_texture_s3tc: "dxt",
1243
- WEBGL_compressed_texture_s3tc_srgb: "dxt-srgb",
1244
- WEBGL_compressed_texture_etc1: "etc1",
1245
- WEBGL_compressed_texture_etc: "etc2",
1246
- WEBGL_compressed_texture_pvrtc: "pvrtc",
1247
- WEBGL_compressed_texture_atc: "atc",
1248
- WEBGL_compressed_texture_astc: "astc",
1249
- EXT_texture_compression_rgtc: "rgtc"
1827
+ WEBGL_compressed_texture_s3tc: [
1828
+ "bc1-rgb-unorm-webgl",
1829
+ "bc1-rgba-unorm",
1830
+ "bc2-rgba-unorm",
1831
+ "bc3-rgba-unorm"
1832
+ ],
1833
+ WEBGL_compressed_texture_s3tc_srgb: [
1834
+ "bc1-rgb-unorm-srgb-webgl",
1835
+ "bc1-rgba-unorm-srgb",
1836
+ "bc2-rgba-unorm-srgb",
1837
+ "bc3-rgba-unorm-srgb"
1838
+ ],
1839
+ EXT_texture_compression_rgtc: ["bc4-r-unorm", "bc4-r-snorm", "bc5-rg-unorm", "bc5-rg-snorm"],
1840
+ EXT_texture_compression_bptc: [
1841
+ "bc6h-rgb-ufloat",
1842
+ "bc6h-rgb-float",
1843
+ "bc7-rgba-unorm",
1844
+ "bc7-rgba-unorm-srgb"
1845
+ ],
1846
+ WEBGL_compressed_texture_etc1: ["etc1-rgb-unorm-webgl"],
1847
+ WEBGL_compressed_texture_etc: [
1848
+ "etc2-rgb8unorm",
1849
+ "etc2-rgb8unorm-srgb",
1850
+ "etc2-rgb8a1unorm",
1851
+ "etc2-rgb8a1unorm-srgb",
1852
+ "etc2-rgba8unorm",
1853
+ "etc2-rgba8unorm-srgb",
1854
+ "eac-r11unorm",
1855
+ "eac-r11snorm",
1856
+ "eac-rg11unorm",
1857
+ "eac-rg11snorm"
1858
+ ],
1859
+ WEBGL_compressed_texture_pvrtc: [
1860
+ "pvrtc-rgb4unorm-webgl",
1861
+ "pvrtc-rgba4unorm-webgl",
1862
+ "pvrtc-rgb2unorm-webgl",
1863
+ "pvrtc-rgba2unorm-webgl"
1864
+ ],
1865
+ WEBGL_compressed_texture_atc: [
1866
+ "atc-rgb-unorm-webgl",
1867
+ "atc-rgba-unorm-webgl",
1868
+ "atc-rgbai-unorm-webgl"
1869
+ ],
1870
+ WEBGL_compressed_texture_astc: [
1871
+ "astc-4x4-unorm",
1872
+ "astc-4x4-unorm-srgb",
1873
+ "astc-5x4-unorm",
1874
+ "astc-5x4-unorm-srgb",
1875
+ "astc-5x5-unorm",
1876
+ "astc-5x5-unorm-srgb",
1877
+ "astc-6x5-unorm",
1878
+ "astc-6x5-unorm-srgb",
1879
+ "astc-6x6-unorm",
1880
+ "astc-6x6-unorm-srgb",
1881
+ "astc-8x5-unorm",
1882
+ "astc-8x5-unorm-srgb",
1883
+ "astc-8x6-unorm",
1884
+ "astc-8x6-unorm-srgb",
1885
+ "astc-8x8-unorm",
1886
+ "astc-8x8-unorm-srgb",
1887
+ "astc-10x5-unorm",
1888
+ "astc-10x5-unorm-srgb",
1889
+ "astc-10x6-unorm",
1890
+ "astc-10x6-unorm-srgb",
1891
+ "astc-10x8-unorm",
1892
+ "astc-10x8-unorm-srgb",
1893
+ "astc-10x10-unorm",
1894
+ "astc-10x10-unorm-srgb",
1895
+ "astc-12x10-unorm",
1896
+ "astc-12x10-unorm-srgb",
1897
+ "astc-12x12-unorm",
1898
+ "astc-12x12-unorm-srgb"
1899
+ ]
1250
1900
  /* eslint-enable camelcase */
1251
1901
  };
1252
- var formats = null;
1253
- function getSupportedGPUTextureFormats(gl) {
1254
- if (!formats) {
1902
+ var textureFormats = null;
1903
+ function detectSupportedTextureFormats(gl) {
1904
+ if (!textureFormats) {
1255
1905
  gl = gl || getWebGLContext() || void 0;
1256
- formats = /* @__PURE__ */ new Set();
1906
+ textureFormats = /* @__PURE__ */ new Set();
1257
1907
  for (const prefix of BROWSER_PREFIXES) {
1258
- for (const extension in WEBGL_EXTENSIONS) {
1908
+ for (const extension in WEBGL_TEXTURE_FORMATS) {
1259
1909
  if (gl && gl.getExtension(`${prefix}${extension}`)) {
1260
- const gpuTextureFormat = WEBGL_EXTENSIONS[extension];
1261
- formats.add(gpuTextureFormat);
1910
+ for (const textureFormat of WEBGL_TEXTURE_FORMATS[extension]) {
1911
+ textureFormats.add(textureFormat);
1912
+ }
1262
1913
  }
1263
1914
  }
1264
1915
  }
1265
1916
  }
1266
- return formats;
1917
+ return textureFormats;
1267
1918
  }
1268
1919
  function getWebGLContext() {
1269
1920
  try {
@@ -1275,73 +1926,154 @@
1275
1926
  }
1276
1927
 
1277
1928
  // src/lib/parsers/parse-basis.ts
1278
- var OutputFormat = {
1929
+ var basisTranscodingLock = Promise.resolve();
1930
+ var BASIS_FORMAT_TO_OUTPUT_OPTIONS = {
1279
1931
  etc1: {
1280
1932
  basisFormat: 0,
1281
1933
  compressed: true,
1282
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL
1934
+ format: GL_COMPRESSED_RGB_ETC1_WEBGL,
1935
+ textureFormat: "etc1-rgb-unorm-webgl"
1936
+ },
1937
+ etc2: {
1938
+ basisFormat: 1,
1939
+ compressed: true,
1940
+ format: GL_COMPRESSED_RGBA8_ETC2_EAC,
1941
+ textureFormat: "etc2-rgba8unorm"
1283
1942
  },
1284
- etc2: { basisFormat: 1, compressed: true },
1285
1943
  bc1: {
1286
1944
  basisFormat: 2,
1287
1945
  compressed: true,
1288
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT
1946
+ format: GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1947
+ textureFormat: "bc1-rgb-unorm-webgl"
1289
1948
  },
1290
1949
  bc3: {
1291
1950
  basisFormat: 3,
1292
1951
  compressed: true,
1293
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT
1952
+ format: GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
1953
+ textureFormat: "bc3-rgba-unorm"
1954
+ },
1955
+ bc4: {
1956
+ basisFormat: 4,
1957
+ compressed: true,
1958
+ format: GL_COMPRESSED_RED_RGTC1_EXT,
1959
+ textureFormat: "bc4-r-unorm"
1960
+ },
1961
+ bc5: {
1962
+ basisFormat: 5,
1963
+ compressed: true,
1964
+ format: GL_COMPRESSED_RED_GREEN_RGTC2_EXT,
1965
+ textureFormat: "bc5-rg-unorm"
1966
+ },
1967
+ "bc7-m6-opaque-only": {
1968
+ basisFormat: 6,
1969
+ compressed: true,
1970
+ format: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,
1971
+ textureFormat: "bc7-rgba-unorm"
1972
+ },
1973
+ "bc7-m5": {
1974
+ basisFormat: 7,
1975
+ compressed: true,
1976
+ format: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,
1977
+ textureFormat: "bc7-rgba-unorm"
1294
1978
  },
1295
- bc4: { basisFormat: 4, compressed: true },
1296
- bc5: { basisFormat: 5, compressed: true },
1297
- "bc7-m6-opaque-only": { basisFormat: 6, compressed: true },
1298
- "bc7-m5": { basisFormat: 7, compressed: true },
1299
1979
  "pvrtc1-4-rgb": {
1300
1980
  basisFormat: 8,
1301
1981
  compressed: true,
1302
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
1982
+ format: GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
1983
+ textureFormat: "pvrtc-rgb4unorm-webgl"
1303
1984
  },
1304
1985
  "pvrtc1-4-rgba": {
1305
1986
  basisFormat: 9,
1306
1987
  compressed: true,
1307
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
1988
+ format: GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
1989
+ textureFormat: "pvrtc-rgba4unorm-webgl"
1308
1990
  },
1309
1991
  "astc-4x4": {
1310
1992
  basisFormat: 10,
1311
1993
  compressed: true,
1312
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR
1994
+ format: GL_COMPRESSED_RGBA_ASTC_4x4_KHR,
1995
+ textureFormat: "astc-4x4-unorm"
1996
+ },
1997
+ "atc-rgb": {
1998
+ basisFormat: 11,
1999
+ compressed: true,
2000
+ format: GL_COMPRESSED_RGB_ATC_WEBGL,
2001
+ textureFormat: "atc-rgb-unorm-webgl"
2002
+ },
2003
+ "atc-rgba-interpolated-alpha": {
2004
+ basisFormat: 12,
2005
+ compressed: true,
2006
+ format: GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL,
2007
+ textureFormat: "atc-rgbai-unorm-webgl"
2008
+ },
2009
+ rgba32: {
2010
+ basisFormat: 13,
2011
+ compressed: false,
2012
+ format: GL_RGBA8,
2013
+ textureFormat: "rgba8unorm"
2014
+ },
2015
+ rgb565: {
2016
+ basisFormat: 14,
2017
+ compressed: false,
2018
+ format: GL_RGB565,
2019
+ textureFormat: "rgb565unorm-webgl"
2020
+ },
2021
+ bgr565: {
2022
+ basisFormat: 15,
2023
+ compressed: false,
2024
+ format: GL_RGB565,
2025
+ textureFormat: "rgb565unorm-webgl"
1313
2026
  },
1314
- "atc-rgb": { basisFormat: 11, compressed: true },
1315
- "atc-rgba-interpolated-alpha": { basisFormat: 12, compressed: true },
1316
- rgba32: { basisFormat: 13, compressed: false },
1317
- rgb565: { basisFormat: 14, compressed: false },
1318
- bgr565: { basisFormat: 15, compressed: false },
1319
- rgba4444: { basisFormat: 16, compressed: false }
2027
+ rgba4444: {
2028
+ basisFormat: 16,
2029
+ compressed: false,
2030
+ format: GL_RGBA4,
2031
+ textureFormat: "rgba4unorm-webgl"
2032
+ }
1320
2033
  };
1321
- async function parseBasis(data, options) {
1322
- if (options.basis.containerFormat === "auto") {
1323
- if (isKTX(data)) {
1324
- const fileConstructors = await loadBasisEncoderModule(options);
1325
- return parseKTX2File(fileConstructors.KTX2File, data, options);
1326
- }
1327
- const { BasisFile } = await loadBasisTranscoderModule(options);
1328
- return parseBasisFile(BasisFile, data, options);
1329
- }
1330
- switch (options.basis.module) {
1331
- case "encoder":
1332
- const fileConstructors = await loadBasisEncoderModule(options);
1333
- switch (options.basis.containerFormat) {
1334
- case "ktx2":
1335
- return parseKTX2File(fileConstructors.KTX2File, data, options);
1336
- case "basis":
1337
- default:
1338
- return parseBasisFile(fileConstructors.BasisFile, data, options);
2034
+ var BASIS_FORMATS = Object.freeze(
2035
+ Object.keys(BASIS_FORMAT_TO_OUTPUT_OPTIONS)
2036
+ );
2037
+ async function withBasisTranscodingLock(transcode) {
2038
+ const previousLock = basisTranscodingLock;
2039
+ let releaseLock;
2040
+ basisTranscodingLock = new Promise((resolve) => {
2041
+ releaseLock = resolve;
2042
+ });
2043
+ await previousLock;
2044
+ try {
2045
+ return await transcode();
2046
+ } finally {
2047
+ releaseLock();
2048
+ }
2049
+ }
2050
+ async function parseBasis(data, options = {}) {
2051
+ const loadLibraryOptions = extractLoadLibraryOptions(options);
2052
+ return await withBasisTranscodingLock(async () => {
2053
+ if (!options.basis?.containerFormat || options.basis.containerFormat === "auto") {
2054
+ if (isKTX(data)) {
2055
+ const fileConstructors = await loadBasisEncoderModule(loadLibraryOptions);
2056
+ return parseKTX2File(fileConstructors.KTX2File, data, options);
1339
2057
  }
1340
- case "transcoder":
1341
- default:
1342
- const { BasisFile } = await loadBasisTranscoderModule(options);
2058
+ const { BasisFile } = await loadBasisTranscoderModule(loadLibraryOptions);
1343
2059
  return parseBasisFile(BasisFile, data, options);
1344
- }
2060
+ }
2061
+ switch (options.basis.module) {
2062
+ case "encoder":
2063
+ const fileConstructors = await loadBasisEncoderModule(loadLibraryOptions);
2064
+ switch (options.basis.containerFormat) {
2065
+ case "ktx2":
2066
+ return parseKTX2File(fileConstructors.KTX2File, data, options);
2067
+ case "basis":
2068
+ default:
2069
+ return parseBasisFile(fileConstructors.BasisFile, data, options);
2070
+ }
2071
+ case "transcoder":
2072
+ default:
2073
+ const { BasisFile } = await loadBasisTranscoderModule(loadLibraryOptions);
2074
+ return parseBasisFile(BasisFile, data, options);
2075
+ }
2076
+ });
1345
2077
  }
1346
2078
  function parseBasisFile(BasisFile, data, options) {
1347
2079
  const basisFile = new BasisFile(new Uint8Array(data));
@@ -1371,7 +2103,7 @@
1371
2103
  const hasAlpha = basisFile.getHasAlpha(
1372
2104
  /* imageIndex, levelIndex */
1373
2105
  );
1374
- const { compressed, format, basisFormat } = getBasisOptions(options, hasAlpha);
2106
+ const { compressed, format, basisFormat, textureFormat } = getBasisOptions(options, hasAlpha);
1375
2107
  const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat);
1376
2108
  const decodedData = new Uint8Array(decodedSize);
1377
2109
  if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {
@@ -1379,11 +2111,13 @@
1379
2111
  }
1380
2112
  return {
1381
2113
  // standard loaders.gl image category payload
2114
+ shape: "texture-level",
1382
2115
  width,
1383
2116
  height,
1384
2117
  data: decodedData,
1385
2118
  compressed,
1386
- format,
2119
+ ...format !== void 0 ? { format } : {},
2120
+ ...textureFormat !== void 0 ? { textureFormat } : {},
1387
2121
  // Additional fields
1388
2122
  // Add levelSize field.
1389
2123
  hasAlpha
@@ -1408,7 +2142,7 @@
1408
2142
  }
1409
2143
  function transcodeKTX2Image(ktx2File, levelIndex, options) {
1410
2144
  const { alphaFlag, height, width } = ktx2File.getImageLevelInfo(levelIndex, 0, 0);
1411
- const { compressed, format, basisFormat } = getBasisOptions(options, alphaFlag);
2145
+ const { compressed, format, basisFormat, textureFormat } = getBasisOptions(options, alphaFlag);
1412
2146
  const decodedSize = ktx2File.getImageTranscodedSizeInBytes(
1413
2147
  levelIndex,
1414
2148
  0,
@@ -1431,48 +2165,98 @@
1431
2165
  }
1432
2166
  return {
1433
2167
  // standard loaders.gl image category payload
2168
+ shape: "texture-level",
1434
2169
  width,
1435
2170
  height,
1436
2171
  data: decodedData,
1437
2172
  compressed,
2173
+ ...format !== void 0 ? { format } : {},
2174
+ ...textureFormat !== void 0 ? { textureFormat } : {},
1438
2175
  // Additional fields
1439
2176
  levelSize: decodedSize,
1440
- hasAlpha: alphaFlag,
1441
- format
2177
+ hasAlpha: alphaFlag
1442
2178
  };
1443
2179
  }
1444
2180
  function getBasisOptions(options, hasAlpha) {
1445
- let format = options && options.basis && options.basis.format;
2181
+ let format = options.basis?.format || "auto";
1446
2182
  if (format === "auto") {
1447
- format = selectSupportedBasisFormat();
2183
+ format = options.basis?.supportedTextureFormats ? selectSupportedBasisFormat(options.basis.supportedTextureFormats) : selectSupportedBasisFormat();
1448
2184
  }
1449
2185
  if (typeof format === "object") {
1450
2186
  format = hasAlpha ? format.alpha : format.noAlpha;
1451
2187
  }
1452
- format = format.toLowerCase();
1453
- return OutputFormat[format];
2188
+ const normalizedFormat = format.toLowerCase();
2189
+ const basisOutputOptions = BASIS_FORMAT_TO_OUTPUT_OPTIONS[normalizedFormat];
2190
+ if (!basisOutputOptions) {
2191
+ throw new Error(`Unknown Basis format ${format}`);
2192
+ }
2193
+ return basisOutputOptions;
1454
2194
  }
1455
- function selectSupportedBasisFormat() {
1456
- const supportedFormats = getSupportedGPUTextureFormats();
1457
- if (supportedFormats.has("astc")) {
2195
+ function selectSupportedBasisFormat(supportedTextureFormats = detectSupportedTextureFormats()) {
2196
+ const textureFormats2 = new Set(supportedTextureFormats);
2197
+ if (hasSupportedTextureFormat(textureFormats2, ["astc-4x4-unorm", "astc-4x4-unorm-srgb"])) {
1458
2198
  return "astc-4x4";
1459
- } else if (supportedFormats.has("dxt")) {
2199
+ } else if (hasSupportedTextureFormat(textureFormats2, ["bc7-rgba-unorm", "bc7-rgba-unorm-srgb"])) {
2200
+ return {
2201
+ alpha: "bc7-m5",
2202
+ noAlpha: "bc7-m6-opaque-only"
2203
+ };
2204
+ } else if (hasSupportedTextureFormat(textureFormats2, [
2205
+ "bc1-rgb-unorm-webgl",
2206
+ "bc1-rgb-unorm-srgb-webgl",
2207
+ "bc1-rgba-unorm",
2208
+ "bc1-rgba-unorm-srgb",
2209
+ "bc2-rgba-unorm",
2210
+ "bc2-rgba-unorm-srgb",
2211
+ "bc3-rgba-unorm",
2212
+ "bc3-rgba-unorm-srgb"
2213
+ ])) {
1460
2214
  return {
1461
2215
  alpha: "bc3",
1462
2216
  noAlpha: "bc1"
1463
2217
  };
1464
- } else if (supportedFormats.has("pvrtc")) {
2218
+ } else if (hasSupportedTextureFormat(textureFormats2, [
2219
+ "pvrtc-rgb4unorm-webgl",
2220
+ "pvrtc-rgba4unorm-webgl",
2221
+ "pvrtc-rgb2unorm-webgl",
2222
+ "pvrtc-rgba2unorm-webgl"
2223
+ ])) {
1465
2224
  return {
1466
2225
  alpha: "pvrtc1-4-rgba",
1467
2226
  noAlpha: "pvrtc1-4-rgb"
1468
2227
  };
1469
- } else if (supportedFormats.has("etc1")) {
1470
- return "etc1";
1471
- } else if (supportedFormats.has("etc2")) {
2228
+ } else if (hasSupportedTextureFormat(textureFormats2, [
2229
+ "etc2-rgb8unorm",
2230
+ "etc2-rgb8unorm-srgb",
2231
+ "etc2-rgb8a1unorm",
2232
+ "etc2-rgb8a1unorm-srgb",
2233
+ "etc2-rgba8unorm",
2234
+ "etc2-rgba8unorm-srgb",
2235
+ "eac-r11unorm",
2236
+ "eac-r11snorm",
2237
+ "eac-rg11unorm",
2238
+ "eac-rg11snorm"
2239
+ ])) {
1472
2240
  return "etc2";
2241
+ } else if (textureFormats2.has("etc1-rgb-unorm-webgl")) {
2242
+ return "etc1";
2243
+ } else if (hasSupportedTextureFormat(textureFormats2, [
2244
+ "atc-rgb-unorm-webgl",
2245
+ "atc-rgba-unorm-webgl",
2246
+ "atc-rgbai-unorm-webgl"
2247
+ ])) {
2248
+ return {
2249
+ alpha: "atc-rgba-interpolated-alpha",
2250
+ noAlpha: "atc-rgb"
2251
+ };
1473
2252
  }
1474
2253
  return "rgb565";
1475
2254
  }
2255
+ function hasSupportedTextureFormat(supportedTextureFormats, candidateTextureFormats) {
2256
+ return candidateTextureFormats.some(
2257
+ (textureFormat) => supportedTextureFormats.has(textureFormat)
2258
+ );
2259
+ }
1476
2260
 
1477
2261
  // src/compressed-texture-loader.ts
1478
2262
  var CompressedTextureWorkerLoader = {
@@ -1481,7 +2265,7 @@
1481
2265
  name: "Texture Containers",
1482
2266
  id: "compressed-texture",
1483
2267
  module: "textures",
1484
- version: VERSION2,
2268
+ version: VERSION4,
1485
2269
  worker: true,
1486
2270
  extensions: [
1487
2271
  "ktx",
@@ -1501,7 +2285,6 @@
1501
2285
  binary: true,
1502
2286
  options: {
1503
2287
  "compressed-texture": {
1504
- libraryPath: "libs/",
1505
2288
  useBasis: false
1506
2289
  }
1507
2290
  }
@@ -1509,13 +2292,13 @@
1509
2292
  var CompressedTextureLoader = {
1510
2293
  ...CompressedTextureWorkerLoader,
1511
2294
  parse: async (arrayBuffer, options) => {
2295
+ options = { ...options };
1512
2296
  if (options?.["compressed-texture"]?.useBasis) {
1513
2297
  options.basis = {
1514
2298
  format: {
1515
2299
  alpha: "BC3",
1516
2300
  noAlpha: "BC1"
1517
2301
  },
1518
- // @ts-expect-error TODO not allowed to modify inputs
1519
2302
  ...options.basis,
1520
2303
  containerFormat: "ktx2",
1521
2304
  module: "encoder"