· 4 years ago · Apr 19, 2021, 10:26 PM
1#pragma once
2
3#define GLFW_INCLUDE_VULKAN
4#include <GLFW/glfw3.h>
5#include <vector>
6
7//Since this is a project to get Vulkan's flow and understand a bit more some key concepts, there will be little to no abstraction.
8//The only objective of this project is get more grasp on this API.
9
10inline VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
11 const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger)
12{
13 auto func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT");
14
15 if (func != nullptr)
16 return func(instance, pCreateInfo, pAllocator, pDebugMessenger);
17 else
18 return VK_ERROR_EXTENSION_NOT_PRESENT;
19}
20
21inline void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator)
22{
23 auto func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT");
24
25 if (func != nullptr)
26 func(instance, debugMessenger, pAllocator);
27
28}
29
30namespace VkP
31{
32 class HelloTriangleApplication
33 {
34 public:
35 void Run();
36
37 private:
38 void InitWindow();
39 void InitVulkan();
40 void SetupDebugMessenger();
41 void CreateInstance();
42 void PickPhysicalDevice();
43 void MainLoop();
44 void CleanUp();
45
46 void PopulateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
47
48 bool CheckValidationLayerSupport();
49 bool IsDeviceSuitable(VkPhysicalDevice device);
50
51 std::vector<const char*> getRequiredExtensions();
52
53
54 static VKAPI_ATTR VkBool32 VKAPI_CALL DebugCallback(
55 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
56 VkDebugUtilsMessageTypeFlagsEXT messaType,
57 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
58 void* pUserData);
59 private:
60 VkInstance m_VkInstance;
61 VkDebugUtilsMessengerEXT m_DebugMessenger;
62 VkPhysicalDevice m_PhysicalDevice = VK_NULL_HANDLE;
63
64 const std::vector<const char*> m_ValidationLayers = { "VK_LAYER_KHRONOS_validation" };
65
66#ifdef NDEBUG
67 const bool m_EnableValidationLayers = false;
68#else
69 const bool m_EnableValidationLayers = true;
70#endif
71
72 //window
73 float m_AspectRatio = 4.0f / 3.0f;
74 uint16_t m_WindowWidth = 800;
75 uint16_t m_WindowHeight = uint16_t(m_WindowWidth / m_AspectRatio);
76 GLFWwindow* m_Window = nullptr;
77 };
78
79}