#pragma once #include #include #include #include "Logger.h" #define GLFW_INCLUDE_VULKAN #include const std::vector DeviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; struct QueueFamilyIndices { std::optional GraphicsFamily; std::optional PresentFamily; bool IsComplete() { return GraphicsFamily.has_value() && PresentFamily.has_value(); } }; struct SwapChainSupportDetails { VkSurfaceCapabilitiesKHR Capabilities; std::vector Formats; std::vector PresentModes; }; class VulkanDeviceManager { public: VulkanDeviceManager(); ~VulkanDeviceManager(); VulkanDeviceManager(const VulkanDeviceManager&) = delete; VulkanDeviceManager& operator=(const VulkanDeviceManager&) = delete; VulkanDeviceManager(VulkanDeviceManager&& Other) noexcept; VulkanDeviceManager& operator=(VulkanDeviceManager&& Other) noexcept; void Initialize( VkInstance Instance, bool EnableValidationLayers, const std::vector& ValidationLayers); void Cleanup(); bool IsInitialized() const { bool bInitialized = PhysicalDevice && Device && Instance && GraphicsQueue; return bInitialized; } static std::vector SwapChainImages; private: VkPhysicalDevice PhysicalDevice = VK_NULL_HANDLE; VkInstance Instance = VK_NULL_HANDLE; VkDevice Device = VK_NULL_HANDLE; VkQueue GraphicsQueue = VK_NULL_HANDLE; VkQueue PresentQueue = VK_NULL_HANDLE; VkSwapchainKHR SwapChain = VK_NULL_HANDLE; VkFormat SwapChainImageFormat; VkExtent2D SwapChainExtent; std::vector SwapChainImageViews; bool bEnableValidationLayers = false; const std::vector* ValidationLayers = nullptr; void PickPhysicalDevice(); bool IsDeviceSuitable(VkPhysicalDevice Device); int RateDeviceSuitability(VkPhysicalDevice Device); bool CheckDeviceExtensionSupport(VkPhysicalDevice Device); QueueFamilyIndices FindQueueFamilies(VkPhysicalDevice Device); void CreateLogicalDevice(); SwapChainSupportDetails QuerySwapChainSupport(VkPhysicalDevice Device); VkSurfaceFormatKHR ChooseSwapSurfaceFormat(const std::vector& AvailableFormats); VkPresentModeKHR ChooseSwapPresentMode(const std::vector& AvailablePresentModes); VkExtent2D ChooseSwapExtent(const VkSurfaceCapabilitiesKHR& Capabilities); void CreateSwapChain(); void CreateImageViews(); };