@loaders.gl/textures 4.4.0-alpha.16 → 4.4.0-alpha.17

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 (74) hide show
  1. package/README.md +44 -0
  2. package/dist/basis-loader.d.ts +17 -8
  3. package/dist/basis-loader.d.ts.map +1 -1
  4. package/dist/basis-loader.js.map +1 -1
  5. package/dist/basis-worker-node.js +317 -188
  6. package/dist/basis-worker.js +252 -123
  7. package/dist/compressed-texture-worker.js +1035 -326
  8. package/dist/crunch-worker.js +141 -82
  9. package/dist/dist.dev.js +1220 -334
  10. package/dist/dist.min.js +1 -2
  11. package/dist/index.cjs +657 -317
  12. package/dist/index.cjs.map +4 -4
  13. package/dist/index.d.ts +2 -4
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +1 -3
  16. package/dist/index.js.map +1 -1
  17. package/dist/ktx2-basis-writer-worker-node.js +2 -2
  18. package/dist/ktx2-basis-writer-worker.js +2 -2
  19. package/dist/lib/gl-extensions.d.ts +164 -58
  20. package/dist/lib/gl-extensions.d.ts.map +1 -1
  21. package/dist/lib/gl-extensions.js +175 -66
  22. package/dist/lib/gl-extensions.js.map +1 -1
  23. package/dist/lib/parsers/parse-basis.d.ts +16 -1
  24. package/dist/lib/parsers/parse-basis.d.ts.map +1 -1
  25. package/dist/lib/parsers/parse-basis.js +216 -43
  26. package/dist/lib/parsers/parse-basis.js.map +1 -1
  27. package/dist/lib/parsers/parse-crunch.d.ts.map +1 -1
  28. package/dist/lib/parsers/parse-crunch.js +4 -4
  29. package/dist/lib/parsers/parse-crunch.js.map +1 -1
  30. package/dist/lib/parsers/parse-dds.d.ts.map +1 -1
  31. package/dist/lib/parsers/parse-dds.js +7 -7
  32. package/dist/lib/parsers/parse-dds.js.map +1 -1
  33. package/dist/lib/parsers/parse-ktx.d.ts.map +1 -1
  34. package/dist/lib/parsers/parse-ktx.js +7 -0
  35. package/dist/lib/parsers/parse-ktx.js.map +1 -1
  36. package/dist/lib/parsers/parse-pvr.d.ts.map +1 -1
  37. package/dist/lib/parsers/parse-pvr.js +28 -70
  38. package/dist/lib/parsers/parse-pvr.js.map +1 -1
  39. package/dist/lib/utils/detect-supported-texture-formats.d.ts +14 -0
  40. package/dist/lib/utils/detect-supported-texture-formats.d.ts.map +1 -0
  41. package/dist/lib/utils/detect-supported-texture-formats.js +197 -0
  42. package/dist/lib/utils/detect-supported-texture-formats.js.map +1 -0
  43. package/dist/lib/utils/extract-mipmap-images.d.ts +2 -2
  44. package/dist/lib/utils/extract-mipmap-images.d.ts.map +1 -1
  45. package/dist/lib/utils/extract-mipmap-images.js +12 -2
  46. package/dist/lib/utils/extract-mipmap-images.js.map +1 -1
  47. package/dist/lib/utils/ktx-format-helper.d.ts +2 -1
  48. package/dist/lib/utils/ktx-format-helper.d.ts.map +1 -1
  49. package/dist/lib/utils/ktx-format-helper.js +67 -109
  50. package/dist/lib/utils/ktx-format-helper.js.map +1 -1
  51. package/dist/lib/utils/texture-format-map.d.ts +3 -0
  52. package/dist/lib/utils/texture-format-map.d.ts.map +1 -0
  53. package/dist/lib/utils/texture-format-map.js +71 -0
  54. package/dist/lib/utils/texture-format-map.js.map +1 -0
  55. package/dist/lib/utils/version.js +1 -1
  56. package/dist/npy-worker.js +1 -1
  57. package/package.json +6 -6
  58. package/src/basis-loader.ts +21 -8
  59. package/src/index.ts +2 -4
  60. package/src/lib/gl-extensions.ts +186 -81
  61. package/src/lib/parsers/parse-basis.ts +274 -40
  62. package/src/lib/parsers/parse-crunch.ts +13 -6
  63. package/src/lib/parsers/parse-dds.ts +16 -9
  64. package/src/lib/parsers/parse-ktx.ts +12 -2
  65. package/src/lib/parsers/parse-pvr.ts +72 -72
  66. package/src/lib/utils/detect-supported-texture-formats.ts +210 -0
  67. package/src/lib/utils/extract-mipmap-images.ts +15 -4
  68. package/src/lib/utils/ktx-format-helper.ts +124 -111
  69. package/src/lib/utils/texture-format-map.ts +135 -0
  70. package/dist/lib/utils/texture-formats.d.ts +0 -8
  71. package/dist/lib/utils/texture-formats.d.ts.map +0 -1
  72. package/dist/lib/utils/texture-formats.js +0 -51
  73. package/dist/lib/utils/texture-formats.js.map +0 -1
  74. package/src/lib/utils/texture-formats.ts +0 -59
@@ -22,7 +22,7 @@
22
22
  globalThis._loadersgl_.version = NPM_TAG;
23
23
  warningIssued = true;
24
24
  } else {
25
- globalThis._loadersgl_.version = "4.4.0-alpha.16";
25
+ globalThis._loadersgl_.version = "4.4.0-alpha.17";
26
26
  }
27
27
  }
28
28
  return globalThis._loadersgl_.version;
@@ -372,7 +372,7 @@
372
372
  }
373
373
 
374
374
  // src/lib/utils/version.ts
375
- var VERSION2 = true ? "4.4.0-alpha.16" : "latest";
375
+ var VERSION2 = true ? "4.4.0-alpha.17" : "latest";
376
376
 
377
377
  // src/lib/parsers/basis-module-loader.ts
378
378
  var BASIS_EXTERNAL_LIBRARIES = {
@@ -452,104 +452,117 @@
452
452
  }
453
453
 
454
454
  // src/lib/gl-extensions.ts
455
- var GL_EXTENSIONS_CONSTANTS = {
456
- // WEBGL_compressed_texture_s3tc
457
- COMPRESSED_RGB_S3TC_DXT1_EXT: 33776,
458
- COMPRESSED_RGBA_S3TC_DXT1_EXT: 33777,
459
- COMPRESSED_RGBA_S3TC_DXT3_EXT: 33778,
460
- COMPRESSED_RGBA_S3TC_DXT5_EXT: 33779,
461
- // WEBGL_compressed_texture_es3
462
- COMPRESSED_R11_EAC: 37488,
463
- COMPRESSED_SIGNED_R11_EAC: 37489,
464
- COMPRESSED_RG11_EAC: 37490,
465
- COMPRESSED_SIGNED_RG11_EAC: 37491,
466
- COMPRESSED_RGB8_ETC2: 37492,
467
- COMPRESSED_RGBA8_ETC2_EAC: 37493,
468
- COMPRESSED_SRGB8_ETC2: 37494,
469
- COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 37495,
470
- COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37496,
471
- COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37497,
472
- // WEBGL_compressed_texture_pvrtc
473
- COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 35840,
474
- COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 35842,
475
- COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 35841,
476
- COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 35843,
477
- // WEBGL_compressed_texture_etc1
478
- COMPRESSED_RGB_ETC1_WEBGL: 36196,
479
- // WEBGL_compressed_texture_atc
480
- COMPRESSED_RGB_ATC_WEBGL: 35986,
481
- COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: 35987,
482
- COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: 34798,
483
- // WEBGL_compressed_texture_astc
484
- COMPRESSED_RGBA_ASTC_4X4_KHR: 37808,
485
- COMPRESSED_RGBA_ASTC_5X4_KHR: 37809,
486
- COMPRESSED_RGBA_ASTC_5X5_KHR: 37810,
487
- COMPRESSED_RGBA_ASTC_6X5_KHR: 37811,
488
- COMPRESSED_RGBA_ASTC_6X6_KHR: 37812,
489
- COMPRESSED_RGBA_ASTC_8X5_KHR: 37813,
490
- COMPRESSED_RGBA_ASTC_8X6_KHR: 37814,
491
- COMPRESSED_RGBA_ASTC_8X8_KHR: 37815,
492
- COMPRESSED_RGBA_ASTC_10X5_KHR: 37816,
493
- COMPRESSED_RGBA_ASTC_10X6_KHR: 37817,
494
- COMPRESSED_RGBA_ASTC_10X8_KHR: 37818,
495
- COMPRESSED_RGBA_ASTC_10X10_KHR: 37819,
496
- COMPRESSED_RGBA_ASTC_12X10_KHR: 37820,
497
- COMPRESSED_RGBA_ASTC_12X12_KHR: 37821,
498
- COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR: 37840,
499
- COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR: 37841,
500
- COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR: 37842,
501
- COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR: 37843,
502
- COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR: 37844,
503
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR: 37845,
504
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR: 37846,
505
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR: 37847,
506
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR: 37848,
507
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR: 37849,
508
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR: 37850,
509
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR: 37851,
510
- COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR: 37852,
511
- COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR: 37853,
512
- // EXT_texture_compression_rgtc
513
- COMPRESSED_RED_RGTC1_EXT: 36283,
514
- COMPRESSED_SIGNED_RED_RGTC1_EXT: 36284,
515
- COMPRESSED_RED_GREEN_RGTC2_EXT: 36285,
516
- COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: 36286,
517
- // WEBGL_compressed_texture_s3tc_srgb
518
- COMPRESSED_SRGB_S3TC_DXT1_EXT: 35916,
519
- COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 35917,
520
- COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 35918,
521
- COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 35919
522
- };
455
+ var GL_RGBA4 = 32854;
456
+ var GL_RGBA8 = 32856;
457
+ var GL_RGB565 = 36194;
458
+ var GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 33776;
459
+ var GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 33779;
460
+ var GL_COMPRESSED_RGBA8_ETC2_EAC = 37493;
461
+ var GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 35840;
462
+ var GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 35842;
463
+ var GL_COMPRESSED_RGB_ETC1_WEBGL = 36196;
464
+ var GL_COMPRESSED_RGB_ATC_WEBGL = 35986;
465
+ var GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL = 34798;
466
+ var GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 37808;
467
+ var GL_COMPRESSED_RED_RGTC1_EXT = 36283;
468
+ var GL_COMPRESSED_RED_GREEN_RGTC2_EXT = 36285;
469
+ var GL_COMPRESSED_RGBA_BPTC_UNORM_EXT = 36492;
523
470
 
524
- // src/lib/utils/texture-formats.ts
471
+ // src/lib/utils/detect-supported-texture-formats.ts
525
472
  var BROWSER_PREFIXES = ["", "WEBKIT_", "MOZ_"];
526
- var WEBGL_EXTENSIONS = {
473
+ var WEBGL_TEXTURE_FORMATS = {
527
474
  /* eslint-disable camelcase */
528
- WEBGL_compressed_texture_s3tc: "dxt",
529
- WEBGL_compressed_texture_s3tc_srgb: "dxt-srgb",
530
- WEBGL_compressed_texture_etc1: "etc1",
531
- WEBGL_compressed_texture_etc: "etc2",
532
- WEBGL_compressed_texture_pvrtc: "pvrtc",
533
- WEBGL_compressed_texture_atc: "atc",
534
- WEBGL_compressed_texture_astc: "astc",
535
- EXT_texture_compression_rgtc: "rgtc"
475
+ WEBGL_compressed_texture_s3tc: [
476
+ "bc1-rgb-unorm-webgl",
477
+ "bc1-rgba-unorm",
478
+ "bc2-rgba-unorm",
479
+ "bc3-rgba-unorm"
480
+ ],
481
+ WEBGL_compressed_texture_s3tc_srgb: [
482
+ "bc1-rgb-unorm-srgb-webgl",
483
+ "bc1-rgba-unorm-srgb",
484
+ "bc2-rgba-unorm-srgb",
485
+ "bc3-rgba-unorm-srgb"
486
+ ],
487
+ EXT_texture_compression_rgtc: ["bc4-r-unorm", "bc4-r-snorm", "bc5-rg-unorm", "bc5-rg-snorm"],
488
+ EXT_texture_compression_bptc: [
489
+ "bc6h-rgb-ufloat",
490
+ "bc6h-rgb-float",
491
+ "bc7-rgba-unorm",
492
+ "bc7-rgba-unorm-srgb"
493
+ ],
494
+ WEBGL_compressed_texture_etc1: ["etc1-rbg-unorm-webgl"],
495
+ WEBGL_compressed_texture_etc: [
496
+ "etc2-rgb8unorm",
497
+ "etc2-rgb8unorm-srgb",
498
+ "etc2-rgb8a1unorm",
499
+ "etc2-rgb8a1unorm-srgb",
500
+ "etc2-rgba8unorm",
501
+ "etc2-rgba8unorm-srgb",
502
+ "eac-r11unorm",
503
+ "eac-r11snorm",
504
+ "eac-rg11unorm",
505
+ "eac-rg11snorm"
506
+ ],
507
+ WEBGL_compressed_texture_pvrtc: [
508
+ "pvrtc-rgb4unorm-webgl",
509
+ "pvrtc-rgba4unorm-webgl",
510
+ "pvrtc-rbg2unorm-webgl",
511
+ "pvrtc-rgba2unorm-webgl"
512
+ ],
513
+ WEBGL_compressed_texture_atc: [
514
+ "atc-rgb-unorm-webgl",
515
+ "atc-rgba-unorm-webgl",
516
+ "atc-rgbai-unorm-webgl"
517
+ ],
518
+ WEBGL_compressed_texture_astc: [
519
+ "astc-4x4-unorm",
520
+ "astc-4x4-unorm-srgb",
521
+ "astc-5x4-unorm",
522
+ "astc-5x4-unorm-srgb",
523
+ "astc-5x5-unorm",
524
+ "astc-5x5-unorm-srgb",
525
+ "astc-6x5-unorm",
526
+ "astc-6x5-unorm-srgb",
527
+ "astc-6x6-unorm",
528
+ "astc-6x6-unorm-srgb",
529
+ "astc-8x5-unorm",
530
+ "astc-8x5-unorm-srgb",
531
+ "astc-8x6-unorm",
532
+ "astc-8x6-unorm-srgb",
533
+ "astc-8x8-unorm",
534
+ "astc-8x8-unorm-srgb",
535
+ "astc-10x5-unorm",
536
+ "astc-10x5-unorm-srgb",
537
+ "astc-10x6-unorm",
538
+ "astc-10x6-unorm-srgb",
539
+ "astc-10x8-unorm",
540
+ "astc-10x8-unorm-srgb",
541
+ "astc-10x10-unorm",
542
+ "astc-10x10-unorm-srgb",
543
+ "astc-12x10-unorm",
544
+ "astc-12x10-unorm-srgb",
545
+ "astc-12x12-unorm",
546
+ "astc-12x12-unorm-srgb"
547
+ ]
536
548
  /* eslint-enable camelcase */
537
549
  };
538
- var formats = null;
539
- function getSupportedGPUTextureFormats(gl) {
540
- if (!formats) {
550
+ var textureFormats = null;
551
+ function detectSupportedTextureFormats(gl) {
552
+ if (!textureFormats) {
541
553
  gl = gl || getWebGLContext() || void 0;
542
- formats = /* @__PURE__ */ new Set();
554
+ textureFormats = /* @__PURE__ */ new Set();
543
555
  for (const prefix of BROWSER_PREFIXES) {
544
- for (const extension in WEBGL_EXTENSIONS) {
556
+ for (const extension in WEBGL_TEXTURE_FORMATS) {
545
557
  if (gl && gl.getExtension(`${prefix}${extension}`)) {
546
- const gpuTextureFormat = WEBGL_EXTENSIONS[extension];
547
- formats.add(gpuTextureFormat);
558
+ for (const textureFormat of WEBGL_TEXTURE_FORMATS[extension]) {
559
+ textureFormats.add(textureFormat);
560
+ }
548
561
  }
549
562
  }
550
563
  }
551
564
  }
552
- return formats;
565
+ return textureFormats;
553
566
  }
554
567
  function getWebGLContext() {
555
568
  try {
@@ -594,49 +607,113 @@
594
607
  }
595
608
 
596
609
  // src/lib/parsers/parse-basis.ts
597
- var OutputFormat = {
610
+ var BASIS_FORMAT_TO_OUTPUT_OPTIONS = {
598
611
  etc1: {
599
612
  basisFormat: 0,
600
613
  compressed: true,
601
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL
614
+ format: GL_COMPRESSED_RGB_ETC1_WEBGL,
615
+ textureFormat: "etc1-rbg-unorm-webgl"
616
+ },
617
+ etc2: {
618
+ basisFormat: 1,
619
+ compressed: true,
620
+ format: GL_COMPRESSED_RGBA8_ETC2_EAC,
621
+ textureFormat: "etc2-rgba8unorm"
602
622
  },
603
- etc2: { basisFormat: 1, compressed: true },
604
623
  bc1: {
605
624
  basisFormat: 2,
606
625
  compressed: true,
607
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT
626
+ format: GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
627
+ textureFormat: "bc1-rgb-unorm-webgl"
608
628
  },
609
629
  bc3: {
610
630
  basisFormat: 3,
611
631
  compressed: true,
612
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT
632
+ format: GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
633
+ textureFormat: "bc3-rgba-unorm"
634
+ },
635
+ bc4: {
636
+ basisFormat: 4,
637
+ compressed: true,
638
+ format: GL_COMPRESSED_RED_RGTC1_EXT,
639
+ textureFormat: "bc4-r-unorm"
640
+ },
641
+ bc5: {
642
+ basisFormat: 5,
643
+ compressed: true,
644
+ format: GL_COMPRESSED_RED_GREEN_RGTC2_EXT,
645
+ textureFormat: "bc5-rg-unorm"
646
+ },
647
+ "bc7-m6-opaque-only": {
648
+ basisFormat: 6,
649
+ compressed: true,
650
+ format: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,
651
+ textureFormat: "bc7-rgba-unorm"
652
+ },
653
+ "bc7-m5": {
654
+ basisFormat: 7,
655
+ compressed: true,
656
+ format: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,
657
+ textureFormat: "bc7-rgba-unorm"
613
658
  },
614
- bc4: { basisFormat: 4, compressed: true },
615
- bc5: { basisFormat: 5, compressed: true },
616
- "bc7-m6-opaque-only": { basisFormat: 6, compressed: true },
617
- "bc7-m5": { basisFormat: 7, compressed: true },
618
659
  "pvrtc1-4-rgb": {
619
660
  basisFormat: 8,
620
661
  compressed: true,
621
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
662
+ format: GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
663
+ textureFormat: "pvrtc-rgb4unorm-webgl"
622
664
  },
623
665
  "pvrtc1-4-rgba": {
624
666
  basisFormat: 9,
625
667
  compressed: true,
626
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
668
+ format: GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
669
+ textureFormat: "pvrtc-rgba4unorm-webgl"
627
670
  },
628
671
  "astc-4x4": {
629
672
  basisFormat: 10,
630
673
  compressed: true,
631
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR
674
+ format: GL_COMPRESSED_RGBA_ASTC_4x4_KHR,
675
+ textureFormat: "astc-4x4-unorm"
676
+ },
677
+ "atc-rgb": {
678
+ basisFormat: 11,
679
+ compressed: true,
680
+ format: GL_COMPRESSED_RGB_ATC_WEBGL,
681
+ textureFormat: "atc-rgb-unorm-webgl"
682
+ },
683
+ "atc-rgba-interpolated-alpha": {
684
+ basisFormat: 12,
685
+ compressed: true,
686
+ format: GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL,
687
+ textureFormat: "atc-rgbai-unorm-webgl"
632
688
  },
633
- "atc-rgb": { basisFormat: 11, compressed: true },
634
- "atc-rgba-interpolated-alpha": { basisFormat: 12, compressed: true },
635
- rgba32: { basisFormat: 13, compressed: false },
636
- rgb565: { basisFormat: 14, compressed: false },
637
- bgr565: { basisFormat: 15, compressed: false },
638
- rgba4444: { basisFormat: 16, compressed: false }
689
+ rgba32: {
690
+ basisFormat: 13,
691
+ compressed: false,
692
+ format: GL_RGBA8,
693
+ textureFormat: "rgba8unorm"
694
+ },
695
+ rgb565: {
696
+ basisFormat: 14,
697
+ compressed: false,
698
+ format: GL_RGB565,
699
+ textureFormat: "rgb565unorm-webgl"
700
+ },
701
+ bgr565: {
702
+ basisFormat: 15,
703
+ compressed: false,
704
+ format: GL_RGB565,
705
+ textureFormat: "rgb565unorm-webgl"
706
+ },
707
+ rgba4444: {
708
+ basisFormat: 16,
709
+ compressed: false,
710
+ format: GL_RGBA4,
711
+ textureFormat: "rgba4unorm-webgl"
712
+ }
639
713
  };
714
+ var BASIS_FORMATS = Object.freeze(
715
+ Object.keys(BASIS_FORMAT_TO_OUTPUT_OPTIONS)
716
+ );
640
717
  async function parseBasis(data, options = {}) {
641
718
  if (!options.basis?.containerFormat || options.basis.containerFormat === "auto") {
642
719
  if (isKTX(data)) {
@@ -690,7 +767,7 @@
690
767
  const hasAlpha = basisFile.getHasAlpha(
691
768
  /* imageIndex, levelIndex */
692
769
  );
693
- const { compressed, format, basisFormat } = getBasisOptions(options, hasAlpha);
770
+ const { compressed, format, basisFormat, textureFormat } = getBasisOptions(options, hasAlpha);
694
771
  const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat);
695
772
  const decodedData = new Uint8Array(decodedSize);
696
773
  if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {
@@ -698,11 +775,13 @@
698
775
  }
699
776
  return {
700
777
  // standard loaders.gl image category payload
778
+ shape: "texture-level",
701
779
  width,
702
780
  height,
703
781
  data: decodedData,
704
782
  compressed,
705
- format,
783
+ ...format !== void 0 ? { format } : {},
784
+ ...textureFormat !== void 0 ? { textureFormat } : {},
706
785
  // Additional fields
707
786
  // Add levelSize field.
708
787
  hasAlpha
@@ -727,7 +806,7 @@
727
806
  }
728
807
  function transcodeKTX2Image(ktx2File, levelIndex, options) {
729
808
  const { alphaFlag, height, width } = ktx2File.getImageLevelInfo(levelIndex, 0, 0);
730
- const { compressed, format, basisFormat } = getBasisOptions(options, alphaFlag);
809
+ const { compressed, format, basisFormat, textureFormat } = getBasisOptions(options, alphaFlag);
731
810
  const decodedSize = ktx2File.getImageTranscodedSizeInBytes(
732
811
  levelIndex,
733
812
  0,
@@ -750,48 +829,98 @@
750
829
  }
751
830
  return {
752
831
  // standard loaders.gl image category payload
832
+ shape: "texture-level",
753
833
  width,
754
834
  height,
755
835
  data: decodedData,
756
836
  compressed,
837
+ ...format !== void 0 ? { format } : {},
838
+ ...textureFormat !== void 0 ? { textureFormat } : {},
757
839
  // Additional fields
758
840
  levelSize: decodedSize,
759
- hasAlpha: alphaFlag,
760
- format
841
+ hasAlpha: alphaFlag
761
842
  };
762
843
  }
763
844
  function getBasisOptions(options, hasAlpha) {
764
- let format = options.basis?.format;
845
+ let format = options.basis?.format || "auto";
765
846
  if (format === "auto") {
766
- format = selectSupportedBasisFormat();
847
+ format = options.basis?.supportedTextureFormats ? selectSupportedBasisFormat(options.basis.supportedTextureFormats) : selectSupportedBasisFormat();
767
848
  }
768
849
  if (typeof format === "object") {
769
850
  format = hasAlpha ? format.alpha : format.noAlpha;
770
851
  }
771
- format = format.toLowerCase();
772
- return OutputFormat[format];
852
+ const normalizedFormat = format.toLowerCase();
853
+ const basisOutputOptions = BASIS_FORMAT_TO_OUTPUT_OPTIONS[normalizedFormat];
854
+ if (!basisOutputOptions) {
855
+ throw new Error(`Unknown Basis format ${format}`);
856
+ }
857
+ return basisOutputOptions;
773
858
  }
774
- function selectSupportedBasisFormat() {
775
- const supportedFormats = getSupportedGPUTextureFormats();
776
- if (supportedFormats.has("astc")) {
859
+ function selectSupportedBasisFormat(supportedTextureFormats = detectSupportedTextureFormats()) {
860
+ const textureFormats2 = new Set(supportedTextureFormats);
861
+ if (hasSupportedTextureFormat(textureFormats2, ["astc-4x4-unorm", "astc-4x4-unorm-srgb"])) {
777
862
  return "astc-4x4";
778
- } else if (supportedFormats.has("dxt")) {
863
+ } else if (hasSupportedTextureFormat(textureFormats2, ["bc7-rgba-unorm", "bc7-rgba-unorm-srgb"])) {
864
+ return {
865
+ alpha: "bc7-m5",
866
+ noAlpha: "bc7-m6-opaque-only"
867
+ };
868
+ } else if (hasSupportedTextureFormat(textureFormats2, [
869
+ "bc1-rgb-unorm-webgl",
870
+ "bc1-rgb-unorm-srgb-webgl",
871
+ "bc1-rgba-unorm",
872
+ "bc1-rgba-unorm-srgb",
873
+ "bc2-rgba-unorm",
874
+ "bc2-rgba-unorm-srgb",
875
+ "bc3-rgba-unorm",
876
+ "bc3-rgba-unorm-srgb"
877
+ ])) {
779
878
  return {
780
879
  alpha: "bc3",
781
880
  noAlpha: "bc1"
782
881
  };
783
- } else if (supportedFormats.has("pvrtc")) {
882
+ } else if (hasSupportedTextureFormat(textureFormats2, [
883
+ "pvrtc-rgb4unorm-webgl",
884
+ "pvrtc-rgba4unorm-webgl",
885
+ "pvrtc-rbg2unorm-webgl",
886
+ "pvrtc-rgba2unorm-webgl"
887
+ ])) {
784
888
  return {
785
889
  alpha: "pvrtc1-4-rgba",
786
890
  noAlpha: "pvrtc1-4-rgb"
787
891
  };
788
- } else if (supportedFormats.has("etc1")) {
789
- return "etc1";
790
- } else if (supportedFormats.has("etc2")) {
892
+ } else if (hasSupportedTextureFormat(textureFormats2, [
893
+ "etc2-rgb8unorm",
894
+ "etc2-rgb8unorm-srgb",
895
+ "etc2-rgb8a1unorm",
896
+ "etc2-rgb8a1unorm-srgb",
897
+ "etc2-rgba8unorm",
898
+ "etc2-rgba8unorm-srgb",
899
+ "eac-r11unorm",
900
+ "eac-r11snorm",
901
+ "eac-rg11unorm",
902
+ "eac-rg11snorm"
903
+ ])) {
791
904
  return "etc2";
905
+ } else if (textureFormats2.has("etc1-rbg-unorm-webgl")) {
906
+ return "etc1";
907
+ } else if (hasSupportedTextureFormat(textureFormats2, [
908
+ "atc-rgb-unorm-webgl",
909
+ "atc-rgba-unorm-webgl",
910
+ "atc-rgbai-unorm-webgl"
911
+ ])) {
912
+ return {
913
+ alpha: "atc-rgba-interpolated-alpha",
914
+ noAlpha: "atc-rgb"
915
+ };
792
916
  }
793
917
  return "rgb565";
794
918
  }
919
+ function hasSupportedTextureFormat(supportedTextureFormats, candidateTextureFormats) {
920
+ return candidateTextureFormats.some(
921
+ (textureFormat) => supportedTextureFormats.has(textureFormat)
922
+ );
923
+ }
795
924
 
796
925
  // src/basis-loader.ts
797
926
  var BasisWorkerLoader = {