Changeset 502bd0b in opengl-game for vulkan-utils.cpp


Ignore:
Timestamp:
Sep 23, 2019, 2:02:47 AM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
91c89f7
Parents:
c1c2021
Message:

In vulkangame, add code to create a swap chain

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-utils.cpp

    rc1c2021 r502bd0b  
    125125   return details;
    126126}
     127
     128VkSurfaceFormatKHR VulkanUtils::chooseSwapSurfaceFormat(const vector<VkSurfaceFormatKHR>& availableFormats) {
     129   for (const auto& availableFormat : availableFormats) {
     130      if (availableFormat.format == VK_FORMAT_B8G8R8A8_UNORM && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
     131         return availableFormat;
     132      }
     133   }
     134
     135   return availableFormats[0];
     136}
     137
     138VkPresentModeKHR VulkanUtils::chooseSwapPresentMode(const vector<VkPresentModeKHR>& availablePresentModes) {
     139   VkPresentModeKHR bestMode = VK_PRESENT_MODE_FIFO_KHR;
     140
     141   for (const auto& availablePresentMode : availablePresentModes) {
     142      if (availablePresentMode == VK_PRESENT_MODE_MAILBOX_KHR) {
     143         return availablePresentMode;
     144      }
     145      else if (availablePresentMode == VK_PRESENT_MODE_IMMEDIATE_KHR) {
     146         bestMode = availablePresentMode;
     147      }
     148   }
     149
     150   return bestMode;
     151}
     152
     153VkExtent2D VulkanUtils::chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, int width, int height) {
     154   if (capabilities.currentExtent.width != numeric_limits<uint32_t>::max()) {
     155      return capabilities.currentExtent;
     156   } else {
     157      VkExtent2D actualExtent = {
     158         static_cast<uint32_t>(width),
     159         static_cast<uint32_t>(height)
     160      };
     161
     162      actualExtent.width = std::max(capabilities.minImageExtent.width, std::min(capabilities.maxImageExtent.width, actualExtent.width));
     163      actualExtent.height = std::max(capabilities.minImageExtent.height, std::min(capabilities.maxImageExtent.height, actualExtent.height));
     164
     165      return actualExtent;
     166   }
     167}
Note: See TracChangeset for help on using the changeset viewer.