Skip to content

Commit

Permalink
Fix doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
MDeiml committed Nov 7, 2022
1 parent 5c03cb9 commit ac6fa7d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 40 deletions.
37 changes: 2 additions & 35 deletions crates/bevy_render/src/view/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use bevy_app::{App, Plugin};
use bevy_ecs::prelude::*;
use bevy_utils::{tracing::debug, HashMap, HashSet};
use bevy_window::{
AbstractWindowHandle, CompositeAlphaMode, PresentMode, RawHandleWrapper, WindowClosed,
WindowId, Windows,
AbstractWindowHandle, CompositeAlphaMode, PresentMode, WindowClosed, WindowId, Windows,
};
use std::ops::{Deref, DerefMut};
use wgpu::TextureFormat;
Expand Down Expand Up @@ -184,8 +183,7 @@ pub fn prepare_windows(
.entry(window.id)
.or_insert_with(|| unsafe {
// NOTE: On some OSes this MUST be called from the main thread.
let surface = render_instance
.create_surface(&window.raw_handle.as_ref().unwrap().get_handle());
let surface = render_instance.create_surface(&handle.get_handle());
let format = *surface
.get_supported_formats(&render_adapter)
.get(0)
Expand All @@ -199,24 +197,6 @@ pub fn prepare_windows(
}),
AbstractWindowHandle::Virtual => continue,
};
let surface_data = window_surfaces
.surfaces
.entry(window.id)
.or_insert_with(|| unsafe {
// NOTE: On some OSes this MUST be called from the main thread.
let surface = render_instance
.create_surface(&window.raw_handle.as_ref().unwrap().get_handle());
let format = *surface
.get_supported_formats(&render_adapter)
.get(0)
.unwrap_or_else(|| {
panic!(
"No supported formats found for surface {:?} on adapter {:?}",
surface, render_adapter
)
});
SurfaceData { surface, format }
});

let surface_configuration = wgpu::SurfaceConfiguration {
format: surface_data.format,
Expand Down Expand Up @@ -267,17 +247,4 @@ pub fn prepare_windows(
window.swap_chain_texture = Some(TextureView::from(frame));
window.swap_chain_texture_format = Some(surface_data.format);
}

let frame = match surface.get_current_texture() {
Ok(swap_chain_frame) => swap_chain_frame,
Err(wgpu::SurfaceError::Outdated) => {
render_device.configure_surface(surface, &swap_chain_descriptor);
surface
.get_current_texture()
.expect("Error reconfiguring surface")
}
err => err.expect("Failed to acquire next swap chain texture!"),
};

window.swap_chain_texture = Some(TextureView::from(frame));
}
9 changes: 5 additions & 4 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl WindowResizeConstraints {
#[derive(Clone, Debug)]
pub enum AbstractWindowHandle {
/// The window corresponds to an operator system window.
RawWindowHandle(RawWindowHandleWrapper),
RawWindowHandle(RawHandleWrapper),
/// The window does not to correspond to an operator system window.
///
/// It differs from a non-virtual window, in that the caller is responsible
Expand Down Expand Up @@ -256,13 +256,13 @@ pub enum AbstractWindowHandle {
/// resize_constraints,
/// ..default()
/// };
/// let mut window = Window::new(
/// let mut window = Window::new_virtual(
/// WindowId::new(),
/// &window_descriptor,
/// 100, // physical_width
/// 100, // physical_height
/// 1.0, // scale_factor
/// None, None);
/// None);
///
/// let area = compute_window_area(&window);
/// assert_eq!(area, 100.0 * 100.0);
Expand Down Expand Up @@ -482,7 +482,7 @@ impl Window {
resizable: window_descriptor.resizable,
decorations: window_descriptor.decorations,
cursor_visible: window_descriptor.cursor_visible,
cursor_locked: window_descriptor.cursor_locked,
cursor_grab_mode: window_descriptor.cursor_grab_mode,
cursor_icon: CursorIcon::Default,
physical_cursor_position: None,
window_handle: AbstractWindowHandle::Virtual,
Expand All @@ -491,6 +491,7 @@ impl Window {
canvas: window_descriptor.canvas.clone(),
fit_canvas_to_parent: window_descriptor.fit_canvas_to_parent,
command_queue: Vec::new(),
alpha_mode: window_descriptor.alpha_mode,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_winit/src/winit_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl WinitWindows {
inner_size.height,
scale_factor,
position,
raw_window_handle,
raw_handle,
)
}

Expand Down

0 comments on commit ac6fa7d

Please sign in to comment.