Categories
Code Snippets WebGL

WebGL on the iPad

I recently wanted to access some WebGL based web-sites from my iPad and quickly discovered that WebGL is currently NOT supported, or at least not enabled, in the iPad’s version of Safari.

However, Nathan de Vries discovered that the UIWebView class does seem to have in-built support for WebGL. Read all the details at

http://atnan.com/blog/2011/11/03/enabling-and-using-webgl-on-ios/

This work evolved into GoWebGL, which  is an example of how a simple WebGL supported browser can be written for iOS5 devices

https://github.com/gauthiier/GoWebGL

In the example app, simple gestures and inputs are provided allowing a user to enter a required URL in a text edit box launched using a two finger double-tap, to browse forward by a swipe left or browse backwards with a swipe right.

Support for WebGL in UIWebView is enabled as shown in the following code extract

//-> init + setup UIWebView (from Nathan)
    UIWebView* webView = [[[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    id webDocumentView = [webView performSelector:@selector(_browserView)];
    id backingWebView = [webDocumentView performSelector:@selector(webView)];
    [backingWebView _setWebGLEnabled:YES]; //<-- !!!

Because this is an undocumented feature, using it is unlikely to be approved by Apple. It does enable me, however, to explore and research the potential for using WebGL applications on the iPad. In the future, I have no doubt that Apple will provide official support for using WebGL on the iPad.