@@ -138,7 +138,7 @@ impl RenderContextBuilder {
138138 . configure_with_defaults (
139139 & gpu,
140140 size,
141- platform :: surface:: PresentMode :: Fifo ,
141+ surface:: PresentMode :: default ( ) . to_platform ( ) ,
142142 texture:: TextureUsages :: RENDER_ATTACHMENT . to_platform ( ) ,
143143 )
144144 . map_err ( |e| {
@@ -148,13 +148,14 @@ impl RenderContextBuilder {
148148 ) )
149149 } ) ?;
150150
151- let config = surface. configuration ( ) . cloned ( ) . ok_or_else ( || {
151+ let config = surface. configuration ( ) . ok_or_else ( || {
152152 RenderContextError :: SurfaceConfig (
153153 "Surface was not configured" . to_string ( ) ,
154154 )
155155 } ) ?;
156+ let config = surface:: SurfaceConfig :: from_platform ( config) ;
156157 let present_mode = config. present_mode ;
157- let texture_usage = texture :: TextureUsages :: from_platform ( config. usage ) ;
158+ let texture_usage = config. usage ;
158159
159160 // Initialize a depth texture matching the surface size.
160161 let depth_format = platform:: texture:: DepthFormat :: Depth32Float ;
@@ -211,8 +212,8 @@ pub struct RenderContext {
211212 instance : platform:: instance:: Instance ,
212213 surface : platform:: surface:: Surface < ' static > ,
213214 gpu : platform:: gpu:: Gpu ,
214- config : platform :: surface:: SurfaceConfig ,
215- present_mode : platform :: surface:: PresentMode ,
215+ config : surface:: SurfaceConfig ,
216+ present_mode : surface:: PresentMode ,
216217 texture_usage : texture:: TextureUsages ,
217218 size : ( u32 , u32 ) ,
218219 depth_texture : Option < platform:: texture:: DepthTexture > ,
@@ -344,7 +345,7 @@ impl RenderContext {
344345 return & self . gpu ;
345346 }
346347
347- pub ( crate ) fn surface_format ( & self ) -> platform :: texture:: TextureFormat {
348+ pub ( crate ) fn surface_format ( & self ) -> texture:: TextureFormat {
348349 return self . config . format ;
349350 }
350351
@@ -356,9 +357,10 @@ impl RenderContext {
356357 & self ,
357358 sample_count : u32 ,
358359 ) -> bool {
359- return self
360- . gpu
361- . supports_sample_count_for_format ( self . config . format , sample_count) ;
360+ return self . gpu . supports_sample_count_for_format (
361+ self . config . format . to_platform ( ) ,
362+ sample_count,
363+ ) ;
362364 }
363365
364366 pub ( crate ) fn supports_depth_sample_count (
@@ -407,15 +409,18 @@ impl RenderContext {
407409
408410 let mut frame = match self . surface . acquire_next_frame ( ) {
409411 Ok ( frame) => frame,
410- Err ( platform:: surface:: SurfaceError :: Lost )
411- | Err ( platform:: surface:: SurfaceError :: Outdated ) => {
412- self . reconfigure_surface ( self . size ) ?;
413- self
414- . surface
415- . acquire_next_frame ( )
416- . map_err ( RenderError :: Surface ) ?
412+ Err ( err) => {
413+ let high_level_err = surface:: SurfaceError :: from ( err) ;
414+ match high_level_err {
415+ surface:: SurfaceError :: Lost | surface:: SurfaceError :: Outdated => {
416+ self . reconfigure_surface ( self . size ) ?;
417+ self . surface . acquire_next_frame ( ) . map_err ( |e| {
418+ RenderError :: Surface ( surface:: SurfaceError :: from ( e) )
419+ } ) ?
420+ }
421+ _ => return Err ( RenderError :: Surface ( high_level_err) ) ,
422+ }
417423 }
418- Err ( err) => return Err ( RenderError :: Surface ( err) ) ,
419424 } ;
420425
421426 let view = frame. texture_view ( ) ;
@@ -472,7 +477,7 @@ impl RenderContext {
472477 if need_recreate {
473478 self . msaa_color = Some (
474479 platform:: texture:: ColorAttachmentTextureBuilder :: new (
475- self . config . format ,
480+ self . config . format . to_platform ( ) ,
476481 )
477482 . with_size ( self . size . 0 . max ( 1 ) , self . size . 1 . max ( 1 ) )
478483 . with_sample_count ( sample_count)
@@ -1039,12 +1044,13 @@ impl RenderContext {
10391044 . resize ( & self . gpu , size)
10401045 . map_err ( RenderError :: Configuration ) ?;
10411046
1042- let config = self . surface . configuration ( ) . cloned ( ) . ok_or_else ( || {
1047+ let platform_config = self . surface . configuration ( ) . ok_or_else ( || {
10431048 RenderError :: Configuration ( "Surface was not configured" . to_string ( ) )
10441049 } ) ?;
10451050
1051+ let config = surface:: SurfaceConfig :: from_platform ( platform_config) ;
10461052 self . present_mode = config. present_mode ;
1047- self . texture_usage = texture :: TextureUsages :: from_platform ( config. usage ) ;
1053+ self . texture_usage = config. usage ;
10481054 self . config = config;
10491055 return Ok ( ( ) ) ;
10501056 }
@@ -1089,12 +1095,12 @@ impl RenderContext {
10891095/// acquisition or command encoding. The renderer logs these and continues when
10901096/// possible; callers SHOULD treat them as warnings unless persistent.
10911097pub enum RenderError {
1092- Surface ( platform :: surface:: SurfaceError ) ,
1098+ Surface ( surface:: SurfaceError ) ,
10931099 Configuration ( String ) ,
10941100}
10951101
1096- impl From < platform :: surface:: SurfaceError > for RenderError {
1097- fn from ( error : platform :: surface:: SurfaceError ) -> Self {
1102+ impl From < surface:: SurfaceError > for RenderError {
1103+ fn from ( error : surface:: SurfaceError ) -> Self {
10981104 return RenderError :: Surface ( error) ;
10991105 }
11001106}
0 commit comments