Skip to content

Commit

Permalink
layer_brush with rpass
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Feb 12, 2024
1 parent 378b92e commit 2774d90
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
12 changes: 10 additions & 2 deletions sugarloaf/src/components/layer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,24 @@ impl LayerBrush {
self.prepare_layer += 1;
}

#[inline]
pub fn render<'a>(
&'a self,
layer: usize,
bounds: Rectangle<u32>,
render_pass: &mut wgpu::RenderPass<'a>,
rect_bounds: Option<Rectangle<u32>>,
) {
if let Some(layer) = self.layers.get(layer) {
render_pass.set_pipeline(&self.pipeline);

render_pass.set_scissor_rect(bounds.x, bounds.y, bounds.width, bounds.height);
if let Some(bounds) = rect_bounds {
render_pass.set_scissor_rect(
bounds.x,
bounds.y,
bounds.width,
bounds.height,
);
}

render_pass.set_bind_group(1, &self.texture, &[]);
render_pass
Expand Down
26 changes: 14 additions & 12 deletions sugarloaf/src/sugarloaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ impl Sugarloaf {
// } else {
// wgpu::LoadOp::Load
// };
if let Some(bg_image) = &self.background_image {
self.layer_brush.prepare_ref(
&mut encoder,
&mut self.ctx,
&[bg_image],
);
}

{
let mut rpass =
Expand All @@ -365,18 +372,9 @@ impl Sugarloaf {
depth_stencil_attachment: None,
});

// if let Some(bg_image) = &self.background_image {
// self.layer_brush.prepare_ref(
// &mut encoder,
// &mut self.ctx,
// &[bg_image],
// );

// self.layer_brush
// .render_with_encoder(0, view, &mut encoder, None);

// self.layer_brush.end_frame();
// }
if self.background_image.is_some() {
self.layer_brush.render(0, &mut rpass, None);
}

self.rect_brush
.render(&mut rpass, view, &self.state, &mut self.ctx);
Expand Down Expand Up @@ -428,6 +426,10 @@ impl Sugarloaf {
// self.layer_brush.end_frame();
}

if self.background_image.is_some() {
self.layer_brush.end_frame();
}

self.ctx.queue.submit(Some(encoder.finish()));
frame.present();
}
Expand Down

0 comments on commit 2774d90

Please sign in to comment.