| 9 | const uint32_t HEIGHT = 600; |
| 10 | |
| 11 | class HelloTriangleApplication { |
| 12 | public: |
| 13 | void run() { |
| 14 | initWindow(); |
| 15 | initVulkan(); |
| 16 | mainLoop(); |
| 17 | cleanup(); |
| 18 | } |
| 19 | |
| 20 | private: |
| 21 | GLFWwindow* window; |
| 22 | |
| 23 | VkInstance instance; |
| 24 | |
| 25 | void initWindow() { |
| 26 | glfwInit(); |
| 27 | |
| 28 | glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); |
| 29 | glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); |
| 30 | |
| 31 | window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr); |
| 32 | } |
| 33 | |
| 34 | void initVulkan() { |
| 35 | createInstance(); |
| 36 | } |
| 37 | |
| 38 | void mainLoop() { |
| 39 | while (!glfwWindowShouldClose(window)) { |
| 40 | glfwPollEvents(); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | void cleanup() { |
| 45 | vkDestroyInstance(instance, nullptr); |
| 46 | |
| 47 | glfwDestroyWindow(window); |
| 48 | |
| 49 | glfwTerminate(); |
| 50 | } |
| 51 | |
| 52 | void createInstance() { |
| 53 | VkApplicationInfo appInfo{}; |
| 54 | appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
| 55 | appInfo.pApplicationName = "Hello Triangle"; |
| 56 | appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0); |
| 57 | appInfo.pEngineName = "No Engine"; |
| 58 | appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0); |
| 59 | appInfo.apiVersion = VK_API_VERSION_1_0; |
| 60 | |
| 61 | VkInstanceCreateInfo createInfo{}; |
| 62 | createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
| 63 | createInfo.pApplicationInfo = &appInfo; |
| 64 | |
| 65 | uint32_t glfwExtensionCount = 0; |
| 66 | const char** glfwExtensions; |
| 67 | glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); |
| 68 |
nothing calls this directly
no outgoing calls
no test coverage detected