Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee94881

Browse files
committed
Remove handling of VK_FORMAT_UNDEFINED (fixes #135)
1 parent 6a0a3f7 commit ee94881

25 files changed

Lines changed: 25 additions & 132 deletions

03_Drawing_a_triangle/01_Presentation/01_Swap_chain.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,7 @@ Working directly with SRGB colors is a little bit challenging, so we'll use
233233
standard RGB for the color format, of which one of the most common ones is
234234
`VK_FORMAT_B8G8R8A8_UNORM`.
235235
236-
The best case scenario is that the surface has no preferred format, which Vulkan
237-
indicates by only returning one `VkSurfaceFormatKHR` entry which has its
238-
`format` member set to `VK_FORMAT_UNDEFINED`.
239-
240-
```c++
241-
if (availableFormats.size() == 1 && availableFormats[0].format == VK_FORMAT_UNDEFINED) {
242-
return {VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
243-
}
244-
```
245-
246-
If we're not free to choose any format, then we'll go through the list and see
247-
if the preferred combination is available:
236+
Let's go through the list and see if the preferred combination is available:
248237
249238
```c++
250239
for (const auto& availableFormat : availableFormats) {

code/06_swap_chain_creation.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class HelloTriangleApplication {
155155
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
156156
} else {
157157
createInfo.enabledLayerCount = 0;
158-
158+
159159
createInfo.pNext = nullptr;
160160
}
161161

@@ -310,10 +310,6 @@ class HelloTriangleApplication {
310310
}
311311

312312
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats) {
313-
if (availableFormats.size() == 1 && availableFormats[0].format == VK_FORMAT_UNDEFINED) {
314-
return {VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
315-
}
316-
317313
for (const auto& availableFormat : availableFormats) {
318314
if (availableFormat.format == VK_FORMAT_B8G8R8A8_UNORM && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
319315
return availableFormat;

code/07_image_views.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class HelloTriangleApplication {
161161
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
162162
} else {
163163
createInfo.enabledLayerCount = 0;
164-
164+
165165
createInfo.pNext = nullptr;
166166
}
167167

@@ -341,10 +341,6 @@ class HelloTriangleApplication {
341341
}
342342

343343
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats) {
344-
if (availableFormats.size() == 1 && availableFormats[0].format == VK_FORMAT_UNDEFINED) {
345-
return {VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
346-
}
347-
348344
for (const auto& availableFormat : availableFormats) {
349345
if (availableFormat.format == VK_FORMAT_B8G8R8A8_UNORM && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
350346
return availableFormat;

code/08_graphics_pipeline.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class HelloTriangleApplication {
162162
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
163163
} else {
164164
createInfo.enabledLayerCount = 0;
165-
165+
166166
createInfo.pNext = nullptr;
167167
}
168168

@@ -346,10 +346,6 @@ class HelloTriangleApplication {
346346
}
347347

348348
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats) {
349-
if (availableFormats.size() == 1 && availableFormats[0].format == VK_FORMAT_UNDEFINED) {
350-
return {VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
351-
}
352-
353349
for (const auto& availableFormat : availableFormats) {
354350
if (availableFormat.format == VK_FORMAT_B8G8R8A8_UNORM && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
355351
return availableFormat;

code/09_shader_modules.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class HelloTriangleApplication {
163163
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
164164
} else {
165165
createInfo.enabledLayerCount = 0;
166-
166+
167167
createInfo.pNext = nullptr;
168168
}
169169

@@ -382,10 +382,6 @@ class HelloTriangleApplication {
382382
}
383383

384384
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats) {
385-
if (availableFormats.size() == 1 && availableFormats[0].format == VK_FORMAT_UNDEFINED) {
386-
return {VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
387-
}
388-
389385
for (const auto& availableFormat : availableFormats) {
390386
if (availableFormat.format == VK_FORMAT_B8G8R8A8_UNORM && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
391387
return availableFormat;

code/10_fixed_functions.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class HelloTriangleApplication {
167167
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
168168
} else {
169169
createInfo.enabledLayerCount = 0;
170-
170+
171171
createInfo.pNext = nullptr;
172172
}
173173

@@ -454,10 +454,6 @@ class HelloTriangleApplication {
454454
}
455455

456456
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats) {
457-
if (availableFormats.size() == 1 && availableFormats[0].format == VK_FORMAT_UNDEFINED) {
458-
return {VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
459-
}
460-
461457
for (const auto& availableFormat : availableFormats) {
462458
if (availableFormat.format == VK_FORMAT_B8G8R8A8_UNORM && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
463459
return availableFormat;

code/11_render_passes.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class HelloTriangleApplication {
170170
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
171171
} else {
172172
createInfo.enabledLayerCount = 0;
173-
173+
174174
createInfo.pNext = nullptr;
175175
}
176176

@@ -489,10 +489,6 @@ class HelloTriangleApplication {
489489
}
490490

491491
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats) {
492-
if (availableFormats.size() == 1 && availableFormats[0].format == VK_FORMAT_UNDEFINED) {
493-
return {VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
494-
}
495-
496492
for (const auto& availableFormat : availableFormats) {
497493
if (availableFormat.format == VK_FORMAT_B8G8R8A8_UNORM && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
498494
return availableFormat;

code/12_graphics_pipeline_complete.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class HelloTriangleApplication {
172172
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
173173
} else {
174174
createInfo.enabledLayerCount = 0;
175-
175+
176176
createInfo.pNext = nullptr;
177177
}
178178

@@ -510,10 +510,6 @@ class HelloTriangleApplication {
510510
}
511511

512512
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats) {
513-
if (availableFormats.size() == 1 && availableFormats[0].format == VK_FORMAT_UNDEFINED) {
514-
return {VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
515-
}
516-
517513
for (const auto& availableFormat : availableFormats) {
518514
if (availableFormat.format == VK_FORMAT_B8G8R8A8_UNORM && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
519515
return availableFormat;

code/13_framebuffers.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class HelloTriangleApplication {
178178
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
179179
} else {
180180
createInfo.enabledLayerCount = 0;
181-
181+
182182
createInfo.pNext = nullptr;
183183
}
184184

@@ -539,10 +539,6 @@ class HelloTriangleApplication {
539539
}
540540

541541
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats) {
542-
if (availableFormats.size() == 1 && availableFormats[0].format == VK_FORMAT_UNDEFINED) {
543-
return {VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
544-
}
545-
546542
for (const auto& availableFormat : availableFormats) {
547543
if (availableFormat.format == VK_FORMAT_B8G8R8A8_UNORM && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
548544
return availableFormat;

code/14_command_buffers.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class HelloTriangleApplication {
185185
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
186186
} else {
187187
createInfo.enabledLayerCount = 0;
188-
188+
189189
createInfo.pNext = nullptr;
190190
}
191191

@@ -605,10 +605,6 @@ class HelloTriangleApplication {
605605
}
606606

607607
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats) {
608-
if (availableFormats.size() == 1 && availableFormats[0].format == VK_FORMAT_UNDEFINED) {
609-
return {VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
610-
}
611-
612608
for (const auto& availableFormat : availableFormats) {
613609
if (availableFormat.format == VK_FORMAT_B8G8R8A8_UNORM && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
614610
return availableFormat;

0 commit comments

Comments
 (0)