Use crawl Pass system

This commit is contained in:
Jarrod Doyle 2024-04-27 14:45:37 +01:00
parent 04348d96f3
commit 8072576869
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
2 changed files with 6 additions and 20 deletions

View File

@ -13,6 +13,7 @@ fn main() -> Result<()> {
.build(), .build(),
)?; )?;
let renderer = VoxelRenderer::new(&context)?; let renderer = VoxelRenderer::new(&context)?;
let passes: Vec<Box<dyn crawl::Pass>> = vec![Box::new(renderer)];
event_loop.run(|event, elwt| match event { event_loop.run(|event, elwt| match event {
Event::WindowEvent { window_id, event } if window_id == context.window.id() => { 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 WindowEvent::RedrawRequested = event {
if let Err(err) = renderer.render(&context) { if let Err(err) = context.render(passes.as_slice()) {
log::error!("{err:?}"); log::error!("{err:?}");
} }

View File

@ -36,23 +36,14 @@ impl VoxelRenderer {
render_pipeline, render_pipeline,
}) })
} }
}
pub fn render(&self, context: &crawl::Context) -> Result<()> { impl crawl::Pass for VoxelRenderer {
let frame = context.surface.get_current_texture()?; fn execute(&self, encoder: &mut wgpu::CommandEncoder, view: &wgpu::TextureView) {
let view = frame
.texture
.create_view(&wgpu::TextureViewDescriptor::default());
let mut encoder = context
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("Base Render Encoder"),
});
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"), label: Some("Render Pass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment { color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view, view,
resolve_target: None, resolve_target: None,
ops: wgpu::Operations::default(), ops: wgpu::Operations::default(),
})], })],
@ -61,11 +52,5 @@ impl VoxelRenderer {
render_pass.set_pipeline(&self.render_pipeline); render_pass.set_pipeline(&self.render_pipeline);
render_pass.set_bind_group(0, &self.render_texture.bind_group, &[]); render_pass.set_bind_group(0, &self.render_texture.bind_group, &[]);
render_pass.draw(0..6, 0..1); render_pass.draw(0..6, 0..1);
drop(render_pass);
context.queue.submit(Some(encoder.finish()));
frame.present();
Ok(())
} }
} }