76 lines
2.6 KiB
C++
76 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include <optional>
|
|
|
|
#define GLFW_INCLUDE_VULKAN
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
#ifdef _DEBUG
|
|
#include <assert.h>
|
|
#define VK_CHECK(res) assert(res == VK_SUCCESS)
|
|
#else
|
|
#define VK_CHECK(res) if ((res) != VK_SUCCESS) throw std::runtime_error("Vulkan error: " + std::to_string(res))
|
|
#endif
|
|
|
|
class CoreInstance;
|
|
|
|
class RenderEngine
|
|
{
|
|
struct QueueFamilyIndices
|
|
{
|
|
std::optional<uint32_t> graphycs_family;
|
|
std::optional<uint32_t> present_family;
|
|
bool is_complete();
|
|
};
|
|
struct SwapchainSupportDetails
|
|
{
|
|
VkSurfaceCapabilitiesKHR capabilities;
|
|
std::vector<VkSurfaceFormatKHR> formats;
|
|
std::vector<VkPresentModeKHR> present_modes;
|
|
};
|
|
|
|
static const std::vector<const char*> deviceExtensions;
|
|
|
|
CoreInstance& core_;
|
|
GLFWwindow* window_;
|
|
VkInstance instance_ = VK_NULL_HANDLE;
|
|
VkSurfaceKHR surface_ = VK_NULL_HANDLE;
|
|
VkPhysicalDevice physical_device_ = VK_NULL_HANDLE;
|
|
VkDevice device_ = VK_NULL_HANDLE;
|
|
VkQueue graphics_queue_ = VK_NULL_HANDLE;
|
|
VkQueue present_queue_ = VK_NULL_HANDLE;
|
|
VkSwapchainKHR swapchain_ = VK_NULL_HANDLE;
|
|
std::vector<VkImage> swapchain_images_;
|
|
VkFormat swapchain_image_format_;
|
|
VkExtent2D swapchain_extent_;
|
|
|
|
#ifdef _DEBUG
|
|
VkResult enable_layer_validation(VkDebugUtilsMessengerCreateInfoEXT* create_info);
|
|
VkDebugUtilsMessengerEXT debug_messenger_;
|
|
#endif
|
|
SwapchainSupportDetails query_swapchain_details();
|
|
|
|
static std::vector<const char*> get_required_extensions();
|
|
static bool is_device_suitable(VkPhysicalDevice device, VkSurfaceKHR surface);
|
|
static bool check_device_extensions_support(VkPhysicalDevice device);
|
|
static QueueFamilyIndices find_queue_family_indices(VkPhysicalDevice physical_device, VkSurfaceKHR surface);
|
|
static VkSurfaceFormatKHR choose_surface_format(const std::vector<VkSurfaceFormatKHR>& surface_formats);
|
|
static VkPresentModeKHR choose_present_mode(const std::vector<VkPresentModeKHR>& present_modes, VkPresentModeKHR desired_present_mode);
|
|
static VkExtent2D choose_extent(const VkSurfaceCapabilitiesKHR& capabilities, GLFWwindow* window);
|
|
|
|
void create_instance();
|
|
void create_surface();
|
|
void pick_physical_device();
|
|
void create_logical_device();
|
|
void create_swapchain(VkPresentModeKHR desired_present_mode);
|
|
public:
|
|
// Can throw the exception
|
|
RenderEngine(CoreInstance& core, GLFWwindow* window, VkPresentModeKHR desired_present_mode = VK_PRESENT_MODE_MAILBOX_KHR);
|
|
~RenderEngine();
|
|
|
|
void start();
|
|
void stop_render();
|
|
}; |