A Quicksilver Chanukah, Day 8: Rust Gamedev and the Web

29 Dec 2019

This year has been great for Rust gamedev on the web. Huge progress has been made towards a full game stack being available more-or-less “for free:” most of the foundational crates have available web support, in one way or another.

Windowing and Input

For opening a window and receiving events from it, the Rust ecosystem has winit. Along with Héctor Ramón (hecrj) and and Ben Merritt (blm768), I worked on adding web support. It has been merged and released, and is used in coffee and blinds. While using winit directly does require some glue code to plug your canvas into the webpage, intermediate layers like game frameworks can take care of the details.

While winit doesn’t currently provide gamepad events, gilrs fills that gap nicely. In the beginning of the year I added web support via stdweb, which should translate to wasm-bindgen when necessary. Unlike winit, which requires a little glue code to connect to your webpage, gilrs Just Works. It functions nearly the same as the desktop version, with the only limitations being those the web platform imposes.

Graphics

When it comes to graphics on the web, there are two APIs to keep in mind. One is WebGL, which is the current way of writing graphics code for the web. The other is WebGPU, an evolving standard based on newer, more modern APIs that will be the way forward. Currently WebGPU is just in the draft phase, so we can’t target it just yet. Targeting WebGL directly is an option, but it seems like a waste to write OpenGL code for desktop and then again for web. Enter glow, which brings a unified API across destop and WebGL.

Built on top of glow is gfx-backend-gl, which brings gfx-hal to desktop GL and web. By extension comes wgpu, an idiomatic Rust implementation of the upcoming WebGPU specification. It uses WebGL for now, but when WebGPU is stabilization and available, we’ll have a modern graphics API that works seamlessly across desktop and web.

Audio

The audio story for Rust on the web is not there yet, unfortunately. cpal, a cross-platform library for Rust audio, doesn’t have web support yet. However, there is hope! Mozilla announced a grant to Nannou that includes web support in cpal as a core goal. The relevant issue is cpal #212, which will hopefully yield some information early next year.

That’s it for my updates! This was a good year for Rust on the web, and laid the groundwork for the changes I’ve talked about in Quicksilver. I’ll be back in the new year with a State of Quicksilver 2020, which should come along with an alpha release of the new Quicksilver version.

If you’re interested in updates from other places in the Rust ecosystem, check out the State of GGEZ 2020 and the Rust Gamedev Working Group’s newsletters. See you in the new year!

  1. The introduction post
  2. platter: An async file-loading API for desktop and web
  3. gestalt: An API to manage bundling and saving data locally on desktop and web
  4. blinds: An easy-to-use async wrapper of winit
  5. golem: An opinionated mostly-safe graphics library for desktop and web GL
  6. Changes to the Quicksilver application lifecycle
  7. Changes to the Quicksilver graphics API
  8. This post!