-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Wait before making window visible #9692
Wait before making window visible #9692
Conversation
would it work with a fixed number of frames rather than a timed delay? |
Good idea, I just tried using a fixed number of frames and for me it works with 3 frames. |
I noticed the other systems don't use the |
285236c
to
e11b83f
Compare
e11b83f
to
a9b8fb1
Compare
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.
Nice. I no longer see the white window on Windows 11.
examples/window/window_settings.rs
Outdated
// There might still be a white frame when doing it in startup. | ||
// Alternatively, you could have a system that waits a few seconds before making the window visible. | ||
primary_window.single_mut().visible = true; | ||
fn toggle_visible(mut window: Query<&mut Window>, frames: Res<FrameCount>) { |
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 have a good suggestion, but other toggle_
systems in this example are triggered by user input, while this one is more like a delayed setup
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.
Good point, how about make_visible
or automatically_toggle_visible
to make it more obvious?
If you set window theme to |
The dark theme makes it less noticeable, but the fix in this PR makes it completely disappear and only ever render when it's ready. The main issue is that it needs to be done by the user. |
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.
Nice, why aren't we doing this by default in every app?
The main reason is that for pretty much every other bevy api if a user configures a value bevy won't change it. Implementing this in bevy would require bevy itself taking control of the visible flag. This was mildly controversial when a PR tried to do that last year. With that being said, there could be ways to do it without this issue. Like, if the flag is set to visible, we could still spawn the window as invisible and then make it visible when the gpu is ready. So we wouldn't actually touch the user controlled visible flag. I can look into making a PR with this approach. |
Doing this directly in engine, a few things would have to be checked:
|
I did some quick testing for this and it looks like only the first window is affected, spawning new windows after that doesn't produce any flash.
It definitely happens on windows and I've seen some linux users mention it too. I don't know about macOS or mobile
From what I understand we mostly need a way to detect the first present on the swap chain. This would require a way to communicate back from the render world to the main world. It's certainly possible but waiting a frame after the window creation also does the trick and is much easier to implement. This PR needs more than a frame because I think the window doesn't get created instantly. |
For non-game style apps it is common to avoid requesting a new frame to be drawn on every vsync, right? In that case I would expect it to be possible to have the frame count get stuck at a value smaller than 3 until the user directly interacts with the app to trigger a rerender. |
@bjorn3 yes that's also something that would need to be considered in a built-in solution. That's why this is just an example to show how to use the api to enable/disable window visibility. |
# Objective - The current example still has one white frame before it starts rendering. ## Solution - Wait 3 frames before toggling visibility
Objective
Solution