bgfx support many platform, let's see if we can embed it on this post...

Bgfx + Emscripten?

  • Bgfx is a powerful rendering API help you to deal with lots of cross platform/low-level graphics API stuff!

  • Emscripten allows you code in familiar native language like C++ and compile it to WebAssembly (wasm) that runs in browser. There are some limitation of course but good thing about wasm is: your app can be accessed by anyone with modern browser (webgl).

  • WebGL & mobile graphics is the relative low end, if you manage to run on these platform, it also prove that it can run anywhere else.

  • If you are believer of wasm ...

Here's code repo to compile a simple example from bgfx.

Tips

  1. Using nix and direnv saved a lot of rampup works, if you are interested. Check out my previous post.
  2. BGFX can build wasm but failed to compile some examples, you need to compile wasm without example like this
  3. Emscripten provides virtual file system but you need to specify the path in configuration and use @: path@virtualpath
  4. To use emcc with webgl or glfw you need to treat specially instead of compile yourself. A bunch of flags I have to add to make things work.
  5. shader and assets build requires tools build. You can write your own make or reuse ninja script from examples.
  6. To generate compile_commands.json, you can use compiledb.
  7. To serve the local wasm html files, you can just miniserve -p 9000 which is included in the nix or emrun.
  8. To debug the wasm, you need to add -g flag and use google-chrome browser with DWARF plugin (see here). It's just this feature's still in beta version.

If you have some patience and modern browser, you should be able to see the 3D bunny in the iframe below:

...