Skip to content

Support HTML canvas as WGPUSurfaceSource #481

Open
@mmueller2012

Description

@mmueller2012

I would like to use wgpu-native to translate from webgpu to webgl2. The library seems to compile fine with wasm32-unknown-emscripten as target 1, but there is no way to specify a HTML canvas as a surface source, which renders this approach useless.

My idea would be to add something like this:

typedef struct WGPUSurfaceSourceCanvas {
    WGPUChainedStruct chain;
    WGPUStringView canvasId;
} WGPUSurfaceSourceCanvas WGPU_STRUCTURE_ATTRIBUTE;

I used a string to represent the HTML document Id of the canvas, because I don't think there is a standardized way to directly pass a reference to a canvas through a ffi. This also seems to fit the behavior of SDL3 which supports querying the ID of the HTML canvas element when using emscripten.

Maybe someone with more knowledge in rust and emscripten can take a look at it :)

Footnotes

  1. I used the following command: cargo build --target=wasm32-unknown-emscripten --features wgc/fragile-send-sync-non-atomic-wasm --release --lib

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions