Share a single render pass

This commit is contained in:
Hanno Braun 2024-11-25 21:10:10 +01:00
parent b32b232a06
commit 8d38eb0005
2 changed files with 30 additions and 66 deletions

View File

@ -108,36 +108,9 @@ impl<V> Pipeline<V> {
pub fn draw(
&self,
encoder: &mut wgpu::CommandEncoder,
color_view: &wgpu::TextureView,
depth_view: &wgpu::TextureView,
render_pass: &mut wgpu::RenderPass,
geometry: &Geometry<V>,
) {
let mut render_pass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: color_view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: Some(
wgpu::RenderPassDepthStencilAttachment {
view: depth_view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Load,
store: wgpu::StoreOp::Store,
}),
stencil_ops: None,
},
),
timestamp_writes: None,
occlusion_query_set: None,
});
if geometry.num_indices > 0 {
render_pass.set_index_buffer(
geometry.indices.slice(..),

View File

@ -89,45 +89,36 @@ impl Renderer {
.create_view(&wgpu::TextureViewDescriptor::default());
{
// No need to do anything else with the render pass. Creating and
// then dropping it is enough to clear the background.
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &color_view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::WHITE),
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: Some(
wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Clear(1.0),
store: wgpu::StoreOp::Store,
}),
stencil_ops: None,
},
),
timestamp_writes: None,
occlusion_query_set: None,
});
}
let mut render_pass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[Some(
wgpu::RenderPassColorAttachment {
view: &color_view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::WHITE),
store: wgpu::StoreOp::Store,
},
},
)],
depth_stencil_attachment: Some(
wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Clear(1.0),
store: wgpu::StoreOp::Store,
}),
stencil_ops: None,
},
),
timestamp_writes: None,
occlusion_query_set: None,
});
self.pipelines.vertices.draw(
&mut encoder,
&color_view,
&self.depth_view,
&vertices,
);
self.pipelines.triangles.draw(
&mut encoder,
&color_view,
&self.depth_view,
&triangles,
);
self.pipelines.vertices.draw(&mut render_pass, &vertices);
self.pipelines.triangles.draw(&mut render_pass, &triangles);
}
self.queue.submit(Some(encoder.finish()));
frame.present();