summaryrefslogtreecommitdiffstats
path: root/wgpu/src/primitive.rs
diff options
context:
space:
mode:
authorLibravatar Bingus <shankern@protonmail.com>2023-09-14 13:58:36 -0700
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-11-14 11:31:44 +0100
commit781ef1f94c4859aeeb852f801b72be095b8ff82b (patch)
tree63e2678eca11dd41c26a40633c04341fd795d733 /wgpu/src/primitive.rs
parent817f72868746461891ca4e74473c555f3b5c5703 (diff)
downloadiced-781ef1f94c4859aeeb852f801b72be095b8ff82b.tar.gz
iced-781ef1f94c4859aeeb852f801b72be095b8ff82b.tar.bz2
iced-781ef1f94c4859aeeb852f801b72be095b8ff82b.zip
Added support for custom shader widget for iced_wgpu backend.
Diffstat (limited to 'wgpu/src/primitive.rs')
-rw-r--r--wgpu/src/primitive.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/wgpu/src/primitive.rs b/wgpu/src/primitive.rs
index 8dbf3008..4347dcda 100644
--- a/wgpu/src/primitive.rs
+++ b/wgpu/src/primitive.rs
@@ -1,6 +1,10 @@
//! Draw using different graphical primitives.
use crate::core::Rectangle;
+use crate::custom;
use crate::graphics::{Damage, Mesh};
+use std::any::Any;
+use std::fmt::Debug;
+use std::sync::Arc;
/// The graphical primitives supported by `iced_wgpu`.
pub type Primitive = crate::graphics::Primitive<Custom>;
@@ -10,12 +14,44 @@ pub type Primitive = crate::graphics::Primitive<Custom>;
pub enum Custom {
/// A mesh primitive.
Mesh(Mesh),
+ /// A custom shader primitive
+ Shader(Shader),
+}
+
+impl Custom {
+ /// Create a custom [`Shader`] primitive.
+ pub fn shader<P: custom::Primitive>(
+ bounds: Rectangle,
+ primitive: P,
+ ) -> Self {
+ Self::Shader(Shader {
+ bounds,
+ primitive: Arc::new(primitive),
+ })
+ }
}
impl Damage for Custom {
fn bounds(&self) -> Rectangle {
match self {
Self::Mesh(mesh) => mesh.bounds(),
+ Self::Shader(shader) => shader.bounds,
}
}
}
+
+#[derive(Clone, Debug)]
+/// A custom primitive which can be used to render primitives associated with a custom pipeline.
+pub struct Shader {
+ /// The bounds of the [`Shader`].
+ pub bounds: Rectangle,
+
+ /// The [`custom::Primitive`] to render.
+ pub primitive: Arc<dyn custom::Primitive>,
+}
+
+impl PartialEq for Shader {
+ fn eq(&self, other: &Self) -> bool {
+ self.primitive.type_id() == other.primitive.type_id()
+ }
+}