summary refs log tree commit diff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs85
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,