Revert PresentMode split

This commit is contained in:
Jan Hohenheim 2025-07-07 22:06:02 +02:00
parent 157b67b511
commit 9631ee091c
No known key found for this signature in database
18 changed files with 64 additions and 110 deletions

View File

@ -101,19 +101,11 @@ impl DerefMut for ExtractedWindows {
fn extract_windows(
mut extracted_windows: ResMut<ExtractedWindows>,
mut closing: Extract<EventReader<WindowClosing>>,
windows: Extract<
Query<(
Entity,
&Window,
&PresentMode,
&RawHandleWrapper,
Option<&PrimaryWindow>,
)>,
>,
windows: Extract<Query<(Entity, &Window, &RawHandleWrapper, Option<&PrimaryWindow>)>>,
mut removed: Extract<RemovedComponents<RawHandleWrapper>>,
mut window_surfaces: ResMut<WindowSurfaces>,
) {
for (entity, window, present_mode, handle, primary) in windows.iter() {
for (entity, window, handle, primary) in windows.iter() {
if primary.is_some() {
extracted_windows.primary = Some(entity);
}
@ -128,7 +120,7 @@ fn extract_windows(
handle: handle.clone(),
physical_width: new_width,
physical_height: new_height,
present_mode: *present_mode,
present_mode: window.present_mode,
desired_maximum_frame_latency: window.desired_maximum_frame_latency,
swap_chain_texture: None,
swap_chain_texture_view: None,
@ -142,7 +134,8 @@ fn extract_windows(
extracted_window.swap_chain_texture_view = None;
extracted_window.size_changed = new_width != extracted_window.physical_width
|| new_height != extracted_window.physical_height;
extracted_window.present_mode_changed = *present_mode != extracted_window.present_mode;
extracted_window.present_mode_changed =
window.present_mode != extracted_window.present_mode;
if extracted_window.size_changed {
debug!(
@ -159,9 +152,9 @@ fn extract_windows(
if extracted_window.present_mode_changed {
debug!(
"Window Present Mode changed from {:?} to {:?}",
extracted_window.present_mode, *present_mode
extracted_window.present_mode, window.present_mode
);
extracted_window.present_mode = *present_mode;
extracted_window.present_mode = window.present_mode;
}
}

View File

@ -161,8 +161,10 @@ impl ContainsEntity for NormalizedWindowRef {
all(feature = "serialize", feature = "bevy_reflect"),
reflect(Serialize, Deserialize)
)]
#[require(CursorOptions, PresentMode)]
#[require(CursorOptions)]
pub struct Window {
/// What presentation mode to give the window.
pub present_mode: PresentMode,
/// Which fullscreen or windowing mode should be used.
pub mode: WindowMode,
/// Where the window should be placed.
@ -468,6 +470,7 @@ impl Default for Window {
fn default() -> Self {
Self {
title: DEFAULT_WINDOW_TITLE.to_owned(),
present_mode: PresentMode::default(),
name: None,
mode: Default::default(),
position: Default::default(),
@ -1205,11 +1208,11 @@ pub enum VideoModeSelection {
/// [`AutoVsync`]: PresentMode::AutoVsync
/// [`AutoNoVsync`]: PresentMode::AutoNoVsync
#[repr(C)]
#[derive(Component, Default, Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Default, Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "bevy_reflect",
derive(Reflect),
reflect(Component, Debug, PartialEq, Hash, Clone)
reflect(Debug, PartialEq, Hash, Clone)
)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(

View File

@ -163,14 +163,11 @@ fn main() {
.run();
}
fn configure_window(
trigger: On<Add, PrimaryWindow>,
mut window: Query<(&mut Window, &mut PresentMode)>,
) {
let (mut window, mut present_mode) = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.title = "BevyMark".to_string();
window.resolution = WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0);
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
#[derive(Resource)]

View File

@ -41,13 +41,10 @@ fn main() {
.run();
}
fn configure_window(
trigger: On<Add, PrimaryWindow>,
mut window: Query<(&mut Window, &mut PresentMode)>,
) {
let (mut window, mut present_mode) = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.resolution = WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0);
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
fn setup(

View File

@ -123,13 +123,10 @@ fn main() {
app.insert_resource(args).run();
}
fn configure_window(
trigger: On<Add, PrimaryWindow>,
mut window: Query<(&mut Window, &mut PresentMode)>,
) {
let (mut window, mut present_mode) = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.resolution = WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0);
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
fn set_text_colors_changed(mut colors: Query<&mut TextColor>) {

View File

@ -18,13 +18,10 @@ fn main() {
.run();
}
fn configure_window(
trigger: On<Add, PrimaryWindow>,
mut window: Query<(&mut Window, &mut PresentMode)>,
) {
let (mut window, mut present_mode) = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.resolution = WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0);
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
const CAMERA_ROWS: usize = 4;

View File

@ -125,13 +125,10 @@ fn main() {
app.insert_resource(args).run();
}
fn configure_window(
trigger: On<Add, PrimaryWindow>,
mut window: Query<(&mut Window, &mut PresentMode)>,
) {
let (mut window, mut present_mode) = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.resolution = WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0);
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
const WIDTH: usize = 200;

View File

@ -68,14 +68,11 @@ fn main() {
.run();
}
fn configure_window(
trigger: On<Add, PrimaryWindow>,
mut window: Query<(&mut Window, &mut PresentMode)>,
) {
let (mut window, mut present_mode) = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.title = "🦊🦊🦊 Many Foxes! 🦊🦊🦊".to_string();
window.resolution = WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0);
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
#[derive(Resource)]

View File

@ -37,14 +37,11 @@ fn main() {
app.run();
}
fn configure_window(
trigger: On<Add, PrimaryWindow>,
mut window: Query<(&mut Window, &mut PresentMode)>,
) {
let (mut window, mut present_mode) = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.title = "Many Debug Lines".to_string();
window.resolution = WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0);
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
#[derive(Resource, Debug)]

View File

@ -58,13 +58,10 @@ fn main() {
app.insert_resource(args).run();
}
fn configure_window(
trigger: On<Add, PrimaryWindow>,
mut window: Query<(&mut Window, &mut PresentMode)>,
) {
let (mut window, mut present_mode) = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.resolution = WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0);
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
fn setup(mut commands: Commands, args: Res<Args>) {

View File

@ -33,14 +33,11 @@ fn main() {
.run();
}
fn configure_window(
trigger: On<Add, PrimaryWindow>,
mut window: Query<(&mut Window, &mut PresentMode)>,
) {
let (mut window, mut present_mode) = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.title = "many_lights".to_string();
window.resolution = WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0);
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
fn setup(

View File

@ -35,14 +35,11 @@ fn main() {
.run();
}
fn configure_window(
trigger: On<Add, PrimaryWindow>,
mut window: Query<(&mut Window, &mut PresentMode)>,
) {
let (mut window, mut present_mode) = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.resolution = WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0);
window.title = "many_materials".into();
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
fn setup(

View File

@ -48,13 +48,10 @@ fn main() {
.run();
}
fn configure_window(
trigger: On<Add, PrimaryWindow>,
mut window: Query<(&mut Window, &mut PresentMode)>,
) {
let (mut window, mut present_mode) = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.resolution = WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0);
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
fn setup(mut commands: Commands, assets: Res<AssetServer>, color_tint: Res<ColorTint>) {

View File

@ -95,13 +95,10 @@ impl Default for PrintingTimer {
}
}
fn configure_window(
trigger: On<Add, PrimaryWindow>,
mut window: Query<(&mut Window, &mut PresentMode)>,
) {
let (mut window, mut present_mode) = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.resolution = WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0);
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
fn setup(mut commands: Commands, font: Res<FontHandle>, args: Res<Args>) {

View File

@ -28,13 +28,10 @@ fn main() {
.run();
}
fn configure_window(
trigger: On<Add, PrimaryWindow>,
mut window: Query<(&mut Window, &mut PresentMode)>,
) {
let (mut window, mut present_mode) = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.resolution = WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0);
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {

View File

@ -19,9 +19,9 @@ fn main() {
.run();
}
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut PresentMode>) {
let mut present_mode = window.get_mut(trigger.target()).unwrap();
*present_mode = PresentMode::AutoNoVsync;
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.present_mode = PresentMode::AutoNoVsync;
}
#[derive(Component)]

View File

@ -37,10 +37,10 @@ fn main() {
.run();
}
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut PresentMode>) {
let mut present_mode = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
// Turn off vsync to maximize CPU/GPU usage
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
#[derive(Resource, Debug)]

View File

@ -38,11 +38,8 @@ fn main() {
.run();
}
fn configure_window(
trigger: On<Add, PrimaryWindow>,
mut window: Query<(&mut Window, &mut PresentMode)>,
) {
let (mut window, mut present_mode) = window.get_mut(trigger.target()).unwrap();
fn configure_window(trigger: On<Add, PrimaryWindow>, mut window: Query<&mut Window>) {
let mut window = window.get_mut(trigger.target()).unwrap();
window.title = "I am a window!".into();
window.name = Some("bevy.app".into());
window.resolution = (500., 300.).into();
@ -57,7 +54,7 @@ fn configure_window(
// This is useful when you want to avoid the white window that shows up before the GPU is ready to render the app.
window.visible = false;
*present_mode = PresentMode::AutoNoVsync;
window.present_mode = PresentMode::AutoNoVsync;
}
fn make_visible(mut window: Single<&mut Window>, frames: Res<FrameCount>) {
@ -72,14 +69,14 @@ fn make_visible(mut window: Single<&mut Window>, frames: Res<FrameCount>) {
/// This system toggles the vsync mode when pressing the button V.
/// You'll see fps increase displayed in the console.
fn toggle_vsync(input: Res<ButtonInput<KeyCode>>, mut present_mode: Single<&mut PresentMode>) {
fn toggle_vsync(input: Res<ButtonInput<KeyCode>>, mut window: Single<&mut Window>) {
if input.just_pressed(KeyCode::KeyV) {
**present_mode = if matches!(**present_mode, PresentMode::AutoVsync) {
window.present_mode = if matches!(window.present_mode, PresentMode::AutoVsync) {
PresentMode::AutoNoVsync
} else {
PresentMode::AutoVsync
};
info!("PRESENT_MODE: {:?}", *present_mode);
info!("PRESENT_MODE: {:?}", window.present_mode);
}
}