Skip to content

Instantly share code, notes, and snippets.

@SeanZoR
Created August 20, 2015 12:48
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save SeanZoR/cfa7a6206983b775a858 to your computer and use it in GitHub Desktop.
Save SeanZoR/cfa7a6206983b775a858 to your computer and use it in GitHub Desktop.
Detect WebGL with JS in browser
/**
* 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;
};
@hiepxanh
Copy link

nice, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment