102 lines
2.4 KiB
C++
102 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include <optional>
|
|
#include <vector>
|
|
#include <map>
|
|
|
|
#include "Logger.h"
|
|
|
|
#define GLFW_INCLUDE_VULKAN
|
|
#include <GLFW/glfw3.h>
|
|
|
|
const std::vector<const char*> DeviceExtensions = {
|
|
VK_KHR_SWAPCHAIN_EXTENSION_NAME
|
|
};
|
|
|
|
struct QueueFamilyIndices
|
|
{
|
|
std::optional<uint32_t> GraphicsFamily;
|
|
std::optional<uint32_t> PresentFamily;
|
|
|
|
bool IsComplete()
|
|
{
|
|
return GraphicsFamily.has_value() && PresentFamily.has_value();
|
|
}
|
|
};
|
|
|
|
struct SwapChainSupportDetails
|
|
{
|
|
VkSurfaceCapabilitiesKHR Capabilities;
|
|
std::vector<VkSurfaceFormatKHR> Formats;
|
|
std::vector<VkPresentModeKHR> 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<const char*>& ValidationLayers);
|
|
|
|
void Cleanup();
|
|
|
|
bool IsInitialized() const
|
|
{
|
|
bool bInitialized = PhysicalDevice && Device && Instance && GraphicsQueue;
|
|
return bInitialized;
|
|
}
|
|
|
|
static std::vector<VkImage> 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<VkImageView> SwapChainImageViews;
|
|
|
|
bool bEnableValidationLayers = false;
|
|
|
|
const std::vector<const char*>* 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<VkSurfaceFormatKHR>& AvailableFormats);
|
|
|
|
VkPresentModeKHR ChooseSwapPresentMode(const std::vector<VkPresentModeKHR>& AvailablePresentModes);
|
|
|
|
VkExtent2D ChooseSwapExtent(const VkSurfaceCapabilitiesKHR& Capabilities);
|
|
|
|
void CreateSwapChain();
|
|
|
|
void CreateImageViews();
|
|
};
|