I'm not sure why rust and webassembly are significant here. All the webgl commands still need to be javascript and the shaders still need to be glsl. Almost nothing in a demo like this needs to be done on the cpu.
- I see that I poorly communicated this in the title, but I was actually shooting less for "Rust/WASM makes this better!!" and more for "Hey, this is possible with pretty much just Rust/WASM!" I ended up hand writing about 10 lines of JS [1] in total
- More minor point - WebGL commands don't need to be called via JS [2] after anyref and host bindings land, and I think that it's important for people to know that it's possible to do things on the web without JS (whether that's a good idea is very situational)!
So yeah apologies if the title could be a bit better - but the main goal was to share with others that it's possible to build 3d experiences on the web with Rust today!
And - just to not come off wrong here - I'm not saying whether this is right or wrong and when to go this route. I am just interested in demonstrating how to do it :)
But all in all you're right - all of this same experience could totally be built with only JS if someone so desired!
Such a weird comment... all the webgl commands in the article are clearly written in Rust - `gl.bind_framebuffer(GL::FRAMEBUFFER, framebuffer.as_ref());` - and that's only possible because of WebAssembly. How are they not significant?
That said, it's unnecessarily dismissive. It's still a cool project! And a useful resource for anyone who does need to use Rust with WebGL for whatever reason.
Miiiiinor point/caveat here but jotting it down just for others that might be less familiar!
Today WebGL is commonly referred to as a JS API because pretty much every WebGL app is written using JS.
But, even though that MDN link quite literally says "JavaScript API", it turns out that WebGL is entirely specified in WebIDL and isn't coupled to JS.
Because of this, `wasm-bindgen` [1] is able to auto-generate all of the WebGL bindings [2] that I used for this demo.
Today `wasm-bindgen` automatically generates some JS shims because that's the only way to call the WebGL APIs at this time, but once anyref and host bindings land you'll be able to interface with the WebGL APIs directly without going through JS.
`wasm-bindgen` already plans to just replace those JS shims with direct host bindings.
But yup - totally agree with your points here - just sharing this minor detail that will be more relevant in the future!
Yup! I'm actually working on a project that needs to use WebGL but can't use JS bindings for a quirky reason. So I'm actually super glad you posted this — it's a great resource. Thank you!
- I see that I poorly communicated this in the title, but I was actually shooting less for "Rust/WASM makes this better!!" and more for "Hey, this is possible with pretty much just Rust/WASM!" I ended up hand writing about 10 lines of JS [1] in total
- More minor point - WebGL commands don't need to be called via JS [2] after anyref and host bindings land, and I think that it's important for people to know that it's possible to do things on the web without JS (whether that's a good idea is very situational)!
So yeah apologies if the title could be a bit better - but the main goal was to share with others that it's possible to build 3d experiences on the web with Rust today!
And - just to not come off wrong here - I'm not saying whether this is right or wrong and when to go this route. I am just interested in demonstrating how to do it :)
But all in all you're right - all of this same experience could totally be built with only JS if someone so desired!
[1] - https://github.com/chinedufn/webgl-water-tutorial/blob/maste...
[2] - https://github.com/WebAssembly/reference-types/blob/master/p...