@loaders.gl/textures 4.4.0-alpha.9 → 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 (164) 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 +0 -1
  5. package/dist/basis-loader.js.map +1 -1
  6. package/dist/basis-worker-node.js +797 -9971
  7. package/dist/basis-worker.js +300 -145
  8. package/dist/compressed-texture-loader.d.ts +0 -4
  9. package/dist/compressed-texture-loader.d.ts.map +1 -1
  10. package/dist/compressed-texture-loader.js +0 -1
  11. package/dist/compressed-texture-loader.js.map +1 -1
  12. package/dist/compressed-texture-worker.js +1110 -358
  13. package/dist/crunch-loader.d.ts +1 -5
  14. package/dist/crunch-loader.d.ts.map +1 -1
  15. package/dist/crunch-loader.js +1 -3
  16. package/dist/crunch-loader.js.map +1 -1
  17. package/dist/crunch-worker.js +168 -87
  18. package/dist/dist.dev.js +2647 -670
  19. package/dist/dist.min.js +1 -2
  20. package/dist/index.cjs +1642 -428
  21. package/dist/index.cjs.map +4 -4
  22. package/dist/index.d.ts +13 -4
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +6 -3
  25. package/dist/index.js.map +1 -1
  26. package/dist/ktx2-basis-writer-worker-node.js +444 -9763
  27. package/dist/ktx2-basis-writer-worker.js +13 -3
  28. package/dist/lib/composite-image/image-texture-cube.d.ts +47 -0
  29. package/dist/lib/composite-image/image-texture-cube.d.ts.map +1 -0
  30. package/dist/lib/composite-image/image-texture-cube.js +42 -0
  31. package/dist/lib/composite-image/image-texture-cube.js.map +1 -0
  32. package/dist/lib/composite-image/parse-composite-image.d.ts +43 -0
  33. package/dist/lib/composite-image/parse-composite-image.d.ts.map +1 -0
  34. package/dist/lib/composite-image/parse-composite-image.js +437 -0
  35. package/dist/lib/composite-image/parse-composite-image.js.map +1 -0
  36. package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts.map +1 -1
  37. package/dist/lib/encoders/encode-ktx2-basis-texture.js +2 -1
  38. package/dist/lib/encoders/encode-ktx2-basis-texture.js.map +1 -1
  39. package/dist/lib/gl-extensions.d.ts +166 -58
  40. package/dist/lib/gl-extensions.d.ts.map +1 -1
  41. package/dist/lib/gl-extensions.js +177 -66
  42. package/dist/lib/gl-extensions.js.map +1 -1
  43. package/dist/lib/gl-types.d.ts +4 -0
  44. package/dist/lib/gl-types.d.ts.map +1 -0
  45. package/dist/lib/gl-types.js +5 -0
  46. package/dist/lib/gl-types.js.map +1 -0
  47. package/dist/lib/parsers/crunch-module-loader.d.ts +2 -2
  48. package/dist/lib/parsers/crunch-module-loader.d.ts.map +1 -1
  49. package/dist/lib/parsers/crunch-module-loader.js.map +1 -1
  50. package/dist/lib/parsers/parse-basis.d.ts +24 -2
  51. package/dist/lib/parsers/parse-basis.d.ts.map +1 -1
  52. package/dist/lib/parsers/parse-basis.js +262 -64
  53. package/dist/lib/parsers/parse-basis.js.map +1 -1
  54. package/dist/lib/parsers/parse-crunch.d.ts.map +1 -1
  55. package/dist/lib/parsers/parse-crunch.js +6 -6
  56. package/dist/lib/parsers/parse-crunch.js.map +1 -1
  57. package/dist/lib/parsers/parse-dds.d.ts.map +1 -1
  58. package/dist/lib/parsers/parse-dds.js +10 -11
  59. package/dist/lib/parsers/parse-dds.js.map +1 -1
  60. package/dist/lib/parsers/parse-hdr.d.ts +21 -0
  61. package/dist/lib/parsers/parse-hdr.d.ts.map +1 -0
  62. package/dist/lib/parsers/parse-hdr.js +305 -0
  63. package/dist/lib/parsers/parse-hdr.js.map +1 -0
  64. package/dist/lib/parsers/parse-ktx.d.ts.map +1 -1
  65. package/dist/lib/parsers/parse-ktx.js +10 -3
  66. package/dist/lib/parsers/parse-ktx.js.map +1 -1
  67. package/dist/lib/parsers/parse-pvr.d.ts.map +1 -1
  68. package/dist/lib/parsers/parse-pvr.js +31 -74
  69. package/dist/lib/parsers/parse-pvr.js.map +1 -1
  70. package/dist/lib/texture-api/generate-url.d.ts.map +1 -1
  71. package/dist/lib/texture-api/generate-url.js +2 -10
  72. package/dist/lib/texture-api/generate-url.js.map +1 -1
  73. package/dist/lib/texture-api/load-image-array.d.ts +6 -3
  74. package/dist/lib/texture-api/load-image-array.d.ts.map +1 -1
  75. package/dist/lib/texture-api/load-image-array.js +5 -3
  76. package/dist/lib/texture-api/load-image-array.js.map +1 -1
  77. package/dist/lib/texture-api/load-image-cube.d.ts +7 -11
  78. package/dist/lib/texture-api/load-image-cube.d.ts.map +1 -1
  79. package/dist/lib/texture-api/load-image-cube.js +8 -20
  80. package/dist/lib/texture-api/load-image-cube.js.map +1 -1
  81. package/dist/lib/texture-api/load-image.d.ts +6 -3
  82. package/dist/lib/texture-api/load-image.d.ts.map +1 -1
  83. package/dist/lib/texture-api/load-image.js +8 -4
  84. package/dist/lib/texture-api/load-image.js.map +1 -1
  85. package/dist/lib/texture-api/texture-api-types.d.ts +13 -0
  86. package/dist/lib/texture-api/texture-api-types.d.ts.map +1 -1
  87. package/dist/lib/utils/detect-supported-texture-formats.d.ts +14 -0
  88. package/dist/lib/utils/detect-supported-texture-formats.d.ts.map +1 -0
  89. package/dist/lib/utils/detect-supported-texture-formats.js +197 -0
  90. package/dist/lib/utils/detect-supported-texture-formats.js.map +1 -0
  91. package/dist/lib/utils/extract-mipmap-images.d.ts +6 -2
  92. package/dist/lib/utils/extract-mipmap-images.d.ts.map +1 -1
  93. package/dist/lib/utils/extract-mipmap-images.js +13 -2
  94. package/dist/lib/utils/extract-mipmap-images.js.map +1 -1
  95. package/dist/lib/utils/ktx-format-helper.d.ts +9 -1
  96. package/dist/lib/utils/ktx-format-helper.d.ts.map +1 -1
  97. package/dist/lib/utils/ktx-format-helper.js +76 -109
  98. package/dist/lib/utils/ktx-format-helper.js.map +1 -1
  99. package/dist/lib/utils/texture-format-map.d.ts +10 -0
  100. package/dist/lib/utils/texture-format-map.d.ts.map +1 -0
  101. package/dist/lib/utils/texture-format-map.js +87 -0
  102. package/dist/lib/utils/texture-format-map.js.map +1 -0
  103. package/dist/lib/utils/version.js +1 -1
  104. package/dist/lib/utils/version.js.map +1 -1
  105. package/dist/npy-loader.d.ts +2 -2
  106. package/dist/npy-worker.js +1 -1
  107. package/dist/radiance-hdr-loader.d.ts +25 -0
  108. package/dist/radiance-hdr-loader.d.ts.map +1 -0
  109. package/dist/radiance-hdr-loader.js +23 -0
  110. package/dist/radiance-hdr-loader.js.map +1 -0
  111. package/dist/texture-array-loader.d.ts +25 -0
  112. package/dist/texture-array-loader.d.ts.map +1 -0
  113. package/dist/texture-array-loader.js +24 -0
  114. package/dist/texture-array-loader.js.map +1 -0
  115. package/dist/texture-cube-array-loader.d.ts +25 -0
  116. package/dist/texture-cube-array-loader.d.ts.map +1 -0
  117. package/dist/texture-cube-array-loader.js +24 -0
  118. package/dist/texture-cube-array-loader.js.map +1 -0
  119. package/dist/texture-cube-loader.d.ts +25 -0
  120. package/dist/texture-cube-loader.d.ts.map +1 -0
  121. package/dist/texture-cube-loader.js +24 -0
  122. package/dist/texture-cube-loader.js.map +1 -0
  123. package/dist/texture-loader.d.ts +25 -0
  124. package/dist/texture-loader.d.ts.map +1 -0
  125. package/dist/texture-loader.js +24 -0
  126. package/dist/texture-loader.js.map +1 -0
  127. package/dist/workers/crunch-worker.d.ts +1 -3
  128. package/dist/workers/crunch-worker.d.ts.map +1 -1
  129. package/package.json +6 -6
  130. package/src/basis-loader.ts +19 -9
  131. package/src/compressed-texture-loader.ts +0 -3
  132. package/src/crunch-loader.ts +1 -5
  133. package/src/index.ts +21 -4
  134. package/src/lib/composite-image/image-texture-cube.ts +49 -0
  135. package/src/lib/composite-image/parse-composite-image.ts +699 -0
  136. package/src/lib/encoders/encode-ktx2-basis-texture.ts +2 -1
  137. package/src/lib/gl-extensions.ts +188 -81
  138. package/src/lib/gl-types.ts +136 -0
  139. package/src/lib/parsers/crunch-module-loader.ts +4 -4
  140. package/src/lib/parsers/parse-basis.ts +326 -62
  141. package/src/lib/parsers/parse-crunch.ts +11 -8
  142. package/src/lib/parsers/parse-dds.ts +11 -12
  143. package/src/lib/parsers/parse-hdr.ts +426 -0
  144. package/src/lib/parsers/parse-ktx.ts +13 -3
  145. package/src/lib/parsers/parse-pvr.ts +33 -75
  146. package/src/lib/texture-api/generate-url.ts +2 -12
  147. package/src/lib/texture-api/load-image-array.ts +15 -6
  148. package/src/lib/texture-api/load-image-cube.ts +20 -34
  149. package/src/lib/texture-api/load-image.ts +19 -8
  150. package/src/lib/texture-api/texture-api-types.ts +15 -0
  151. package/src/lib/utils/detect-supported-texture-formats.ts +210 -0
  152. package/src/lib/utils/extract-mipmap-images.ts +23 -4
  153. package/src/lib/utils/ktx-format-helper.ts +135 -111
  154. package/src/lib/utils/texture-format-map.ts +162 -0
  155. package/src/radiance-hdr-loader.ts +36 -0
  156. package/src/texture-array-loader.ts +46 -0
  157. package/src/texture-cube-array-loader.ts +49 -0
  158. package/src/texture-cube-loader.ts +46 -0
  159. package/src/texture-loader.ts +49 -0
  160. package/dist/lib/utils/texture-formats.d.ts +0 -8
  161. package/dist/lib/utils/texture-formats.d.ts.map +0 -1
  162. package/dist/lib/utils/texture-formats.js +0 -51
  163. package/dist/lib/utils/texture-formats.js.map +0 -1
  164. 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 ||= {};
@@ -29,15 +564,15 @@
29
564
  globalThis._loadersgl_.version = NPM_TAG;
30
565
  warningIssued = true;
31
566
  } else {
32
- globalThis._loadersgl_.version = "4.4.0-alpha.9";
567
+ globalThis._loadersgl_.version = "4.4.0";
33
568
  }
34
569
  }
35
570
  return globalThis._loadersgl_.version;
36
571
  }
37
- var VERSION = getVersion();
572
+ var VERSION3 = getVersion();
38
573
 
39
574
  // ../worker-utils/src/lib/env-utils/assert.ts
40
- function assert2(condition, message) {
575
+ function assert3(condition, message) {
41
576
  if (!condition) {
42
577
  throw new Error(message || "loaders.gl assertion failed.");
43
578
  }
@@ -51,10 +586,10 @@
51
586
  document: typeof document !== "undefined" && document
52
587
  };
53
588
  var self_ = globals.self || globals.window || globals.global || {};
54
- var window_ = globals.window || globals.self || globals.global || {};
55
- var global_ = globals.global || globals.self || globals.window || {};
56
- var document_ = globals.document || {};
57
- 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 = (
58
593
  // @ts-ignore process.browser
59
594
  typeof process !== "object" || String(process) !== "[object process]" || process.browser
60
595
  );
@@ -183,6 +718,16 @@
183
718
 
184
719
  // ../worker-utils/src/lib/library-utils/library-utils.ts
185
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
+ }
186
731
  async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null) {
187
732
  if (moduleName) {
188
733
  libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
@@ -203,12 +748,12 @@
203
748
  if (modules[libraryName]) {
204
749
  return modules[libraryName];
205
750
  }
206
- if (!isBrowser) {
751
+ if (!isBrowser2) {
207
752
  return `modules/${moduleName}/dist/libs/${libraryName}`;
208
753
  }
209
754
  if (options.CDN) {
210
- assert2(options.CDN.startsWith("http"));
211
- return `${options.CDN}/${moduleName}@${VERSION}/dist/libs/${libraryName}`;
755
+ assert3(options.CDN.startsWith("http"));
756
+ return `${options.CDN}/${moduleName}@${VERSION3}/dist/libs/${libraryName}`;
212
757
  }
213
758
  if (isWorker) {
214
759
  return `../src/libs/${libraryName}`;
@@ -219,7 +764,7 @@
219
764
  if (libraryUrl.endsWith("wasm")) {
220
765
  return await loadAsArrayBuffer(libraryUrl);
221
766
  }
222
- if (!isBrowser) {
767
+ if (!isBrowser2) {
223
768
  const { requireFromFile } = globalThis.loaders || {};
224
769
  try {
225
770
  const result = await requireFromFile?.(libraryUrl);
@@ -245,7 +790,7 @@
245
790
  return loadLibraryFromString(scriptSource, libraryUrl);
246
791
  }
247
792
  function loadLibraryFromString(scriptSource, id) {
248
- if (!isBrowser) {
793
+ if (!isBrowser2) {
249
794
  const { requireFromString } = globalThis.loaders || {};
250
795
  return requireFromString?.(scriptSource, id);
251
796
  }
@@ -265,7 +810,7 @@
265
810
  }
266
811
  async function loadAsArrayBuffer(url) {
267
812
  const { readFileAsArrayBuffer } = globalThis.loaders || {};
268
- if (isBrowser || !readFileAsArrayBuffer || url.startsWith("http")) {
813
+ if (isBrowser2 || !readFileAsArrayBuffer || url.startsWith("http")) {
269
814
  const response = await fetch(url);
270
815
  return await response.arrayBuffer();
271
816
  }
@@ -280,7 +825,7 @@
280
825
  }
281
826
  async function loadAsText(url) {
282
827
  const { readFileAsText } = globalThis.loaders || {};
283
- if (isBrowser || !readFileAsText || url.startsWith("http")) {
828
+ if (isBrowser2 || !readFileAsText || url.startsWith("http")) {
284
829
  const response = await fetch(url);
285
830
  return await response.text();
286
831
  }
@@ -379,7 +924,7 @@
379
924
  }
380
925
 
381
926
  // src/lib/utils/version.ts
382
- var VERSION2 = true ? "4.4.0-alpha.9" : "latest";
927
+ var VERSION4 = true ? "4.4.0" : "latest";
383
928
 
384
929
  // ../../node_modules/ktx-parse/dist/ktx-parse.modern.js
385
930
  var KHR_SUPERCOMPRESSION_NONE = 0;
@@ -630,23 +1175,178 @@
630
1175
  return container;
631
1176
  }
632
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
+
633
1324
  // src/lib/utils/extract-mipmap-images.ts
634
1325
  function extractMipmapImages(data, options) {
635
1326
  const images = new Array(options.mipMapLevels);
1327
+ const textureFormat = options.textureFormat || getTextureFormatFromWebGLFormat(options.internalFormat);
1328
+ const format = options.internalFormat || getWebGLFormatFromTextureFormat(options.textureFormat);
636
1329
  let levelWidth = options.width;
637
1330
  let levelHeight = options.height;
638
1331
  let offset = 0;
639
1332
  for (let i = 0; i < options.mipMapLevels; ++i) {
640
1333
  const levelSize = getLevelSize(options, levelWidth, levelHeight, data, i);
641
1334
  const levelData = getLevelData(data, i, offset, levelSize);
642
- images[i] = {
1335
+ const image = {
1336
+ shape: "texture-level",
643
1337
  compressed: true,
644
- format: options.internalFormat,
645
1338
  data: levelData,
646
1339
  width: levelWidth,
647
1340
  height: levelHeight,
648
1341
  levelSize
649
1342
  };
1343
+ if (format !== void 0) {
1344
+ image.format = format;
1345
+ }
1346
+ if (textureFormat) {
1347
+ image.textureFormat = textureFormat;
1348
+ }
1349
+ images[i] = image;
650
1350
  levelWidth = Math.max(1, levelWidth >> 1);
651
1351
  levelHeight = Math.max(1, levelHeight >> 1);
652
1352
  offset += levelSize;
@@ -666,190 +1366,81 @@
666
1366
  return options.sizeFunction(data[index]);
667
1367
  }
668
1368
 
669
- // src/lib/gl-extensions.ts
670
- var GL_EXTENSIONS_CONSTANTS = {
671
- // WEBGL_compressed_texture_s3tc
672
- COMPRESSED_RGB_S3TC_DXT1_EXT: 33776,
673
- COMPRESSED_RGBA_S3TC_DXT1_EXT: 33777,
674
- COMPRESSED_RGBA_S3TC_DXT3_EXT: 33778,
675
- COMPRESSED_RGBA_S3TC_DXT5_EXT: 33779,
676
- // WEBGL_compressed_texture_es3
677
- COMPRESSED_R11_EAC: 37488,
678
- COMPRESSED_SIGNED_R11_EAC: 37489,
679
- COMPRESSED_RG11_EAC: 37490,
680
- COMPRESSED_SIGNED_RG11_EAC: 37491,
681
- COMPRESSED_RGB8_ETC2: 37492,
682
- COMPRESSED_RGBA8_ETC2_EAC: 37493,
683
- COMPRESSED_SRGB8_ETC2: 37494,
684
- COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 37495,
685
- COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37496,
686
- COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37497,
687
- // WEBGL_compressed_texture_pvrtc
688
- COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 35840,
689
- COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 35842,
690
- COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 35841,
691
- COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 35843,
692
- // WEBGL_compressed_texture_etc1
693
- COMPRESSED_RGB_ETC1_WEBGL: 36196,
694
- // WEBGL_compressed_texture_atc
695
- COMPRESSED_RGB_ATC_WEBGL: 35986,
696
- COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: 35987,
697
- COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: 34798,
698
- // WEBGL_compressed_texture_astc
699
- COMPRESSED_RGBA_ASTC_4X4_KHR: 37808,
700
- COMPRESSED_RGBA_ASTC_5X4_KHR: 37809,
701
- COMPRESSED_RGBA_ASTC_5X5_KHR: 37810,
702
- COMPRESSED_RGBA_ASTC_6X5_KHR: 37811,
703
- COMPRESSED_RGBA_ASTC_6X6_KHR: 37812,
704
- COMPRESSED_RGBA_ASTC_8X5_KHR: 37813,
705
- COMPRESSED_RGBA_ASTC_8X6_KHR: 37814,
706
- COMPRESSED_RGBA_ASTC_8X8_KHR: 37815,
707
- COMPRESSED_RGBA_ASTC_10X5_KHR: 37816,
708
- COMPRESSED_RGBA_ASTC_10X6_KHR: 37817,
709
- COMPRESSED_RGBA_ASTC_10X8_KHR: 37818,
710
- COMPRESSED_RGBA_ASTC_10X10_KHR: 37819,
711
- COMPRESSED_RGBA_ASTC_12X10_KHR: 37820,
712
- COMPRESSED_RGBA_ASTC_12X12_KHR: 37821,
713
- COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR: 37840,
714
- COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR: 37841,
715
- COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR: 37842,
716
- COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR: 37843,
717
- COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR: 37844,
718
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR: 37845,
719
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR: 37846,
720
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR: 37847,
721
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR: 37848,
722
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR: 37849,
723
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR: 37850,
724
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR: 37851,
725
- COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR: 37852,
726
- COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR: 37853,
727
- // EXT_texture_compression_rgtc
728
- COMPRESSED_RED_RGTC1_EXT: 36283,
729
- COMPRESSED_SIGNED_RED_RGTC1_EXT: 36284,
730
- COMPRESSED_RED_GREEN_RGTC2_EXT: 36285,
731
- COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: 36286,
732
- // WEBGL_compressed_texture_s3tc_srgb
733
- COMPRESSED_SRGB_S3TC_DXT1_EXT: 35916,
734
- COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 35917,
735
- COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 35918,
736
- COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 35919
737
- };
738
-
739
1369
  // src/lib/utils/ktx-format-helper.ts
740
1370
  var VULKAN_TO_WEBGL_FORMAT_MAP = {
741
- 131: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
742
- 132: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_S3TC_DXT1_EXT,
743
- 133: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT1_EXT,
744
- 134: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
745
- 135: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
746
- 136: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
747
- 137: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
748
- 138: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,
749
- 139: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RED_RGTC1_EXT,
750
- 140: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_RED_RGTC1_EXT,
751
- 141: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RED_GREEN_RGTC2_EXT,
752
- 142: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT,
753
- 147: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_ETC2,
754
- 148: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ETC2,
755
- 149: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
756
- 150: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
757
- 151: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA8_ETC2_EAC,
758
- 152: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
759
- 153: GL_EXTENSIONS_CONSTANTS.COMPRESSED_R11_EAC,
760
- 154: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_R11_EAC,
761
- 155: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RG11_EAC,
762
- 156: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SIGNED_RG11_EAC,
763
- // @ts-ignore
764
- 157: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4x4_KHR,
765
- // @ts-ignore
766
- 158: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
767
- // @ts-ignore
768
- 159: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x4_KHR,
769
- // @ts-ignore
770
- 160: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR,
771
- // @ts-ignore
772
- 161: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x5_KHR,
773
- // @ts-ignore
774
- 162: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
775
- // @ts-ignore
776
- 163: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x5_KHR,
777
- // @ts-ignore
778
- 164: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
779
- // @ts-ignore
780
- 165: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x6_KHR,
781
- // @ts-ignore
782
- 166: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
783
- // @ts-ignore
784
- 167: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x5_KHR,
785
- // @ts-ignore
786
- 168: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
787
- // @ts-ignore
788
- 169: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x6_KHR,
789
- // @ts-ignore
790
- 170: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
791
- // @ts-ignore
792
- 171: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x8_KHR,
793
- // @ts-ignore
794
- 172: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
795
- // @ts-ignore
796
- 173: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x5_KHR,
797
- // @ts-ignore
798
- 174: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
799
- // @ts-ignore
800
- 175: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x6_KHR,
801
- // @ts-ignore
802
- 176: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
803
- // @ts-ignore
804
- 177: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x8_KHR,
805
- // @ts-ignore
806
- 178: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
807
- // @ts-ignore
808
- 179: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x10_KHR,
809
- // @ts-ignore
810
- 180: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
811
- // @ts-ignore
812
- 181: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x10_KHR,
813
- // @ts-ignore
814
- 182: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
815
- // @ts-ignore
816
- 183: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x12_KHR,
817
- // @ts-ignore
818
- 184: GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
819
- 1000054e3: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,
820
- 1000054001: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
821
- // @ts-ignore
822
- 1000066e3: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4x4_KHR,
823
- // @ts-ignore
824
- 1000066001: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x4_KHR,
825
- // @ts-ignore
826
- 1000066002: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5x5_KHR,
827
- // @ts-ignore
828
- 1000066003: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x5_KHR,
829
- // @ts-ignore
830
- 1000066004: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6x6_KHR,
831
- // @ts-ignore
832
- 1000066005: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x5_KHR,
833
- // @ts-ignore
834
- 1000066006: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x6_KHR,
835
- // @ts-ignore
836
- 1000066007: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8x8_KHR,
837
- // @ts-ignore
838
- 1000066008: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x5_KHR,
839
- // @ts-ignore
840
- 1000066009: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x6_KHR,
841
- // @ts-ignore
842
- 1000066010: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x8_KHR,
843
- // @ts-ignore
844
- 1000066011: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10x10_KHR,
845
- // @ts-ignore
846
- 1000066012: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12x10_KHR,
847
- // @ts-ignore
848
- 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
849
1437
  };
850
1438
  function mapVkFormatToWebGL(vkFormat) {
851
1439
  return VULKAN_TO_WEBGL_FORMAT_MAP[vkFormat];
852
1440
  }
1441
+ function mapVkFormatToTextureFormat(vkFormat) {
1442
+ return getTextureFormatFromWebGLFormat(mapVkFormatToWebGL(vkFormat));
1443
+ }
853
1444
 
854
1445
  // src/lib/parsers/parse-ktx.ts
855
1446
  var KTX2_ID2 = [
@@ -889,13 +1480,18 @@
889
1480
  const mipMapLevels = Math.max(1, ktx.levels.length);
890
1481
  const width = ktx.pixelWidth;
891
1482
  const height = ktx.pixelHeight;
892
- 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
+ }
893
1489
  return extractMipmapImages(ktx.levels, {
894
1490
  mipMapLevels,
895
1491
  width,
896
1492
  height,
897
1493
  sizeFunction: (level) => level.uncompressedByteLength,
898
- internalFormat
1494
+ textureFormat
899
1495
  });
900
1496
  }
901
1497
 
@@ -914,13 +1510,13 @@
914
1510
  DDSD_MIPMAPCOUNT: 131072,
915
1511
  DDPF_FOURCC: 4
916
1512
  };
917
- var DDS_PIXEL_FORMATS = {
918
- DXT1: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
919
- DXT3: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
920
- DXT5: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
921
- "ATC ": GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ATC_WEBGL,
922
- ATCA: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL,
923
- 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"
924
1520
  };
925
1521
  var getATCLevelSize = getDxt1LevelSize;
926
1522
  var getATCALevelSize = getDxtXLevelSize;
@@ -946,9 +1542,9 @@
946
1542
  "DDS: Unsupported format, must contain a FourCC code"
947
1543
  );
948
1544
  const fourCC = int32ToFourCC(pixelFormatNumber);
949
- const internalFormat = DDS_PIXEL_FORMATS[fourCC];
1545
+ const textureFormat = DDS_TEXTURE_FORMATS[fourCC];
950
1546
  const sizeFunction = DDS_SIZE_FUNCTIONS[fourCC];
951
- assert(internalFormat && sizeFunction, `DDS: Unknown pixel format ${pixelFormatNumber}`);
1547
+ assert(textureFormat && sizeFunction, `DDS: Unknown pixel format ${pixelFormatNumber}`);
952
1548
  let mipMapLevels = 1;
953
1549
  if (header[DDS_CONSTANTS.HEADER_FLAGS_INDEX] & DDS_CONSTANTS.DDSD_MIPMAPCOUNT) {
954
1550
  mipMapLevels = Math.max(1, header[DDS_CONSTANTS.MIPMAPCOUNT_INDEX]);
@@ -962,7 +1558,7 @@
962
1558
  width,
963
1559
  height,
964
1560
  sizeFunction,
965
- internalFormat
1561
+ textureFormat
966
1562
  });
967
1563
  }
968
1564
  function getDxt1LevelSize(width, height) {
@@ -994,76 +1590,34 @@
994
1590
  MIPMAPCOUNT_INDEX: 11,
995
1591
  METADATA_SIZE_INDEX: 12
996
1592
  };
997
- var PVR_PIXEL_FORMATS = {
998
- 0: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG],
999
- 1: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG],
1000
- 2: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG],
1001
- 3: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG],
1002
- 6: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL],
1003
- 7: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT],
1004
- 9: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT],
1005
- 11: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT],
1006
- 22: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_ETC2],
1007
- 23: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA8_ETC2_EAC],
1008
- 24: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2],
1009
- 25: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_R11_EAC],
1010
- 26: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RG11_EAC],
1011
- 27: [
1012
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR,
1013
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR
1014
- ],
1015
- 28: [
1016
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X4_KHR,
1017
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR
1018
- ],
1019
- 29: [
1020
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X5_KHR,
1021
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR
1022
- ],
1023
- 30: [
1024
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X5_KHR,
1025
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR
1026
- ],
1027
- 31: [
1028
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X6_KHR,
1029
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR
1030
- ],
1031
- 32: [
1032
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X5_KHR,
1033
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR
1034
- ],
1035
- 33: [
1036
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X6_KHR,
1037
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR
1038
- ],
1039
- 34: [
1040
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X8_KHR,
1041
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR
1042
- ],
1043
- 35: [
1044
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X5_KHR,
1045
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR
1046
- ],
1047
- 36: [
1048
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X6_KHR,
1049
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR
1050
- ],
1051
- 37: [
1052
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X8_KHR,
1053
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR
1054
- ],
1055
- 38: [
1056
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X10_KHR,
1057
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR
1058
- ],
1059
- 39: [
1060
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X10_KHR,
1061
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR
1062
- ],
1063
- 40: [
1064
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X12_KHR,
1065
- GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR
1066
- ]
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"]
1067
1621
  };
1068
1622
  var PVR_SIZE_FUNCTIONS = {
1069
1623
  0: pvrtc2bppSize,
@@ -1096,15 +1650,15 @@
1096
1650
  };
1097
1651
  function isPVR(data) {
1098
1652
  const header = new Uint32Array(data, 0, PVR_CONSTANTS.HEADER_LENGTH);
1099
- const version = header[PVR_CONSTANTS.MAGIC_NUMBER_INDEX];
1100
- 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;
1101
1655
  }
1102
1656
  function parsePVR(data) {
1103
1657
  const header = new Uint32Array(data, 0, PVR_CONSTANTS.HEADER_LENGTH);
1104
1658
  const pvrFormat = header[PVR_CONSTANTS.PIXEL_FORMAT_INDEX];
1105
1659
  const colourSpace = header[PVR_CONSTANTS.COLOUR_SPACE_INDEX];
1106
- const pixelFormats = PVR_PIXEL_FORMATS[pvrFormat] || [];
1107
- 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];
1108
1662
  const sizeFunction = PVR_SIZE_FUNCTIONS[pvrFormat];
1109
1663
  const mipMapLevels = header[PVR_CONSTANTS.MIPMAPCOUNT_INDEX];
1110
1664
  const width = header[PVR_CONSTANTS.WIDTH_INDEX];
@@ -1116,7 +1670,7 @@
1116
1670
  width,
1117
1671
  height,
1118
1672
  sizeFunction,
1119
- internalFormat
1673
+ textureFormat
1120
1674
  });
1121
1675
  }
1122
1676
  function pvrtc2bppSize(width, height) {
@@ -1266,35 +1820,101 @@
1266
1820
  });
1267
1821
  }
1268
1822
 
1269
- // src/lib/utils/texture-formats.ts
1823
+ // src/lib/utils/detect-supported-texture-formats.ts
1270
1824
  var BROWSER_PREFIXES = ["", "WEBKIT_", "MOZ_"];
1271
- var WEBGL_EXTENSIONS = {
1825
+ var WEBGL_TEXTURE_FORMATS = {
1272
1826
  /* eslint-disable camelcase */
1273
- WEBGL_compressed_texture_s3tc: "dxt",
1274
- WEBGL_compressed_texture_s3tc_srgb: "dxt-srgb",
1275
- WEBGL_compressed_texture_etc1: "etc1",
1276
- WEBGL_compressed_texture_etc: "etc2",
1277
- WEBGL_compressed_texture_pvrtc: "pvrtc",
1278
- WEBGL_compressed_texture_atc: "atc",
1279
- WEBGL_compressed_texture_astc: "astc",
1280
- 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
+ ]
1281
1900
  /* eslint-enable camelcase */
1282
1901
  };
1283
- var formats = null;
1284
- function getSupportedGPUTextureFormats(gl) {
1285
- if (!formats) {
1902
+ var textureFormats = null;
1903
+ function detectSupportedTextureFormats(gl) {
1904
+ if (!textureFormats) {
1286
1905
  gl = gl || getWebGLContext() || void 0;
1287
- formats = /* @__PURE__ */ new Set();
1906
+ textureFormats = /* @__PURE__ */ new Set();
1288
1907
  for (const prefix of BROWSER_PREFIXES) {
1289
- for (const extension in WEBGL_EXTENSIONS) {
1908
+ for (const extension in WEBGL_TEXTURE_FORMATS) {
1290
1909
  if (gl && gl.getExtension(`${prefix}${extension}`)) {
1291
- const gpuTextureFormat = WEBGL_EXTENSIONS[extension];
1292
- formats.add(gpuTextureFormat);
1910
+ for (const textureFormat of WEBGL_TEXTURE_FORMATS[extension]) {
1911
+ textureFormats.add(textureFormat);
1912
+ }
1293
1913
  }
1294
1914
  }
1295
1915
  }
1296
1916
  }
1297
- return formats;
1917
+ return textureFormats;
1298
1918
  }
1299
1919
  function getWebGLContext() {
1300
1920
  try {
@@ -1306,73 +1926,154 @@
1306
1926
  }
1307
1927
 
1308
1928
  // src/lib/parsers/parse-basis.ts
1309
- var OutputFormat = {
1929
+ var basisTranscodingLock = Promise.resolve();
1930
+ var BASIS_FORMAT_TO_OUTPUT_OPTIONS = {
1310
1931
  etc1: {
1311
1932
  basisFormat: 0,
1312
1933
  compressed: true,
1313
- 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"
1314
1942
  },
1315
- etc2: { basisFormat: 1, compressed: true },
1316
1943
  bc1: {
1317
1944
  basisFormat: 2,
1318
1945
  compressed: true,
1319
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT
1946
+ format: GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1947
+ textureFormat: "bc1-rgb-unorm-webgl"
1320
1948
  },
1321
1949
  bc3: {
1322
1950
  basisFormat: 3,
1323
1951
  compressed: true,
1324
- 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"
1325
1978
  },
1326
- bc4: { basisFormat: 4, compressed: true },
1327
- bc5: { basisFormat: 5, compressed: true },
1328
- "bc7-m6-opaque-only": { basisFormat: 6, compressed: true },
1329
- "bc7-m5": { basisFormat: 7, compressed: true },
1330
1979
  "pvrtc1-4-rgb": {
1331
1980
  basisFormat: 8,
1332
1981
  compressed: true,
1333
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
1982
+ format: GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
1983
+ textureFormat: "pvrtc-rgb4unorm-webgl"
1334
1984
  },
1335
1985
  "pvrtc1-4-rgba": {
1336
1986
  basisFormat: 9,
1337
1987
  compressed: true,
1338
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
1988
+ format: GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
1989
+ textureFormat: "pvrtc-rgba4unorm-webgl"
1339
1990
  },
1340
1991
  "astc-4x4": {
1341
1992
  basisFormat: 10,
1342
1993
  compressed: true,
1343
- 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"
1344
2014
  },
1345
- "atc-rgb": { basisFormat: 11, compressed: true },
1346
- "atc-rgba-interpolated-alpha": { basisFormat: 12, compressed: true },
1347
- rgba32: { basisFormat: 13, compressed: false },
1348
- rgb565: { basisFormat: 14, compressed: false },
1349
- bgr565: { basisFormat: 15, compressed: false },
1350
- rgba4444: { basisFormat: 16, compressed: false }
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"
2026
+ },
2027
+ rgba4444: {
2028
+ basisFormat: 16,
2029
+ compressed: false,
2030
+ format: GL_RGBA4,
2031
+ textureFormat: "rgba4unorm-webgl"
2032
+ }
1351
2033
  };
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
+ }
1352
2050
  async function parseBasis(data, options = {}) {
1353
- if (!options.basis?.containerFormat || options.basis.containerFormat === "auto") {
1354
- if (isKTX(data)) {
1355
- const fileConstructors = await loadBasisEncoderModule(options?.core || {});
1356
- return parseKTX2File(fileConstructors.KTX2File, data, options);
1357
- }
1358
- const { BasisFile } = await loadBasisTranscoderModule(options?.core || {});
1359
- return parseBasisFile(BasisFile, data, options);
1360
- }
1361
- switch (options.basis.module) {
1362
- case "encoder":
1363
- const fileConstructors = await loadBasisEncoderModule(options?.core || {});
1364
- switch (options.basis.containerFormat) {
1365
- case "ktx2":
1366
- return parseKTX2File(fileConstructors.KTX2File, data, options);
1367
- case "basis":
1368
- default:
1369
- return parseBasisFile(fileConstructors.BasisFile, 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);
1370
2057
  }
1371
- case "transcoder":
1372
- default:
1373
- const { BasisFile } = await loadBasisTranscoderModule(options.core || {});
2058
+ const { BasisFile } = await loadBasisTranscoderModule(loadLibraryOptions);
1374
2059
  return parseBasisFile(BasisFile, data, options);
1375
- }
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
+ });
1376
2077
  }
1377
2078
  function parseBasisFile(BasisFile, data, options) {
1378
2079
  const basisFile = new BasisFile(new Uint8Array(data));
@@ -1402,7 +2103,7 @@
1402
2103
  const hasAlpha = basisFile.getHasAlpha(
1403
2104
  /* imageIndex, levelIndex */
1404
2105
  );
1405
- const { compressed, format, basisFormat } = getBasisOptions(options, hasAlpha);
2106
+ const { compressed, format, basisFormat, textureFormat } = getBasisOptions(options, hasAlpha);
1406
2107
  const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat);
1407
2108
  const decodedData = new Uint8Array(decodedSize);
1408
2109
  if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {
@@ -1410,11 +2111,13 @@
1410
2111
  }
1411
2112
  return {
1412
2113
  // standard loaders.gl image category payload
2114
+ shape: "texture-level",
1413
2115
  width,
1414
2116
  height,
1415
2117
  data: decodedData,
1416
2118
  compressed,
1417
- format,
2119
+ ...format !== void 0 ? { format } : {},
2120
+ ...textureFormat !== void 0 ? { textureFormat } : {},
1418
2121
  // Additional fields
1419
2122
  // Add levelSize field.
1420
2123
  hasAlpha
@@ -1439,7 +2142,7 @@
1439
2142
  }
1440
2143
  function transcodeKTX2Image(ktx2File, levelIndex, options) {
1441
2144
  const { alphaFlag, height, width } = ktx2File.getImageLevelInfo(levelIndex, 0, 0);
1442
- const { compressed, format, basisFormat } = getBasisOptions(options, alphaFlag);
2145
+ const { compressed, format, basisFormat, textureFormat } = getBasisOptions(options, alphaFlag);
1443
2146
  const decodedSize = ktx2File.getImageTranscodedSizeInBytes(
1444
2147
  levelIndex,
1445
2148
  0,
@@ -1462,48 +2165,98 @@
1462
2165
  }
1463
2166
  return {
1464
2167
  // standard loaders.gl image category payload
2168
+ shape: "texture-level",
1465
2169
  width,
1466
2170
  height,
1467
2171
  data: decodedData,
1468
2172
  compressed,
2173
+ ...format !== void 0 ? { format } : {},
2174
+ ...textureFormat !== void 0 ? { textureFormat } : {},
1469
2175
  // Additional fields
1470
2176
  levelSize: decodedSize,
1471
- hasAlpha: alphaFlag,
1472
- format
2177
+ hasAlpha: alphaFlag
1473
2178
  };
1474
2179
  }
1475
2180
  function getBasisOptions(options, hasAlpha) {
1476
- let format = options.basis?.format;
2181
+ let format = options.basis?.format || "auto";
1477
2182
  if (format === "auto") {
1478
- format = selectSupportedBasisFormat();
2183
+ format = options.basis?.supportedTextureFormats ? selectSupportedBasisFormat(options.basis.supportedTextureFormats) : selectSupportedBasisFormat();
1479
2184
  }
1480
2185
  if (typeof format === "object") {
1481
2186
  format = hasAlpha ? format.alpha : format.noAlpha;
1482
2187
  }
1483
- format = format.toLowerCase();
1484
- 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;
1485
2194
  }
1486
- function selectSupportedBasisFormat() {
1487
- const supportedFormats = getSupportedGPUTextureFormats();
1488
- 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"])) {
1489
2198
  return "astc-4x4";
1490
- } 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
+ ])) {
1491
2214
  return {
1492
2215
  alpha: "bc3",
1493
2216
  noAlpha: "bc1"
1494
2217
  };
1495
- } 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
+ ])) {
1496
2224
  return {
1497
2225
  alpha: "pvrtc1-4-rgba",
1498
2226
  noAlpha: "pvrtc1-4-rgb"
1499
2227
  };
1500
- } else if (supportedFormats.has("etc1")) {
1501
- return "etc1";
1502
- } 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
+ ])) {
1503
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
+ };
1504
2252
  }
1505
2253
  return "rgb565";
1506
2254
  }
2255
+ function hasSupportedTextureFormat(supportedTextureFormats, candidateTextureFormats) {
2256
+ return candidateTextureFormats.some(
2257
+ (textureFormat) => supportedTextureFormats.has(textureFormat)
2258
+ );
2259
+ }
1507
2260
 
1508
2261
  // src/compressed-texture-loader.ts
1509
2262
  var CompressedTextureWorkerLoader = {
@@ -1512,7 +2265,7 @@
1512
2265
  name: "Texture Containers",
1513
2266
  id: "compressed-texture",
1514
2267
  module: "textures",
1515
- version: VERSION2,
2268
+ version: VERSION4,
1516
2269
  worker: true,
1517
2270
  extensions: [
1518
2271
  "ktx",
@@ -1532,7 +2285,6 @@
1532
2285
  binary: true,
1533
2286
  options: {
1534
2287
  "compressed-texture": {
1535
- libraryPath: "libs/",
1536
2288
  useBasis: false
1537
2289
  }
1538
2290
  }