118 - Goodbye WebGL

May 09, 2021

This week I continued working on the runtime texture allocator.

I made more progress on the handling of texture groups problems that I mentioned in 117.

I've begun working on a couple of new renderer conformance tests to ensure that renderer implementations such as the MetalRenderer and the WebGpuRenderer can properly copy bytes between textures.

I also made the decision to drop support for WebGL and only support WebGPU for the web.

Moving Away from WebGL

Ever since I first heard of WebGPU a couple of years ago I became excited about the potential to one day stop using WebGL. My code base and this dev journal are littered with dozens of comments to the tune of "we have to do things in this unfortunate way because of WebGL".

I've had to just roll with that since there is no other graphics API for the web that is supported in the major browsers, and it seems like WebGPU won't be well supported until 2022 or 2023.

The straw that broke the camel's back was not being able to read directly from a texture or copy between textures in WebGL. I found out that you need to use framebuffers as intermediaries for reading and copying.

Granted, this pales in comparison to what I had to do to support tiling textures in 072, but for me this was the final straw.

Going forwards I will no longer support WebGL as a backend for the game's rendering.

Instead, I will use WebGPU on the web and just display a modal for now for users that don't have it enabled letting them know how they can enable it.

Over the next year or two that means that way fewer people will end up trying the game, but that's fine because in reality I have a year or two of work before the game is worth trying in the first place.

I'm excited about taking this step. There are a number of graphics features such as texture arrays that I haven't been using since they don't work in WebGL that I can now start to make use of.

I think that the engine has a bright future, and this decision will bring me closer to that future. I just need to make due with the lack of WebGPU support in modern browsers in the near term.

Other Notes / Progress

  • While working on this I pulled our some of my conformance testing code into a new crate called conformer.

Next Journal Entry

My first priority is implementing a couple bits of the render graph that the runtime texture allocation needs to make use of. Namely copying subtexture regions between textures.

After that I will switch the game from using the WebGlRenderer on the web to using the WebGpuRenderer.

This switch in and of itself should be fairly straightforwards since the game is designed to work with anything that implements my Renderer trait.

Still, there will be a good bit of work to do to see the game running on top of WebGPU since my WebGpuRenderer currently only passes a small fraction of my renderer test suite.

I'm looking forwards to getting passed this hurdle since the modern graphics APIs like Metal and WebGPU are significantly better to work with than older APIs like WebGL.

There will be some pain over the next year or so while browsers don't yet support WebGPU, but once the major browsers support it I will be in a spectacular position.

I just need to ride it out until then and be okay with way fewer people trying out the game in the meantime, since virtually no one will have WebGPU enabled and very few will elect to enable it.

It's fine though. WebGL was really holding me back from diving in to some more advanced features that I want to implement but would have been either a pain or impossible with WebGL.


Well Wishes,

- CFN