Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Nannou run in WASM environment #811

Merged
merged 1 commit into from
Apr 8, 2022

Conversation

Woyten
Copy link
Contributor

@Woyten Woyten commented Dec 4, 2021

I managed to execute my synthesizer microwave in Firefox using WGPU's WebGL2 backend. A running demo can be tested here. The graphics is super fast but the audio (without any parameter tuning) is surprisingly slow and underruns on my Firefox. As a side note, audio has always been a problem during my WASM experiments and seems to be a weak point of CPAL.

The path to WASM via WebGL seems straightforward:

@mitchmindtree
Copy link
Member

mitchmindtree commented Dec 15, 2021

@Woyten, this is so ridiculously cool, nice work on all these PRs! The microwave demo appears to work really well in my firefox browser too.

As a side note, audio has always been a problem during my WASM experiments and seems to be a weak point of CPAL.

Yeah totally, I realise that audio support for CPAL is still difficult/lacking, hopefully we can improve upon it in the future and eventually see nannou_audio working on the web too, but I totally understand omitting going down that route for now. This is already a huge step for nannou :)

Reduce the device limits to Limits::downlevel_webgl2_defaults()

I just tried checking for the commit linked for this but looks like it might have moved?

Otherwise I think we should be ready to rebase this PR onto master for that last step of attaching the windows to the DOM and adding the wgpu webgl feature.

Thanks again for all this work, can't wait to have a play at some point! It feels good to know we have the built-in CI for the wasm target too to hopefully keep this relatively stable. After this it could be cool to start something like a examples/wasm or examples/web directory with some basics, and maybe add a tutorial to https://guide.nannou.cc.

@Woyten
Copy link
Contributor Author

Woyten commented Dec 15, 2021

@mitchmindtree Yes it's awesome that so many people made wgpu a really powerful multi-platform crate and that Nannou is always catching up with wgpu's nasty breaking changes! And thanks for making it possible to merge PRs in an uncomplicated manner!

Sorry the given link to my branch was broken. I had three WASM branches two of which I could remove eventually. The link should be working now.

As for the PR: I will rebase the branch as soon as possible s.t. we can see what's still missing.

@AJTJ
Copy link

AJTJ commented Dec 25, 2021

I'm excited by this! Thanks @Woyten!

@AJTJ
Copy link

AJTJ commented Feb 13, 2022

@Woyten can I help with getting this PR complete?

@Woyten
Copy link
Contributor Author

Woyten commented Feb 13, 2022

@AJTJ The last missing pieces for a very basic WASM experience are DOM mounting/unmounting. This PR contains code which mounts a window to the DOM after creation.

What's missing?

  • DOM unmounting. You could help by adding a PR which removes a window from the DOM once it gets destructed.
  • Multiple windows. For some reason, only a single window can be created. You could help by finding out why creating a second window fails.

@mitchmindtree How do yo want to proceed with this PR? I could make it merge-ready and we address the points mentioned above in separate PRs. This PR will only affect the wasm32 architecture due to the feature toggle.

@AJTJ
Copy link

AJTJ commented Feb 24, 2022

I just started a new job and so I don't have the space for this anymore, but I'll check back in at a later date to see if this still needs work and I have more space.

@that-coder
Copy link

Is this in the release branch yet?

@Woyten
Copy link
Contributor Author

Woyten commented Mar 19, 2022

@that-coder Everything needed to make a basic Nannou experience on WASM a reality has been merged into the master branch except for this PR. This PR could be merged right now (it will only have an effect if the wasm-experimental feature is active) but, as mentioned in the previous comments, DOM unmounting and multi-window support aren't working yet.

@Woyten Woyten force-pushed the webgl-poc branch 2 times, most recently from 470e9d6 to 0807a93 Compare March 19, 2022 21:52
@Woyten Woyten marked this pull request as ready for review March 19, 2022 21:55
@that-coder
Copy link

Thanks. Is there any docs related to nannou wasm integration that I can refer too?

@mitchmindtree
Copy link
Member

Long overdue on my part - great stuff @Woyten ❤️

@mitchmindtree mitchmindtree merged commit 07009da into nannou-org:master Apr 8, 2022
@Digma
Copy link

Digma commented Dec 19, 2023

Hi, am I understanding properly that I should be able to mount the canvas to a specific DOM element?

If so, how is that done? When configuring the app window (e.g. some option of app.new_window()or is there a way to use something like element.set_inner_html("Hello from Rust!"); in web_sys ?

I tried looking into the code and documentation but could not find it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants