/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/utils/browser/isWebGLSupported.ts
70 строк
2 KB
Zyie
chore: improve api doc comments (#11455)
03 июн 2025, 21:27
Не верифицирован
03 июн 2025, 21:27
0dbf899
Код
Авторство
О чём код?
import { DOMAdapter } from '../../environment/adapter'; import { AbstractRenderer } from '../../rendering/renderers/shared/system/AbstractRenderer'; let _isWebGLSupported: boolean | undefined; /** * Helper for checking for WebGL support in the current environment. * * Results are cached after first call for better performance. * @example * ```ts * // Basic WebGL support check * if (isWebGLSupported()) { * console.log('WebGL is available'); * } * ``` * @param failIfMajorPerformanceCaveat - Whether to fail if there is a major performance caveat * @returns True if WebGL is supported * @category utils * @standard */ export function isWebGLSupported( failIfMajorPerformanceCaveat?: boolean ): boolean { if (_isWebGLSupported !== undefined) return _isWebGLSupported; _isWebGLSupported = ((): boolean => { const contextOptions = { stencil: true, failIfMajorPerformanceCaveat: failIfMajorPerformanceCaveat ?? AbstractRenderer.defaultOptions.failIfMajorPerformanceCaveat, }; try { if (!DOMAdapter.get().getWebGLRenderingContext()) { return false; } const canvas = DOMAdapter.get().createCanvas(); let gl = canvas.getContext('webgl', contextOptions); const success = !!gl?.getContextAttributes()?.stencil; if (gl) { const loseContext = gl.getExtension('WEBGL_lose_context'); if (loseContext) { loseContext.loseContext(); } } gl = null; return success; } catch (_e) { return false; } })(); return _isWebGLSupported; }