summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-11-03 05:06:09 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-11-03 05:06:09 +0100
commit93e309f491a8941bafb919e75d660e65071475f4 (patch)
tree642954d963667d001c3a9fbf4fb7a6b216a58f1e
parent99cf98971dae22ae65adb2104c5a3eec578649f1 (diff)
downloadiced-93e309f491a8941bafb919e75d660e65071475f4.tar.gz
iced-93e309f491a8941bafb919e75d660e65071475f4.tar.bz2
iced-93e309f491a8941bafb919e75d660e65071475f4.zip
Reuse last set pipeline for `triangle` in `iced_wgpu`
-rw-r--r--wgpu/src/triangle.rs19
-rw-r--r--wgpu/src/triangle/gradient.rs8
-rw-r--r--wgpu/src/triangle/solid.rs8
3 files changed, 33 insertions, 2 deletions
diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs
index 28051edf..6e64e189 100644
--- a/wgpu/src/triangle.rs
+++ b/wgpu/src/triangle.rs
@@ -186,6 +186,7 @@ impl Pipeline {
let mut num_solids = 0;
let mut num_gradients = 0;
+ let mut last_is_solid = None;
for (index, mesh) in meshes.iter().enumerate() {
let clip_bounds = (mesh.clip_bounds * scale_factor).snap();
@@ -199,17 +200,35 @@ impl Pipeline {
match mesh.style {
mesh::Style::Solid(_) => {
+ if !last_is_solid.unwrap_or(false) {
+ self.pipelines
+ .solid
+ .set_render_pass_pipeline(&mut render_pass);
+
+ last_is_solid = Some(true);
+ }
+
self.pipelines.solid.configure_render_pass(
&mut render_pass,
num_solids,
);
+
num_solids += 1;
}
mesh::Style::Gradient(_) => {
+ if last_is_solid.unwrap_or(true) {
+ self.pipelines
+ .gradient
+ .set_render_pass_pipeline(&mut render_pass);
+
+ last_is_solid = Some(false);
+ }
+
self.pipelines.gradient.configure_render_pass(
&mut render_pass,
num_gradients,
);
+
num_gradients += 1;
}
};
diff --git a/wgpu/src/triangle/gradient.rs b/wgpu/src/triangle/gradient.rs
index 03332234..b06cbac6 100644
--- a/wgpu/src/triangle/gradient.rs
+++ b/wgpu/src/triangle/gradient.rs
@@ -245,6 +245,13 @@ impl Pipeline {
self.color_stops_pending_write.color_stops.clear();
}
+ pub fn set_render_pass_pipeline<'a>(
+ &'a self,
+ render_pass: &mut wgpu::RenderPass<'a>,
+ ) {
+ render_pass.set_pipeline(&self.pipeline);
+ }
+
/// Configures the current render pass to draw the gradient at its offset stored in the
/// [DynamicBuffer] at [index].
pub fn configure_render_pass<'a>(
@@ -252,7 +259,6 @@ impl Pipeline {
render_pass: &mut wgpu::RenderPass<'a>,
count: usize,
) {
- render_pass.set_pipeline(&self.pipeline);
render_pass.set_bind_group(
0,
&self.bind_group,
diff --git a/wgpu/src/triangle/solid.rs b/wgpu/src/triangle/solid.rs
index 6b5dad41..2e1052f2 100644
--- a/wgpu/src/triangle/solid.rs
+++ b/wgpu/src/triangle/solid.rs
@@ -147,6 +147,13 @@ impl Pipeline {
self.buffer.write(device, staging_belt, encoder);
}
+ pub fn set_render_pass_pipeline<'a>(
+ &'a self,
+ render_pass: &mut wgpu::RenderPass<'a>,
+ ) {
+ render_pass.set_pipeline(&self.pipeline);
+ }
+
/// Configures the current render pass to draw the solid at its offset stored in the
/// [DynamicBuffer] at [index].
pub fn configure_render_pass<'a>(
@@ -154,7 +161,6 @@ impl Pipeline {
render_pass: &mut wgpu::RenderPass<'a>,
count: usize,
) {
- render_pass.set_pipeline(&self.pipeline);
render_pass.set_bind_group(
0,
&self.bind_group,