Skip to content

Commit b7c6b0f

Browse files
authored
(fix) Smooth resizing for macOS (#7)
1 parent f145f88 commit b7c6b0f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/graphics.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ impl<'window> Gpu<'window> {
6565
let surface = instance.create_surface(Arc::clone(&window)).unwrap();
6666
let push_const_size = std::mem::size_of::<[f32; 2]>() as u32;
6767

68+
// Jitter when resizing windows on macOS
69+
// https://github.com/gfx-rs/wgpu/issues/3756
70+
// https://github.com/gfx-rs/wgpu/pull/6107
71+
// https://thume.ca/2019/06/19/glitchless-metal-window-resizing/
72+
// https://raphlinus.github.io/rust/gui/2019/06/21/smooth-resize-test.html
73+
#[allow(invalid_reference_casting)]
74+
unsafe {
75+
surface.as_hal::<wgpu::hal::metal::Api, _, ()>(|surface| {
76+
if let Some(surface_ref) = surface {
77+
let surface_mut = &mut *(surface_ref as *const wgpu::hal::metal::Surface
78+
as *mut wgpu::hal::metal::Surface);
79+
surface_mut.present_with_transaction = true;
80+
}
81+
});
82+
}
83+
6884
let adapter = instance
6985
.request_adapter(&wgpu::RequestAdapterOptions {
7086
power_preference: wgpu::PowerPreference::default(),

0 commit comments

Comments
 (0)