@@ -186,6 +186,10 @@ impl RenderState {
186186 }
187187
188188 pub ( crate ) fn resize ( & mut self , width : u32 , height : u32 ) {
189+ if width == self . desired_width && height == self . desired_height {
190+ return ;
191+ }
192+
189193 self . desired_width = width;
190194 self . desired_height = height;
191195
@@ -238,6 +242,14 @@ impl RenderState {
238242 }
239243
240244 pub ( crate ) fn render ( & mut self , window : & Window ) -> Result < ( ) , RenderError > {
245+ let ui_scale = if let Some ( ui_texture) = & self . ui_texture
246+ && ( self . desired_width != ui_texture. width ( ) || self . desired_height != ui_texture. height ( ) )
247+ {
248+ Some ( [ self . desired_width as f32 / ui_texture. width ( ) as f32 , self . desired_height as f32 / ui_texture. height ( ) as f32 ] )
249+ } else {
250+ None
251+ } ;
252+
241253 if let Some ( scene) = self . overlays_scene . take ( ) {
242254 self . render_overlays ( scene) ;
243255 }
@@ -255,7 +267,7 @@ impl RenderState {
255267 view : & view,
256268 resolve_target : None ,
257269 ops : wgpu:: Operations {
258- load : wgpu:: LoadOp :: Clear ( wgpu:: Color { r : 0.01 , g : 0.01 , b : 0.01 , a : 1.0 } ) ,
270+ load : wgpu:: LoadOp :: Clear ( wgpu:: Color { r : 0.01 , g : 0.01 , b : 0.01 , a : 1. } ) ,
259271 store : wgpu:: StoreOp :: Store ,
260272 } ,
261273 depth_slice : None ,
@@ -272,6 +284,8 @@ impl RenderState {
272284 bytemuck:: bytes_of ( & Constants {
273285 viewport_scale : self . viewport_scale ,
274286 viewport_offset : self . viewport_offset ,
287+ ui_scale : ui_scale. unwrap_or ( [ 1. , 1. ] ) ,
288+ background_color : [ 255. / 33. , 255. / 33. , 255. / 33. , 255. / 33. ] , // #212121
275289 } ) ,
276290 ) ;
277291 if let Some ( bind_group) = & self . bind_group {
@@ -285,9 +299,7 @@ impl RenderState {
285299 window. pre_present_notify ( ) ;
286300 output. present ( ) ;
287301
288- if let Some ( ui_texture) = & self . ui_texture
289- && ( self . desired_width != ui_texture. width ( ) || self . desired_height != ui_texture. height ( ) )
290- {
302+ if ui_scale. is_some ( ) {
291303 return Err ( RenderError :: OutdatedUITextureError ) ;
292304 }
293305
@@ -336,4 +348,6 @@ pub(crate) enum RenderError {
336348struct Constants {
337349 viewport_scale : [ f32 ; 2 ] ,
338350 viewport_offset : [ f32 ; 2 ] ,
351+ ui_scale : [ f32 ; 2 ] ,
352+ background_color : [ f32 ; 4 ] ,
339353}
0 commit comments