Archived
1
Fork 0

Properly choose swapchain image format

This commit is contained in:
Joshua Goins 2018-09-29 21:28:15 -04:00
parent 517c4504c6
commit 322309061d

View file

@ -39,6 +39,12 @@ RenderTarget* Renderer::createSurfaceRenderTarget(VkSurfaceKHR surface) {
VkSurfaceFormatKHR* surfaceFormats = new VkSurfaceFormatKHR[surfaceFormatCount];
vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice_, surface, &surfaceFormatCount, surfaceFormats);
uint32_t chosenFormat = 0;
for(uint32_t i = 0; i < surfaceFormatCount; i++) {
if(surfaceFormats[i].colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
chosenFormat = i;
}
VkBool32 supported = false;
vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice_, queueIndices.presentation, surface, &supported);
@ -46,8 +52,8 @@ RenderTarget* Renderer::createSurfaceRenderTarget(VkSurfaceKHR surface) {
swapchainCreateInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
swapchainCreateInfo.surface = surface;
swapchainCreateInfo.minImageCount = surfaceCapabilities.minImageCount;
swapchainCreateInfo.imageColorSpace = surfaceFormats[0].colorSpace;
swapchainCreateInfo.imageFormat = surfaceFormats[0].format;
swapchainCreateInfo.imageColorSpace = surfaceFormats[chosenFormat].colorSpace;
swapchainCreateInfo.imageFormat = surfaceFormats[chosenFormat].format;
swapchainCreateInfo.imageExtent = surfaceCapabilities.currentExtent;
swapchainCreateInfo.imageArrayLayers = 1;
swapchainCreateInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;