UNPKG

@pixi/utils

Version:

Collection of utilities used by PixiJS

1 lines 2.22 kB
{"version":3,"file":"isWebGLSupported.mjs","sources":["../../src/browser/isWebGLSupported.ts"],"sourcesContent":["import { settings } from '../settings';\n\nlet supported: boolean | undefined;\n\n/**\n * Helper for checking for WebGL support.\n * @memberof PIXI.utils\n * @function isWebGLSupported\n * @returns {boolean} Is WebGL supported.\n */\nexport function isWebGLSupported(): boolean\n{\n if (typeof supported === 'undefined')\n {\n supported = (function supported(): boolean\n {\n const contextOptions = {\n stencil: true,\n failIfMajorPerformanceCaveat: settings.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT,\n };\n\n try\n {\n if (!settings.ADAPTER.getWebGLRenderingContext())\n {\n return false;\n }\n\n const canvas = settings.ADAPTER.createCanvas();\n let gl = (\n canvas.getContext('webgl', contextOptions)\n || canvas.getContext('experimental-webgl', contextOptions)\n ) as WebGLRenderingContext | null;\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\n return supported;\n}\n"],"names":[],"mappings":";;AAEA,IAAI;AAQG,SAAS,mBAChB;AACI,SAAI,OAAO,YAAc,QAErB,YAAa,WACb;AACI,UAAM,iBAAiB;AAAA,MACnB,SAAS;AAAA,MACT,8BAA8B,SAAS;AAAA,IAAA;AAI3C,QAAA;AACQ,UAAA,CAAC,SAAS,QAAQ,yBAAyB;AAEpC,eAAA;AAGL,YAAA,SAAS,SAAS,QAAQ,aAAa;AACzC,UAAA,KACA,OAAO,WAAW,SAAS,cAAc,KACtC,OAAO,WAAW,sBAAsB,cAAc;AAG7D,YAAM,UAAU,CAAC,CAAC,IAAI,wBAAwB;AAE9C,UAAI,IACJ;AACU,cAAA,cAAc,GAAG,aAAa,oBAAoB;AAEpD,uBAEA,YAAY;MAEpB;AAEA,aAAA,KAAK,MAEE;AAAA,IAAA,QAGX;AACW,aAAA;AAAA,IACX;AAAA,EAAA,EAID,IAAA;AACX;"}