

WebGL in Firefox Nightly Builds - e1ven
http://blog.vlad1.com/2009/09/18/webgl-in-firefox-nightly-builds/

======
mr_luc
I'm interested in why it's not working on for me.

I'll edit this to update on problems as they come. For people trying to run
the existing webgl samples (using something like utils3d.js) that are out
there with the nightly ff build:

    
    
      1) canvasElement.getContext("moz-webgl"), not "webkitwhatever"
    

(Conflicts w/presentation slides pdf on the khronos site, which says "3D" with
a capital D)

    
    
      2) context.clearDepth(...) -> .clearDepthf(...)
      3) CanvasFloatArray        -> WebGLFloatArray
    

That's how far I've gotten so far. Much more perplexing to me is a case where
their code seems (I want to stress, _seems!_ ; maybe it's staring me in the
face and I just don't get how they changed it) to break an opengl function:
glBindBuffer. <http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml>

The specs say, call glBindBuffer with (arg, arg2), and arg2 will be an
unsigned int which refers to a buffer.

The reference above says, calling it with an arg2 of 0 and it'll reset. The
webkit examples use it this way. But, their implementation of the wrapped
BindBuffer method doesn't like this; if you pass in 0, it gives you an error
that suggests you mean null. Pass in null, and there's an uncaught exception
and an error in glBufferData, telling you that, surprise, you want an Unsigned
Short.

In their code,

    
    
      NS_IMETHODIMP
      WebGLContext::BindBuffer(GLenum target, nsIWebGLBuffer *buffer)
      {
        WebGLBuffer *wbuf = static_cast<WebGLBuffer*>(buffer);
        ...
    

The typing of the args won't let you pass in a zero, and the typing on the
constructor for the cast is what kills it if you pass in a javascript null (it
wants an integer).

And if you try to instantiate a WebGLBuffer instance with javascript -- whose
constructor _expects_ an int -- it won't let you.

    
    
      nbuf = new WebGLBuffer(0);
      -> [Exception... "Cannot convert WrappedNative to function"...
    

You could try calling glGet... on the buffer early on, caching the default
value it returns to you and then using that to invoke bindBuffer (just to be
sure you're not calling it with something it shouldn't understand) but this
doesn't wrap opengl directly enough; it's just whatever you see implemented
here ([http://mxr.mozilla.org/mozilla-
central/source/content/canvas...](http://mxr.mozilla.org/mozilla-
central/source/content/canvas/src/WebGLContextGL.cpp)). Some functions, like
bindbuffer, are implemented. The others are named very differently, and look
like this:

    
    
      NS_IMETHODIMP
      WebGLContext::GetCurrentArrayBufferBinding(nsIWebGLBuffer **aCurrentArrayBufferBinding)
      {
        return NS_ERROR_NOT_IMPLEMENTED;
      }
    

Heh. Well ... I guess I'll see if I can find an example that never needs to
reset the buffer binding. :P

------
oomkiller
This is great, a single standard being implemented in WebKit AND Firefox.
Someone will probably have to write a plugin for IE though, since it's HIGHLY
doubtful Microsoft would cooperate.

~~~
mcav
It's frustrating that this is the state we're in.

We've got just about everyone EXCEPT the major browser vendor working on cool,
useful, forward-thinking innovations, and standardizing on them with relative
ease. Yet all of this innovation is so sorely limited without Microsoft's
contribution (to IE).

Normally I just nod my head and move on, but the future doesn't look any
brighter for IE. Hopefully Microsoft's halfhearted interest in HTML5 will
improve.

But then again, MS could drop WebKit into IE9, and we'd _still_ be stuck,
unless Microsoft shoves IE9 down the Automatic Update pipeline as a required
update. Which they should, IMHO. Progress is worth some pain.

~~~
omouse
_We've got just about everyone EXCEPT the major browser vendor working on
cool, useful, forward-thinking innovations, and standardizing on them with
relative ease. Yet all of this innovation is so sorely limited without
Microsoft's contribution (to IE)._

Microsoft's ActiveX has been around for a long time. And I remember a little
something called VRML that was supported by the major browsers of the time.

~~~
mcav
I'm looking more for something community-or-compatibility driven. The web
community pushes for certain things; when everyone except IE gets on board,
Microsoft should strive to pursue those standards.

Poor word choice on my part: Microsoft has innovated before, yes. They're
innovating now in various spaces. But they're dragging their feet in areas
that could really boost the web as a platform, and that slows progress.

~~~
weaksauce
It scares them to have the web as a platform as it marginalizes two of it's
cash cows: Office and Windows.

Them not innovating is actually a smart business decision from their angle.

------
mr_luc
I just downloaded and installed the latest Minefield nightly. I enabled the
single webgl option in about:config.

Not a single one of the examples from <http://trac.webkit.org/changeset/48330>
are loading for me.

They all error with:

Error: uncaught exception: [Exception... "Component returned failure code:
0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOMHTMLCanvasElement.getContext]"
nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame ::
[http://trac.webkit.org/export/48330/trunk/WebCore/manual-
tes...](http://trac.webkit.org/export/48330/trunk/WebCore/manual-
tests/webgl/resources/utils3d.js) :: initWebGL :: line 19" data: no]

etc.

Anyone on here get it working?

~~~
gcb
the offending line is: var gl = canvas.getContext("webkit-3d");

I tried to change it to all the values I found on developer's blogs and even
in the Painting the Web Oreily book.

"3d", "-moz-webgl2.0", "webgl2.0", "webgl", "gl", "moz-gles11"

All got me the same NS_ERROR_ILLEGAL_VALUE

~~~
gcb
tried to grep the source. but all I could find was

// IID for the nsIRenderingContext interface

// 37762dd8-8df0-48cd-a5d6-24573ffdb5b6

#define NS_IRENDERING_CONTEXT_IID \

{ 0x37762dd8, 0x8df0, 0x48cd, \

    
    
      { 0xa5, 0xd6, 0x24, 0x57, 0x3f, 0xfd, 0xb5, 0xb6 } }
    
    

which does not mean anything to me.

other example, that also do not work with minefield: <http://www.c3dl.org/>

Official word: <https://wiki.mozilla.org/Canvas:3D>

~~~
mr_luc
Woot! Got Canvas3D to create a buffer! (I got distracted by NPR's telling of
the ADM price-fixing story, sorry).

Okay, the relevant/revelatory code can be seen at:

[http://mxr.mozilla.org/mozilla-
central/source/content/html/c...](http://mxr.mozilla.org/mozilla-
central/source/content/html/content/src/nsHTMLCanvasElement.cpp#441)

Here's the string being constructed in the getContext method, after some
checking:

    
    
      nsCString ctxString("@mozilla.org/content/canvas-rendering-context;1?id=");
      ctxString.Append(ctxId);
    

Where ctxId is, say, "2d".

I'd assume it's some kind of resource naming convention or somesuch ... but,
anyway, searching for strings "@mozilla.org/" and canvas and gl ...

You get nsLayoutModule.cpp

    
    
      ...
      { "Canvas WebGL Rendering Context",
        NS_CANVASRENDERINGCONTEXTWEBGL_CID,
        "@mozilla.org/content/canvas-rendering-context;1?id=moz-webgl",
        CreateCanvasRenderingContextWebGL },
      ...
    

bingo! "moz-webgl" WORKS.

The first example I tried fails:

    
    
      gl.clearDepth is not a function.
    

:(

But, anyway, it's a start.

~~~
mastersenbie
Try using "for in" to iterate through the returned canvas's properties. You'll
get all the methods of the canvas. So far this sort of stuff works (OSX
Leopard): gl.clearColor(0,0,0,0); gl.clear(gl.COLOR_BUFFER_BIT);

------
thristian
Interesting, but not much use until somebody writes some demo pages to show it
off.

~~~
mikedouglas
samples: <http://trac.webkit.org/changeset/48330>

video:
[http://www.youtube.com/watch?v=2rpKpj6ZO9w&hd=1](http://www.youtube.com/watch?v=2rpKpj6ZO9w&hd=1)

~~~
mr_luc
Does the FF nightly work for you? It doesn't for me at the moment, at least
not with those samples (link to my post below, in case this discussion gets
big: <http://news.ycombinator.com/item?id=831988>).

Any tips appreciated. I'll have a few hours free this afternoon, so I may muck
around with this!

