From df6bb48766c28b91401ea8fe0981a67fd37b3ef9 Mon Sep 17 00:00:00 2001 From: Christoph Haag Date: Tue, 31 Jan 2017 15:51:33 +0100 Subject: [PATCH] explicitely choose VK_FORMAT_B8G8R8A8_UNORM if it's not available, select the first available color format --- base/vulkanswapchain.hpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/base/vulkanswapchain.hpp b/base/vulkanswapchain.hpp index fe4f1ea7..1da64a20 100644 --- a/base/vulkanswapchain.hpp +++ b/base/vulkanswapchain.hpp @@ -225,16 +225,33 @@ public: if ((formatCount == 1) && (surfaceFormats[0].format == VK_FORMAT_UNDEFINED)) { colorFormat = VK_FORMAT_B8G8R8A8_UNORM; + colorSpace = surfaceFormats[0].colorSpace; } else { - // Always select the first available color format - // If you need a specific format (e.g. SRGB) you'd need to // iterate over the list of available surface format and - // check for it's presence - colorFormat = surfaceFormats[0].format; + // check for the presence of VK_FORMAT_B8G8R8A8_UNORM + bool found_B8G8R8A8_UNORM = false; + for (auto&& surfaceFormat : surfaceFormats) + { + if (surfaceFormat.format == VK_FORMAT_B8G8R8A8_UNORM) + { + colorFormat = surfaceFormat.format; + colorSpace = surfaceFormat.colorSpace; + found_B8G8R8A8_UNORM = true; + break; + } + } + + // in case VK_FORMAT_B8G8R8A8_UNORM is not available + // select the first available color format + if (!found_B8G8R8A8_UNORM) + { + colorFormat = surfaceFormats[0].format; + colorSpace = surfaceFormats[0].colorSpace; + } } - colorSpace = surfaceFormats[0].colorSpace; + } /**