-
-
Save vip3r011/8f3c21e6c56497447650d6e3e6718676 to your computer and use it in GitHub Desktop.
Detect WebGL with JS in browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Detects if WebGL is enabled. | |
* Inspired from http://www.browserleaks.com/webgl#howto-detect-webgl | |
* | |
* @return { number } -1 for not Supported, | |
* 0 for disabled | |
* 1 for enabled | |
*/ | |
function detectWebGL() | |
{ | |
// Check for the WebGL rendering context | |
if ( !! window.WebGLRenderingContext) { | |
var canvas = document.createElement("canvas"), | |
names = ["webgl", "experimental-webgl", "moz-webgl", "webkit-3d"], | |
context = false; | |
for (var i in names) { | |
try { | |
context = canvas.getContext(names[i]); | |
if (context && typeof context.getParameter === "function") { | |
// WebGL is enabled. | |
return 1; | |
} | |
} catch (e) {} | |
} | |
// WebGL is supported, but disabled. | |
return 0; | |
} | |
// WebGL not supported. | |
return -1; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment