Use crawl Pass system
This commit is contained in:
parent
04348d96f3
commit
8072576869
|
@ -13,6 +13,7 @@ fn main() -> Result<()> {
|
|||
.build(),
|
||||
)?;
|
||||
let renderer = VoxelRenderer::new(&context)?;
|
||||
let passes: Vec<Box<dyn crawl::Pass>> = 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:?}");
|
||||
}
|
||||
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue