diff --git a/examples/hello_triangle_c/main.c b/examples/hello_triangle_c/main.c index e2536cba7f..32f0e06bf5 100644 --- a/examples/hello_triangle_c/main.c +++ b/examples/hello_triangle_c/main.c @@ -197,6 +197,7 @@ int main() { .format = WGPUTextureFormat_Bgra8Unorm, .width = prev_width, .height = prev_height, + .present_mode = WGPUPresentMode_Vsync, }); while (!glfwWindowShouldClose(window)) { @@ -213,6 +214,7 @@ int main() { .format = WGPUTextureFormat_Bgra8Unorm, .width = width, .height = height, + .present_mode = WGPUPresentMode_Vsync, }); } diff --git a/ffi/wgpu.h b/ffi/wgpu.h index b78df368f7..3ac3a6b58d 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -1,6 +1,6 @@ #define WGPU_LOCAL -/* Generated with cbindgen:0.8.7 */ +/* Generated with cbindgen:0.9.0 */ #include #include @@ -110,6 +110,11 @@ typedef enum { WGPUPowerPreference_HighPerformance = 2, } WGPUPowerPreference; +typedef enum { + WGPUPresentMode_NoVsync = 0, + WGPUPresentMode_Vsync = 1, +} WGPUPresentMode; + typedef enum { WGPUPrimitiveTopology_PointList = 0, WGPUPrimitiveTopology_LineList = 1, @@ -577,6 +582,7 @@ typedef struct { WGPUTextureFormat format; uint32_t width; uint32_t height; + WGPUPresentMode present_mode; } WGPUSwapChainDescriptor; typedef struct { diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index 819405abe5..0a816b614d 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -1816,6 +1816,10 @@ pub fn device_create_swap_chain( ); //TODO: check for supported config.composite_alpha = hal::window::CompositeAlpha::OPAQUE; + config.present_mode = match desc.present_mode { + swap_chain::PresentMode::NoVsync => hal::PresentMode::Immediate, + swap_chain::PresentMode::Vsync => hal::PresentMode::Fifo, + }; if let Some(formats) = formats { assert!( diff --git a/wgpu-native/src/swap_chain.rs b/wgpu-native/src/swap_chain.rs index 491cecadfe..8f4417c14b 100644 --- a/wgpu-native/src/swap_chain.rs +++ b/wgpu-native/src/swap_chain.rs @@ -80,6 +80,13 @@ pub struct SwapChain { pub(crate) command_pool: hal::CommandPool, } +#[repr(C)] +#[derive(Copy, Clone, Debug)] +pub enum PresentMode { + NoVsync = 0, + Vsync = 1, +} + #[repr(C)] #[derive(Clone, Debug)] pub struct SwapChainDescriptor { @@ -87,6 +94,7 @@ pub struct SwapChainDescriptor { pub format: resource::TextureFormat, pub width: u32, pub height: u32, + pub present_mode: PresentMode, } impl SwapChainDescriptor {