Skip to content

Commit

Permalink
Merge pull request #323 from janhohenheim/fix-white
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim authored Jul 2, 2024
2 parents 45a96be + 04a02c3 commit 9baf7b5
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions src/bevy_config.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
use crate::util::error;
use bevy::render::settings::{WgpuFeatures, WgpuSettings};
use bevy::render::RenderPlugin;
use bevy::core::FrameCount;
use bevy::{prelude::*, window::PrimaryWindow, winit::WinitWindows};
use std::io::Cursor;
use winit::window::Icon;

/// Overrides the default Bevy plugins and configures things like the screen settings.
pub(super) fn plugin(app: &mut App) {
app.add_plugins(
DefaultPlugins
.set(WindowPlugin {
primary_window: Some(Window {
title: "Foxtrot".to_string(),
..default()
}),
DefaultPlugins.set(WindowPlugin {
primary_window: Window {
title: "Foxtrot".to_string(),
// This will spawn an invisible window
// The window will be made visible in the make_visible() system after 3 frames.
// This is useful when you want to avoid the white window that shows up before the GPU is ready to render the app.
visible: false,
..default()
})
.set(RenderPlugin {
render_creation: create_wgpu_settings().into(),
synchronous_pipeline_compilation: false,
}),
}
.into(),
..default()
}),
)
.insert_resource(Msaa::Sample4)
.insert_resource(ClearColor(Color::rgb(0.4, 0.4, 0.4)))
.add_systems(Startup, set_window_icon.pipe(error));
}

fn create_wgpu_settings() -> WgpuSettings {
let mut wgpu_settings = WgpuSettings::default();
wgpu_settings
.features
.set(WgpuFeatures::VERTEX_WRITABLE_STORAGE, true);
wgpu_settings
.add_systems(Startup, set_window_icon.pipe(error))
.add_systems(Update, make_visible);
}

// Sets the icon on Windows and X11
Expand All @@ -55,3 +47,14 @@ fn set_window_icon(
};
Ok(())
}

/// Source: <https://github.com/bevyengine/bevy/blob/v0.14.0-rc.4/examples/window/window_settings.rs#L56>
fn make_visible(mut window: Query<&mut Window>, frames: Res<FrameCount>) {
// The delay may be different for your app or system.
if frames.0 == 3 {
// At this point the gpu is ready to show the app so we can make the window visible.
// Alternatively, you could toggle the visibility in Startup.
// It will work, but it will have one white frame before it starts rendering
window.single_mut().visible = true;
}
}

0 comments on commit 9baf7b5

Please sign in to comment.