WebGL around the net, 2 September 2010

Whoops, I’ve let a bit of a backlog of links build up — here’s the first batch.

Software rendering

A while back, Vladimir Vukićević updated the OSMESA32.dll build he’s created for people to use on Windows machines that use software rendering, so that it would work with recent builds of Firefox. I’d been intending to test it on my Intel-graphics machine for a while, but it was in storage and a pain to access… but the other day, Pranamya checked it out and was good enough to report that it worked, so good news — if you’ve been staying with an older version of Firefox so that you could use software rendering, you can now finally upgrade!

More API changes

Kevin Theisen, the creator of the WebGL chemistry tool ChemDoodle 3D, dropped me a line to highlight a change that has just hit WebKit and Chromium — they’ve moved entirely over to the new JavaScript Typed Array specification, so classes like WebGLFloatArray and WebGLUnsignedShortArray have been replaced by the new Float32Array and Uint16Array respectively. Yes, that’s right: WebGLFloatArray no longer exists.

This is a big change — I’ve fixed the tutorials on this site, and Kevin has (of course!) updated ChemDoodle, but it looks like almost every other WebGL demo out there needs updating :-( Luckily, it’s just a simple search and replace on the array types.

WebGL around the net, 10 August 2010

WebGL around the net, 7 August 2010

Just one link for today:

WebGL around the net, 6 August 2010

Some great links for today!

Retrospective changes to the lessons for the spec update

I’ve updated my tutorials to reflect the WebGL spec changes; they should now run just fine on the most recent versions of WebKit, Chromium, and Minefield, with shader validation switched on. I’ll be updating the lesson text later on this evening.[UPDATE the lessons are all now updated.]

If you’ve still to update your own WebGL pages to match the spec, here are the precise changes I made — they might make things easier for you.

At the start of every fragment shader, I put this:

  #ifdef GL_ES
  precision highp float;
  #endif

This is because all fragment shaders now need a qualifier to say what kind of floating-point precision they use; precision highp float gives you (as you’d expect) the highest precision. The #ifdef around it is a bit of guard code to stop this bit of code being executed in older browsers that don’t support this bit of the spec yet.

The other change I had to make was to update the way I called texImage2D. I used to do this:

    gl.texImage2D(gl.TEXTURE_2D, 0, texture.image, true);

This created a texture using the HTML image element bound to texture.image, with a mip level of 0. It also flipped the image around the X axis, which I find useful because it allows me to have texture coordinates that have Y axes that increase as you go up the screen, but to use texture images in formats like GIF, whose Y coordinates increase as you go down the image. This now requires two steps: firstly, I call gl.pixelStorei with appropriate parameters to say that all textures I use should be flipped around the X axis:

    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);

Then, when I want to create a texture, I call this:

    gl.texImage2D(
        gl.TEXTURE_2D, 0,
        gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE,
        texture.image
    );

The first two parameters are the same as before, and the last parameter is the same image as before. In the middle, we have a constant to tell WebGL that the image that we’re loading has red, green, blue and alpha components, another to say that we want to store it in the same way [UPDATE: in the comments, Benoit Jacob from the Mozilla team explains that these two must be the same value, and actually specify how the image is stored on the graphics card; so long as you're loading the image from an HTML element, WebGL knows already what format it's on], and a final one to say that each component is stored as an unsigned byte.

Those changes were all that were necessary to get everything working for me; let me know if you have any problems!

Shader validation and other API changes

There are some API changes coming in WebGL, which will probably require pretty much all of the WebGL content out there to be modified; the changes are likely to go live in Minefield in a week or two, so we need to get moving! Vladimir Vukićević and Benoit Jacob have given the details in two posts on the public WebGL mailing list. Here’s a summary:

  • Fragment shaders will now be validated to make sure that they are correct for WebGL / OpenGL ES; previously you could get away with using quite a lot of desktop OpenGL stuff, in particular missing out the mandatory precision specifier in fragment shaders (see the mailing list for details and a fix from Vladimir). In the short term, whether or not this validation happens will be optional, decided by the brower’s user, and off by default. However, it will become mandatory, so you should switch it on now to test your content. To switch it on:
    • In Minefield, go to about:config and change webgl.shader_validator to true.
    • In Chromium, pass --enable-glsl-translator in on the command line.
    • There are no details on how to do it in WebKit yet.
  • The gl.texImage2D function has changed its signature. Brandon Jones posted about this the other week, noting that Chromium warnsyou when you use the old form; both old and new forms of the function have been supported by the browsers for a while, but the old one will soon be gone.
  • As Andor Salga mentioned recently, gl.readPixels has also changed.

So, I’m going to go through all of my demos and tutorial code and change to the new APIs; if you have WebGL content live on the Web, you should too!

WebGL around the net, 28 July 2010

Quite a lot of links for today, some of them quite old — but now my backlog is cleared, and just in time: SIGGRAPH is running right now — Dennis Ippel and Benjamin Delillo, who often appear in these roundups, are there — so I’m sure we can expect a rush of further news over the next few days :-)

WebGL around the net, 21 July 2010

Subscribe to RSS Feed Follow me on Twitter!