From 807257686942b24b0c48a50a62c3d90626fb863a Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sat, 27 Apr 2024 14:45:37 +0100 Subject: [PATCH] Use crawl Pass system --- src/main.rs | 3 ++- src/renderer.rs | 23 ++++------------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index 701af27..0318612 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ fn main() -> Result<()> { .build(), )?; let renderer = VoxelRenderer::new(&context)?; + let passes: Vec> = vec![Box::new(renderer)]; event_loop.run(|event, elwt| match event { Event::WindowEvent { window_id, event } if window_id == context.window.id() => { @@ -21,7 +22,7 @@ fn main() -> Result<()> { } if let WindowEvent::RedrawRequested = event { - if let Err(err) = renderer.render(&context) { + if let Err(err) = context.render(passes.as_slice()) { log::error!("{err:?}"); } diff --git a/src/renderer.rs b/src/renderer.rs index abf54e0..5603778 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -36,23 +36,14 @@ impl VoxelRenderer { render_pipeline, }) } +} - pub fn render(&self, context: &crawl::Context) -> Result<()> { - let frame = context.surface.get_current_texture()?; - let view = frame - .texture - .create_view(&wgpu::TextureViewDescriptor::default()); - - let mut encoder = context - .device - .create_command_encoder(&wgpu::CommandEncoderDescriptor { - label: Some("Base Render Encoder"), - }); - +impl crawl::Pass for VoxelRenderer { + fn execute(&self, encoder: &mut wgpu::CommandEncoder, view: &wgpu::TextureView) { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &view, + view, resolve_target: None, ops: wgpu::Operations::default(), })], @@ -61,11 +52,5 @@ impl VoxelRenderer { render_pass.set_pipeline(&self.render_pipeline); render_pass.set_bind_group(0, &self.render_texture.bind_group, &[]); render_pass.draw(0..6, 0..1); - drop(render_pass); - - context.queue.submit(Some(encoder.finish())); - frame.present(); - - Ok(()) } }