|
| 1 | +#include <algorithm> |
1 | 2 | #include <iostream> |
2 | 3 | #include <stdexcept> |
3 | 4 | #include <cstdlib> |
@@ -58,11 +59,27 @@ class HelloTriangleApplication { |
58 | 59 | .pEngineName = "No Engine", |
59 | 60 | .engineVersion = VK_MAKE_VERSION( 1, 0, 0 ), |
60 | 61 | .apiVersion = vk::ApiVersion14 }; |
| 62 | + |
| 63 | + // Get the required instance extensions from GLFW. |
61 | 64 | uint32_t glfwExtensionCount = 0; |
62 | 65 | auto glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); |
| 66 | + |
| 67 | + // Check if the required GLFW extensions are supported by the Vulkan implementation. |
| 68 | + auto extensionProperties = context.enumerateInstanceExtensionProperties(); |
| 69 | + for (uint32_t i = 0; i < glfwExtensionCount; ++i) |
| 70 | + { |
| 71 | + if (std::ranges::none_of(extensionProperties, |
| 72 | + [glfwExtension = glfwExtensions[i]](auto const& extensionProperty) |
| 73 | + { return strcmp(extensionProperty.extensionName, glfwExtension) == 0; })) |
| 74 | + { |
| 75 | + throw std::runtime_error("Required GLFW extension not supported: " + std::string(glfwExtensions[i])); |
| 76 | + } |
| 77 | + } |
| 78 | + |
63 | 79 | vk::InstanceCreateInfo createInfo{ |
64 | 80 | .pApplicationInfo = &appInfo, |
65 | | - .ppEnabledLayerNames = glfwExtensions}; |
| 81 | + .enabledExtensionCount = glfwExtensionCount, |
| 82 | + .ppEnabledExtensionNames = glfwExtensions}; |
66 | 83 | instance = vk::raii::Instance(context, createInfo); |
67 | 84 | } |
68 | 85 | }; |
|
0 commit comments