UNPKG

@loaders.gl/textures

Version:

Framework-independent loaders for compressed and super compressed (basis) textures

4 lines 188 kB
{ "version": 3, "sources": ["../src/index.ts", "../src/lib/utils/version.ts", "../src/lib/parsers/parse-basis.ts", "../src/lib/parsers/basis-module-loader.ts", "../src/lib/gl-extensions.ts", "../src/lib/utils/detect-supported-texture-formats.ts", "../src/lib/parsers/parse-ktx.ts", "../src/lib/utils/texture-format-map.ts", "../src/lib/utils/extract-mipmap-images.ts", "../src/lib/utils/ktx-format-helper.ts", "../src/basis-loader.ts", "../src/lib/parsers/parse-dds.ts", "../src/lib/parsers/parse-pvr.ts", "../src/lib/parsers/parse-compressed-texture.ts", "../src/compressed-texture-loader.ts", "../src/crunch-loader.ts", "../src/lib/parsers/parse-hdr.ts", "../src/radiance-hdr-loader.ts", "../src/lib/parsers/parse-npy.ts", "../src/npy-loader.ts", "../src/lib/composite-image/parse-composite-image.ts", "../src/lib/texture-api/async-deep-map.ts", "../src/lib/composite-image/image-texture-cube.ts", "../src/texture-loader.ts", "../src/texture-array-loader.ts", "../src/texture-cube-loader.ts", "../src/texture-cube-array-loader.ts", "../src/lib/parsers/crunch-module-loader.ts", "../src/lib/encoders/encode-texture.ts", "../src/compressed-texture-writer.ts", "../src/lib/encoders/encode-ktx2-basis-texture.ts", "../src/ktx2-basis-writer.ts", "../src/lib/texture-api/load-image.ts", "../src/lib/texture-api/generate-url.ts", "../src/lib/texture-api/load-image-array.ts", "../src/lib/texture-api/load-image-cube.ts"], "sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {VERSION} from './lib/utils/version';\n\n// Types\nexport type {GPUTextureFormat, TextureFormat} from '@loaders.gl/schema';\n\n// Loaders\nexport type {BasisLoaderOptions} from './basis-loader';\nexport {BasisLoader, BasisWorkerLoader} from './basis-loader';\n\nexport type {CompressedTextureLoaderOptions} from './compressed-texture-loader';\nexport {CompressedTextureLoader, CompressedTextureWorkerLoader} from './compressed-texture-loader';\n\nexport type {CrunchLoaderOptions} from './crunch-loader';\nexport {CrunchLoader} from './crunch-loader';\n\nexport type {RadianceHDRLoaderOptions} from './radiance-hdr-loader';\nexport type {RadianceHDRMetadata} from './lib/parsers/parse-hdr';\nexport {RadianceHDRLoader} from './radiance-hdr-loader';\n\nexport type {NPYLoaderOptions} from './npy-loader';\nexport {NPYLoader, NPYWorkerLoader} from './npy-loader';\n\nexport type {TextureManifestLoaderOptions, TextureManifest} from './texture-loader';\nexport {TextureLoader} from './texture-loader';\n\nexport type {TextureArrayLoaderOptions, TextureArrayManifest} from './texture-array-loader';\nexport {TextureArrayLoader} from './texture-array-loader';\n\nexport type {TextureCubeLoaderOptions, TextureCubeManifest} from './texture-cube-loader';\nexport {TextureCubeLoader} from './texture-cube-loader';\n\nexport type {\n TextureCubeArrayLoaderOptions,\n TextureCubeArrayManifest\n} from './texture-cube-array-loader';\nexport {TextureCubeArrayLoader} from './texture-cube-array-loader';\n\n// Module constants\nexport {BASIS_EXTERNAL_LIBRARIES} from './lib/parsers/basis-module-loader';\nexport {CRUNCH_EXTERNAL_LIBRARIES} from './lib/parsers/crunch-module-loader';\n\n// Writers\nexport {CompressedTextureWriter} from './compressed-texture-writer';\nexport {KTX2BasisWriter} from './ktx2-basis-writer';\n\nexport const KTX2BasisWriterWorker = {\n name: 'Basis Universal Supercompressed GPU Texture',\n id: 'ktx2-basis-writer',\n module: 'textures',\n version: VERSION,\n extensions: ['ktx2'],\n worker: true,\n options: {\n useSRGB: false,\n qualityLevel: 10,\n encodeUASTC: false,\n mipmaps: false\n }\n};\n\n// Texture Loading API\nexport {loadImageTexture} from './lib/texture-api/load-image';\nexport {loadImageTextureArray} from './lib/texture-api/load-image-array';\nexport {loadImageTextureCube} from './lib/texture-api/load-image-cube';\n\n// Utilities\nexport * from './lib/gl-extensions';\n\n// DEPRECATED\n// @deprecated\nexport {CrunchLoader as CrunchWorkerLoader} from './crunch-loader';\n// @deprecated\nexport type {CompressedTextureLoaderOptions as TextureLoaderOptions} from './compressed-texture-loader';\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n// Version constant cannot be imported, it needs to correspond to the build version of **this** module.\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nexport const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n/* eslint-disable camelcase */\n/* eslint-disable indent */\nimport type {TextureFormat, TextureLevel} from '@loaders.gl/schema';\nimport {extractLoadLibraryOptions} from '@loaders.gl/worker-utils';\nimport {loadBasisEncoderModule, loadBasisTranscoderModule} from './basis-module-loader';\nimport type {GLTextureFormat} from '../gl-types';\nimport {\n GL_COMPRESSED_RED_GREEN_RGTC2_EXT,\n GL_COMPRESSED_RED_RGTC1_EXT,\n GL_COMPRESSED_RGB_ATC_WEBGL,\n GL_COMPRESSED_RGB_ETC1_WEBGL,\n GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,\n GL_COMPRESSED_RGB_S3TC_DXT1_EXT,\n GL_COMPRESSED_RGBA8_ETC2_EAC,\n GL_COMPRESSED_RGBA_ASTC_4x4_KHR,\n GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL,\n GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,\n GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,\n GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,\n GL_RGB565,\n GL_RGBA4,\n GL_RGBA8\n} from '../gl-extensions';\nimport {detectSupportedTextureFormats} from '../utils/detect-supported-texture-formats';\nimport {isKTX} from './parse-ktx';\n\n// TODO - circular type import\nimport type {BasisLoaderOptions} from '../../basis-loader';\n\nexport type BasisFormat =\n | 'etc1'\n | 'etc2'\n | 'bc1'\n | 'bc3'\n | 'bc4'\n | 'bc5'\n | 'bc7-m6-opaque-only'\n | 'bc7-m5'\n | 'pvrtc1-4-rgb'\n | 'pvrtc1-4-rgba'\n | 'astc-4x4'\n | 'atc-rgb'\n | 'atc-rgba-interpolated-alpha'\n | 'rgba32'\n | 'rgb565'\n | 'bgr565'\n | 'rgba4444';\n\ntype BasisOutputOptions = {\n basisFormat: number;\n compressed: boolean;\n format?: GLTextureFormat;\n textureFormat?: TextureFormat;\n};\n\nlet basisTranscodingLock: Promise<void> = Promise.resolve();\n\nexport const BASIS_FORMAT_TO_OUTPUT_OPTIONS: Record<BasisFormat, BasisOutputOptions> = {\n etc1: {\n basisFormat: 0,\n compressed: true,\n format: GL_COMPRESSED_RGB_ETC1_WEBGL,\n textureFormat: 'etc1-rgb-unorm-webgl'\n },\n etc2: {\n basisFormat: 1,\n compressed: true,\n format: GL_COMPRESSED_RGBA8_ETC2_EAC,\n textureFormat: 'etc2-rgba8unorm'\n },\n bc1: {\n basisFormat: 2,\n compressed: true,\n format: GL_COMPRESSED_RGB_S3TC_DXT1_EXT,\n textureFormat: 'bc1-rgb-unorm-webgl'\n },\n bc3: {\n basisFormat: 3,\n compressed: true,\n format: GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,\n textureFormat: 'bc3-rgba-unorm'\n },\n bc4: {\n basisFormat: 4,\n compressed: true,\n format: GL_COMPRESSED_RED_RGTC1_EXT,\n textureFormat: 'bc4-r-unorm'\n },\n bc5: {\n basisFormat: 5,\n compressed: true,\n format: GL_COMPRESSED_RED_GREEN_RGTC2_EXT,\n textureFormat: 'bc5-rg-unorm'\n },\n 'bc7-m6-opaque-only': {\n basisFormat: 6,\n compressed: true,\n format: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,\n textureFormat: 'bc7-rgba-unorm'\n },\n 'bc7-m5': {\n basisFormat: 7,\n compressed: true,\n format: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,\n textureFormat: 'bc7-rgba-unorm'\n },\n 'pvrtc1-4-rgb': {\n basisFormat: 8,\n compressed: true,\n format: GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,\n textureFormat: 'pvrtc-rgb4unorm-webgl'\n },\n 'pvrtc1-4-rgba': {\n basisFormat: 9,\n compressed: true,\n format: GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,\n textureFormat: 'pvrtc-rgba4unorm-webgl'\n },\n 'astc-4x4': {\n basisFormat: 10,\n compressed: true,\n format: GL_COMPRESSED_RGBA_ASTC_4x4_KHR,\n textureFormat: 'astc-4x4-unorm'\n },\n 'atc-rgb': {\n basisFormat: 11,\n compressed: true,\n format: GL_COMPRESSED_RGB_ATC_WEBGL,\n textureFormat: 'atc-rgb-unorm-webgl'\n },\n 'atc-rgba-interpolated-alpha': {\n basisFormat: 12,\n compressed: true,\n format: GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL,\n textureFormat: 'atc-rgbai-unorm-webgl'\n },\n rgba32: {\n basisFormat: 13,\n compressed: false,\n format: GL_RGBA8,\n textureFormat: 'rgba8unorm'\n },\n rgb565: {\n basisFormat: 14,\n compressed: false,\n format: GL_RGB565,\n textureFormat: 'rgb565unorm-webgl'\n },\n bgr565: {\n basisFormat: 15,\n compressed: false,\n format: GL_RGB565,\n textureFormat: 'rgb565unorm-webgl'\n },\n rgba4444: {\n basisFormat: 16,\n compressed: false,\n format: GL_RGBA4,\n textureFormat: 'rgba4unorm-webgl'\n }\n};\n\nexport const BASIS_FORMATS = Object.freeze(\n Object.keys(BASIS_FORMAT_TO_OUTPUT_OPTIONS) as BasisFormat[]\n);\n\nexport type ParseBasisOptions = {\n format: 'auto' | BasisFormat | {alpha: BasisFormat; noAlpha: BasisFormat};\n containerFormat: 'auto' | 'ktx2' | 'basis';\n module: 'transcoder' | 'encoder';\n supportedTextureFormats?: TextureFormat[];\n};\n\n/**\n * Serializes access to the Basis transcoder so concurrent callers do not enter the non-reentrant\n * decoder path at the same time.\n * @param transcode - Transcode operation to run with exclusive access.\n * @returns The transcode result.\n */\nexport async function withBasisTranscodingLock<T>(transcode: () => Promise<T> | T): Promise<T> {\n const previousLock = basisTranscodingLock;\n let releaseLock!: () => void;\n\n basisTranscodingLock = new Promise((resolve) => {\n releaseLock = resolve;\n });\n\n await previousLock;\n\n try {\n return await transcode();\n } finally {\n releaseLock();\n }\n}\n\n/**\n * parse data with a Binomial Basis_Universal module\n * @param data\n * @param options\n * @returns compressed texture data\n */\n// eslint-disable-next-line complexity\nexport async function parseBasis(\n data: ArrayBuffer,\n options: BasisLoaderOptions = {}\n): Promise<TextureLevel[][]> {\n const loadLibraryOptions = extractLoadLibraryOptions(options);\n\n return await withBasisTranscodingLock(async () => {\n if (!options.basis?.containerFormat || options.basis.containerFormat === 'auto') {\n if (isKTX(data)) {\n const fileConstructors = await loadBasisEncoderModule(loadLibraryOptions);\n return parseKTX2File(fileConstructors.KTX2File, data, options);\n }\n const {BasisFile} = await loadBasisTranscoderModule(loadLibraryOptions);\n return parseBasisFile(BasisFile, data, options);\n }\n switch (options.basis.module) {\n case 'encoder':\n const fileConstructors = await loadBasisEncoderModule(loadLibraryOptions);\n switch (options.basis.containerFormat) {\n case 'ktx2':\n return parseKTX2File(fileConstructors.KTX2File, data, options);\n case 'basis':\n default:\n return parseBasisFile(fileConstructors.BasisFile, data, options);\n }\n case 'transcoder':\n default:\n const {BasisFile} = await loadBasisTranscoderModule(loadLibraryOptions);\n return parseBasisFile(BasisFile, data, options);\n }\n });\n}\n\n/**\n * Parse *.basis file data\n * @param BasisFile - initialized transcoder module\n * @param data\n * @param options\n * @returns compressed texture data\n */\nfunction parseBasisFile(\n BasisFile,\n data: ArrayBuffer,\n options: BasisLoaderOptions\n): TextureLevel[][] {\n const basisFile = new BasisFile(new Uint8Array(data));\n\n try {\n if (!basisFile.startTranscoding()) {\n throw new Error('Failed to start basis transcoding');\n }\n\n const imageCount = basisFile.getNumImages();\n const images: TextureLevel[][] = [];\n\n for (let imageIndex = 0; imageIndex < imageCount; imageIndex++) {\n const levelsCount = basisFile.getNumLevels(imageIndex);\n const levels: TextureLevel[] = [];\n\n for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {\n levels.push(transcodeImage(basisFile, imageIndex, levelIndex, options));\n }\n\n images.push(levels);\n }\n\n return images;\n } finally {\n basisFile.close();\n basisFile.delete();\n }\n}\n\n/**\n * Parse the particular level image of a basis file\n * @param basisFile\n * @param imageIndex\n * @param levelIndex\n * @param options\n * @returns compressed texture data\n */\nfunction transcodeImage(\n basisFile,\n imageIndex: number,\n levelIndex: number,\n options: BasisLoaderOptions\n): TextureLevel {\n const width = basisFile.getImageWidth(imageIndex, levelIndex);\n const height = basisFile.getImageHeight(imageIndex, levelIndex);\n\n // See https://github.com/BinomialLLC/basis_universal/pull/83\n const hasAlpha = basisFile.getHasAlpha(/* imageIndex, levelIndex */);\n\n // Check options for output format etc\n const {compressed, format, basisFormat, textureFormat} = getBasisOptions(options, hasAlpha);\n\n const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat);\n const decodedData = new Uint8Array(decodedSize);\n\n if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {\n throw new Error('failed to start Basis transcoding');\n }\n\n return {\n // standard loaders.gl image category payload\n shape: 'texture-level',\n width,\n height,\n data: decodedData,\n compressed,\n ...(format !== undefined ? {format} : {}),\n ...(textureFormat !== undefined ? {textureFormat} : {}),\n\n // Additional fields\n // Add levelSize field.\n hasAlpha\n };\n}\n\n/**\n * Parse *.ktx2 file data\n * @param KTX2File\n * @param data\n * @param options\n * @returns compressed texture data\n */\nfunction parseKTX2File(KTX2File, data: ArrayBuffer, options: BasisLoaderOptions): TextureLevel[][] {\n const ktx2File = new KTX2File(new Uint8Array(data));\n\n try {\n if (!ktx2File.startTranscoding()) {\n throw new Error('failed to start KTX2 transcoding');\n }\n const levelsCount = ktx2File.getLevels();\n const levels: TextureLevel[] = [];\n\n for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {\n levels.push(transcodeKTX2Image(ktx2File, levelIndex, options));\n }\n\n return [levels];\n } finally {\n ktx2File.close();\n ktx2File.delete();\n }\n}\n\n/**\n * Parse the particular level image of a ktx2 file\n * @param ktx2File\n * @param levelIndex\n * @param options\n * @returns\n */\nfunction transcodeKTX2Image(\n ktx2File,\n levelIndex: number,\n options: BasisLoaderOptions\n): TextureLevel {\n const {alphaFlag, height, width} = ktx2File.getImageLevelInfo(levelIndex, 0, 0);\n\n // Check options for output format etc\n const {compressed, format, basisFormat, textureFormat} = getBasisOptions(options, alphaFlag);\n\n const decodedSize = ktx2File.getImageTranscodedSizeInBytes(\n levelIndex,\n 0 /* layerIndex */,\n 0 /* faceIndex */,\n basisFormat\n );\n const decodedData = new Uint8Array(decodedSize);\n\n if (\n !ktx2File.transcodeImage(\n decodedData,\n levelIndex,\n 0 /* layerIndex */,\n 0 /* faceIndex */,\n basisFormat,\n 0,\n -1 /* channel0 */,\n -1 /* channel1 */\n )\n ) {\n throw new Error('Failed to transcode KTX2 image');\n }\n\n return {\n // standard loaders.gl image category payload\n shape: 'texture-level',\n width,\n height,\n data: decodedData,\n compressed,\n ...(format !== undefined ? {format} : {}),\n ...(textureFormat !== undefined ? {textureFormat} : {}),\n\n // Additional fields\n levelSize: decodedSize,\n hasAlpha: alphaFlag\n };\n}\n\n/**\n * Get BasisFormat by loader format option\n * @param options\n * @param hasAlpha\n * @returns BasisFormat data\n */\nfunction getBasisOptions(options: BasisLoaderOptions, hasAlpha: boolean): BasisOutputOptions {\n let format = options.basis?.format || 'auto';\n if (format === 'auto') {\n format = options.basis?.supportedTextureFormats\n ? selectSupportedBasisFormat(options.basis.supportedTextureFormats)\n : selectSupportedBasisFormat();\n }\n if (typeof format === 'object') {\n format = hasAlpha ? format.alpha : format.noAlpha;\n }\n const normalizedFormat = format.toLowerCase() as BasisFormat;\n const basisOutputOptions = BASIS_FORMAT_TO_OUTPUT_OPTIONS[normalizedFormat];\n if (!basisOutputOptions) {\n throw new Error(`Unknown Basis format ${format}`);\n }\n return basisOutputOptions;\n}\n\n/**\n * Select transcode format from the list of supported formats\n * @returns key for OutputFormat map\n */\nexport function selectSupportedBasisFormat():\n | BasisFormat\n | {\n alpha: BasisFormat;\n noAlpha: BasisFormat;\n };\nexport function selectSupportedBasisFormat(supportedTextureFormats?: Iterable<TextureFormat>):\n | BasisFormat\n | {\n alpha: BasisFormat;\n noAlpha: BasisFormat;\n };\nexport function selectSupportedBasisFormat(\n supportedTextureFormats: Iterable<TextureFormat> = detectSupportedTextureFormats()\n): BasisFormat | {alpha: BasisFormat; noAlpha: BasisFormat} {\n const textureFormats = new Set(supportedTextureFormats);\n\n if (hasSupportedTextureFormat(textureFormats, ['astc-4x4-unorm', 'astc-4x4-unorm-srgb'])) {\n return 'astc-4x4';\n } else if (hasSupportedTextureFormat(textureFormats, ['bc7-rgba-unorm', 'bc7-rgba-unorm-srgb'])) {\n return {\n alpha: 'bc7-m5',\n noAlpha: 'bc7-m6-opaque-only'\n };\n } else if (\n hasSupportedTextureFormat(textureFormats, [\n 'bc1-rgb-unorm-webgl',\n 'bc1-rgb-unorm-srgb-webgl',\n 'bc1-rgba-unorm',\n 'bc1-rgba-unorm-srgb',\n 'bc2-rgba-unorm',\n 'bc2-rgba-unorm-srgb',\n 'bc3-rgba-unorm',\n 'bc3-rgba-unorm-srgb'\n ])\n ) {\n return {\n alpha: 'bc3',\n noAlpha: 'bc1'\n };\n } else if (\n hasSupportedTextureFormat(textureFormats, [\n 'pvrtc-rgb4unorm-webgl',\n 'pvrtc-rgba4unorm-webgl',\n 'pvrtc-rgb2unorm-webgl',\n 'pvrtc-rgba2unorm-webgl'\n ])\n ) {\n return {\n alpha: 'pvrtc1-4-rgba',\n noAlpha: 'pvrtc1-4-rgb'\n };\n } else if (\n hasSupportedTextureFormat(textureFormats, [\n 'etc2-rgb8unorm',\n 'etc2-rgb8unorm-srgb',\n 'etc2-rgb8a1unorm',\n 'etc2-rgb8a1unorm-srgb',\n 'etc2-rgba8unorm',\n 'etc2-rgba8unorm-srgb',\n 'eac-r11unorm',\n 'eac-r11snorm',\n 'eac-rg11unorm',\n 'eac-rg11snorm'\n ])\n ) {\n return 'etc2';\n } else if (textureFormats.has('etc1-rgb-unorm-webgl')) {\n return 'etc1';\n } else if (\n hasSupportedTextureFormat(textureFormats, [\n 'atc-rgb-unorm-webgl',\n 'atc-rgba-unorm-webgl',\n 'atc-rgbai-unorm-webgl'\n ])\n ) {\n return {\n alpha: 'atc-rgba-interpolated-alpha',\n noAlpha: 'atc-rgb'\n };\n }\n return 'rgb565';\n}\n\nexport function getSupportedBasisFormats(\n supportedTextureFormats: Iterable<TextureFormat> = detectSupportedTextureFormats()\n): BasisFormat[] {\n const textureFormats = new Set(supportedTextureFormats);\n const basisFormats: BasisFormat[] = [];\n\n if (hasSupportedTextureFormat(textureFormats, ['astc-4x4-unorm', 'astc-4x4-unorm-srgb'])) {\n basisFormats.push('astc-4x4');\n }\n if (\n hasSupportedTextureFormat(textureFormats, [\n 'bc1-rgb-unorm-webgl',\n 'bc1-rgb-unorm-srgb-webgl',\n 'bc1-rgba-unorm',\n 'bc1-rgba-unorm-srgb',\n 'bc2-rgba-unorm',\n 'bc2-rgba-unorm-srgb',\n 'bc3-rgba-unorm',\n 'bc3-rgba-unorm-srgb'\n ])\n ) {\n basisFormats.push('bc1', 'bc3');\n }\n if (hasSupportedTextureFormat(textureFormats, ['bc4-r-unorm', 'bc4-r-snorm'])) {\n basisFormats.push('bc4');\n }\n if (hasSupportedTextureFormat(textureFormats, ['bc5-rg-unorm', 'bc5-rg-snorm'])) {\n basisFormats.push('bc5');\n }\n if (hasSupportedTextureFormat(textureFormats, ['bc7-rgba-unorm', 'bc7-rgba-unorm-srgb'])) {\n basisFormats.push('bc7-m5', 'bc7-m6-opaque-only');\n }\n if (\n hasSupportedTextureFormat(textureFormats, [\n 'pvrtc-rgb4unorm-webgl',\n 'pvrtc-rgba4unorm-webgl',\n 'pvrtc-rgb2unorm-webgl',\n 'pvrtc-rgba2unorm-webgl'\n ])\n ) {\n basisFormats.push('pvrtc1-4-rgb', 'pvrtc1-4-rgba');\n }\n if (\n hasSupportedTextureFormat(textureFormats, [\n 'etc2-rgb8unorm',\n 'etc2-rgb8unorm-srgb',\n 'etc2-rgb8a1unorm',\n 'etc2-rgb8a1unorm-srgb',\n 'etc2-rgba8unorm',\n 'etc2-rgba8unorm-srgb',\n 'eac-r11unorm',\n 'eac-r11snorm',\n 'eac-rg11unorm',\n 'eac-rg11snorm'\n ])\n ) {\n basisFormats.push('etc2');\n }\n if (textureFormats.has('etc1-rgb-unorm-webgl')) {\n basisFormats.push('etc1');\n }\n if (\n hasSupportedTextureFormat(textureFormats, [\n 'atc-rgb-unorm-webgl',\n 'atc-rgba-unorm-webgl',\n 'atc-rgbai-unorm-webgl'\n ])\n ) {\n basisFormats.push('atc-rgb', 'atc-rgba-interpolated-alpha');\n }\n\n basisFormats.push('rgba32', 'rgb565', 'bgr565', 'rgba4444');\n return basisFormats;\n}\n\nfunction hasSupportedTextureFormat(\n supportedTextureFormats: Set<TextureFormat>,\n candidateTextureFormats: TextureFormat[]\n): boolean {\n return candidateTextureFormats.some((textureFormat) =>\n supportedTextureFormats.has(textureFormat)\n );\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {registerJSModules, getJSModuleOrNull} from '@loaders.gl/loader-utils';\nimport {loadLibrary, LoadLibraryOptions} from '@loaders.gl/worker-utils';\n\nexport const BASIS_EXTERNAL_LIBRARIES = {\n /** Basis transcoder, javascript wrapper part */\n TRANSCODER: 'basis_transcoder.js',\n /** Basis transcoder, compiled web assembly part */\n TRANSCODER_WASM: 'basis_transcoder.wasm',\n /** Basis encoder, javascript wrapper part */\n ENCODER: 'basis_encoder.js',\n /** Basis encoder, compiled web assembly part */\n ENCODER_WASM: 'basis_encoder.wasm'\n};\n\nlet loadBasisTranscoderPromise;\n\n/**\n * Loads wasm transcoder module\n * @param options\n * @returns {BasisFile} promise\n */\nexport async function loadBasisTranscoderModule(options: LoadLibraryOptions) {\n registerJSModules(options.modules);\n const basis = getJSModuleOrNull('basis');\n if (basis) {\n return basis;\n }\n\n loadBasisTranscoderPromise ||= loadBasisTranscoder(options);\n return await loadBasisTranscoderPromise;\n}\n\n/**\n * Loads wasm transcoder module\n * @param options\n * @returns {BasisFile} promise\n */\nasync function loadBasisTranscoder(options: LoadLibraryOptions) {\n let BASIS = null;\n let wasmBinary = null;\n\n [BASIS, wasmBinary] = await Promise.all([\n await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER, 'textures', options),\n await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER_WASM, 'textures', options)\n ]);\n\n // Depends on how import happened...\n // @ts-ignore TS2339: Property does not exist on type\n BASIS = BASIS || globalThis.BASIS;\n return await initializeBasisTranscoderModule(BASIS, wasmBinary);\n}\n\n/**\n * Initialize wasm transcoder module\n * @param BasisModule - js part of the module\n * @param wasmBinary - wasm part of the module\n * @returns {BasisFile} promise\n */\nfunction initializeBasisTranscoderModule(BasisModule, wasmBinary) {\n const options: {wasmBinary?} = {};\n\n if (wasmBinary) {\n options.wasmBinary = wasmBinary;\n }\n\n return new Promise((resolve) => {\n // if you try to return BasisModule the browser crashes!\n BasisModule(options).then((module) => {\n const {BasisFile, initializeBasis} = module;\n initializeBasis();\n resolve({BasisFile});\n });\n });\n}\n\nlet loadBasisEncoderPromise;\n\n/**\n * Loads wasm encoder module\n * @param options\n * @returns {BasisFile, KTX2File} promise\n */\nexport async function loadBasisEncoderModule(options: LoadLibraryOptions) {\n const modules = options.modules || {};\n if (modules.basisEncoder) {\n return modules.basisEncoder;\n }\n\n loadBasisEncoderPromise = loadBasisEncoderPromise || loadBasisEncoder(options);\n return await loadBasisEncoderPromise;\n}\n\n/**\n * Loads wasm encoder module\n * @param options\n * @returns {BasisFile, KTX2File} promise\n */\nasync function loadBasisEncoder(options: LoadLibraryOptions) {\n let BASIS_ENCODER = null;\n let wasmBinary = null;\n\n [BASIS_ENCODER, wasmBinary] = await Promise.all([\n await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER, 'textures', options),\n await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER_WASM, 'textures', options)\n ]);\n\n // Depends on how import happened...\n // @ts-ignore TS2339: Property does not exist on type\n BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS;\n return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary);\n}\n\n/**\n * Initialize wasm transcoder module\n * @param BasisEncoderModule - js part of the module\n * @param wasmBinary - wasm part of the module\n * @returns {BasisFile, KTX2File} promise\n */\nfunction initializeBasisEncoderModule(BasisEncoderModule, wasmBinary) {\n const options: {wasmBinary?} = {};\n\n if (wasmBinary) {\n options.wasmBinary = wasmBinary;\n }\n\n return new Promise((resolve) => {\n // if you try to return BasisModule the browser crashes!\n BasisEncoderModule(options).then((module) => {\n const {BasisFile, KTX2File, initializeBasis, BasisEncoder} = module;\n initializeBasis();\n resolve({BasisFile, KTX2File, BasisEncoder});\n });\n });\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n/* eslint-disable camelcase */\n\n// Core WebGL texture formats\nexport const GL_RGB = 0x1907;\nexport const GL_RGBA = 0x1908;\nexport const GL_RGBA4 = 0x8056;\nexport const GL_RGB5_A1 = 0x8057;\nexport const GL_RGBA8 = 0x8058;\nexport const GL_RGB565 = 0x8d62;\nexport const GL_RGBA32F = 0x8814;\n\n// WEBGL_compressed_texture_s3tc\nexport const GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83f0;\nexport const GL_COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83f1;\nexport const GL_COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83f2;\nexport const GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83f3;\n\n// WEBGL_compressed_texture_es3\nexport const GL_COMPRESSED_R11_EAC = 0x9270;\nexport const GL_COMPRESSED_SIGNED_R11_EAC = 0x9271;\nexport const GL_COMPRESSED_RG11_EAC = 0x9272;\nexport const GL_COMPRESSED_SIGNED_RG11_EAC = 0x9273;\nexport const GL_COMPRESSED_RGB8_ETC2 = 0x9274;\nexport const GL_COMPRESSED_RGBA8_ETC2_EAC = 0x9275;\nexport const GL_COMPRESSED_SRGB8_ETC2 = 0x9276;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9277;\nexport const GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9278;\nexport const GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9279;\n\n// WEBGL_compressed_texture_pvrtc\nexport const GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8c00;\nexport const GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8c01;\nexport const GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8c02;\nexport const GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8c03;\n\n// WEBGL_compressed_texture_etc1\nexport const GL_COMPRESSED_RGB_ETC1_WEBGL = 0x8d64;\n\n// WEBGL_compressed_texture_atc\nexport const GL_COMPRESSED_RGB_ATC_WEBGL = 0x8c92;\nexport const GL_COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL = 0x8c93;\nexport const GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL = 0x87ee;\n\n// WEBGL_compressed_texture_astc\nexport const GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93b0;\nexport const GL_COMPRESSED_RGBA_ASTC_5x4_KHR = 0x93b1;\nexport const GL_COMPRESSED_RGBA_ASTC_5x5_KHR = 0x93b2;\nexport const GL_COMPRESSED_RGBA_ASTC_6x5_KHR = 0x93b3;\nexport const GL_COMPRESSED_RGBA_ASTC_6x6_KHR = 0x93b4;\nexport const GL_COMPRESSED_RGBA_ASTC_8x5_KHR = 0x93b5;\nexport const GL_COMPRESSED_RGBA_ASTC_8x6_KHR = 0x93b6;\nexport const GL_COMPRESSED_RGBA_ASTC_8x8_KHR = 0x93b7;\nexport const GL_COMPRESSED_RGBA_ASTC_10x5_KHR = 0x93b8;\nexport const GL_COMPRESSED_RGBA_ASTC_10x6_KHR = 0x93b9;\nexport const GL_COMPRESSED_RGBA_ASTC_10x8_KHR = 0x93ba;\nexport const GL_COMPRESSED_RGBA_ASTC_10x10_KHR = 0x93bb;\nexport const GL_COMPRESSED_RGBA_ASTC_12x10_KHR = 0x93bc;\nexport const GL_COMPRESSED_RGBA_ASTC_12x12_KHR = 0x93bd;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = 0x93d0;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR = 0x93d1;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR = 0x93d2;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR = 0x93d3;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR = 0x93d4;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR = 0x93d5;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR = 0x93d6;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR = 0x93d7;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR = 0x93d8;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR = 0x93d9;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR = 0x93da;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR = 0x93db;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR = 0x93dc;\nexport const GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR = 0x93dd;\n\n// EXT_texture_compression_rgtc\nexport const GL_COMPRESSED_RED_RGTC1_EXT = 0x8dbb;\nexport const GL_COMPRESSED_SIGNED_RED_RGTC1_EXT = 0x8dbc;\nexport const GL_COMPRESSED_RED_GREEN_RGTC2_EXT = 0x8dbd;\nexport const GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT = 0x8dbe;\n\n// EXT_texture_compression_bptc\nexport const GL_COMPRESSED_RGBA_BPTC_UNORM_EXT = 0x8e8c;\nexport const GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT = 0x8e8d;\nexport const GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT = 0x8e8e;\nexport const GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT = 0x8e8f;\n\n// WEBGL_compressed_texture_s3tc_srgb\nexport const GL_COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8c4c;\nexport const GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 0x8c4d;\nexport const GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 0x8c4e;\nexport const GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8c4f;\n\nexport const GL_EXTENSIONS_CONSTANTS = {\n RGB: GL_RGB,\n RGBA: GL_RGBA,\n RGBA4: GL_RGBA4,\n RGB5_A1: GL_RGB5_A1,\n RGBA8: GL_RGBA8,\n RGB565: GL_RGB565,\n RGBA32F: GL_RGBA32F,\n COMPRESSED_RGB_S3TC_DXT1_EXT: GL_COMPRESSED_RGB_S3TC_DXT1_EXT,\n COMPRESSED_RGBA_S3TC_DXT1_EXT: GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,\n COMPRESSED_RGBA_S3TC_DXT3_EXT: GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,\n COMPRESSED_RGBA_S3TC_DXT5_EXT: GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,\n COMPRESSED_R11_EAC: GL_COMPRESSED_R11_EAC,\n COMPRESSED_SIGNED_R11_EAC: GL_COMPRESSED_SIGNED_R11_EAC,\n COMPRESSED_RG11_EAC: GL_COMPRESSED_RG11_EAC,\n COMPRESSED_SIGNED_RG11_EAC: GL_COMPRESSED_SIGNED_RG11_EAC,\n COMPRESSED_RGB8_ETC2: GL_COMPRESSED_RGB8_ETC2,\n COMPRESSED_RGBA8_ETC2_EAC: GL_COMPRESSED_RGBA8_ETC2_EAC,\n COMPRESSED_SRGB8_ETC2: GL_COMPRESSED_SRGB8_ETC2,\n COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,\n COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,\n COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,\n COMPRESSED_RGB_PVRTC_4BPPV1_IMG: GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,\n COMPRESSED_RGB_PVRTC_2BPPV1_IMG: GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG,\n COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,\n COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,\n COMPRESSED_RGB_ETC1_WEBGL: GL_COMPRESSED_RGB_ETC1_WEBGL,\n COMPRESSED_RGB_ATC_WEBGL: GL_COMPRESSED_RGB_ATC_WEBGL,\n COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: GL_COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL,\n COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL,\n COMPRESSED_RGBA_ASTC_4x4_KHR: GL_COMPRESSED_RGBA_ASTC_4x4_KHR,\n COMPRESSED_RGBA_ASTC_5x4_KHR: GL_COMPRESSED_RGBA_ASTC_5x4_KHR,\n COMPRESSED_RGBA_ASTC_5x5_KHR: GL_COMPRESSED_RGBA_ASTC_5x5_KHR,\n COMPRESSED_RGBA_ASTC_6x5_KHR: GL_COMPRESSED_RGBA_ASTC_6x5_KHR,\n COMPRESSED_RGBA_ASTC_6x6_KHR: GL_COMPRESSED_RGBA_ASTC_6x6_KHR,\n COMPRESSED_RGBA_ASTC_8x5_KHR: GL_COMPRESSED_RGBA_ASTC_8x5_KHR,\n COMPRESSED_RGBA_ASTC_8x6_KHR: GL_COMPRESSED_RGBA_ASTC_8x6_KHR,\n COMPRESSED_RGBA_ASTC_8x8_KHR: GL_COMPRESSED_RGBA_ASTC_8x8_KHR,\n COMPRESSED_RGBA_ASTC_10x5_KHR: GL_COMPRESSED_RGBA_ASTC_10x5_KHR,\n COMPRESSED_RGBA_ASTC_10x6_KHR: GL_COMPRESSED_RGBA_ASTC_10x6_KHR,\n COMPRESSED_RGBA_ASTC_10x8_KHR: GL_COMPRESSED_RGBA_ASTC_10x8_KHR,\n COMPRESSED_RGBA_ASTC_10x10_KHR: GL_COMPRESSED_RGBA_ASTC_10x10_KHR,\n COMPRESSED_RGBA_ASTC_12x10_KHR: GL_COMPRESSED_RGBA_ASTC_12x10_KHR,\n COMPRESSED_RGBA_ASTC_12x12_KHR: GL_COMPRESSED_RGBA_ASTC_12x12_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,\n COMPRESSED_RED_RGTC1_EXT: GL_COMPRESSED_RED_RGTC1_EXT,\n COMPRESSED_SIGNED_RED_RGTC1_EXT: GL_COMPRESSED_SIGNED_RED_RGTC1_EXT,\n COMPRESSED_RED_GREEN_RGTC2_EXT: GL_COMPRESSED_RED_GREEN_RGTC2_EXT,\n COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT,\n COMPRESSED_RGBA_BPTC_UNORM_EXT: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,\n COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT,\n COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,\n COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,\n COMPRESSED_SRGB_S3TC_DXT1_EXT: GL_COMPRESSED_SRGB_S3TC_DXT1_EXT,\n COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,\n COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,\n COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,\n // Deprecated legacy aliases with non-standard ASTC casing.\n COMPRESSED_RGBA_ASTC_4X4_KHR: GL_COMPRESSED_RGBA_ASTC_4x4_KHR,\n COMPRESSED_RGBA_ASTC_5X4_KHR: GL_COMPRESSED_RGBA_ASTC_5x4_KHR,\n COMPRESSED_RGBA_ASTC_5X5_KHR: GL_COMPRESSED_RGBA_ASTC_5x5_KHR,\n COMPRESSED_RGBA_ASTC_6X5_KHR: GL_COMPRESSED_RGBA_ASTC_6x5_KHR,\n COMPRESSED_RGBA_ASTC_6X6_KHR: GL_COMPRESSED_RGBA_ASTC_6x6_KHR,\n COMPRESSED_RGBA_ASTC_8X5_KHR: GL_COMPRESSED_RGBA_ASTC_8x5_KHR,\n COMPRESSED_RGBA_ASTC_8X6_KHR: GL_COMPRESSED_RGBA_ASTC_8x6_KHR,\n COMPRESSED_RGBA_ASTC_8X8_KHR: GL_COMPRESSED_RGBA_ASTC_8x8_KHR,\n COMPRESSED_RGBA_ASTC_10X5_KHR: GL_COMPRESSED_RGBA_ASTC_10x5_KHR,\n COMPRESSED_RGBA_ASTC_10X6_KHR: GL_COMPRESSED_RGBA_ASTC_10x6_KHR,\n COMPRESSED_RGBA_ASTC_10X8_KHR: GL_COMPRESSED_RGBA_ASTC_10x8_KHR,\n COMPRESSED_RGBA_ASTC_10X10_KHR: GL_COMPRESSED_RGBA_ASTC_10x10_KHR,\n COMPRESSED_RGBA_ASTC_12X10_KHR: GL_COMPRESSED_RGBA_ASTC_12x10_KHR,\n COMPRESSED_RGBA_ASTC_12X12_KHR: GL_COMPRESSED_RGBA_ASTC_12x12_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,\n COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR: GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR\n} as const;\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {GPUTextureFormat, TextureFormat} from '@loaders.gl/schema';\n\nconst BROWSER_PREFIXES = ['', 'WEBKIT_', 'MOZ_'];\n\nconst WEBGL_TEXTURE_FORMATS: {[key: string]: TextureFormat[]} = {\n /* eslint-disable camelcase */\n WEBGL_compressed_texture_s3tc: [\n 'bc1-rgb-unorm-webgl',\n 'bc1-rgba-unorm',\n 'bc2-rgba-unorm',\n 'bc3-rgba-unorm'\n ],\n WEBGL_compressed_texture_s3tc_srgb: [\n 'bc1-rgb-unorm-srgb-webgl',\n 'bc1-rgba-unorm-srgb',\n 'bc2-rgba-unorm-srgb',\n 'bc3-rgba-unorm-srgb'\n ],\n EXT_texture_compression_rgtc: ['bc4-r-unorm', 'bc4-r-snorm', 'bc5-rg-unorm', 'bc5-rg-snorm'],\n EXT_texture_compression_bptc: [\n 'bc6h-rgb-ufloat',\n 'bc6h-rgb-float',\n 'bc7-rgba-unorm',\n 'bc7-rgba-unorm-srgb'\n ],\n WEBGL_compressed_texture_etc1: ['etc1-rgb-unorm-webgl'],\n WEBGL_compressed_texture_etc: [\n 'etc2-rgb8unorm',\n 'etc2-rgb8unorm-srgb',\n 'etc2-rgb8a1unorm',\n 'etc2-rgb8a1unorm-srgb',\n 'etc2-rgba8unorm',\n 'etc2-rgba8unorm-srgb',\n 'eac-r11unorm',\n 'eac-r11snorm',\n 'eac-rg11unorm',\n 'eac-rg11snorm'\n ],\n WEBGL_compressed_texture_pvrtc: [\n 'pvrtc-rgb4unorm-webgl',\n 'pvrtc-rgba4unorm-webgl',\n 'pvrtc-rgb2unorm-webgl',\n 'pvrtc-rgba2unorm-webgl'\n ],\n WEBGL_compressed_texture_atc: [\n 'atc-rgb-unorm-webgl',\n 'atc-rgba-unorm-webgl',\n 'atc-rgbai-unorm-webgl'\n ],\n WEBGL_compressed_texture_astc: [\n 'astc-4x4-unorm',\n 'astc-4x4-unorm-srgb',\n 'astc-5x4-unorm',\n 'astc-5x4-unorm-srgb',\n 'astc-5x5-unorm',\n 'astc-5x5-unorm-srgb',\n 'astc-6x5-unorm',\n 'astc-6x5-unorm-srgb',\n 'astc-6x6-unorm',\n 'astc-6x6-unorm-srgb',\n 'astc-8x5-unorm',\n 'astc-8x5-unorm-srgb',\n 'astc-8x6-unorm',\n 'astc-8x6-unorm-srgb',\n 'astc-8x8-unorm',\n 'astc-8x8-unorm-srgb',\n 'astc-10x5-unorm',\n 'astc-10x5-unorm-srgb',\n 'astc-10x6-unorm',\n 'astc-10x6-unorm-srgb',\n 'astc-10x8-unorm',\n 'astc-10x8-unorm-srgb',\n 'astc-10x10-unorm',\n 'astc-10x10-unorm-srgb',\n 'astc-12x10-unorm',\n 'astc-12x10-unorm-srgb',\n 'astc-12x12-unorm',\n 'astc-12x12-unorm-srgb'\n ]\n /* eslint-enable camelcase */\n};\n\nconst GPU_TEXTURE_FORMATS: {[key in GPUTextureFormat]: TextureFormat[]} = {\n dxt: ['bc1-rgb-unorm-webgl', 'bc1-rgba-unorm', 'bc2-rgba-unorm', 'bc3-rgba-unorm'],\n 'dxt-srgb': [\n 'bc1-rgb-unorm-srgb-webgl',\n 'bc1-rgba-unorm-srgb',\n 'bc2-rgba-unorm-srgb',\n 'bc3-rgba-unorm-srgb'\n ],\n etc1: ['etc1-rgb-unorm-webgl'],\n etc2: [\n 'etc2-rgb8unorm',\n 'etc2-rgb8unorm-srgb',\n 'etc2-rgb8a1unorm',\n 'etc2-rgb8a1unorm-srgb',\n 'etc2-rgba8unorm',\n 'etc2-rgba8unorm-srgb',\n 'eac-r11unorm',\n 'eac-r11snorm',\n 'eac-rg11unorm',\n 'eac-rg11snorm'\n ],\n pvrtc: [\n 'pvrtc-rgb4unorm-webgl',\n 'pvrtc-rgba4unorm-webgl',\n 'pvrtc-rgb2unorm-webgl',\n 'pvrtc-rgba2unorm-webgl'\n ],\n atc: ['atc-rgb-unorm-webgl', 'atc-rgba-unorm-webgl', 'atc-rgbai-unorm-webgl'],\n astc: [\n 'astc-4x4-unorm',\n 'astc-4x4-unorm-srgb',\n 'astc-5x4-unorm',\n 'astc-5x4-unorm-srgb',\n 'astc-5x5-unorm',\n 'astc-5x5-unorm-srgb',\n 'astc-6x5-unorm',\n 'astc-6x5-unorm-srgb',\n 'astc-6x6-unorm',\n 'astc-6x6-unorm-srgb',\n 'astc-8x5-unorm',\n 'astc-8x5-unorm-srgb',\n 'astc-8x6-unorm',\n 'astc-8x6-unorm-srgb',\n 'astc-8x8-unorm',\n 'astc-8x8-unorm-srgb',\n 'astc-10x5-unorm',\n 'astc-10x5-unorm-srgb',\n 'astc-10x6-unorm',\n 'astc-10x6-unorm-srgb',\n 'astc-10x8-unorm',\n 'astc-10x8-unorm-srgb',\n 'astc-10x10-unorm',\n 'astc-10x10-unorm-srgb',\n 'astc-12x10-unorm',\n 'astc-12x10-unorm-srgb',\n 'astc-12x12-unorm',\n 'astc-12x12-unorm-srgb'\n ],\n rgtc: ['bc4-r-unorm', 'bc4-r-snorm', 'bc5-rg-unorm', 'bc5-rg-snorm']\n};\n\nlet formats: Set<GPUTextureFormat> | null = null;\nlet textureFormats: Set<TextureFormat> | null = null;\n\n// DEPRECATED\n/**\n * @deprecated Pass `basis.supportedTextureFormats` to Basis loaders instead of relying on global detection.\n */\nexport function detectSupportedTextureFormats(gl?: WebGLRenderingContext): Set<TextureFormat> {\n if (!textureFormats) {\n gl = gl || getWebGLContext() || undefined;\n textureFormats = new Set<TextureFormat>();\n\n for (const prefix of BROWSER_PREFIXES) {\n for (const extension in WEBGL_TEXTURE_FORMATS) {\n if (gl && gl.getExtension(`${prefix}${extension}`)) {\n for (const textureFormat of WEBGL_TEXTURE_FORMATS[extension]) {\n textureFormats.add(textureFormat);\n }\n }\n }\n }\n }\n\n return textureFormats;\n}\n\n// DEPRECATED\n/**\n * Returns a list of formats.\n * Creates a temporary WebGLRenderingContext if none is provided.\n *\n * @deprecated Pass `basis.supportedTextureFormats` to Basis loaders instead of relying on global detection.\n * @param gl - Optional context.\n */\nexport function detectSupportedGPUTextureFormats(gl?: WebGLRenderingContext): Set<string> {\n if (!formats) {\n formats = new Set<GPUTextureFormat>();\n const supportedTextureFormats = detectSupportedTextureFormats(gl);\n\n for (const gpuTextureFormat in GPU_TEXTURE_FORMATS) {\n const textureFormatsForGroup = GPU_TEXTURE_FORMATS[gpuTextureFormat as GPUTextureFormat];\n if (\n textureFormatsForGroup.some((textureFormat) => supportedTextureFormats.has(textureFormat))\n ) {\n formats.add(gpuTextureFormat as GPUTextureFormat);\n }\n }\n }\n\n return formats;\n}\n\n/**\n * @returns {WebGLRenderingContext?}\n */\nfunction getWebGLContext() {\n try {\n const canvas = document.createElement('canvas');\n return canvas.getContext('webgl');\n } catch (error) {\n return null;\n }\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {TextureLevel} from '@loaders.gl/schema';\nimport {log} from '@loaders.gl/loader-utils';\nimport {read} from 'ktx-parse';\nimport {extractMipmapImages} from '../utils/extract-mipmap-images';\nimport {mapVkFormatToTextureFormat} from '../utils/ktx-format-helper';\n\nconst KTX2_ID = [\n // '\u00B4', 'K', 'T', 'X', '2', '0', '\u00AA', '\\r', '\\n', '\\x1A', '\\n'\n 0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a\n];\n\n// eslint-disable-next-line complexity\nexport function isKTX(data: ArrayBuffer) {\n // const id = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n const id = new Uint8Array(data);\n const notKTX =\n id.byteLength < KTX2_ID.length ||\n id[0] !== KTX2_ID[0] || // '\u00B4'\n id[1] !== KTX2_ID[1] || // 'K'\n id[2] !== KTX2_ID[2] || // 'T'\n id[3] !== KTX2_ID[3] || // 'X'\n id[4] !== KTX2_ID[4] || // ' '\n id[5] !== KTX2_ID[5] || // '2'\n id[6] !== KTX2_ID[6] || // '0'\n id[7] !== KTX2_ID[7] || // '\u00AA'\n id[8] !== KTX2_ID[8] || // '\\r'\n id[9] !== KTX2_ID[9] || // '\\n'\n id[10] !== KTX2_ID[10] || // '\\x1A'\n id[11] !== KTX2_ID[11]; // '\\n'\n\n return !notKTX;\n}\n\nexport function parseKTX(arrayBuffer: ArrayBuffer): TextureLevel[] {\n const uint8Array = new Uint8Array(arrayBuffer);\n const ktx = read(uint8Array);\n const mipMapLevels = Math.max(1, ktx.levels.length);\n const width = ktx.pixelWidth;\n const height = ktx.pixelHeight;\n const textureFormat = mapVkFormatToTextureFormat(ktx.vkFormat);\n\n if (textureFormat === undefined) {\n // TODO: Basis-backed and otherwise unknown-format KTX2 files should preserve the\n // legacy CompressedTextureLoader behavior for now. Do not fail here or add implicit\n // transcoding in this parser path; just return levels without `format` metadata.\n log.warn(\n `KTX2 container vkFormat ${ktx.vkFormat} does not map to a known texture format; returning texture levels without format metadata.`\n )();\n }\n\n return extractMipmapImages(ktx.levels, {\n mipMapLevels,\n width,\n height,\n sizeFunction: (level: any): number => level.uncompressedByteLength,\n textureFormat\n });\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n/* eslint-disable camelcase */\nimport type {TextureFormat} from '@loaders.gl/schema';\nimport type {GLTextureFormat} from '../gl-types';\nimport {\n GL_RGBA32F,\n GL_COMPRESSED_R11_EAC,\n GL_COMPRESSED_RED_GREEN_RGTC2_EXT,\n GL_COMPRESSED_RED_RGTC1_EXT,\n GL_COMPRESSED_RG11_EAC,\n GL_COMPRESSED_RGB8_ETC2,\n GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,\n GL_COMPRESSED_RGB_ATC_WEBGL,\n GL_COMPRESSED_RGB_ETC1_WEBGL,\n GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG,\n GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,\n GL_COMPRESSED_RGB_S3TC_DXT1_EXT,\n GL_COMPRESSED_RGBA8_ETC2_EAC,\n GL_COMPRESSED_RGBA_ASTC_10x10_KHR,\n GL_COMPRESSED_RGBA_ASTC_10x5_KHR,\n GL_COMPRESSED_RGBA_ASTC_10x6_KHR,\n GL_COMPRESSED_RGBA_ASTC_10x8_KHR,\n GL_COMPRESSED_RGBA_ASTC_12x10_KHR,\n GL_COMPRESSED_RGBA_ASTC_12x12_KHR,\n GL_COMPRESSED_RGBA_ASTC_4x4_KHR,\n GL_COMPRESSED_RGBA_ASTC_5x4_KHR,\n GL_COMPRESSED_RGBA_ASTC_5x5_KHR,\n GL_COMPRESSED_RGBA_ASTC_6x5_KHR,\n GL_COMPRESSED_RGBA_ASTC_6x6_KHR,\n GL_COMPRESSED_RGBA_ASTC_8x5_KHR,\n GL_COMPRESSED_RGBA_ASTC_8x6_KHR,\n GL_COMPRESSED_RGBA_ASTC_8x8_KHR,\n GL_COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL,\n GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL,\n GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,\n GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,\n GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,\n GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,\n GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,\n GL_COMPRESSED_SIGNED_R11_EAC,\n GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT,\n GL_COMPRESSED_SIGNED_RED_RGTC1_EXT,\n GL_COMPRESSED_SIGNED_RG11_EAC,\n GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,\n GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,\n GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,\n GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,\n GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,\n GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,\n GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,\n GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,\n GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,\n GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,\n GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,\n GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,\n GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,\n GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,\n GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,\n GL_COMPRESSED_SRGB8_ETC2,\n GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,\n GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,\n GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,\n GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,\n GL_COMPRESSED_SRGB_S3TC_DXT1_EXT\n} from '../gl-extensions';\n\nconst WEBGL_TO_TEXTURE_FORMAT: Record<number, TextureFormat> = {\n [GL_RGBA32F]: 'rgba32float',\n [GL_COMPRESSED_RGB_S3TC_DXT1_EXT]: 'bc1-rgb-unorm-webgl',\n [GL_COMPRESSED_SRGB_S3TC_DXT1_EXT]: 'bc1-rgb-unorm-srgb-webgl',\n [GL_COMPRESSED_RGBA_S3TC_DXT1_EXT]: 'bc1-rgba-unorm',\n [GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT]: 'bc1-rgba-unorm-srgb',\n [GL_COMPRESSED_RGBA_S3TC_DXT3_EXT]: 'bc2-rgba-unorm',\n [GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT]: 'bc2-rgba-unorm-srgb',\n [GL_COMPRESSED_RGBA_S3TC_DXT5_EXT]: 'bc3-rgba-unorm',\n [GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT]: 'bc3-rgba-unorm-srgb',\n [GL_COMPRESSED_RED_RGTC1_EXT]: 'bc4-r-unorm',\n [GL_COMPRESSED_SIGNED_RED_RGTC1_EXT]: 'bc4-r-snorm',\n [GL_COMPRESSED_RED_GREEN_RGTC2_EXT]: 'bc5-rg-unorm',\n [GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT]: 'bc5-rg-snorm',\n [GL_COMPRESSED_RGB8_ETC2]: 'etc2-rgb8unorm',\n [GL_COMPRESSED_SRGB8_ETC2]: 'etc2-rgb8unorm-srgb',\n [GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2]: 'etc2-rgb8a1unorm',\n [GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2]: 'etc2-rgb8a1unorm-srgb',\n [GL_COMPRESSED_RGBA8_ETC2_EAC]: 'etc2-rgba8unorm',\n [GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC]: 'etc2-rgba8unorm-srgb',\n [GL_COMPRESSED_R11_EAC]: 'eac-r11unorm',\n [GL_COMPRESSED_SIGNED_R11_EAC]: 'eac-r11snorm',\n [GL_COMPRESSED_RG11_EAC]: 'eac-rg11unorm',\n [GL_COMPRESSED_SIGNED_RG11_EAC]: 'eac-rg11snorm',\n [GL_COMPRESSED_RGBA_ASTC_4x4_KHR]: 'astc-4x4-unorm',\n [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR]: 'astc-4x4-unorm-srgb',\n [GL_COMPRESSED_RGBA_ASTC_5x4_KHR]: 'astc-5x4-unorm',\n [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR]: 'astc-5x4-unorm-srgb',\n [GL_COMPRESSED_RGBA_ASTC_5x5_KHR]: 'astc-5x5-unorm',\n [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR]: 'astc-5x5-unorm-srgb',\n [GL_COMPRESSED_RGBA_ASTC_6x5_KHR]: 'astc-6x5-unorm',\n [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR]: 'astc-6x5-unorm-srgb',\n [GL_COMPRESSED_RGBA_ASTC_6x6_KHR]: 'astc-6x6-unorm',\n [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR]: 'astc-6x6-unorm-srgb',\n [GL_COMPRESSED_RGBA_ASTC_8x5_KHR]: 'astc-8x5-unorm',\n [GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR]: 'astc-8x5-unorm-srgb',\n [GL_COMPRESSED_RGBA_ASTC_8x6_KHR]: 'astc-8x6-unorm',\n [GL_COMPRESSED_SRGB8_ALPHA8