Skip to content

Commit

Permalink
[rs] Handle resizing in hello-triangle
Browse files Browse the repository at this point in the history
  • Loading branch information
quadrupleslap committed Jan 11, 2020
1 parent 6a746ac commit b10b76f
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions wgpu/examples/hello-triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,26 @@ fn main() {
alpha_to_coverage_enabled: false,
});

let mut swap_chain = device.create_swap_chain(
&surface,
&wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
format: wgpu::TextureFormat::Bgra8UnormSrgb,
width: size.width.round() as u32,
height: size.height.round() as u32,
present_mode: wgpu::PresentMode::Vsync,
},
);
let mut sc_desc = wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
format: wgpu::TextureFormat::Bgra8UnormSrgb,
width: size.width.round() as u32,
height: size.height.round() as u32,
present_mode: wgpu::PresentMode::Vsync,
};

let mut swap_chain = device.create_swap_chain(&surface, &sc_desc);

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {
event::Event::MainEventsCleared => window.request_redraw(),
event::Event::WindowEvent { event: event::WindowEvent::Resized(size), .. } => {
let physical = size.to_physical(window.hidpi_factor());
sc_desc.width = physical.width.round() as u32;
sc_desc.height = physical.height.round() as u32;
swap_chain = device.create_swap_chain(&surface, &sc_desc);
}
event::Event::RedrawRequested(_) => {
let frame = swap_chain
.get_next_texture()
Expand Down

0 comments on commit b10b76f

Please sign in to comment.