webgpu embedding

This commit is contained in:
Jorijn van der Graaf 2026-07-19 01:38:25 +02:00
commit a879c834c7
4 changed files with 86 additions and 4 deletions

View file

@ -31,6 +31,23 @@ namespace Crafter::WebGPU {
__attribute__((import_module("env"), import_name("wgpuInit")))
extern "C" void wgpuInit();
// Reparent the render canvas into a host DOM element so a scene renders
// inline inside the app's own layout rather than as a full-page layer.
// `idPtr`/`idLen` is a UTF-8 string naming an element id; an empty id
// detaches the canvas back to <body> and hides it. Implemented in
// additional/dom-webgpu.js. Prefer the SetCanvasMount() wrapper below.
__attribute__((import_module("env"), import_name("wgpuSetCanvasMount")))
extern "C" void wgpuSetCanvasMount(const void* idPtr, std::int32_t idLen);
// Mount the render canvas into the DOM element with id `elementId`
// (the render surface is sized to that element each frame). Pass an
// empty string to detach and hide the canvas, leaving a plain DOM page.
// Safe to call any time after the module has started — e.g. from a
// route handler once the target element exists in the DOM.
export inline void SetCanvasMount(std::string_view elementId) {
wgpuSetCanvasMount(elementId.data(), static_cast<std::int32_t>(elementId.size()));
}
__attribute__((import_module("env"), import_name("wgpuCreateBuffer")))
extern "C" std::uint32_t wgpuCreateBuffer(std::int32_t byteSize);
__attribute__((import_module("env"), import_name("wgpuWriteBuffer")))