#pragma once #include #include #include #include "utils.h" #include "physicaldevice.h" #include "surface.h" namespace Engine { class Engine; class SwapChain; class LogicalDevice { friend class Engine; public: LogicalDevice( PhysicalDevice* physicalDevice, Surface* surface, const std::vector& extensions, const std::vector layers ); ~LogicalDevice(); void createSwapChain(); void clearSwapChain(); void createGraphicsPipeline(const std::string& vertexShaderPath, const std::string& fragmentShaderPath); void recreateSwapChain(); void drawFrame(); VkResult waitIdle(); VkResult waitForFence(const VkFence& fence); VkResult resetFence(const VkFence& fence); VkExtent2D chooseSwapExtent() const; VkResult createVkSwapChain(const VkExtent2D& extent, VkSwapchainKHR& out); void destroyVkSwapChain(VkSwapchainKHR& swapChain); VkResult getVkSwapChainImages(VkSwapchainKHR& swapChain, std::vector& out); VkResult createVkImageView(const VkImage& image, VkImageView& out); void destroyVkImageView(VkImageView& view); VkResult createVkFrameBuffer(const VkImageView& imageView, const VkExtent2D& extent, VkFramebuffer& out); void destroyVkFrameBuffer(VkFramebuffer& buffer); private: VkShaderModule createShaderModule(const std::string& path); void destroyShaderModule(VkShaderModule shaderModule); void createDevice( VkPhysicalDevice physicalDevice, const QueueFamilyIndices& indices, const std::vector& extensions, const std::vector layers ); void createQueues(uint32_t graphicsFamilyIndex, uint32_t presenFamilyIndex); void createCommandPool(uint32_t queueFamilyIndex); void createCommandBuffers(); void createSyncObjects(); void createRenderPass(VkFormat format); VkResult queueSubmitGraphics( const VkSemaphore& wait, const VkCommandBuffer& buffer, const VkSemaphore& signal, const VkFence& fence ); VkResult queuePresent(const VkSemaphore& signal, uint32_t index); void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex); private: PhysicalDevice* phys; VkDevice vk; VkQueue graphicsQueue; VkQueue presentQueue; VkRenderPass renderPass; VkPipelineLayout pipelineLayout; VkPipeline graphicsPipeline; VkCommandPool commandPool; std::vector commandBuffers; std::vector imageAvailableSemaphores; std::vector renderFinishedSemaphores; std::vector inFlightFences; uint32_t currentFrame; bool framebufferResized; bool hasPipeline; Surface* surface; VkSurfaceFormatKHR surfaceFormat; SwapChain* swapChain; }; }