Some issues with Apples iOS WebGL implementation

Jun. 08, 2014
comments

Now that Apple has released iOS 8 beta, I had a look at their WebGL implementation in mobile safari. I think it's great that WebGL is finally coming to iOS.

However I could not help to notice some shortcomings of their implementation, and I'd like to expand upon those in this post.

Contents

Update: iOS 8 Beta 3

Most of the closed tickets for extensions are now merged into that beta. Still outstanding are the same ones that aren't implemented since Beta 2 (see below.

Update: iOS 8 Beta 2

iOS 8 Beta 2 did not improve the current WebGL implementation over iOS 8 Beta 1. I assume the changes in webkit have yet to be merged.

Webkit has also yet to implement these tickets:

WebGL capabilities

In hardware accelerated realtime graphics it is important to get as close to the machine as possible. Apple certainly understands that with the release of Metal.

This is also true in WebGL, where differing hardware characteristics such as numbers of textures that can be used, the amount of uniforms or the support for some extended functionality and so forth is exposed to the application programmer.

You can learn more about the ways in which WebGL implementations may differ at the links below.

Hardcoded constraints on iOS

Apples iOS WebGL implementation has some fixed parameters, disregarding the actual device capabilities. The table below lists these parameters both as they appear natively and as they appear to WebGL, discrepancies are highlighted red.

iPod touch 5th geniPad mini retina
CapabilityNativeWebGLNativeWebGL
MAX_COMBINED_TEXTURE _IMAGE_UNITS 8 8 32 8
MAX_TEXTURE _IMAGE_UNITS 8 8 16 8
MAX_VERTEX_TEXTURE _IMAGE_UNITS 8 8 16 8
MAX_FRAGMENT _UNIFORM_VECTORS 64 64 224 64
MAX_VERTEX _UNIFORM_VECTORS 128 128 512 128
MAX_VARYING_VECTORS 8 8 15 8

As you can see, an iPad mini retina is treated to the same constraints as an iPod touch 5th gen. Even though in reality the iPad mini retina has vastly expanded capabilities.

Ticket 133745

Missing Extensions

Present on Android/Nexus4

The following extensions are present on a Nexus4 and on the iOS devices natively, but not in WebGL.

both iPod and iPadNexus 4
ExtensionTicketNativeWebGLWebGL
OES_texture_float 133627 yes no yes
OES_texture_half_float 133628 yes no yes
OES_vertex_array_object 133629 yes no yes
OES_texture_half_float_linear 133630 yes no yes

Present natively but missing in WebGL

The extensions below are supported natively (either as ES 2.0 extension or as ES 3.0 core functionality), but they are missing from WebGL.

both iPod and iPad
ExtensionTicketNativeWebGL
OES_texture_float_linear 133631 yes no
WEBGL_color_buffer_float 133632 yes no
EXT_color_buffer_half_float 133639 yes no
EXT_blend_minmax 128974 yes no
EXT_shader_texture_lod 133633 yes no

The following extensions are supported by the iPad mini retina natively, but not in WebGL.

iPad mini retina
ExtensionTicketNativeWebGL
WEBGL_draw_buffers 133634 yes no
EXT_frag_depth 133635 yes no
EXT_sRGB 109332 yes no

Bugs

  • Running the WebGL conformance test crashed the mobile safari tab after about a dozen test suites.
  • Update: This has been fixed with ticket 133388. The argument to canvas.getContext of "preserveDrawingBuffer:false" is only honored for the color buffer, but not for the depth buffer (you have to manually clear it).