Amazing. Thanks so much. One last thing, not a bug this time I promise, a suggestion. I was updating my graphics driver the other day and once it installed it messed around with already open Chrome and long and the short I notice that the default behaviour for your library if it cannot get a WebGL context is to blast you with an alert saying you don’t have WebGL which then takes you to the get WebGL website.
A lot of the time this is desirable behaviour but not always. For example WebGL might only be a section of the page and the other stuff is still useful even if the WebGL isn’t working in which case it’s pretty annoying if you keep getting redirected whenever you tried to load it up. Also redirecting with alerts like that can screw up the back button on some browsers I think (because you can’t go back twice since you keep getting redirected). So perhaps A) include a function to test if WebGL is supported (also turns out you can test whether it is the browser not supporting WebGL or the hardware) and B) make the popup behaviour default but optional for the developer?
Anyway here is a quick function I wrote to test for WebGL support:
/**
* Returns null is WebGL is supported otherwise a String giving the reason why not.
*/
private static native String isWebGLSupported() /*-{
var canvas = $doc.createElement("canvas");
var gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
if(gl && gl instanceof $wnd.WebGLRenderingContext) {
return null;
} else {
if($wnd.WebGLRenderingContext ) {
return "Hardware does not support WebGL";
} else {
return "Browser does not support WebGL";
}
}
}-*/;
I think there are a few reasons you might not be able to create a WebGL context if the browser supports it but I’m pretty sure I’m getting this from the WebGL spec on MDN so seems fairly legit. Also not 100% on the creating an offscreen canvas and canvas just to test for support but this is apparently the established method according to MDN again. Also if you incorporate this into the actual context creation then it’s a non-problem.
Obviously just my penny’s worth but what do you think?