Woyten / tune

Make xenharmonic music and create synthesizer tuning files for microtonal scales.
MIT License
134 stars 6 forks source link

Find a graphics engine that works well on desktop environments and WASM #7

Closed Woyten closed 1 year ago

Woyten commented 4 years ago

Just waiting until https://github.com/nannou-org/nannou/issues/657 is solved might be a solution.

Woyten commented 3 years ago

@x31eq Do you have an opinion which GUI framework to use? ATM Nannou is used but I could switch to another framework. Being undecided about the framework is the reason why GUI-heavy issues like #9 are blocked.

x31eq commented 3 years ago

I got the Druid example from here working the other day (with the code from the website — the repo isn't quite the same):

https://dev.to/davidedelpapa/rust-gui-introduction-a-k-a-the-state-of-rust-gui-libraries-as-of-january-2021-40gl#druid

I like it and they say it works with Wasm. I haven't tried it on Wasm. There are other things that mention it on that page, including the comments. I know no more

x31eq commented 3 years ago

Got the egui template working as well, native and Wasm.

https://github.com/emilk/egui

Looks interesting, but it's one of these GUIs that completely ignores native conventions: double-click select is idiosyncratic, copy/paste doesn't work. The native one does at least use the window manager's frame. Both binaries about 4MB (stripped).

Woyten commented 3 years ago

@x31eq Thanks for digging into this! My feelings about the different frameworks are the following:

I chose Nannou arbitrarily because it was presented at RustFest. Do you think there is a compelling reason to switch to one of the other frameworks?

x31eq commented 3 years ago

The compelling reason for me is that it'd work on my desktop! I skipped Iced because of the OpenGL requirement. If I build the hello world I get

thread 'main' panicked at '0:1(10): error: GLSL 3.30 is not supported. Supported
versions are: 1.10, 1.20, and 1.00 ES

GLSL is a mathematics library. I don't know why this requires an older version.

Woyten commented 3 years ago

From what I know GLSL is a shading language. But unlike Vulkan, GLSL should work on any system...strange...! :laughing:

x31eq commented 3 years ago

It isn't normal for Debian stable to provide a too recent library version. I expect this was a sign of the immature OpenGL support in Iced. The repo I pulled is pointing to a specific commit from last November. I can build the latest Iced library, I think there's some OpenGL support in there. I don't know how to specify it.

Wouldn't keyboard events come from a different library?

Harmoxen looks good. It works for me with Druid. The Iced branch builds against Vulkan.

Egui looks promising for what it is. That isn't something I have a use for. I think I'll write something in Druid and find out what problems it has. I see it lists as a non-goal "Support rendering to HTML when targeting the web." That suggests Iced will be better on the Wasm side

Woyten commented 3 years ago

Wouldn't keyboard events come from a different library?

I am not sure how that would integrate with the event loops provided by the frameworks. Besides that, is there any cross-platform library for keyboard events? The closest candidate that I can think of is winit.

I might give egui a try this weekend although from reading the docs I can tell that the keyboard event model is too restricted.

By the way, Bevy looks very promising but has no official support for WASM as far as I can tell.

So, at the moment it looks as if Druid has all the required features: WASM and physical keyboard events. But before completely switching to another framework I will request some feedback in the Rust Subreddit.

Woyten commented 3 years ago

Current progress: I gave winit a try (wasm-new branch). It has access to physical key locations i.e. scancodes but those scancodes are platform dependent (https://github.com/rust-windowing/winit/issues/1806). Druid scancodes might be platform independent and the Reddit community recommends it (https://www.reddit.com/r/rust/comments/nl0d3b).

Woyten commented 3 years ago

So, it seems that Druid is the most promising candidate: It comes with multi-platform support and it's designed with complex graphics in mind. The keyboard model is the best I could find in any of the GUI frameworks but I don't know how well the model works in practice. The only downside of Druid that I know of is that rendering to VST hosts is not possible at the moment (https://github.com/Azorlogh/harmoxen/issues/6, @Azorlogh thanks for sharing your thoughts!). @x31eq Do you think this is a show stopper?

The second best option might be Iced. It worked smoothly in my expriments and can render to VST hosts. The big problems are that it has no access to physical key locations and, since it depends on wgpu, it somehow requires a platform with Vulkan support. I hope what I say here is correct...

Woyten commented 1 year ago

Bevy is by far the best suitable framework for the task. It is

Closing this ticket now since I made my decision.