Hacker News new | ask | show | jobs
by adrift 651 days ago
Having a C API like that is always nice. I don't wanna fight Rust.
2 comments

WebGPU has a (mostly) standardized C API: https://github.com/webgpu-native/webgpu-headers
wgpu supports WebGPU: https://github.com/gfx-rs/wgpu :

> While WebGPU does not support any shading language other than WGSL, we will automatically convert your non-WGSL shaders if you're running on WebGPU.

That’s just for the shading language
The Rust wgpu project has an alternative C API which is identical (or at least closely matches, I haven't looked in detail at it yet) the official webgpu.h header. For instance all examples in here are written in C:

https://github.com/gfx-rs/wgpu-native/tree/trunk/examples

There's definitely also people using wgpu from Zig via the C bindings.

I found:

shlomnissan/sdl-wasm: https://github.com/shlomnissan/sdl-wasm :

> A simple example of compiling C/SDL to WebAssembly and binding it to an HTML5 canvas.

erik-larsen/emscripten-sdl2-ogles2: https://github.com/erik-larsen/emscripten-sdl2-ogles2 :

> C++/SDL2/OpenGLES2 samples running in the browser via Emscripten

IDK how much work there is to migrate these to SDL3?

Are there WASM compilation advantages to SDL3 vs SDL2?

It exists, but IMO it's not a good choice.

First of all, it doesn't support RenderGeometry or RenderGeometryRaw, which are necessary for high-performance 2D rendering (absent the new GPU API). I doubt it will support any of the GPU API at this rate, as the geometry rendering is a much simpler API. Maybe both will land all at once, though. To wit, the relevant issue hasn't seen much activity: https://github.com/Rust-SDL2/rust-sdl2/issues/1180

Secondly, the abstractions chosen by rust-sdl2 are quite different from those of SDL2 itself. There seems to have been an aggressive attempt by the Rust library authors to make something more Rust-friendly, which maybe has made it more approachable for people who don't know SDL2 already, but it has IMO made it less approachable for people who do know SDL2. The crate gets plenty of downloads, so maybe it's just me.