/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/compressed-textures/shared/detectCompressed.ts
85 строк
2 KB
Zyie
chore: add standard/advanced tags to documentation (#11448)
03 июн 2025, 10:12
Не верифицирован
03 июн 2025, 10:12
7d91234
Код
Авторство
О чём код?
import { ExtensionType } from '../../extensions/Extensions'; // eslint-disable-next-line max-len import { getSupportedCompressedTextureFormats } from '../../rendering/renderers/shared/texture/utils/getSupportedCompressedTextureFormats'; import { isWebGLSupported } from '../../utils/browser/isWebGLSupported'; import { isWebGPUSupported } from '../../utils/browser/isWebGPUSupported'; import { validFormats } from './resolveCompressedTextureUrl'; import type { FormatDetectionParser } from '../../assets/detections/types'; import type { TEXTURE_FORMATS } from '../../rendering/renderers/shared/texture/const'; let compressedTextureExtensions: string[]; /** * Detects if the browser supports compressed texture formats. * @category assets * @internal */ export const detectCompressed = { extension: { type: ExtensionType.DetectionParser, priority: 2, }, test: async (): Promise<boolean> => { if (await isWebGPUSupported()) return true; if (isWebGLSupported()) return true; return false; }, add: async (formats: string[]): Promise<string[]> => { const supportedCompressedTextureFormats = await getSupportedCompressedTextureFormats(); compressedTextureExtensions = extractExtensionsForCompressedTextureFormats(supportedCompressedTextureFormats); return [...compressedTextureExtensions, ...formats]; }, remove: async (formats: string[]): Promise<string[]> => { if (compressedTextureExtensions) { return formats.filter((f) => !(f in compressedTextureExtensions)); } return formats; }, } as FormatDetectionParser; function extractExtensionsForCompressedTextureFormats(formats: TEXTURE_FORMATS[]): string[] { const extensions: string[] = ['basis']; const dupeMap: Record<string, boolean> = {}; formats.forEach((format) => { const extension = format.split('-')[0]; if (extension && !dupeMap[extension]) { dupeMap[extension] = true; extensions.push(extension); } }); // sort extensions by priority extensions.sort((a, b) => { const aIndex = validFormats.indexOf(a); const bIndex = validFormats.indexOf(b); if (aIndex === -1) { return 1; } if (bIndex === -1) { return -1; } return aIndex - bIndex; }); return extensions; }