AssemblyScript / assemblyscript

A TypeScript-like language for WebAssembly.
https://www.assemblyscript.org
Apache License 2.0
16.87k stars 658 forks source link

is graphics rendering possible? #4

Closed goldenratio closed 6 years ago

goldenratio commented 6 years ago

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?

ColinEberhardt commented 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.

goldenratio commented 6 years ago

clear now thanks.

tiye commented 6 years ago

Does WebAssembly have Canvas API support?

ColinEberhardt commented 6 years ago

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 ...

dcodeIO commented 6 years ago

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".

goldenratio commented 6 years ago

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/

dcodeIO commented 6 years ago

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.

goldenratio commented 6 years ago

@dcodeIO thanks! :) you made it really clear for me.