-
Notifications
You must be signed in to change notification settings - Fork 65
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
Fixes to the Glium example #117
base: master
Are you sure you want to change the base?
Conversation
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.
Really happy to see the new glutin
and winit
being used via a glium
update! There are a few design choices we might want to address though, and I don't think the CI will succeed on this yet.
examples/glium.rs
Outdated
print!( | ||
"\rms: {}\t (buffer) + {}\t (UI)", | ||
println!( | ||
"ms: {}\t (buffer) + {}\t (UI)", |
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 think \r
without ln
was here to continuously overwrite the same line.
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.
Oops, I forgot about this. I found it a lot more useful for debugging to print every frame on its own line, though.
event_loop | ||
.run(move |event, elwt| { | ||
fn user_event(&mut self, event_loop: &ActiveEventLoop, event: UserEvent) { | ||
(self.user_event)(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.
Is there a reason to not inline the original run
code directly here?
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 closure captures the environment. The struct would have to turn every captured variable into a field, so I just took the easiest path.
Should I turn it into a struct?
let _ = event_loop_proxy.send_event(UserEvent::WakeUp); | ||
tx.send(data).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.
Could we send data
though the proxy instead of needing a separate channel?
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.
Kinda, but I think that would make control flow even more complicated. Not every buffer will result in a rendered frame, some buffers will be dropped. Waking up on every buffer from a stream where we can't skip events means that every buffer will have to render, even if there's another one enqueued.
(I'll add the frame skipping next.)
examples/glium.rs
Outdated
|
||
event_loop | ||
.run(move |event, elwt| { | ||
fn user_event(&mut self, event_loop: &ActiveEventLoop, event: UserEvent) { |
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.
Note that if you know a value can only have one variant, you can pattern-match on it in the function signature:
fn user_event(&mut self, event_loop: &ActiveEventLoop, event: UserEvent) { | |
fn user_event(&mut self, event_loop: &ActiveEventLoop, UserEvent::WakeUp: UserEvent) { |
This even works to unpack a tuple or struct field if you pass data
as part of UserEvent
. Then, since there's only one event, you can also change enum
to struct
.
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 think using the signature as the trait defines it is more readable.
About keeping this as an enum, I think most real-world applications are going to have some form of an enum, so this should make it easier to integrate.
I'm willing to change both if it's required for merging, though.
examples/glium.rs
Outdated
} | ||
|
||
event_loop.run_app(&mut LoopHandler { | ||
user_event: move |_event| { | ||
let t0 = Instant::now(); | ||
let data = rx.recv().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.
Glad to see that this blocking code now only runs on fn user_event()
, rather than on every event that used to be delivered in the past!
Fwiw I'd argue that this won't fly on tiling window managers, where the size of the window cannot be dictated by the input source (unless the window is made floating). Here the easiest to expect is scaling/stretching? |
If a window manager wants to use a different size, then setting the size hint isn't going to stop it. Meanwhile, window managers respecting the size will have the right size. The right solution for wrong size would be letterboxing, but I'm not ready to tackle that in this moment. |
I added frame skipping here. Tested by adding an artificial delay in the rendering code and observing that frame latencies don't keep growing forever. |
The example had several problems: freezing, wrong window size, and old glium version.
This fixes the problems.