| 46 | }; |
| 47 | |
| 48 | class HelloTriangleApplication { |
| 49 | public: |
| 50 | void run() { |
| 51 | initWindow(); |
| 52 | initVulkan(); |
| 53 | mainLoop(); |
| 54 | cleanup(); |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | GLFWwindow* window; |
| 59 | |
| 60 | VkInstance instance; |
| 61 | VkDebugUtilsMessengerEXT debugMessenger; |
| 62 | |
| 63 | VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; |
| 64 | |
| 65 | void initWindow() { |
| 66 | glfwInit(); |
| 67 | |
| 68 | glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); |
| 69 | glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); |
| 70 | |
| 71 | window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr); |
| 72 | } |
| 73 | |
| 74 | void initVulkan() { |
| 75 | createInstance(); |
| 76 | setupDebugMessenger(); |
| 77 | pickPhysicalDevice(); |
| 78 | } |
| 79 | |
| 80 | void mainLoop() { |
| 81 | while (!glfwWindowShouldClose(window)) { |
| 82 | glfwPollEvents(); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | void cleanup() { |
| 87 | if (enableValidationLayers) { |
| 88 | DestroyDebugUtilsMessengerEXT(instance, debugMessenger, nullptr); |
| 89 | } |
| 90 | |
| 91 | vkDestroyInstance(instance, nullptr); |
| 92 | |
| 93 | glfwDestroyWindow(window); |
| 94 | |
| 95 | glfwTerminate(); |
| 96 | } |
| 97 | |
| 98 | void createInstance() { |
| 99 | if (enableValidationLayers && !checkValidationLayerSupport()) { |
| 100 | throw std::runtime_error("validation layers requested, but not available!"); |
| 101 | } |
| 102 | |
| 103 | VkApplicationInfo appInfo{}; |
| 104 | appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
| 105 | appInfo.pApplicationName = "Hello Triangle"; |
nothing calls this directly
no outgoing calls
no test coverage detected