diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:23 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:23 +0100 |
commit | 6ef351de4ba506e7f0f285569aa0e22255bb68c6 (patch) | |
tree | 7aaf25bb93e3d97ba03c408fdef9f7b1933ea7bc /stockton-render/src/draw/draw_passes/level.rs | |
parent | 2e33320e62a3dc26555f17e1a79e129a53672a1b (diff) |
refactor(render): slight leveldrawpass refactors
Diffstat (limited to 'stockton-render/src/draw/draw_passes/level.rs')
-rw-r--r-- | stockton-render/src/draw/draw_passes/level.rs | 75 |
1 files changed, 35 insertions, 40 deletions
diff --git a/stockton-render/src/draw/draw_passes/level.rs b/stockton-render/src/draw/draw_passes/level.rs index 3a4e748..d23990d 100644 --- a/stockton-render/src/draw/draw_passes/level.rs +++ b/stockton-render/src/draw/draw_passes/level.rs @@ -1,6 +1,6 @@ //! Minimal code for drawing any level, based on traits from stockton-levels -use super::{DrawPass, IntoDrawPass}; +use super::{util::TargetSpecificResources, DrawPass, IntoDrawPass}; use crate::{ draw::{ buffers::{ @@ -69,9 +69,8 @@ pub struct LevelDrawPass<'a, M> { active_camera: Entity, draw_buffers: DrawBuffers<'a, UvPoint>, - framebuffers: Vec<FramebufferT>, - depth_buffers: Vec<DedicatedLoadedImage>, - next_resources: usize, + framebuffers: TargetSpecificResources<FramebufferT>, + depth_buffers: TargetSpecificResources<DedicatedLoadedImage>, _d: PhantomData<M>, } @@ -106,9 +105,8 @@ where let map = map_lock.read().map_err(|_| LockPoisoned::Map)?; // Get framebuffer and depth buffer - let fb = &self.framebuffers[self.next_resources]; - let db = &self.depth_buffers[self.next_resources]; - self.next_resources = (self.next_resources + 1) % self.framebuffers.len(); + let fb = self.framebuffers.get_next(); + let db = self.depth_buffers.get_next(); unsafe { cmd_buffer.begin_render_pass( @@ -253,10 +251,10 @@ where let mut device = device_lock.write().map_err(|_| LockPoisoned::Device)?; self.pipeline.deactivate(&mut device); self.draw_buffers.deactivate(&mut device); - for fb in self.framebuffers.into_iter() { + for fb in self.framebuffers.dissolve() { device.destroy_framebuffer(fb); } - for db in self.depth_buffers.into_iter() { + for db in self.depth_buffers.dissolve() { db.deactivate(&mut device); } } @@ -391,45 +389,43 @@ where ) .context("Error building pipeline")?; - let mut framebuffers = Vec::with_capacity(swapchain_properties.image_count as usize); - let mut depth_buffers = Vec::with_capacity(swapchain_properties.image_count as usize); - let fat = FramebufferAttachment { - usage: Usage::COLOR_ATTACHMENT, - format: swapchain_properties.format, - view_caps: ViewCapabilities::empty(), - }; + let fat = swapchain_properties.framebuffer_attachment(); let dat = FramebufferAttachment { usage: Usage::DEPTH_STENCIL_ATTACHMENT, format: swapchain_properties.depth_format, view_caps: ViewCapabilities::empty(), }; - for _i in 0..swapchain_properties.image_count { - unsafe { - framebuffers.push(device.create_framebuffer( + let framebuffers = TargetSpecificResources::new( + || unsafe { + Ok(device.create_framebuffer( &pipeline.renderpass, IntoIter::new([fat.clone(), dat.clone()]), swapchain_properties.extent, - )?); - depth_buffers.push( - DedicatedLoadedImage::new( - &mut device, - adapter, - swapchain_properties.depth_format, - Usage::DEPTH_STENCIL_ATTACHMENT, - SubresourceRange { - aspects: Aspects::DEPTH, - level_start: 0, - level_count: Some(1), - layer_start: 0, - layer_count: Some(1), - }, - swapchain_properties.extent.width as usize, - swapchain_properties.extent.height as usize, - ) - .context("Error creating depth buffer")?, + )?) + }, + swapchain_properties.image_count as usize, + )?; + let depth_buffers = TargetSpecificResources::new( + || { + DedicatedLoadedImage::new( + &mut device, + adapter, + swapchain_properties.depth_format, + Usage::DEPTH_STENCIL_ATTACHMENT, + SubresourceRange { + aspects: Aspects::DEPTH, + level_start: 0, + level_count: Some(1), + layer_start: 0, + layer_count: Some(1), + }, + swapchain_properties.extent.width as usize, + swapchain_properties.extent.height as usize, ) - } - } + .context("Error creating depth buffer") + }, + swapchain_properties.image_count as usize, + )?; (draw_buffers, pipeline, framebuffers, depth_buffers) }; @@ -442,7 +438,6 @@ where _d: PhantomData, framebuffers, depth_buffers, - next_resources: 0, }) } |