Vulkan capabilities.currentExtent.width 为 uint32_t max 的意义

在看交换链的那一节 https://vulkan-tutorial.com/Drawing_a_triangle/Presentation/Swap_chain

这里面说到设置 SwapExtent 的时候要将 capabilities.currentExtent.width 和 uint32_t max 比较

#include  // Necessary for uint32_t
#include  // Necessary for std::numeric_limits
#include  // Necessary for std::clamp

...

VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities) {
    if (capabilities.currentExtent.width != std::numeric_limits<uint32_t>::max()) {
        return capabilities.currentExtent;
    } else {
        int width, height;
        glfwGetFramebufferSize(window, &width, &height);

        VkExtent2D actualExtent = {
            static_cast<uint32_t>(width),
            static_cast<uint32_t>(height)
        };

        actualExtent.width = std::clamp(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width);
        actualExtent.height = std::clamp(actualExtent.height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height);

        return actualExtent;
    }
}

我不知道为什么要和 max 比……?难道是默认是 max?看上去也不像啊

搜了一下 https://books.google.com.hk/books?id=aVqWDwAAQBAJ&pg=PA307&lpg=PA307&dq=capabilities.currentExtent.width+!%3D+std::numeric_limits%3Cuint32_t%3E::max()&source=bl&ots=IhVg_ZgxyI&sig=ACfU3U3Q6EOcZHGmlPMq1RfQo2S3VDZE3Q&hl=en&sa=X&ved=2ahUKEwiYudLXgdqAAxXvmVYBHdSnDcwQ6AF6BAgmEAM#v=onepage&q&f=false

这里面说到,如果屏幕中的像素长宽与窗口的长宽不一致的话,window manager 就会把 capabilities.currentExtent.width 设为 uint32_t max

所以这里我们发现了不一致的话,我们就要重新设置

你可能感兴趣的:(GameEngineDev,c++,vulkan)