Add context surface resizing
This commit is contained in:
		
							parent
							
								
									ba301451af
								
							
						
					
					
						commit
						1a92b52630
					
				| 
						 | 
					@ -66,4 +66,13 @@ impl Context {
 | 
				
			||||||
            queue,
 | 
					            queue,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn resize(&mut self, new_size: PhysicalSize<u32>) {
 | 
				
			||||||
 | 
					        if new_size.width > 0 && new_size.height > 0 {
 | 
				
			||||||
 | 
					            self.size = new_size;
 | 
				
			||||||
 | 
					            self.surface_config.width = new_size.width;
 | 
				
			||||||
 | 
					            self.surface_config.height = new_size.height;
 | 
				
			||||||
 | 
					            self.surface.configure(&self.device, &self.surface_config);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,7 @@ pub async fn run() {
 | 
				
			||||||
        .build(&event_loop)
 | 
					        .build(&event_loop)
 | 
				
			||||||
        .unwrap();
 | 
					        .unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let render_ctx = gfx::Context::new(&window, wgpu::Limits::default()).await;
 | 
					    let mut render_ctx = gfx::Context::new(&window, wgpu::Limits::default()).await;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    event_loop.run(move |event, _, control_flow| match event {
 | 
					    event_loop.run(move |event, _, control_flow| match event {
 | 
				
			||||||
        Event::WindowEvent {
 | 
					        Event::WindowEvent {
 | 
				
			||||||
| 
						 | 
					@ -32,6 +32,12 @@ pub async fn run() {
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                ..
 | 
					                ..
 | 
				
			||||||
            } => *control_flow = ControlFlow::Exit,
 | 
					            } => *control_flow = ControlFlow::Exit,
 | 
				
			||||||
 | 
					            WindowEvent::Resized(physical_size) => {
 | 
				
			||||||
 | 
					                render_ctx.resize(*physical_size);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
 | 
				
			||||||
 | 
					                render_ctx.resize(**new_inner_size);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            _ => {}
 | 
					            _ => {}
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        _ => {}
 | 
					        _ => {}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue