| 48 | }; |
| 49 | |
| 50 | class HelloTriangleApplication { |
| 51 | public: |
| 52 | void run() { |
| 53 | initWindow(); |
| 54 | initVulkan(); |
| 55 | mainLoop(); |
| 56 | cleanup(); |
| 57 | } |
| 58 | |
| 59 | private: |
| 60 | GLFWwindow* window; |
| 61 | |
| 62 | VkInstance instance; |
| 63 | VkDebugUtilsMessengerEXT debugMessenger; |
| 64 | VkSurfaceKHR surface; |
| 65 | |
| 66 | VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; |
| 67 | VkDevice device; |
| 68 | |
| 69 | VkQueue graphicsQueue; |
| 70 | VkQueue presentQueue; |
| 71 | |
| 72 | void initWindow() { |
| 73 | glfwInit(); |
| 74 | |
| 75 | glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); |
| 76 | glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); |
| 77 | |
| 78 | window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr); |
| 79 | } |
| 80 | |
| 81 | void initVulkan() { |
| 82 | createInstance(); |
| 83 | setupDebugMessenger(); |
| 84 | createSurface(); |
| 85 | pickPhysicalDevice(); |
| 86 | createLogicalDevice(); |
| 87 | } |
| 88 | |
| 89 | void mainLoop() { |
| 90 | while (!glfwWindowShouldClose(window)) { |
| 91 | glfwPollEvents(); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | void cleanup() { |
| 96 | vkDestroyDevice(device, nullptr); |
| 97 | |
| 98 | if (enableValidationLayers) { |
| 99 | DestroyDebugUtilsMessengerEXT(instance, debugMessenger, nullptr); |
| 100 | } |
| 101 | |
| 102 | vkDestroySurfaceKHR(instance, surface, nullptr); |
| 103 | vkDestroyInstance(instance, nullptr); |
| 104 | |
| 105 | glfwDestroyWindow(window); |
| 106 | |
| 107 | glfwTerminate(); |
nothing calls this directly
no outgoing calls
no test coverage detected