Skip to content

Commit 3d57154

Browse files
committed
Rework checkValidationLayerSupport to make it easier to follow
Fixes #56
1 parent dcdbedd commit 3d57154

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

en/03_Drawing_a_triangle/00_Setup/02_Validation_layers.adoc

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const std::vector<const char*> validationLayers = {
7474

7575
We'll add a new function `checkValidationLayerSupport` that checks if all of the requested layers are available.
7676
First list all of the available layers using the `vkEnumerateInstanceLayerProperties` function.
77-
Its usage is identical to that of `vkEnumerateInstanceExtensionProperties` which was discussed in the instance creation chapter.
77+
Its usage is identical to that of `vkEnumerateInstanceExtensionProperties` which was discussed in the instance creation chapter. Next, check if all of the layers in `validationLayers` exist in the `availableLayers` list. You may need to include `<cstring>` for `strcmp`.
7878

7979
[,c++]
8080
----
@@ -85,31 +85,23 @@ bool checkValidationLayerSupport() {
8585
std::vector<VkLayerProperties> availableLayers(layerCount);
8686
vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data());
8787
88-
return false;
89-
}
90-
----
88+
for (const char* layerName : validationLayers) {
89+
bool layerFound = false;
9190
92-
Next, check if all of the layers in `validationLayers` exist in the `availableLayers` list.
93-
You may need to include `<cstring>` for `strcmp`.
94-
95-
[,c++]
96-
----
97-
for (const char* layerName : validationLayers) {
98-
bool layerFound = false;
91+
for (const auto& layerProperties : availableLayers) {
92+
if (strcmp(layerName, layerProperties.layerName) == 0) {
93+
layerFound = true;
94+
break;
95+
}
96+
}
9997
100-
for (const auto& layerProperties : availableLayers) {
101-
if (strcmp(layerName, layerProperties.layerName) == 0) {
102-
layerFound = true;
103-
break;
98+
if (!layerFound) {
99+
return false;
104100
}
105101
}
106102
107-
if (!layerFound) {
108-
return false;
109-
}
103+
return true;
110104
}
111-
112-
return true;
113105
----
114106

115107
We can now use this function in `createInstance`:

0 commit comments

Comments
 (0)