summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-11-28 23:13:38 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-11-28 23:13:38 +0100
commitab7dae554cac801aeed5d9aa4d3850d50be86263 (patch)
tree4165df808d50fbaa4cb9b27ded59077b769a4135 /wgpu
parent100d15f30654d446cffe2fb60a435c79c81b0188 (diff)
downloadiced-ab7dae554cac801aeed5d9aa4d3850d50be86263.tar.gz
iced-ab7dae554cac801aeed5d9aa4d3850d50be86263.tar.bz2
iced-ab7dae554cac801aeed5d9aa4d3850d50be86263.zip
Provide actual bounds to `Shader` primitives
... and allow for proper translation and scissoring.
Diffstat (limited to '')
-rw-r--r--wgpu/src/backend.rs8
-rw-r--r--wgpu/src/layer.rs15
-rw-r--r--wgpu/src/layer/pipeline.rs17
-rw-r--r--wgpu/src/primitive/pipeline.rs5
4 files changed, 30 insertions, 15 deletions
diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs
index 88caad06..25134d68 100644
--- a/wgpu/src/backend.rs
+++ b/wgpu/src/backend.rs
@@ -192,9 +192,9 @@ impl Backend {
format,
device,
queue,
+ pipeline.bounds,
target_size,
scale_factor,
- transformation,
&mut self.pipeline_storage,
);
}
@@ -327,17 +327,17 @@ impl Backend {
let _ = ManuallyDrop::into_inner(render_pass);
for pipeline in &layer.pipelines {
- let bounds = (pipeline.bounds * scale_factor).snap();
+ let viewport = (pipeline.viewport * scale_factor).snap();
- if bounds.width < 1 || bounds.height < 1 {
+ if viewport.width < 1 || viewport.height < 1 {
continue;
}
pipeline.primitive.render(
&self.pipeline_storage,
- bounds,
target,
target_size,
+ viewport,
encoder,
);
}
diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs
index 33aaf670..98e49f1a 100644
--- a/wgpu/src/layer.rs
+++ b/wgpu/src/layer.rs
@@ -1,11 +1,13 @@
//! Organize rendering primitives into a flattened list of layers.
mod image;
+mod pipeline;
mod text;
pub mod mesh;
pub use image::Image;
pub use mesh::Mesh;
+pub use pipeline::Pipeline;
pub use text::Text;
use crate::core;
@@ -36,7 +38,7 @@ pub struct Layer<'a> {
pub images: Vec<Image>,
/// The custom pipelines of this [`Layer`].
- pub pipelines: Vec<primitive::Pipeline>,
+ pub pipelines: Vec<Pipeline>,
}
impl<'a> Layer<'a> {
@@ -314,17 +316,14 @@ impl<'a> Layer<'a> {
},
primitive::Custom::Pipeline(pipeline) => {
let layer = &mut layers[current_layer];
-
- let bounds = Rectangle::new(
- Point::new(translation.x, translation.y),
- pipeline.bounds.size(),
- );
+ let bounds = pipeline.bounds + translation;
if let Some(clip_bounds) =
layer.bounds.intersection(&bounds)
{
- layer.pipelines.push(primitive::Pipeline {
- bounds: clip_bounds,
+ layer.pipelines.push(Pipeline {
+ bounds,
+ viewport: clip_bounds,
primitive: pipeline.primitive.clone(),
});
}
diff --git a/wgpu/src/layer/pipeline.rs b/wgpu/src/layer/pipeline.rs
new file mode 100644
index 00000000..6dfe6750
--- /dev/null
+++ b/wgpu/src/layer/pipeline.rs
@@ -0,0 +1,17 @@
+use crate::core::Rectangle;
+use crate::primitive::pipeline::Primitive;
+
+use std::sync::Arc;
+
+#[derive(Clone, Debug)]
+/// A custom primitive which can be used to render primitives associated with a custom pipeline.
+pub struct Pipeline {
+ /// The bounds of the [`Pipeline`].
+ pub bounds: Rectangle,
+
+ /// The viewport of the [`Pipeline`].
+ pub viewport: Rectangle,
+
+ /// The [`Primitive`] to render.
+ pub primitive: Arc<dyn Primitive>,
+}
diff --git a/wgpu/src/primitive/pipeline.rs b/wgpu/src/primitive/pipeline.rs
index 5dbd6697..302e38f6 100644
--- a/wgpu/src/primitive/pipeline.rs
+++ b/wgpu/src/primitive/pipeline.rs
@@ -1,6 +1,5 @@
//! Draw primitives using custom pipelines.
use crate::core::{Rectangle, Size};
-use crate::graphics::Transformation;
use std::any::{Any, TypeId};
use std::collections::HashMap;
@@ -41,9 +40,9 @@ pub trait Primitive: Debug + Send + Sync + 'static {
format: wgpu::TextureFormat,
device: &wgpu::Device,
queue: &wgpu::Queue,
+ bounds: Rectangle,
target_size: Size<u32>,
scale_factor: f32,
- transform: Transformation,
storage: &mut Storage,
);
@@ -51,9 +50,9 @@ pub trait Primitive: Debug + Send + Sync + 'static {
fn render(
&self,
storage: &Storage,
- bounds: Rectangle<u32>,
target: &wgpu::TextureView,
target_size: Size<u32>,
+ viewport: Rectangle<u32>,
encoder: &mut wgpu::CommandEncoder,
);
}