Closed goldenratio closed 6 years ago
No, WebAssembly does not have direct DOM access. The only way to render to canvas, or update any HTML is via importing JavaScript functions into your wasm module.
clear now thanks.
Does WebAssembly have Canvas API support?
No, it doesn’t have support directly. All WebAssembly can do is perform computations, reading and writing to memory. For everything else, you’ll need to import JavaScript functions that provide an interface into DOM / canvas etc ...
Things like these will become more efficient once host-bindings lands. From an AssemblyScript point of view, this could then look like in this String experiment, being part of stdlib, so Web-APIs "just work".
what about webgl? can we use that for rendering in WASM. Recently I have been looking into rust lang. It seems to be possible. Related RUST + GL + WASM repo https://github.com/kvark/wasm-triangle Some more info on reddit https://www.reddit.com/r/rust_gamedev/comments/7mc7yk/is_there_any_wasm_friendly_2d_rendering_lib/drto3p9/
It's just like with the game of life example: They are importing their own helpers to make it possible. You can do the same in AS.
@dcodeIO thanks! :) you made it really clear for me.
Hi,
I am looking to render graphics in canvas element via WASM, instead of JavaScript. Is this possible with AssemblyScript?
For example, in game of life demo - rendering is done via javascript, is it possible to move it to assembly code?