Merge pull request #387 from hatoo/add-comment

Add a comment of how to clear the display to `integration` example
This commit is contained in:
Héctor Ramón 2020-06-05 17:36:18 +02:00 committed by GitHub
commit ca6ff874a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 34 deletions

View file

@ -154,15 +154,20 @@ pub fn main() {
&wgpu::CommandEncoderDescriptor { label: None }, &wgpu::CommandEncoderDescriptor { label: None },
); );
// We draw the scene first
let program = state.program(); let program = state.program();
scene.draw( {
&mut encoder, // We clear the frame
let mut render_pass = scene.clear(
&frame.view, &frame.view,
&mut encoder,
program.background_color(), program.background_color(),
); );
// Draw the scene
scene.draw(&mut render_pass);
}
// And then iced on top // And then iced on top
let mouse_interaction = renderer.backend_mut().draw( let mouse_interaction = renderer.backend_mut().draw(
&mut device, &mut device,

View file

@ -16,16 +16,14 @@ impl Scene {
} }
} }
pub fn draw( pub fn clear<'a>(
&self, &self,
encoder: &mut wgpu::CommandEncoder, target: &'a wgpu::TextureView,
target: &wgpu::TextureView, encoder: &'a mut wgpu::CommandEncoder,
background_color: Color, background_color: Color,
) { ) -> wgpu::RenderPass<'a> {
let mut rpass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor { encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[ color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
wgpu::RenderPassColorAttachmentDescriptor {
attachment: target, attachment: target,
resolve_target: None, resolve_target: None,
load_op: wgpu::LoadOp::Clear, load_op: wgpu::LoadOp::Clear,
@ -40,14 +38,15 @@ impl Scene {
a: a as f64, a: a as f64,
} }
}, },
}, }],
],
depth_stencil_attachment: None, depth_stencil_attachment: None,
}); })
}
rpass.set_pipeline(&self.pipeline); pub fn draw<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) {
rpass.set_bind_group(0, &self.bind_group, &[]); render_pass.set_pipeline(&self.pipeline);
rpass.draw(0..3, 0..1); render_pass.set_bind_group(0, &self.bind_group, &[]);
render_pass.draw(0..3, 0..1);
} }
} }