From d995d66f8969006ea3b43baf2be62f248291393a Mon Sep 17 00:00:00 2001 From: Asuro Date: Wed, 3 Nov 2021 05:01:42 +0100 Subject: [PATCH] vsync --- src/config.rs | 24 ++++++++++++++++++++++-- src/vulkan/mod.rs | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 92cb1b3..7235797 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,7 +2,7 @@ use std::{convert::TryInto, fs}; use serde_derive::{Deserialize, Serialize}; use toml; -use vulkano::image::SampleCount; +use vulkano::{image::SampleCount, swapchain::PresentMode}; #[derive(Debug, Serialize, Deserialize, Clone, Copy)] pub struct LogConfigInput { @@ -27,7 +27,8 @@ impl LogConfig { #[derive(Debug, Serialize, Deserialize, Clone, Copy)] pub struct RenderConfig { - pub msaa_samples: u32 + pub msaa_samples: u32, + pub vsync: PresentModeConfig, } impl RenderConfig { @@ -38,4 +39,23 @@ impl RenderConfig { pub fn get_msaa(&self) -> Option { if self.msaa_samples > 0 { self.msaa_samples.try_into().ok() } else { None } } +} + +#[derive(Debug, Serialize, Deserialize, Clone, Copy)] +pub enum PresentModeConfig { + Immediate, + Mailbox, + Fifo, + FifoRelaxed, +} + +impl Into for PresentModeConfig { + fn into(self) -> PresentMode { + match self { + PresentModeConfig::Immediate => PresentMode::Immediate, + PresentModeConfig::Mailbox => PresentMode::Mailbox, + PresentModeConfig::Fifo => PresentMode::Fifo, + PresentModeConfig::FifoRelaxed => PresentMode::Relaxed, + } + } } \ No newline at end of file diff --git a/src/vulkan/mod.rs b/src/vulkan/mod.rs index bab14aa..69b2a8d 100644 --- a/src/vulkan/mod.rs +++ b/src/vulkan/mod.rs @@ -245,7 +245,7 @@ impl VulkanRenderer { .sharing_mode(&queue) .transform(SurfaceTransform::Identity) .composite_alpha(alpha) - .present_mode(PresentMode::Fifo) + .present_mode(render_config.vsync.into()) .fullscreen_exclusive(FullscreenExclusive::Default) .clipped(true) .color_space(color_space)