From 13fe63b6bf33ed9f940517ea44660ed6d4463ea3 Mon Sep 17 00:00:00 2001 From: amy Date: Tue, 7 Nov 2023 22:06:40 +0100 Subject: [PATCH] move to c++23; better swap mode determination --- .idea/QtSettings.xml | 10 +++++++++- CMakeLists.txt | 2 +- engine/vk/Swapchain.cpp | 21 +++++++++++++++------ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.idea/QtSettings.xml b/.idea/QtSettings.xml index 78911ca..c5f50f3 100644 --- a/.idea/QtSettings.xml +++ b/.idea/QtSettings.xml @@ -7,7 +7,15 @@ - + + + + + + diff --git a/CMakeLists.txt b/CMakeLists.txt index b5fd576..24beb93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.25) project("Vixen") set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) diff --git a/engine/vk/Swapchain.cpp b/engine/vk/Swapchain.cpp index 0d0e561..87e56ec 100644 --- a/engine/vk/Swapchain.cpp +++ b/engine/vk/Swapchain.cpp @@ -15,6 +15,9 @@ namespace Vixen::Vk { } VkSurfaceFormatKHR Swapchain::determineSurfaceFormat(const std::vector &available) { + if (available.empty()) + throw std::runtime_error("Failed to find suitable surface format"); + for (const auto &format: available) { if (format.format == VK_FORMAT_B8G8R8A8_SRGB && format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) @@ -25,13 +28,19 @@ namespace Vixen::Vk { } VkPresentModeKHR Swapchain::determinePresentMode(const std::vector &available) { - for (const auto &mode: available) { - if (mode == VK_PRESENT_MODE_MAILBOX_KHR) { - return mode; - } - } + if (available.empty()) + throw std::runtime_error("Failed to find suitable present mode"); + + if (std::ranges::contains(available, VK_PRESENT_MODE_MAILBOX_KHR)) + return VK_PRESENT_MODE_MAILBOX_KHR; + else if (std::ranges::contains(available, VK_PRESENT_MODE_FIFO_KHR)) + return VK_PRESENT_MODE_FIFO_KHR; + else if (std::ranges::contains(available, VK_PRESENT_MODE_FIFO_RELAXED_KHR)) + return VK_PRESENT_MODE_FIFO_RELAXED_KHR; + else if (std::ranges::contains(available, VK_PRESENT_MODE_IMMEDIATE_KHR)) + return VK_PRESENT_MODE_IMMEDIATE_KHR; - return VK_PRESENT_MODE_FIFO_KHR; + return available[0]; } const VkSurfaceFormatKHR &Swapchain::getFormat() const {