Skip to content

Commit

Permalink
Try #245:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] committed Jul 16, 2019
2 parents 183058d + c5c7092 commit bcf2567
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/hello_triangle_c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ int main() {
.format = WGPUTextureFormat_Bgra8Unorm,
.width = prev_width,
.height = prev_height,
.present_mode = WGPUPresentMode_Vsync,
});

while (!glfwWindowShouldClose(window)) {
Expand All @@ -213,6 +214,7 @@ int main() {
.format = WGPUTextureFormat_Bgra8Unorm,
.width = width,
.height = height,
.present_mode = WGPUPresentMode_Vsync,
});
}

Expand Down
8 changes: 7 additions & 1 deletion ffi/wgpu.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define WGPU_LOCAL

/* Generated with cbindgen:0.8.7 */
/* Generated with cbindgen:0.9.0 */

#include <stdarg.h>
#include <stdbool.h>
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -577,6 +582,7 @@ typedef struct {
WGPUTextureFormat format;
uint32_t width;
uint32_t height;
WGPUPresentMode present_mode;
} WGPUSwapChainDescriptor;

typedef struct {
Expand Down
4 changes: 4 additions & 0 deletions wgpu-native/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
8 changes: 8 additions & 0 deletions wgpu-native/src/swap_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,21 @@ pub struct SwapChain<B: hal::Backend> {
pub(crate) command_pool: hal::CommandPool<B, hal::General>,
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub enum PresentMode {
NoVsync = 0,
Vsync = 1,
}

#[repr(C)]
#[derive(Clone, Debug)]
pub struct SwapChainDescriptor {
pub usage: resource::TextureUsage,
pub format: resource::TextureFormat,
pub width: u32,
pub height: u32,
pub present_mode: PresentMode,
}

impl SwapChainDescriptor {
Expand Down

0 comments on commit bcf2567

Please sign in to comment.