MCPcopy Create free account
hub / github.com/SFML/SFML / setupSwapchain

Method setupSwapchain

examples/vulkan/Vulkan.cpp:734–852  ·  view source on GitHub ↗

Query surface formats and set up swapchain

Source from the content-addressed store, hash-verified

732
733 // Query surface formats and set up swapchain
734 void setupSwapchain()
735 {
736 // Select a surface format that supports RGBA color format
737 std::uint32_t objectCount = 0;
738
739 std::vector<VkSurfaceFormatKHR> surfaceFormats;
740
741 if (vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &objectCount, nullptr) != VK_SUCCESS)
742 {
743 vulkanAvailable = false;
744 return;
745 }
746
747 surfaceFormats.resize(objectCount);
748
749 if (vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &objectCount, surfaceFormats.data()) != VK_SUCCESS)
750 {
751 vulkanAvailable = false;
752 return;
753 }
754
755 if ((surfaceFormats.size() == 1) && (surfaceFormats[0].format == VK_FORMAT_UNDEFINED))
756 {
757 swapchainFormat.format = VK_FORMAT_B8G8R8A8_UNORM;
758 swapchainFormat.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
759 }
760 else if (!surfaceFormats.empty())
761 {
762 for (const VkSurfaceFormatKHR& surfaceFormat : surfaceFormats)
763 {
764 if ((surfaceFormat.format == VK_FORMAT_B8G8R8A8_UNORM) &&
765 (surfaceFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR))
766 {
767 swapchainFormat.format = VK_FORMAT_B8G8R8A8_UNORM;
768 swapchainFormat.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
769
770 break;
771 }
772 }
773
774 if (swapchainFormat.format == VK_FORMAT_UNDEFINED)
775 swapchainFormat = surfaceFormats[0];
776 }
777 else
778 {
779 vulkanAvailable = false;
780 return;
781 }
782
783 // Select a swapchain present mode
784 std::vector<VkPresentModeKHR> presentModes;
785
786 if (vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &objectCount, nullptr) != VK_SUCCESS)
787 {
788 vulkanAvailable = false;
789 return;
790 }
791

Callers

nothing calls this directly

Calls 3

resizeMethod · 0.45
getSizeMethod · 0.45

Tested by

no test coverage detected