MCPcopy Create free account
hub / github.com/Overv/VulkanTutorial / HelloTriangleApplication

Class HelloTriangleApplication

code/02_validation_layers.cpp:39–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39class HelloTriangleApplication {
40public:
41 void run() {
42 initWindow();
43 initVulkan();
44 mainLoop();
45 cleanup();
46 }
47
48private:
49 GLFWwindow* window;
50
51 VkInstance instance;
52 VkDebugUtilsMessengerEXT debugMessenger;
53
54 void initWindow() {
55 glfwInit();
56
57 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
58 glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
59
60 window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
61 }
62
63 void initVulkan() {
64 createInstance();
65 setupDebugMessenger();
66 }
67
68 void mainLoop() {
69 while (!glfwWindowShouldClose(window)) {
70 glfwPollEvents();
71 }
72 }
73
74 void cleanup() {
75 if (enableValidationLayers) {
76 DestroyDebugUtilsMessengerEXT(instance, debugMessenger, nullptr);
77 }
78
79 vkDestroyInstance(instance, nullptr);
80
81 glfwDestroyWindow(window);
82
83 glfwTerminate();
84 }
85
86 void createInstance() {
87 if (enableValidationLayers && !checkValidationLayerSupport()) {
88 throw std::runtime_error("validation layers requested, but not available!");
89 }
90
91 VkApplicationInfo appInfo{};
92 appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
93 appInfo.pApplicationName = "Hello Triangle";
94 appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
95 appInfo.pEngineName = "No Engine";
96 appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected