#pragma once #include #include "glfw/glfw_window.h" #include "precomp.h" namespace veng { class Graphics final { public: Graphics(gsl::not_null window); ~Graphics(); private: struct QueueFamilyIndices { std::optional graphics_family = std::nullopt; std::optional presentation_family = std::nullopt; bool IsValid() const { return graphics_family.has_value() && presentation_family.has_value(); } }; struct SwapChainProperties { VkSurfaceCapabilitiesKHR capabilities = {}; std::vector formats; std::vector present_modes; bool IsValid() const { return !formats.empty() && !present_modes.empty(); } }; void InitializeVulkan(); void CreateInstance(); void SetupDebugMessenger(); void PickPhysicalDevice(); void CreateLogicalDeviceAndQueues(); void CreateSurface(); void CreateSwapChain(); void CreateImageViews(); void CreateRenderPass(); void CreateGraphicsPipeline(); std::vector GetRequiredInstanceExtentions(); static gsl::span GetSuggestedInstanceExtentions(); static std::vector GetSupprotedInstanceExtensions(); static bool AreAllExtensionsSupported(gsl::span extensions); static std::vector GetSupprotedValidationLayers(); static bool AreAllLayersSupported(gsl::span extensions); QueueFamilyIndices FindQueueFamilies(VkPhysicalDevice device); SwapChainProperties GetSwapChainProperties(VkPhysicalDevice device); bool IsDeviceSuitable(VkPhysicalDevice device); std::vector GetAvailableDevices(); bool AreAllDeviceExtensionsSupported(VkPhysicalDevice device); std::vector GetDeviceAvailableExtensions( VkPhysicalDevice device); VkSurfaceFormatKHR ChooseSwapSurfaceFormat( gsl::span formats); VkPresentModeKHR ChooseSwapPresentMode( gsl::span present_modes); VkExtent2D ChooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities); std::uint32_t ChooseSwapImageCount(const VkSurfaceCapabilitiesKHR& capabilities); VkShaderModule CreateShaderModule(gsl::span buffer); std::array required_device_extentions_ = { VK_KHR_SWAPCHAIN_EXTENSION_NAME}; VkInstance instance_ = VK_NULL_HANDLE; VkDebugUtilsMessengerEXT debug_messenger_; VkPhysicalDevice physical_device_ = VK_NULL_HANDLE; VkDevice logical_device_ = VK_NULL_HANDLE; VkQueue graphics_queue_ = VK_NULL_HANDLE; VkQueue present_queue_ = VK_NULL_HANDLE; VkSurfaceKHR surface_ = VK_NULL_HANDLE; VkSwapchainKHR swap_chain_ = VK_NULL_HANDLE; VkSurfaceFormatKHR surface_format_; VkPresentModeKHR present_mode_; VkExtent2D extent_; std::vector swap_chain_images_; std::vector swap_chain_image_views_; VkPipelineLayout pipeline_layout_ = VK_NULL_HANDLE; VkRenderPass render_pass_ = VK_NULL_HANDLE; VkPipeline pipeline_ = VK_NULL_HANDLE; gsl::not_null window_; bool validation_enabled_ = false; }; VkDebugUtilsMessengerCreateInfoEXT GetCreateMessengerInfo(); bool IsExtensionSupported(gsl::span extensions, gsl::czstring name); } // namespace veng