Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebGL not working in PhoneGap Android KitKat

I'm trying to render some WebGL in my PhoneGap/Cordova app but I'm having no luck.

var canvas = document.createElement('canvas');
var gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
if (!gl) {
    console.log('WebGL not supported');
} 

The gl variable is always null.

I've tried with a OnePlus One and a Nexus 5 which are both Android KitKat v4.4.4 Chrome 38.

The same code works fine on iOS8 and on a desktop.

The code works on a normal webpage loaded in chrome on those devices. So does http://get.webgl.org/

I've even tried using CCA which uses crosswalk to bundle Chrome into the app.

I've tried Googling bug I'm flooded with people having problems from when devices didnt support it (iOS < v8 and Android < v4.4).

I'm thinking that it might be something that I have to enable in the build chain.

Thank you in advance.

Glen

like image 959
Garrows Avatar asked Nov 07 '14 01:11

Garrows


1 Answers

I've figured it out with some help.

Even though I have Chrome 38 installed, the WebView is actually not using the installed chrome version but another version that ships with the OS and doesn't auto update.

The WebView is actually Chrome 33 which doesn't support WebGL.

When Android L comes out, it will support WebGL in the WebView which will automatically update too.

In regards to the CCA version, it bundles Chrome 37 which supports WebGL. It works on devices that don't have blacklisted GPUs. If you follow these instructions it tells you that you can make it ignore the blacklist and run on all devices but might have unstable results.

like image 55
Garrows Avatar answered Sep 21 '22 00:09

Garrows