An updated version of the prototype Canvas 3D extension is finally available, with a good number of improvements. Many of these came from Ilmari Heikkinen, who's done some great work in fixing bugs and plugging holes/errors in the implementation. Also, with this release, support for the OpenGL ES 1.1-based context has been dropped, in order to focus on the more forward-looking ES 2.0-based work. You can download the new release (0.4.2) here.
There are a few changes in this version from the API mapping and description I posted earlier. One of the things I mentioned in that original post was changing some functions to try to make them more palatable to JS. However, no matter how much you munge the GL API, it's still a low-level API. So, with this version, a bunch of helpers went away, such as uniformf, uniformi, uniformMatrix, and vertexAttrib. They added significant complexity on the native side, and just confused matters for those who are already familiar with the OpenGL family of APIs. Instead of those helpers, the GL-like uniform[1234][if][v] and similar should be used. This doesn't prevent a convenience wrapper from being made, but it should be done on the JS side, not hardcoded into the native implementation. Additionally, some arguments to functions such as vertexAttribPointer were originally omitted; those are back, and follow the GL prototype. There are, however, still some changes, particularly in getter functions — the full mapping list is available on the API mapping page.
This release of the extension also adds support for software rendering, using the Mesa GL library. Software rendering shims are included for all 3 platforms, though only for the 32-bit Intel variants (which is why the extension download is bigger than previous versions). Software rendering should be used automatically if hardware rendering can't be (due to lack of OpenGL or lack of specific extensions), but you can also set the extensions.canvas3d.software_render pref to true in about:config to force it. Also, if the version of OSMesa included isn't being found, or if you'd like to try a different OSMesa renderer, extensions.canvas3d.osmesalib can be set to the full path of the library to load. Note that the functions are assumed to be prefixed with "mgl" as opposed to "gl" when loading this library.
I also went ahead and ported most of the native code examples from the OpenGL ES 2.0 Programming Guide. These are really API examples, and are not intended to demonstrate what can be done with OpenGL support in the browser. You can view them here:
- Chapter 2, Hello Triangle
- Chapter 8, Simple Vertex Shader
- Chapter 9, Simple 2D Texture
- Chapter 9, Simple Cubemap Texture
- Chapter 10, Multitexturing
As the examples progress, they build up common functionality and move them into helper js libraries; if those are useful, feel free to use them in your own experiments. A list of more interesting demos will be coming as soon as I compile one.
Along with this release, I've set up a Canvas 3D group at Google Groups, as the old labs forums are going away shortly. Please use the forums there for reporting problems (soon to be Bugzilla, but it's not quite set up yet). I'd like to hear any feedback, or find out about any demos/experiments that may be using Canvas 3D!
Note: I've identified a problem with 0.4.1 that will cause crashes on Windows systems when software rendering is used (either selected or forced). An updated 0.4.2 with a fix for this problem will be available soon.
Note: 0.4.2 is available at the link above; it fixes the Windows crash and a number of other software rendering problems on other platforms.
I get the following inthe error console on running the examples with the plugin on Firefox 3.1beta3 on linux:
Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://people.mozilla.com/~vladimir/canvas3d/examples/gles2book/ch2-hello-triangle.html :: init :: line 55" data: no]
The same error for all examples.
There seems to be a problem with the official builds of 3.1b3 and this; until I track it down, grabbing the latest nightly build should work. They’re available at http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-mozilla-1.9.1/ . Working to figure out what’s going on with the release builds now…
Works great on the latest nightly. Now I only need to brush up on my OGL… it’s been a while.
One thing that I noticed is that the constants are not listed on the interface page, so you have to view the XPT inside the XPI if you get random illegal value errors. The constants are listed in the bottom 20%.
Why do you tied it to OpenGL instead of abstracting it away from any particular 3D api? The fact is that around 50% of the desktop computers in the world does not OpenGL drivers installed that support acceleration (and Windows install with MS drivers, linux, …). By tying it to OpenGL, you make it harder to implement support for a DirectX backend.
Golem.de has posted a short news item:
http://www.golem.de/0903/66197.html
It’s quite short, but from what I see it looks like quite a good summary.
Rough translation:
“Canvas 3D – 3D extension for Firefox updated
OpenGL ES 2.0 code samples run in browser
Mozilla developer Vladimir Vukicevic has published a new version of his experimental Firefox extension Canvas 3D. The 3D interface for browsers can be used via OpenGL ES 2.0.
Canas 3D version 0.4.1 offers several minor enhancements and bugfixes, many of which were developed by Ilmari Heikkinen. The support for OpenGL ES 1.1 on the other hand was dropped, as it increased the complexity of the implementation considerably.
The API was also stripped of some helper functions. They would have added unnecessary complexity and confused people for are familiar with the OpenGL-API, explains Vukicevic.
New in version 0.4.1 is support for software rendering, which is offerered by the Mesa-GL library. It can be used on all three supported Intel 32 bit platforms – Windows, Linux and MacOS X. Software rendering is used automatically when no hardware rendering is available.
Vukicevic has also ported some of the native code sameples from “OpenGL ES 2.0 Programming Guide” to Canvas 3D. Future development of the 3D interface for browsers will take place at Khronos-Group.”
Has there been any thoughts to making a DOM representation to manipulate an open gl scene graph. And then using CSS to style it? I would so much love to use Jquery to manipulate opengl just like I can with regular html docs.
Petter — it’s very very good that vladimir has NOT abstracted the OpenGL API. OpenGL and D3D are both effective and evolved low-level 3D APIs, so it makes sense to implement one or the other. It makes less sense to design a third API that nobody is familiar with.
Steve — a scene graph could be implemented in JS on top of an immediate-mode API. Personally I don’t think scene graphs are very fun to use for 3D so I’m glad to see a real immediate-mode API.