@@ -77,6 +77,7 @@ pub struct GlassWindow {
7777 exit_on_esc : bool ,
7878 has_focus : bool ,
7979 last_surface_size : [ u32 ; 2 ] ,
80+ allowed_formats : Vec < TextureFormat > ,
8081}
8182
8283impl GlassWindow {
@@ -88,13 +89,11 @@ impl GlassWindow {
8889 ) -> Result < GlassWindow , CreateSurfaceError > {
8990 let size = [ window. inner_size ( ) . width , window. inner_size ( ) . height ] ;
9091 let surface = context. instance ( ) . create_surface ( window. clone ( ) ) ?;
91- let allowed_formats = GlassWindow :: allowed_surface_formats ( ) ;
92- if !( config. surface_format == allowed_formats[ 0 ]
93- || config. surface_format == allowed_formats[ 1 ] )
94- {
92+ let formats = surface. get_capabilities ( & context. adapter ( ) ) . formats ;
93+ if !formats. contains ( & config. surface_format ) {
9594 panic ! (
96- "{:?} not allowed. Surface should be created with either: {:?} or {:?}" ,
97- config. surface_format, allowed_formats [ 0 ] , allowed_formats [ 1 ]
95+ "{:?} not allowed. Allowed formats: {:?}" ,
96+ config. surface_format, formats
9897 ) ;
9998 }
10099 Ok ( GlassWindow {
@@ -107,6 +106,7 @@ impl GlassWindow {
107106 desired_maximum_frame_latency : config. desired_maximum_frame_latency ,
108107 has_focus : false ,
109108 last_surface_size : size,
109+ allowed_formats : formats,
110110 } )
111111 }
112112
@@ -128,6 +128,12 @@ impl GlassWindow {
128128
129129 /// Configure surface after window has changed. Use this to reconfigure the surface
130130 pub ( crate ) fn configure_surface ( & mut self , device : & Device , config : & SurfaceConfiguration ) {
131+ if !self . allowed_formats . contains ( & config. format ) {
132+ panic ! (
133+ "{:?} not allowed. Allowed formats: {:?}" ,
134+ config. format, self . allowed_formats
135+ ) ;
136+ }
131137 self . surface . configure ( device, config) ;
132138 self . present_mode = config. present_mode ;
133139 self . alpha_mode = config. alpha_mode ;
@@ -180,6 +186,11 @@ impl GlassWindow {
180186 } ;
181187 }
182188
189+ /// Return allowed texture formats for this window [`Surface`](wgpu::Surface)
190+ pub fn allowed_formats ( & self ) -> & Vec < TextureFormat > {
191+ & self . allowed_formats
192+ }
193+
183194 /// Return [`Surface`](wgpu::Surface) belonging to the window
184195 pub fn surface ( & self ) -> & Surface < ' _ > {
185196 & self . surface
@@ -200,12 +211,6 @@ impl GlassWindow {
200211 self . present_mode
201212 }
202213
203- /// Return allowed [`TextureFormat`](wgpu::TextureFormat)s for the surface.
204- /// These are `Bgra8UnormSrgb` and `Bgra8Unorm`
205- pub fn allowed_surface_formats ( ) -> [ TextureFormat ; 2 ] {
206- [ TextureFormat :: Bgra8UnormSrgb , TextureFormat :: Bgra8Unorm ]
207- }
208-
209214 /// Return default [`TextureFormat`](wgpu::TextureFormat)s
210215 pub fn default_surface_format ( ) -> TextureFormat {
211216 #[ cfg( target_os = "linux" ) ]
0 commit comments