Enable WebGL Support For Google Chrome In Linux

One of the hot new Web technologies is HTML5.  With it, websites can be more complex, offering better user interaction and content, as well as making for better web apps.  One of the graphic components available in HTML5 is something known as WebGL.  Spearheaded by Google, among others, WebGL offers incredibly high-quality graphics, right inside your web browser.  To see what WebGL and HTML5 are capable of, head over to Chrome Experiments for some amazing examples.

Chrome_Experiments_Website

Of course, if you’re using Linux as your operating system, and Google Chrome as your web browser (despite its name, Chrome Experiments is open to Firefox users as well), then you may run into problems.  This is because Google Chrome (the Linux version), comes with WebGL support turned off by default.  So, instead of seeing the following example of WebGL being used to create an air hockey game:

Working_WebGL

You’ll see information telling you that it won’t work in your browser.

WebGL_Not_Working

Not every experiment on the Chrome Experiment page needs WebGL, so some will work fine, while others will not.  This means that visiting a random experiment doesn’t truly show your browser’s WebGL capabilities, so head over to this website to make sure.

If your browser is not capable of WebGL, you’ll receive this notice.

WebGL_Not_Supported

If your browser is capable, then you should receive this message.

WebGL_Supported

If you’re using Google Chrome in Linux, and you haven’t made any changes to its launchers or flags, then you saw the first message.  At the end of this article, assuming your computer is WebGL-capable, then you’ll see the second.

The first step in enabling WebGL in Google Chrome is changing the command used to launch it.  From the Terminal, as root, open up the google-chrome.desktop file (found in /opt/google/chrome/ if installed manually) in a text editor.  In Ubuntu, using the nano Terminal-based text editor, the command would be:

sudo nano /opt/google/chrome/google-chrome.desktop

Now, scroll down until you see the following line:

Exec=/opt/google/chrome/google-chrome %U

It will look like this in nano:

Unchanged_Launch_Command

Because WebGL support isn’t a given in Linux, Google has – by default – placed Linux on its GPU blacklist, so WebGL is turned off.  By modifying the command used to launch Google Chrome, we can tell it to ignore this blocklist.  Adding the “–ignore-gpu-blocklist” option to the command shown above (without the quotes), will do the trick.  After editing, the command will look like this:

Exec=/opt/google/chrome/google-chrome –ignore-gpu-blocklist %U

It will look like this if editing via a Terminal text editor:

Modified_Launch_Command

Simply save your changes and the launcher is ready to go.

Note: if you’ve dragged launchers to your Desktop for faster launching, those will need to be changed as well.

Now that we’ve made this change, there’s just one more place we need to visit.  So open up Google Chrome, using your newly-edited launcher, and type chrome://flags into the URL bar.  The following page should appear.

Google_Chrome_Flags_Page

Here is where you’ll find experimental features (you’re warned that these experiments may break or disappear at any time).  If you scroll down a bit, there are two that we need to turn on.  In the following screenshot, they are highlighted in white.

Edit_Two_Flags

The two features we want to activate are called “GPU compositing on all pages” and “GPU Accelerated Canvas 2D.”  To activate them, simply click the little blue link below their description.  The background of that feature will turn white (as shown above), and you’ll need to restart your browser.

One interesting option is the entry called WebGL (just above the GPU Accelerated Canvas 2D entry).  As unintuitive as it is, this entry turns off WebGL support, so we need to ensure that the entry labeled WebGL is disabled, in order to enable WebGL support.  Odd, but true.

Okay, once you’ve edited your launcher and switched the two flags mentioned above, you’re all set.  Restart your browser.  As a quick test, head over to either the Chrome Extensions page and try out an experiment that didn’t work for you, or the Does My Browser Support WebGL page.  Your experiment should work, and if everything is set up correctly (and your computer’s GPU is capable of WebGL, then you should be able to play around with Chrome Experiments like this.

Glass_Shader_Working

Again, no matter what tweaking we may do, your computer may just not be powerful enough for full WebGL support.  Your GPU may not be powerful enough (or new enough), and your graphics stack might not be up-to-date (Mesa 6.9 or newer is required).  If that’s the case, an upgrade will be necessary.  But for those of us with powerful enough computers, this should do the trick.

Leave a Reply