|
| 1 | +export module App; |
| 2 | + |
| 3 | +import std; |
| 4 | +import glfw; |
| 5 | +import vulkan_hpp; |
| 6 | + |
| 7 | +import DataLoader; |
| 8 | +import Context; |
| 9 | +import Window; |
| 10 | +import Device; |
| 11 | +import Swapchain; |
| 12 | +import DepthImage; |
| 13 | +// import RenderPass; |
| 14 | +import GraphicsPipeline; |
| 15 | +import CommandPool; |
| 16 | +import InputAssembly; |
| 17 | +import UniformBuffer; |
| 18 | +import TextureSampler; |
| 19 | +import Descriptor; |
| 20 | +import Drawer; |
| 21 | + |
| 22 | +export namespace vht { |
| 23 | + class App { |
| 24 | + std::shared_ptr<vht::DataLoader> m_data_loader{ nullptr }; |
| 25 | + std::shared_ptr<vht::Context> m_context{ nullptr }; |
| 26 | + std::shared_ptr<vht::Window> m_window{ nullptr }; |
| 27 | + std::shared_ptr<vht::Device> m_device{ nullptr }; |
| 28 | + std::shared_ptr<vht::Swapchain> m_swapchain{ nullptr }; |
| 29 | + std::shared_ptr<vht::DepthImage> m_depth_image{ nullptr }; |
| 30 | + // std::shared_ptr<vht::RenderPass> m_render_pass{ nullptr }; |
| 31 | + std::shared_ptr<vht::GraphicsPipeline> m_graphics_pipeline{ nullptr }; |
| 32 | + std::shared_ptr<vht::CommandPool> m_command_pool{ nullptr }; |
| 33 | + std::shared_ptr<vht::InputAssembly> m_input_assembly{ nullptr }; |
| 34 | + std::shared_ptr<vht::UniformBuffer> m_uniform_buffer{ nullptr }; |
| 35 | + std::shared_ptr<vht::TextureSampler> m_texture_sampler{ nullptr }; |
| 36 | + std::shared_ptr<vht::Descriptor> m_descriptor{ nullptr }; |
| 37 | + std::shared_ptr<vht::Drawer> m_drawer{ nullptr }; |
| 38 | + public: |
| 39 | + void run() { |
| 40 | + init(); |
| 41 | + while (!glfw::window_should_close(m_window->ptr())) { |
| 42 | + glfw::poll_events(); |
| 43 | + m_drawer->draw(); |
| 44 | + } |
| 45 | + std::println("device waitIdle"); |
| 46 | + m_device->device().waitIdle(); |
| 47 | + std::println("finished"); |
| 48 | + } |
| 49 | + private: |
| 50 | + void init() { |
| 51 | + init_data_loader(); |
| 52 | + init_context(); |
| 53 | + init_window(); |
| 54 | + std::println("window created"); |
| 55 | + init_device(); |
| 56 | + std::println("device created"); |
| 57 | + init_swapchain(); |
| 58 | + std::println("swapchain created"); |
| 59 | + init_command_pool(); // 前移命令池的创建 |
| 60 | + std::println("command pool created"); |
| 61 | + init_depth_image(); |
| 62 | + std::println("depth image created"); |
| 63 | + // init_render_pass(); |
| 64 | + // std::println("render pass created"); |
| 65 | + init_graphics_pipeline(); |
| 66 | + std::println("graphics pipeline created"); |
| 67 | + init_uniform_buffer(); |
| 68 | + std::println("uniform buffer created"); |
| 69 | + init_texture_sampler(); |
| 70 | + std::println("texture sampler created"); |
| 71 | + init_input_assembly(); |
| 72 | + std::println("input assembly created"); |
| 73 | + init_descriptor(); |
| 74 | + std::println("descriptor created"); |
| 75 | + init_drawer(); |
| 76 | + std::println("drawer created"); |
| 77 | + } |
| 78 | + void init_data_loader() { m_data_loader = std::make_shared<vht::DataLoader>(); } |
| 79 | + void init_context() { m_context = std::make_shared<vht::Context>( true ); } |
| 80 | + void init_window() { m_window = std::make_shared<vht::Window>( m_context ); } |
| 81 | + void init_device() { m_device = std::make_shared<vht::Device>( m_context, m_window ); } |
| 82 | + void init_swapchain() { m_swapchain = std::make_shared<vht::Swapchain>( m_window, m_device ); } |
| 83 | + void init_depth_image() { m_depth_image = std::make_shared<vht::DepthImage>( m_device, m_swapchain, m_command_pool ); } |
| 84 | + // void init_render_pass() { m_render_pass = std::make_shared<vht::RenderPass>( m_window, m_device, m_swapchain, m_depth_image ); } |
| 85 | + void init_graphics_pipeline() { m_graphics_pipeline = std::make_shared<vht::GraphicsPipeline>( m_device, m_swapchain, m_depth_image ); } |
| 86 | + void init_command_pool() { m_command_pool = std::make_shared<vht::CommandPool>( m_device ); } |
| 87 | + void init_input_assembly() { m_input_assembly = std::make_shared<vht::InputAssembly>( m_data_loader, m_device, m_command_pool ); } |
| 88 | + void init_uniform_buffer() { m_uniform_buffer = std::make_shared<vht::UniformBuffer>( m_window, m_device, m_swapchain ); } |
| 89 | + void init_texture_sampler() { m_texture_sampler = std::make_shared<vht::TextureSampler>( m_device, m_command_pool ); } |
| 90 | + void init_descriptor() { m_descriptor = std::make_shared<vht::Descriptor>( m_device, m_graphics_pipeline, m_uniform_buffer, m_texture_sampler ); } |
| 91 | + void init_drawer() { |
| 92 | + m_drawer = std::make_shared<vht::Drawer>( |
| 93 | + m_data_loader, |
| 94 | + m_window, |
| 95 | + m_device, |
| 96 | + m_swapchain, |
| 97 | + m_depth_image, |
| 98 | + m_graphics_pipeline, |
| 99 | + m_command_pool, |
| 100 | + m_input_assembly, |
| 101 | + m_uniform_buffer, |
| 102 | + m_descriptor |
| 103 | + ); |
| 104 | + } |
| 105 | + }; |
| 106 | +} |
0 commit comments