Skip to content

Commit

Permalink
move to c++23; better swap mode determination
Browse files Browse the repository at this point in the history
  • Loading branch information
WinteryFox committed Nov 7, 2023
1 parent 173494b commit 13fe63b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
10 changes: 9 additions & 1 deletion .idea/QtSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 15 additions & 6 deletions engine/vk/Swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespace Vixen::Vk {
}

VkSurfaceFormatKHR Swapchain::determineSurfaceFormat(const std::vector<VkSurfaceFormatKHR> &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)
Expand All @@ -25,13 +28,19 @@ namespace Vixen::Vk {
}

VkPresentModeKHR Swapchain::determinePresentMode(const std::vector<VkPresentModeKHR> &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 {
Expand Down

0 comments on commit 13fe63b

Please sign in to comment.