Reintroduce support for custom primitives in iced_wgpu
This commit is contained in:
parent
6ea763c2a7
commit
d922b47815
11 changed files with 220 additions and 173 deletions
|
|
@ -101,8 +101,6 @@ impl Renderer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn draw_primitive(&mut self, _primitive: Primitive) {}
|
||||
|
||||
pub fn present<T: AsRef<str>>(
|
||||
&mut self,
|
||||
engine: &mut Engine,
|
||||
|
|
@ -158,6 +156,19 @@ impl Renderer {
|
|||
);
|
||||
}
|
||||
|
||||
if !layer.primitives.is_empty() {
|
||||
for instance in &layer.primitives {
|
||||
instance.primitive.prepare(
|
||||
device,
|
||||
queue,
|
||||
engine.format,
|
||||
&mut engine.primitive_storage,
|
||||
&instance.bounds,
|
||||
viewport,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if !layer.text.is_empty() {
|
||||
engine.text_pipeline.prepare(
|
||||
device,
|
||||
|
|
@ -247,7 +258,9 @@ impl Renderer {
|
|||
continue;
|
||||
};
|
||||
|
||||
let scissor_rect = physical_bounds.snap();
|
||||
let Some(scissor_rect) = physical_bounds.snap() else {
|
||||
continue;
|
||||
};
|
||||
|
||||
if !layer.quads.is_empty() {
|
||||
engine.quad_pipeline.render(
|
||||
|
|
@ -293,6 +306,43 @@ impl Renderer {
|
|||
));
|
||||
}
|
||||
|
||||
if !layer.primitives.is_empty() {
|
||||
let _ = ManuallyDrop::into_inner(render_pass);
|
||||
|
||||
for instance in &layer.primitives {
|
||||
if let Some(clip_bounds) = (instance.bounds * scale)
|
||||
.intersection(&physical_bounds)
|
||||
.and_then(Rectangle::snap)
|
||||
{
|
||||
instance.primitive.render(
|
||||
encoder,
|
||||
&engine.primitive_storage,
|
||||
frame,
|
||||
&clip_bounds,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
render_pass = ManuallyDrop::new(encoder.begin_render_pass(
|
||||
&wgpu::RenderPassDescriptor {
|
||||
label: Some("iced_wgpu render pass"),
|
||||
color_attachments: &[Some(
|
||||
wgpu::RenderPassColorAttachment {
|
||||
view: frame,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Load,
|
||||
store: wgpu::StoreOp::Store,
|
||||
},
|
||||
},
|
||||
)],
|
||||
depth_stencil_attachment: None,
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
if !layer.text.is_empty() {
|
||||
text_layer += engine.text_pipeline.render(
|
||||
&self.text_storage,
|
||||
|
|
@ -520,6 +570,12 @@ impl graphics::geometry::Renderer for Renderer {
|
|||
}
|
||||
}
|
||||
|
||||
impl primitive::Renderer for Renderer {
|
||||
fn draw_primitive(&mut self, bounds: Rectangle, primitive: impl Primitive) {
|
||||
self.layers.draw_primitive(bounds, Box::new(primitive));
|
||||
}
|
||||
}
|
||||
|
||||
impl graphics::compositor::Default for crate::Renderer {
|
||||
type Compositor = window::Compositor;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue