summary refs log tree commit diff
path: root/src/graphics/render_state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphics/render_state.rs')
-rw-r--r--src/graphics/render_state.rs33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/graphics/render_state.rs b/src/graphics/render_state.rs
index d918e9a..5848ac8 100644
--- a/src/graphics/render_state.rs
+++ b/src/graphics/render_state.rs
@@ -4,6 +4,7 @@ use crate::graphics::permanent::{
   PermanentGraphicsState, GraphicsStateForReinit
 };
 use crate::graphics::model::Model;
+use crate::graphics::texture::Texture;
 use crate::graphics::window_dressing::WindowDressing;
 use crate::shader_data::{ Vertex, UniformBlock, VertexPushBlock };
 
@@ -34,18 +35,17 @@ pub struct RenderState {
 impl RenderState {
   pub fn new(permanent: &PermanentGraphicsState,
              for_reinit: &GraphicsStateForReinit,
-             window_dressing: &WindowDressing)
+             window_dressing: &WindowDressing, texture: &Texture)
       -> Result<Self>
   {
     let device = &permanent.device;
+    let primary_command_pool = &permanent.primary_command_pool;
     let sample_count = for_reinit.sample_count;
     let descriptor_set_layout = &for_reinit.descriptor_set_layout;
-    let primary_command_pool = &window_dressing.primary_command_pool;
     let swapchain = &window_dressing.swapchain;
     let depth_format = &window_dressing.depth_format;
     let color_image_view = &window_dressing.color_image_view;
     let depth_image_view = &window_dressing.depth_image_view;
-    let texture_image_view = &window_dressing.texture_image_view;
     let uniform_buffers = &window_dressing.uniform_buffers;
     let descriptor_pool = &window_dressing.descriptor_pool;
     let sampler = &window_dressing.sampler;
@@ -68,7 +68,7 @@ impl RenderState {
             = init_descriptor_sets(device, descriptor_set_layout,
                                    &uniform_buffers, &descriptor_pool,
                                    swapchain.images.len(),
-                                   &texture_image_view, &sampler)?;
+                                   &texture.image_view, &sampler)?;
 
     let model = None;
 
@@ -87,24 +87,23 @@ impl RenderState {
   // idle.
   pub fn reinit(&mut self, permanent: &PermanentGraphicsState,
                 for_reinit: &GraphicsStateForReinit,
-                window_dressing: &WindowDressing)
+                window_dressing: &WindowDressing, texture: &Texture)
       -> Result<()>
   {
+    self.destroy_replaceable(permanent);
+
     let device = &permanent.device;
+    let primary_command_pool = &permanent.primary_command_pool;
     let sample_count = for_reinit.sample_count;
     let descriptor_set_layout = &for_reinit.descriptor_set_layout;
-    let primary_command_pool = &window_dressing.primary_command_pool;
     let swapchain = &window_dressing.swapchain;
     let depth_format = &window_dressing.depth_format;
     let color_image_view = &window_dressing.color_image_view;
     let depth_image_view = &window_dressing.depth_image_view;
-    let texture_image_view = &window_dressing.texture_image_view;
     let uniform_buffers = &window_dressing.uniform_buffers;
     let descriptor_pool = &window_dressing.descriptor_pool;
     let sampler = &window_dressing.sampler;
 
-    self.destroy_replaceable(device, primary_command_pool);
-
     let render_pass = init_render_pass(device, sample_count,
                                        &swapchain.format, &depth_format)?;
 
@@ -124,7 +123,7 @@ impl RenderState {
             = init_descriptor_sets(device, descriptor_set_layout,
                                    &uniform_buffers, &descriptor_pool,
                                    swapchain.images.len(),
-                                   texture_image_view, sampler)?;
+                                   &texture.image_view, sampler)?;
 
     self.render_pass = render_pass;
     self.pipeline = pipeline;
@@ -139,20 +138,20 @@ impl RenderState {
   //   This relies on its caller to have already waited for the device to be
   // idle.
   #[allow(unsafe_code)]
-  pub fn destroy(mut self, device: &Device,
-                 window_dressing: &WindowDressing)
+  pub fn destroy(mut self, permanent: &PermanentGraphicsState)
   {
-    self.destroy_replaceable(device, &window_dressing.primary_command_pool);
+    self.destroy_replaceable(permanent);
 
     if let Some(model) = self.model {
-      model.destroy(device);
+      model.destroy(&permanent.device);
     }
   }
 
   #[allow(unsafe_code)]
-  fn destroy_replaceable(&mut self, device: &Device,
-                         primary_command_pool: &vk::CommandPool)
+  fn destroy_replaceable(&mut self, permanent: &PermanentGraphicsState)
   {
+    let device = &permanent.device;
+
     for framebuffer in &self.framebuffers {
       unsafe { device.destroy_framebuffer(*framebuffer, None) };
     }
@@ -163,7 +162,7 @@ impl RenderState {
     // buffers. We promise ourselves to free buffers in the transient pool
     // immediately after using them.
     unsafe {
-      device.free_command_buffers(*primary_command_pool,
+      device.free_command_buffers(permanent.primary_command_pool,
                                   &self.command_buffers)
     };