UNPKG

pixi.js

Version:

<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">

1 lines 2.98 kB
{"version":3,"file":"isWebGLSupported.mjs","sources":["../../../src/utils/browser/isWebGLSupported.ts"],"sourcesContent":["import { DOMAdapter } from '../../environment/adapter';\nimport { AbstractRenderer } from '../../rendering/renderers/shared/system/AbstractRenderer';\n\nlet _isWebGLSupported: boolean | undefined;\n\n/**\n * Helper for checking for WebGL support in the current environment.\n *\n * Results are cached after first call for better performance.\n * @example\n * ```ts\n * // Basic WebGL support check\n * if (isWebGLSupported()) {\n * console.log('WebGL is available');\n * }\n * ```\n * @param failIfMajorPerformanceCaveat - Whether to fail if there is a major performance caveat\n * @returns True if WebGL is supported\n * @category utils\n * @standard\n */\nexport function isWebGLSupported(\n failIfMajorPerformanceCaveat?: boolean\n): boolean\n{\n if (_isWebGLSupported !== undefined) return _isWebGLSupported;\n\n _isWebGLSupported = ((): boolean =>\n {\n const contextOptions = {\n stencil: true,\n failIfMajorPerformanceCaveat:\n failIfMajorPerformanceCaveat\n ?? AbstractRenderer.defaultOptions.failIfMajorPerformanceCaveat,\n };\n\n try\n {\n if (!DOMAdapter.get().getWebGLRenderingContext())\n {\n return false;\n }\n\n const canvas = DOMAdapter.get().createCanvas();\n let gl = canvas.getContext('webgl', contextOptions);\n\n const success = !!gl?.getContextAttributes()?.stencil;\n\n if (gl)\n {\n const loseContext = gl.getExtension('WEBGL_lose_context');\n\n if (loseContext)\n {\n loseContext.loseContext();\n }\n }\n\n gl = null;\n\n return success;\n }\n catch (_e)\n {\n return false;\n }\n })();\n\n return _isWebGLSupported;\n}\n"],"names":[],"mappings":";;;;AAGA,IAAI,iBAAA,CAAA;AAkBG,SAAS,iBACZ,4BAEJ,EAAA;AACI,EAAA,IAAI,iBAAsB,KAAA,KAAA,CAAA;AAAW,IAAO,OAAA,iBAAA,CAAA;AAE5C,EAAA,iBAAA,GAAA,CAAqB,MACrB;AACI,IAAA,MAAM,cAAiB,GAAA;AAAA,MACnB,OAAS,EAAA,IAAA;AAAA,MACT,4BAAA,EACI,4BACG,IAAA,gBAAA,CAAiB,cAAe,CAAA,4BAAA;AAAA,KAC3C,CAAA;AAEA,IACA,IAAA;AACI,MAAA,IAAI,CAAC,UAAA,CAAW,GAAI,EAAA,CAAE,0BACtB,EAAA;AACI,QAAO,OAAA,KAAA,CAAA;AAAA,OACX;AAEA,MAAA,MAAM,MAAS,GAAA,UAAA,CAAW,GAAI,EAAA,CAAE,YAAa,EAAA,CAAA;AAC7C,MAAA,IAAI,EAAK,GAAA,MAAA,CAAO,UAAW,CAAA,OAAA,EAAS,cAAc,CAAA,CAAA;AAElD,MAAA,MAAM,OAAU,GAAA,CAAC,CAAC,EAAA,EAAI,sBAAwB,EAAA,OAAA,CAAA;AAE9C,MAAA,IAAI,EACJ,EAAA;AACI,QAAM,MAAA,WAAA,GAAc,EAAG,CAAA,YAAA,CAAa,oBAAoB,CAAA,CAAA;AAExD,QAAA,IAAI,WACJ,EAAA;AACI,UAAA,WAAA,CAAY,WAAY,EAAA,CAAA;AAAA,SAC5B;AAAA,OACJ;AAEA,MAAK,EAAA,GAAA,IAAA,CAAA;AAEL,MAAO,OAAA,OAAA,CAAA;AAAA,aAEJ,EACP,EAAA;AACI,MAAO,OAAA,KAAA,CAAA;AAAA,KACX;AAAA,GACD,GAAA,CAAA;AAEH,EAAO,OAAA,iBAAA,CAAA;AACX;;;;"}