@@ -6,7 +6,7 @@ use crate::{
6
6
use bevy_app:: { App , Plugin } ;
7
7
use bevy_ecs:: prelude:: * ;
8
8
use bevy_utils:: { tracing:: debug, HashMap , HashSet } ;
9
- use bevy_window:: { PresentMode , RawWindowHandleWrapper , WindowClosed , WindowId , Windows } ;
9
+ use bevy_window:: { AbstractWindowHandle , PresentMode , WindowClosed , WindowId , Windows } ;
10
10
use std:: ops:: { Deref , DerefMut } ;
11
11
12
12
/// Token to ensure a system runs on the main thread.
@@ -38,7 +38,7 @@ impl Plugin for WindowRenderPlugin {
38
38
39
39
pub struct ExtractedWindow {
40
40
pub id : WindowId ,
41
- pub raw_window_handle : Option < RawWindowHandleWrapper > ,
41
+ pub handle : AbstractWindowHandle ,
42
42
pub physical_width : u32 ,
43
43
pub physical_height : u32 ,
44
44
pub present_mode : PresentMode ,
@@ -83,7 +83,7 @@ fn extract_windows(
83
83
. entry ( window. id ( ) )
84
84
. or_insert ( ExtractedWindow {
85
85
id : window. id ( ) ,
86
- raw_window_handle : window. raw_window_handle ( ) ,
86
+ handle : window. window_handle ( ) ,
87
87
physical_width : new_width,
88
88
physical_height : new_height,
89
89
present_mode : window. present_mode ( ) ,
@@ -132,7 +132,7 @@ pub struct WindowSurfaces {
132
132
133
133
/// Creates and (re)configures window surfaces, and obtains a swapchain texture for rendering.
134
134
///
135
- /// This will not handle [virtual windows](bevy_window::Window::new_virtual ).
135
+ /// This will not handle [virtual windows](bevy_window::AbstractWindowHandle::Virtual ).
136
136
///
137
137
/// NOTE: `get_current_texture` in `prepare_windows` can take a long time if the GPU workload is
138
138
/// the performance bottleneck. This can be seen in profiles as multiple prepare-stage systems all
@@ -165,58 +165,59 @@ pub fn prepare_windows(
165
165
) {
166
166
let window_surfaces = window_surfaces. deref_mut ( ) ;
167
167
for window in windows. windows . values_mut ( ) {
168
- if let Some ( handle ) = & window. handle {
169
- let surface = window_surfaces
168
+ let surface = match & window. handle {
169
+ AbstractWindowHandle :: RawWindowHandle ( handle ) => window_surfaces
170
170
. surfaces
171
171
. entry ( window. id )
172
172
. or_insert_with ( || unsafe {
173
173
// NOTE: On some OSes this MUST be called from the main thread.
174
174
render_instance. create_surface ( & handle. get_handle ( ) )
175
- } ) ;
175
+ } ) ,
176
+ AbstractWindowHandle :: Virtual => continue ,
177
+ } ;
178
+
179
+ let swap_chain_descriptor = wgpu:: SurfaceConfiguration {
180
+ format : * surface
181
+ . get_supported_formats ( & render_adapter)
182
+ . get ( 0 )
183
+ . unwrap_or_else ( || {
184
+ panic ! (
185
+ "No supported formats found for surface {:?} on adapter {:?}" ,
186
+ surface, render_adapter
187
+ )
188
+ } ) ,
189
+ width : window. physical_width ,
190
+ height : window. physical_height ,
191
+ usage : wgpu:: TextureUsages :: RENDER_ATTACHMENT ,
192
+ present_mode : match window. present_mode {
193
+ PresentMode :: Fifo => wgpu:: PresentMode :: Fifo ,
194
+ PresentMode :: Mailbox => wgpu:: PresentMode :: Mailbox ,
195
+ PresentMode :: Immediate => wgpu:: PresentMode :: Immediate ,
196
+ PresentMode :: AutoVsync => wgpu:: PresentMode :: AutoVsync ,
197
+ PresentMode :: AutoNoVsync => wgpu:: PresentMode :: AutoNoVsync ,
198
+ } ,
199
+ } ;
200
+
201
+ // Do the initial surface configuration if it hasn't been configured yet. Or if size or
202
+ // present mode changed.
203
+ if window_surfaces. configured_windows . insert ( window. id )
204
+ || window. size_changed
205
+ || window. present_mode_changed
206
+ {
207
+ render_device. configure_surface ( surface, & swap_chain_descriptor) ;
208
+ }
176
209
177
- let swap_chain_descriptor = wgpu:: SurfaceConfiguration {
178
- format : * surface
179
- . get_supported_formats ( & render_adapter)
180
- . get ( 0 )
181
- . unwrap_or_else ( || {
182
- panic ! (
183
- "No supported formats found for surface {:?} on adapter {:?}" ,
184
- surface, render_adapter
185
- )
186
- } ) ,
187
- width : window. physical_width ,
188
- height : window. physical_height ,
189
- usage : wgpu:: TextureUsages :: RENDER_ATTACHMENT ,
190
- present_mode : match window. present_mode {
191
- PresentMode :: Fifo => wgpu:: PresentMode :: Fifo ,
192
- PresentMode :: Mailbox => wgpu:: PresentMode :: Mailbox ,
193
- PresentMode :: Immediate => wgpu:: PresentMode :: Immediate ,
194
- PresentMode :: AutoVsync => wgpu:: PresentMode :: AutoVsync ,
195
- PresentMode :: AutoNoVsync => wgpu:: PresentMode :: AutoNoVsync ,
196
- } ,
197
- } ;
198
-
199
- // Do the initial surface configuration if it hasn't been configured yet. Or if size or
200
- // present mode changed.
201
- if window_surfaces. configured_windows . insert ( window. id )
202
- || window. size_changed
203
- || window. present_mode_changed
204
- {
210
+ let frame = match surface. get_current_texture ( ) {
211
+ Ok ( swap_chain_frame) => swap_chain_frame,
212
+ Err ( wgpu:: SurfaceError :: Outdated ) => {
205
213
render_device. configure_surface ( surface, & swap_chain_descriptor) ;
214
+ surface
215
+ . get_current_texture ( )
216
+ . expect ( "Error reconfiguring surface" )
206
217
}
218
+ err => err. expect ( "Failed to acquire next swap chain texture!" ) ,
219
+ } ;
207
220
208
- let frame = match surface. get_current_texture ( ) {
209
- Ok ( swap_chain_frame) => swap_chain_frame,
210
- Err ( wgpu:: SurfaceError :: Outdated ) => {
211
- render_device. configure_surface ( surface, & swap_chain_descriptor) ;
212
- surface
213
- . get_current_texture ( )
214
- . expect ( "Error reconfiguring surface" )
215
- }
216
- err => err. expect ( "Failed to acquire next swap chain texture!" ) ,
217
- } ;
218
-
219
- window. swap_chain_texture = Some ( TextureView :: from ( frame) ) ;
220
- }
221
+ window. swap_chain_texture = Some ( TextureView :: from ( frame) ) ;
221
222
}
222
223
}
0 commit comments