JustEnoughMod
Loading...
Searching...
No Matches
Renderer.hpp
1#ifndef RENDER_RENDERER_HPP
2#define RENDER_RENDERER_HPP
3
4#include <core/AppModule.hpp>
5#include <core/Logger.hpp>
6
7#include <vulkan/vulkan.h>
8
9#include <memory>
10#include <vector>
11
12namespace JEM {
13 class Renderer : public AppModule {
14 public:
15 explicit Renderer(std::shared_ptr<Application> app);
16
17 ~Renderer();
18
19 auto clear() -> void {}
20
21 auto draw() -> void {}
22
23 private:
24 VkInstance instance;
25 VkDebugUtilsMessengerEXT debugMessenger;
26
27 const std::vector<const char *> validationLayers = {"VK_LAYER_KHRONOS_validation"};
28
29 auto checkValidationLayerSupport() -> bool;
30 auto getRequiredExtensions() -> std::vector<const char *>;
31 auto populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT &createInfo) -> void;
32 auto CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo,
33 const VkAllocationCallbacks *pAllocator,
34 VkDebugUtilsMessengerEXT *pDebugMessenger) -> VkResult;
35 auto DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger,
36 const VkAllocationCallbacks *pAllocator) -> void;
37
38#ifdef NDEBUG
39 constexpr static const bool enableValidationLayers = false;
40#else
41 constexpr static const bool enableValidationLayers = true;
42#endif
43
44 static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
45 VkDebugUtilsMessageTypeFlagsEXT messageType,
46 const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
47 void *pUserData) {
48
49 std::string prefix = "[UNKNOWN ]";
50
51 switch (messageType) {
52 case VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT:
53 prefix = "[GENERAL ]";
54 break;
55 case VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT:
56 prefix = "[VALIDATION ]";
57 break;
58 case VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT:
59 prefix = "[PERFORMANCE]";
60 break;
61 }
62
63 switch (messageSeverity) {
64 case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT:
65 getVulkanLogger()->trace("{} {}", prefix, pCallbackData->pMessage);
66 break;
67 case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT:
68 getVulkanLogger()->info("{} {}", prefix, pCallbackData->pMessage);
69 break;
70 case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT:
71 getVulkanLogger()->warn("{} {}", prefix, pCallbackData->pMessage);
72 break;
73 case VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT:
74 getVulkanLogger()->error("{} {}", prefix, pCallbackData->pMessage);
75 break;
76 default:
77 getVulkanLogger()->error("UNKNOWN MESSAGE SEVERITY");
78 getVulkanLogger()->error("{} {}", prefix, pCallbackData->pMessage);
79 }
80
81 return VK_FALSE;
82 }
83 };
84} // namespace JEM
85
86#endif
Definition AppModule.hpp:9
Definition Renderer.hpp:13