// vulkan_guide.h : Include file for standard system include files, // or project specific include files. #pragma once #include #include #include "vk_gui.h" struct Transaction { VkCommandBuffer cmd; uint32_t swapchainImageIndex = 0; }; struct DeletionQueue { std::deque> deletors; void push_function(std::function&& function) { deletors.push_back(function); } void flush() { // reverse itererate the deletion queue for(auto it = deletors.rbegin(); it != deletors.rend(); it++) { (*it)(); } deletors.clear(); } }; struct FrameData { VkCommandPool _commandPool; VkCommandBuffer _mainCommandBuffer; VkSemaphore _swapchainSemaphore; VkSemaphore _renderSemaphore; VkFence _renderFence; DeletionQueue _deletionQueue; }; class VulkanEngine { public: VkFence _immFence; VkCommandBuffer _immCommandBuffer; VkCommandPool _immCommandPool; VkPipeline _gradientPipeline; VkPipelineLayout _gradientPipelineLayout; DescriptorAllocator _globalDescriptorAllocator; VkDescriptorSet _drawImageDescriptors; VkDescriptorSetLayout _drawImageDescriptorLayout; // device selection VkInstance _instance; VkDebugUtilsMessengerEXT _debug_messenger; VkPhysicalDevice _chosenGPU; VkDevice _device; VkSurfaceKHR _surface; // swapchain VkSwapchainKHR _swapchain; VkFormat _swapchainImageFormat; std::vector _swapchainImages; std::vector _swapchainImageViews; VkExtent2D _swapchainExtent; // VMA stuff VmaAllocator _allocator; // frames/command buffer unsigned int _frameNumber = 0; FrameData _frames[FRAME_OVERLAP]; FrameData& get_current_frame() { return _frames[_frameNumber % FRAME_OVERLAP]; } VkQueue _graphicsQueue; uint32_t _graphicsQueueFamily; // draw resources AllocatedImage _drawImage; VkExtent2D _drawExtent; // internal data bool _isInitialized{ false }; VkExtent2D _windowExtent{ 1700 , 900 }; struct SDL_Window* _window{ nullptr }; DeletionQueue _mainDeletionQueue; // imgui shader stuff std::vector backgroundEffects; int currentBackgroundEffect{0}; // ZED's REFACTOR VkGUI _gui; static VulkanEngine& Get(); //initializes everything in the engine void init(); //shuts down the engine void cleanup(); //draw loop void draw(); //run main loop void run(); void immediate_submit(std::function&& function); Transaction begin_transaction(); void commit_transaction(Transaction& cmd); private: void init_vulkan(); void init_swapchain(); void init_commands(); void init_sync_structures(); void init_descriptors(); void init_pipelines(); void init_background_pipelines(); void init_shaders(); void load_shader(const char *file_name, const char *entry_point, ComputeEffect data); void create_swapchain(uint32_t width, uint32_t height); void destroy_swapchain(); void draw_background(VkCommandBuffer cmd); };