Retrospective changes to the lessons, part 94

WebGL is increasingly being supported on mobile devices. Firefox on my Android phone (a Samsung Galaxy S II) quite happily displays all of my tutorials, and many other WebGL sites as well. But not all mobile devices are equal; some quite popular ones apparently don’t support highp precision in fragment shaders.

The WebGL spec says that all implementations must support at least mediump, so it looks like that’s the most sensible precision to use as a default for most WebGL sites. I’ve changed the lessons here so that they use it. I also took the opportunity to get rid of some compatibility cruft that dated from the early days of WebGL: the #ifdef GL_ES that surrounded the precision qualifiers.

If you’ve got some WebGL demos out there, I strongly recommend you do likewise!

Many thanks to Ken Russell and Cedric Vivier for the heads-up about this.

[UPDATE: Cedric tweets that the precision operators have no effect on desktop machines right now anyway, so it sounds like there really is no downside to making this change.]

You can leave a response, or trackback from your own site.

6 Responses to “Retrospective changes to the lessons, part 94”

  1. Kevin Reid says:

    Could you explain what the motivation for the #ifdef was? I assume that the “precision” declaration is not part of non-ES GLSL and that is why one would write it at all, but what was the reason for using it in a WebGL application?

  2. giles says:

    Sure! At one stage, right in the early days of WebGL, the shaders were just dumped on the machine’s desktop OpenGL driver. This was a problem for all kinds of reasons (security not least among them), but one of the problems was that most desktop GL drivers would barf on the precision statement (which, as you say, is an OpenGL ES thing). After a while, browser implementations were updated to parse the GLSL using OpenGL ES syntax (with, for example, ANGLE on Windows). But for quite a while, there were browsers out there using both the old and the new systems — so you could never be sure whether the precision statement would be essential (for “proper” WebGL) or erroneous (for older browsers). The #ifdef was a workaround so that people could write one shader that would work on both.

  3. Benoit Jacob says:

    You don’t even need any precision qualifier, do you? Why not just use the defaults?

  4. giles says:

    You do for floating points in fragment shaders — there’s no default.

  5. jd says:

    Will the upcoming FireFox for Kindle Fire support WebGL?

  6. [...] 原文作者Giles在不久前更新了教程,我们的中文版本也作出了相应的修改,这次更新涉及全部16课的课程。下面是这次更新的change log。 [...]

Leave a Reply

Subscribe to RSS Feed Follow Learning WebGL on Twitter