[ocaml-opengl] WebGL (was: LablGL's Raw module)

David Sheets kosmo.zb at gmail.com
Wed Mar 13 22:15:45 GMT 2013


On Wed, Mar 13, 2013 at 1:30 PM, Anthony Tavener
<anthony.tavener at gmail.com> wrote:
> Ah, yes, I did run into mention of David Sheets' work and got stuck at the
> Ashima site with a cute looking game, but I was looking for implementation
> details at the time. ;) Thanks for those links Anil!

Ooman <http://www.ashimagroup.net/demo/game/ooman/tutorial/> is
written in OCamljs 3.12 (Jake Donham's dlambda backend) and then run
through Google's Closure Compiler. There are no OCaml WebGL bindings
in use. Instead, a WebGL driver in JavaScript was written to provide
specifically and efficiently the graphics primitives the game
required.

I would really, really love to see a WebIDL
<http://www.w3.org/TR/WebIDL/> parser with an OCaml code generator.
Perhaps BER N100 MetaOCaml is suited to this task?

I began modeling the WebIDL type system last fall but put that work
aside for a number of technical and non-technical reasons. I think
that we should strive to construct libraries against WebIDL interfaces
in the future to allow for broadest portability. Specifically, as
WebGL is a C -> JS port of OpenGL ES 2.0, there is a subset of WebGL's
WebIDL <https://www.khronos.org/registry/webgl/specs/latest/webgl.idl>
that can be mapped back onto native OpenGL ES 2.0 implementations. In
this way, we may generate OCaml interfaces from the WebGL IDL which
can be instantiated by either browser or native API modules.

You may also be interested in WebGL and OpenGL ES 2.0 modules. In this
case, I invite you to examine
<https://www.khronos.org/registry/webgl/extensions/> at which the
WebIDL for each WebGL extension is available. I authored and now
maintain the specification processing toolchain that produces these
HTML specs from an ad hoc XML vocabulary. For the extensions that
expose GLSL modules (e.g.
<https://www.khronos.org/registry/webgl/extensions/OES_standard_derivatives/>),
the GLSL module signatures are declared in the XML specs.

> I never did get into browser-based applications, but that's the new way now
> and that does seem pretty cool to be able to program OCaml through your
> browser with no installation steps and even leverage WebGL! It sounds
> easy enough that I might try jumping in. Although... one thing about GLES2
> is that it takes a bit of groundwork to be able to use it (being a thinner
> layer between the hardware). Does WebGL add a bunch of convenience
> functions, or does Sheets?

WebGL strives to be an almost direct port of OpenGL ES 2.0. For some
JavaScript convenience functions, you might try
<https://github.com/ashima/webgl-engine/> which is the lowest layer of
the driver upon which Ooman is constructed. Of course, many JS
frameworks exist if you'd like to get loads of convenience functions
but they always some difficult issues, it seems.

> Or is there a lot of copy/paste into TryOCaml
> to get something visible?

Right now, yes, setting up a graphical top-level in TryOCaml is a
pain. It would be a very interesting and worthwhile project, though,
imho.

I have been focusing most closely on the shading language semantics
and tooling as it has the broadest audience. Of course, I will
continue to work on related OCaml+WebGL work.

"Semanticists should be the obstetricians of programming languages,
not the coroners." – John Reynolds, 2 December 2004

I'm happy to chat about any of these topics or others that you're
interested in. I have a lot of project ideas and ideas for hyperlinked
graphics systems.

David

> Buffer abstraction... I use Bigarray a lot. Strings-as-data only if I don't
> care
> about what the data is -- treating it like a binary blob. Because strings
> are
> quite limited, and I think I tend to use them immutably.
>
>
>
> On Wed, Mar 13, 2013 at 1:51 PM, Anil Madhavapeddy <anil at recoil.org> wrote:
>>
>> On 13 Mar 2013, at 19:41, Anthony Tavener <anthony.tavener at gmail.com>
>> wrote:
>> >
>> > In response to this mailing-list starting, and apparent interest in
>> > OpenGL
>> > with OCaml, I looked into the current state of things yesterday. Not
>> > much
>> > has changed... except you (Florent) have gotten a patch into LablGL for
>> > shader support -- hooray! And I also found someone else has added
>> > changes to glcaml/sdlcaml and posted them here:
>>
>> My interest in OpenGL has also been renewed by js_of_ocaml and WebGL...
>> David Sheets did a great presentation on his work on WebGL at the last
>> OCaml workshop: http://www.youtube.com/watch?v=ll9z1ULtgqo
>>
>> ...and there's lots of WebGL/OCaml code up at:
>> https://github.com/ashima/
>> (last I looked, it uses ocamljs and not js_of_ocaml yet, though).
>>
>> I have in my head an awesome demo that involves the TryOCaml js toplevel,
>> and a WebGL window that responds in realtime :-)
>>
>> I'm not really sure what the right buffer abstraction is that will work
>> with js_of_ocaml and OpenGL too. js_of_ocaml has some trickery to cast
>> strings as either immutable (i.e. native Javascript) and mutable (i.e.
>> native OCaml).  This doesn't work in native code, and Bigarrays are
>> much more explicit and flexible since they wrap system memory that is
>> outside the OCaml heap.
>>
>> Anyway, lots to play with here...
>>
>> -anil
>
>


More information about the OpenGL mailing list