/* file VulkanApp.hpp */ #pragma once #include #include #include //#include #include #include class VulkanApp { public: using ImguiDrawFn = std::function; public: VulkanApp(ImguiDrawFn fn); #ifdef NOPE /** set imgui draw function **/ void assign_imgui_draw_frame(ImguiDrawFn fn); #endif /** equivalent to sequence setup(), main_loop(), cleanup() **/ void run(); /** setup before main loop. idempotent **/ void setup(std::function load_fonts); void main_loop(); /** cleanup before shutdown. idempotent **/ void cleanup(); private: void init_window(); void init_vulkan(); void create_instance(); void create_surface(); void pick_physical_device(); void create_logical_device(); void create_swap_chain(); void create_image_views(); void create_render_pass(); void create_framebuffers(); void create_command_pool(); void create_command_buffers(); void create_sync_objects(); void create_descriptor_pool(); void init_imgui(std::function load_fonts); VkCommandBuffer begin_single_time_commands(); void end_single_time_commands(VkCommandBuffer commandBuffer); void record_command_buffer(VkCommandBuffer commandBuffer, uint32_t imageIndex); /** TODO: replace with some generic mechanism **/ void draw_frame(); private: bool setup_done_ = false; bool cleanup_done_ = false; SDL_Window* window = nullptr; ImGuiContext* imgui_cx_ = nullptr; VkInstance instance; VkPhysicalDevice physical_device_; VkDevice device_; VkQueue graphics_queue_; VkSurfaceKHR surface_; VkSwapchainKHR swapchain_; VkFormat swapchain_image_format_; VkExtent2D swapchain_extent_; std::vector swapchainImages; std::vector swapchain_image_views_; VkRenderPass render_pass_; std::vector framebuffers_; VkCommandPool command_pool_; std::vector command_buffers_; /** one per frame (up to MAX_FRAMES_IN_FLIGHT) **/ std::vector image_available_semaphores_; /** one per frame (up to MAX_FRAMES_IN_FLIGHT) **/ std::vector render_finished_semaphores_; std::vector in_flight_fences_; VkDescriptorPool descriptor_pool_; /** image index of current frame **/ uint32_t current_frame_ = 0; uint32_t graphics_queue_family_ = 0; bool quit_ = false; /** draw imgui **/ const ImguiDrawFn imgui_draw_frame_; }; /* end VulkanApp.hpp */