Dual backend strategy
Same renderer API — production Vulkan or experimental WebGPU via Dawn / Emscripten WASM.
Run the same Spectra C++ plotting code natively with Dawn or in the browser with Emscripten. The WebGPU path is experimental, focused on polished 2D plots, dashboards, and browser demos without Vulkan.
WebGPU currently tracks Spectra's 2D drawing model. It is useful for browser demos and embedded dashboards, while Vulkan remains the production backend for the full feature set.
Same renderer API — production Vulkan or experimental WebGPU via Dawn / Emscripten WASM.
dlopenBuild and link against a local Dawn install.
cmake -B build \
-DSPECTRA_USE_WEBGPU=ON \
-Ddawn_DIR=/path/to/dawn/install/lib/cmake/dawn \
-DCMAKE_BUILD_TYPE=Release
cmake --build build --target webgpu_demo
./build/examples/webgpu_demo
You can also link against
wgpu-native
by pointing CMake at its install prefix.
source /path/to/emsdk/emsdk_env.sh
emcmake cmake -B build-wasm \
-DSPECTRA_USE_WEBGPU=ON \
-DCMAKE_BUILD_TYPE=Release
cmake --build build-wasm --target webgpu_demo
# Serve and open in a WebGPU-capable browser (Chrome / Edge 113+)
python3 -m http.server -d build-wasm/examples
# http://localhost:8000/webgpu_demo.html
The static HTML shell is
examples/webgpu_shell.html.
User code is identical to the Vulkan backend. Select WebGPU at
build time with SPECTRA_USE_WEBGPU.
#include <spectra/app.hpp>
#include <spectra/easy.hpp>
int main()
{
spectra::plot({0.f, 1.f, 2.f, 3.f}, {0.f, 1.f, 0.5f, 1.5f}, "c-o");
spectra::title("Hello WebGPU");
spectra::show();
}
The full example is in
examples/webgpu_demo.cpp.
GLSL Vulkan shaders are mirrored as WGSL in
src/render/webgpu/shaders/. When a 2D Vulkan shader changes, port the
equivalent .wgsl file to keep both backends in sync.