| 108 | } |
| 109 | |
| 110 | inline VkSurfaceFormatKHR choose_surface_format( |
| 111 | const VkSurfaceFormatKHR requested_surface_format, |
| 112 | const std::vector<VkSurfaceFormatKHR> &available_surface_formats, |
| 113 | const std::vector<VkSurfaceFormatKHR> &surface_format_priority_list) |
| 114 | { |
| 115 | // Try to find the requested surface format in the supported surface formats |
| 116 | auto surface_format_it = std::ranges::find_if( |
| 117 | available_surface_formats, |
| 118 | [&requested_surface_format](const VkSurfaceFormatKHR &surface) { |
| 119 | if (surface.format == requested_surface_format.format && |
| 120 | surface.colorSpace == requested_surface_format.colorSpace) |
| 121 | { |
| 122 | return true; |
| 123 | } |
| 124 | |
| 125 | return false; |
| 126 | }); |
| 127 | |
| 128 | // If the requested surface format isn't found, then try to request a format from the priority list |
| 129 | if (surface_format_it == available_surface_formats.end()) |
| 130 | { |
| 131 | for (auto &surface_format : surface_format_priority_list) |
| 132 | { |
| 133 | surface_format_it = std::ranges::find_if( |
| 134 | available_surface_formats, |
| 135 | [&surface_format](const VkSurfaceFormatKHR &surface) { |
| 136 | if (surface.format == surface_format.format && |
| 137 | surface.colorSpace == surface_format.colorSpace) |
| 138 | { |
| 139 | return true; |
| 140 | } |
| 141 | |
| 142 | return false; |
| 143 | }); |
| 144 | if (surface_format_it != available_surface_formats.end()) |
| 145 | { |
| 146 | LOGW("(Swapchain) Surface format ({}) not supported. Selecting ({}).", to_string(requested_surface_format), to_string(*surface_format_it)); |
| 147 | return *surface_format_it; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | // If nothing found, default to the first supported surface format |
| 152 | surface_format_it = available_surface_formats.begin(); |
| 153 | LOGW("(Swapchain) Surface format ({}) not supported. Selecting ({}).", to_string(requested_surface_format), to_string(*surface_format_it)); |
| 154 | } |
| 155 | else |
| 156 | { |
| 157 | LOGI("(Swapchain) Surface format selected: {}", to_string(requested_surface_format)); |
| 158 | } |
| 159 | |
| 160 | return *surface_format_it; |
| 161 | } |
| 162 | |
| 163 | inline VkSurfaceTransformFlagBitsKHR choose_transform( |
| 164 | VkSurfaceTransformFlagBitsKHR request_transform, |