-
-
Notifications
You must be signed in to change notification settings - Fork 133
Winit 0.30 #544
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
base: master
Are you sure you want to change the base?
Winit 0.30 #544
Conversation
asny
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super nice work 🥳 thank you for doing this, I know it's not easy, especially with the major refactor that happened in winit 🙏
There's still some issues, but it's a great start! I've left some comments, but in general:
- There's deprecated notices for some of the winit functionality, this might be related to multi window not working.
- We can remove multi window example if it's too much work to fix, it's not a core part of what
three-dshould support. - There's a very different behaviour on web. We can change, but it would be nice to have at least somewhat the same behaviour.
- Winit window example is not compiling on web.
| LogicalSize::new( | ||
| browser_window.inner_width().unwrap().as_f64().unwrap(), | ||
| browser_window.inner_height().unwrap().as_f64().unwrap(), | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This defaulted the canvas to cover the entire browser window (a kind of full screen mode), I guess that part is removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user can still configure the css to make the window take all of the available space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, it's just a change in functionality, but I think it's ok 👍
| use winit::platform::web::WindowExtWebSys; | ||
| self.window | ||
| .canvas() | ||
| _ = self.event_loop.run(move |event, event_loop| match event { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get a deprecation warning about using this! Also, why is the result unhandled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is tricky. It would require to change the way three-d creates windows.
Because now you need to create a loop. And inside that loop, you can create the window. In the same way you are managing windows in the multi window example.
I didn't want to make changes to the three-d API for now.
It could be done later. I guess at some point winit is going to remove it, and we won't have a choice anymore. It needs to be planned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really get the difference 🤔 The event loop is already created first, then the window, so what would the change be?
|
|
||
| let winit_window = window_builder.build(&event_loop)?; | ||
| let winit_window = event_loop | ||
| .create_window(window_builder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get a deprecation warning from this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as the other depreciation warning.
| #[cfg(target_arch = "wasm32")] | ||
| { | ||
| self.gl.swap_buffers().unwrap(); | ||
| // NOTE: This is needed because the canvas resize events are not all received. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's unfortunate that winit events are not working correctly 😞 But I think the fix is good then. However, I think it should just always make a resized event in each frame and then the frame input generator should check whether it actually has changed. That way, you don't need the window_width and window_height functionality on the frame input generator.
| } | ||
| // WindowEvent::ScaleFactorChanged { new_inner_size, .. } => { | ||
| // self.gl.resize(**new_inner_size); | ||
| // } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason scale factor changed is not handled?
| #[cfg(not(target_arch = "wasm32"))] | ||
| use std::time::Instant; | ||
| #[cfg(target_arch = "wasm32")] | ||
| use web_time::Instant; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of this commit : rust-windowing/winit@5bbe879
| pub(crate) fn window_height(&self) -> u32 { | ||
| self.window_height | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for these, see my comment above.
| // self.viewport = Viewport::new_at_origo(new_inner_size.width, new_inner_size.height); | ||
| // let logical_size = new_inner_size.to_logical(self.device_pixel_ratio); | ||
| // self.window_width = logical_size.width; | ||
| // self.window_height = logical_size.height; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's happening here? 🤔
| if let Some(text) = &event.text { | ||
| let mut s = String::new(); | ||
| for ch in text.chars() { | ||
| if is_printable_char(ch) && !self.modifiers.ctrl && !self.modifiers.command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this sanitization?
|
Thanks. I've replied to some of the comments. The other comments, I don't remember, I'll check again the reason for those changes.
I'll take a look at how much work would be needed.
I think it's the same behavior. If you specify max_size, you get a window with this maximum size. If you don't, you get a window taking the whole available space, which can be specified via css. I think this last part is very important if you want to embed the three-d viewer in a web page. If you leave css unspecified, the viewer will take the entire window space.
Thanks. I'll take a look at it. |
|
Thank you for doing this @paul2t! Looking forward to the changes landing in |
|
Hi, I just tested this and I always seem to be getting a SurfaceCreationError using this branch whereas I do not get any kind of error using the main, normal branch from asny. Will be glad to offer any kind of technical info if you would like to look into it. |
|
@asny @paul2t Thank you very much for your efforts and hard work on this! It'd be really great to get this merged, as winit 0.28 depends on the unmaintained |
|
Hello 👋 !
Based on what @paul2t has done so far, I could try to see how the examples would look like with the flow above. I guess the other option would be to ignore the deprecation notice for now and continue with the current approach until the functions are removed. edit: tried to do it only using non-deprecated method but hitting a wall... Here is the code for anyone wanting to try it. The main problem I see is how the main code is configured in the example. In the new winit, one can only get the window and the gl structure after the loop has run... |


Fixes #532
I actually attempted this migration 6 months ago, but failed because of a resize issue on wasm : 07a531e
Then I tried again a month ago and was able to do it but it required a lot of changes in the API, and using a lot of JS to callback and redraw. It wasn't practical.
Today, I am glad to say I fixed it completely: 7e329df
I also had to add a check of the size change in the render loop for some reason: 088d5d7 I'm not sure why, but without it, the rendering is not on the entire canvas surface, there is often a 1 or 2 pixels margin.
Now you can resize the window on the web. The canvas size can be driven by css. Note that
max-widthandmax-heightare required. Otherwise the size will be overwritten by winit.I changed the
index.htmlto make the canvas 50% of the size of the window for the wasm examples.I tested a few examples on native and wasm. I noticed that change partially breaks the
multiwindownative example. Now, when you are focused on a window, the other window freezes. I didn't take the time to investigate this issue. But I guess this is a minor issue. Which can be fixed later.I also updated to
egui 0.31: de00c99