Skip to content

Commit

Permalink
[rs] Merge #157
Browse files Browse the repository at this point in the history
157: Handle resizing in hello-triangle r=kvark a=quadrupleslap

Nothing gets drawn on my computer unless the swap chain is resized along with the window.

```
$ uname -a
Linux red 5.3.7-arch1-1-ARCH #1 SMP PREEMPT Fri Oct 18 00:17:03 UTC 2019 x86_64 GNU/Linux
$ wmctrl -m
Name: bspwm
Class: wm
PID: 665
Window manager's "showing the desktop" mode: N/A
```

Co-authored-by: Ram Kaniyur <quadrupleslap@gmail.com>
  • Loading branch information
bors[bot] and quadrupleslap authored Jan 12, 2020
2 parents 1592567 + b10b76f commit 39e167d
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 39e167d

Please sign in to comment.