#pragma once #include "VulkanUtils.hpp" #include "VulkanTime.hpp" #include class SwapChain; class VulkanWindow { public: VulkanWindow(); ~VulkanWindow(); GLFWwindow* getWindow(); VkDevice getDevice(); RenderCreateInfo getRenderInfo(); void setRenderPass(VkRenderPass renderPass); struct FrameData { VkSemaphore imageAvailableSemaphore; VkSemaphore renderFinishedSemaphore; VkFence inFlightFence; VkCommandBuffer commandBuffer; VkFramebuffer frameBuffer; VkExtent2D extent2D; uint32_t swapChainImageIndex; }; void pollEvents(); void waitDevice(); FrameData startDrawFrame(); void endDrawFrame(const FrameData& frame); void scheduleWindowResize(int sizeX, int sizeY); private: void initWindow(); void initVulkan(); void createLogicalDevice(const std::vector &deviceExtensions); void getQueues(); void createWindowSurface(); void recreateSwapChain(int sizeX, int sizeY); void createSynchronizationObjects(); void destroySynchronizationObjects(); void cleanup(); void createCommandPool(); void createCommandBuffer(); void destroyCommandPool(); public: GLFWwindow *mWindow = nullptr; bool mWindowSizeDirtyFlag = true; TimePoint mWindowSizeDirtyFlagTime = std::chrono::system_clock::now(); TimeMs mWindowSizeApplyMinDelay = 200; std::pair mWindowFramebufferSize = {0, 0}; int mGraphicsQueueFamilyIndex = -1; int mPresentationQueueFamilyIndex = -1; VkCommandPool mCommandPool = VK_NULL_HANDLE; VkCommandBuffer mCommandBuffer = VK_NULL_HANDLE; VkInstance mInstance = VK_NULL_HANDLE; VkPhysicalDevice mPhysicalDevice = VK_NULL_HANDLE; VkDevice mDevice = VK_NULL_HANDLE; VkQueue mGraphicsQueue = VK_NULL_HANDLE; VkQueue mPresentQueue = VK_NULL_HANDLE; VkSurfaceKHR mSurface = VK_NULL_HANDLE; SwapChain* mSwapChain = nullptr; VkRenderPass mRenderPass = VK_NULL_HANDLE; // Renderer* mRenderer = nullptr; VkSemaphore mSemaphoreImageAcquired = VK_NULL_HANDLE; VkSemaphore mSemaphoreFramebufferDrawn = VK_NULL_HANDLE; VkFence mFenceCanStartNewFrame = VK_NULL_HANDLE; };