Sunday, November 3, 2013

Using WebGL on Chrome (AKA: "Why don't I have the WebGLs?!?")

It occurred to me the other day that although WebGL is now available on more devices with Chrome than ever before, Google actually hasn't said a whole lot about who has it, how to get it, and what to look for if you don't have it. Today I'm going to try and fix that!

The TL;DR version is that with some predictable exceptions most devices that run Chrome can get to WebGL at this point, and an increasing number of them have it turned on without any action on the part of the user. If you don't have WebGL on your device of choice it's most likely because we've explicitly identified problems with your hardware or your device hasn't implemented the appropriate safeguards, but in most cases you can still turn it on manually if you really want to.



Do I have WebGL?

First off, if you're not sure if WebGL is working on your device of choice, just visit http://get.webgl.org/. See the spinning cube? You've got WebGL! Congratulations! Nothing more to see here. Go play with ShaderToy!

Should I have WebGL?

Okay, so you didn't get a spinning cube. The next step is to determine if you should have WebGL.

First off, is your device an iPhone, iPad, or iPod touch? If so, sorry but no WebGL for you. This is due to a well documented restriction on Apple's part that only allows one browser backend on the platform. Any browser other than Safari must use Apple's WebView component, which is a more limited version of the same code Safari uses. This means that until Apple either changes that policy or starts exposing WebGL to Safari on iOS there's no (easy or legitimate) way of getting WebGL on your iDevice. Sorry.

On just about anything else, first you need to make sure that you have the right version of Chrome. Go to chrome://version/ to see what the current version of your browser is. On the desktop you need to have at least version 9 or greater, but if you are still stuck on Chrome 8 at this point I think you have far bigger issues than WebGL support! You also need to be running a supported OS, which at this point includes:
  • Windows Vista/ Windows 7/ Windows 8 (Windows 7 or later recommended)
  • Mac OS 10.6 or later (10.8 or later recommended)
  • Linux
  • Chrome OS
(That list pulled from the helpful WebGL and 3D Chrome support page) Yes. XP is not on that list. Terribly sorry, but I'll personally vouch for the fact that Windows 7 is a worthwhile upgrade!

On Android it's a little more complicated. On Chrome 31 and up, WebGL is turned on by default if your device supports the GL_EXT_robustness extension. We require this extension on mobile devices because it means that the GPU is guaranteed to be well behaved in various aspects important for security and stability. Nobody wants their phone to crash because they clicked on a link, least of all the Chrome team! As such it's important that we can trust the devices graphics drivers before we let WebGL loose on your phone.

You can check to see if your device has it by looking at chrome://gpu/. Look for the GL_EXTENSIONS row in the table, which will list all of the OpenGL (not WebGL) extensions that your devices supports. If GL_EXT_robustness is in that list then you should have WebGL support, and there's probably something else blocking it if you don't. On Chrome 25 through 30 WebGL is available as well, but you have to turn it on manually, which we'll discuss in a moment. If you have a version of Chrome less than 25 on your Android device... go upgrade! It's free!

I still don't have the WebGLs!!! Why?!?

If you don't have WebGL but you do have a supported OS and Chrome version then you can figure out why you don't have it by visiting the aforementioned chrome://gpu/. Typically the reason why we haven't enabled WebGL is listed under the "Problems Detected" section. Probably two of the most common reasons are:
  • You device has been blacklisted. This means that we've determined that your device either can't run WebGL correctly or can't run it safely (or both!) and have disabled it to prevent it from causing you problems. In some cases upgrading your graphics drivers may fix the issue, but many times the hardware simply isn't up to the task and never will be.
  • Chrome's GPU process has crashed multiple times, which can indicate serious stability issues. In this case we prevent WebGL from running for the rest of the session. Simply restarting the browser might fix it, and upgrading your graphics drivers is worth a try if the problem persists.
As a general rule we try to turn on WebGL anywhere that we know it's safe to use. If we've blacklisted a device, it's because we know that there are serious issues with your GPU or driver, issues which could pose security or stability problems. Or, you know, maybe it just flat out doesn't work. Some GPUs just aren't up to the challenge. As such, we don't recommend overriding these policies. But, if you're aware of the risks and absolutely must see WebGL running on your device...

But I really really want it!
Okay, but be aware that we're now leaving the happy safe zone of "supported configurations".

On desktop devices (including Chrome OS) visit chrome://flags/ and look for "Override software rendering list" By enabling this, you instruct Chrome to ignore the blacklist and attempt to run no matter what. (You should also make sure that "Disable WebGL" isn't enabled, as that will block WebGL whether it's supported or not.)

On Android devices the same "Override software rendering list" flag also forces WebGL on when you are using Chrome 31 or above. If you are using Chrome 25-30, though, look for an "Enable WebGL" flag. Enabling that flag is the only way to get WebGL running in those version of Chrome for Android.

I don't trust da Google. How do I WebGL with my browser of choice?

Seeing as how I'm a software engineer on the Chrome team, I have a lot more insight into Chrome's inner workings than I do the other browsers. I recommend following the links on http://get.webgl.org/, as it will generally point you in the right direction for your browser. I will say, however, that Firefox has a pretty great WebGL implementation, and Opera is now using the same rendering engine as Chrome so they inherit a lot of Chrome's WebGL goodness.