{"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;AAkBG,SAAS,iBACZ,4BAAA,EAEJ;AACI,EAAA,IAAI,iBAAA,KAAsB,QAAW,OAAO,iBAAA;AAE5C,EAAA,iBAAA,GAAA,CAAqB,MACrB;AACI,IAAA,MAAM,cAAA,GAAiB;AAAA,MACnB,OAAA,EAAS,IAAA;AAAA,MACT,4BAAA,EACI,4BAAA,IACG,gBAAA,CAAiB,cAAA,CAAe;AAAA,KAC3C;AAEA,IAAA,IACA;AACI,MAAA,IAAI,CAAC,UAAA,CAAW,GAAA,EAAI,CAAE,0BAAyB,EAC/C;AACI,QAAA,OAAO,KAAA;AAAA,MACX;AAEA,MAAA,MAAM,MAAA,GAAS,UAAA,CAAW,GAAA,EAAI,CAAE,YAAA,EAAa;AAC7C,MAAA,IAAI,EAAA,GAAK,MAAA,CAAO,UAAA,CAAW,OAAA,EAAS,cAAc,CAAA;AAElD,MAAA,MAAM,OAAA,GAAU,CAAC,CAAC,EAAA,EAAI,sBAAqB,EAAG,OAAA;AAE9C,MAAA,IAAI,EAAA,EACJ;AACI,QAAA,MAAM,WAAA,GAAc,EAAA,CAAG,YAAA,CAAa,oBAAoB,CAAA;AAExD,QAAA,IAAI,WAAA,EACJ;AACI,UAAA,WAAA,CAAY,WAAA,EAAY;AAAA,QAC5B;AAAA,MACJ;AAEA,MAAA,EAAA,GAAK,IAAA;AAEL,MAAA,OAAO,OAAA;AAAA,IACX,SACO,EAAA,EACP;AACI,MAAA,OAAO,KAAA;AAAA,IACX;AAAA,EACJ,CAAA,GAAG;AAEH,EAAA,OAAO,iBAAA;AACX;;;;"}