diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-07-09 12:51:09 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-07-09 12:51:09 -0700 |
| commit | 7873d17c1bc87974a436f8eafb714e5e0779c329 (patch) | |
| tree | aa72f4692e33218c1b9f6a194cc1d65ba268b40f /src | |
| parent | 2f24a8f0916f71df2b48e59cea2b4643b88b11fb (diff) | |
move all the window dressing initialization into its own function
Force-Push: yes Change-Id: I6968fd0332a86e595d2d6983c02c761e51300e9b
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 85 |
1 files changed, 49 insertions, 36 deletions
diff --git a/src/main.rs b/src/main.rs index 53c8c09..883b587 100644 --- a/src/main.rs +++ b/src/main.rs @@ -237,41 +237,7 @@ impl Surreality { = Self::init_vulkan_device(&instance, &surface, enable_validation, enable_portability)?; - if enable_swapchain.0 { - let swapchain = Self::init_swapchain( - &window, &instance, &surface, &physical_device, &device, - &indices)?; - - let render_pass = Surreality::init_render_pass(&device, - &swapchain.format)?; - - let (pipeline_layout, pipeline) - = Self::init_pipeline(&device, &swapchain.extent, - &render_pass)?; - - let framebuffers = Self::init_framebuffers( - &device, &swapchain.extent, &swapchain.image_views, - &render_pass)?; - - let (command_pool, command_buffers) - = Self::init_commands(&device, &swapchain.extent, &framebuffers, - &render_pass, &pipeline, &indices)?; - - let concurrency = Self::init_concurrency(&device, &swapchain.images)?; - - *self.window_dressing.get_mut() = Some(WindowDressing { - swapchain, - render_pass, - pipeline, - pipeline_layout, - framebuffers, - command_pool, - command_buffers, - concurrency, - }); - } - - *self.permanent.get_mut() = Some(PermanentGraphicsState { + let permanent = PermanentGraphicsState { window, entry, instance, @@ -280,7 +246,14 @@ impl Surreality { device, graphics_queue, presentation_queue, - }); + }; + + if enable_swapchain.0 { + *self.window_dressing.get_mut() = Some(Self::init_window_dressing( + &permanent, physical_device, indices)?); + } + + *self.permanent.get_mut() = Some(permanent); Ok(()) } @@ -582,6 +555,46 @@ impl Surreality { enable_swapchain)) } + fn init_window_dressing(permanent: &PermanentGraphicsState, + physical_device: vk::PhysicalDevice, + indices: QueueFamilyIndices) + -> Result<WindowDressing> + { + let window = &permanent.window; + let instance = &permanent.instance; + let surface = &permanent.surface; + let device = &permanent.device; + + let swapchain = Self::init_swapchain( + window, instance, surface, &physical_device, device, &indices)?; + + let render_pass = Surreality::init_render_pass(device, + &swapchain.format)?; + + let (pipeline_layout, pipeline) + = Self::init_pipeline(device, &swapchain.extent, &render_pass)?; + + let framebuffers = Self::init_framebuffers( + device, &swapchain.extent, &swapchain.image_views, &render_pass)?; + + let (command_pool, command_buffers) + = Self::init_commands(device, &swapchain.extent, &framebuffers, + &render_pass, &pipeline, &indices)?; + + let concurrency = Self::init_concurrency(device, &swapchain.images)?; + + Ok(WindowDressing { + swapchain, + render_pass, + pipeline, + pipeline_layout, + framebuffers, + command_pool, + command_buffers, + concurrency, + }) + } + #[allow(unsafe_code)] fn init_swapchain(window: &Window, instance: &Instance, surface: &vk::SurfaceKHR, |