- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
import { settings } from '../settings';
let supported: boolean | undefined;
/**
* Helper for checking for WebGL support.
* @memberof PIXI.utils
* @function isWebGLSupported
* @returns {boolean} Is WebGL supported.
*/
export function isWebGLSupported(): boolean
{
if (typeof supported === 'undefined')
{
supported = (function supported(): boolean
{
const contextOptions = {
stencil: true,
failIfMajorPerformanceCaveat: settings.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT,
};
try
{
if (!settings.ADAPTER.getWebGLRenderingContext())
{
return false;
}
const canvas = settings.ADAPTER.createCanvas();
let gl = (
canvas.getContext('webgl', contextOptions)
|| canvas.getContext('experimental-webgl', contextOptions)
) as WebGLRenderingContext;
const success = !!(gl && 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 supported;
}