2023-06-29 07:55:52 +02:00
|
|
|
//! Draw using different graphical primitives.
|
2023-06-29 07:48:03 +02:00
|
|
|
use crate::core::Rectangle;
|
2023-09-14 13:58:36 -07:00
|
|
|
use crate::custom;
|
2023-06-29 07:48:03 +02:00
|
|
|
use crate::graphics::{Damage, Mesh};
|
2023-09-14 13:58:36 -07:00
|
|
|
use std::any::Any;
|
|
|
|
|
use std::fmt::Debug;
|
|
|
|
|
use std::sync::Arc;
|
2023-06-29 07:48:03 +02:00
|
|
|
|
2023-06-29 07:55:52 +02:00
|
|
|
/// The graphical primitives supported by `iced_wgpu`.
|
2023-06-22 00:38:36 +02:00
|
|
|
pub type Primitive = crate::graphics::Primitive<Custom>;
|
|
|
|
|
|
2023-06-29 07:55:52 +02:00
|
|
|
/// The custom primitives supported by `iced_wgpu`.
|
2023-06-29 07:48:03 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
|
pub enum Custom {
|
2023-06-29 07:55:52 +02:00
|
|
|
/// A mesh primitive.
|
2023-06-29 07:48:03 +02:00
|
|
|
Mesh(Mesh),
|
2023-09-14 13:58:36 -07:00
|
|
|
/// 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),
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-06-29 07:48:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Damage for Custom {
|
|
|
|
|
fn bounds(&self) -> Rectangle {
|
|
|
|
|
match self {
|
|
|
|
|
Self::Mesh(mesh) => mesh.bounds(),
|
2023-09-14 13:58:36 -07:00
|
|
|
Self::Shader(shader) => shader.bounds,
|
2023-06-29 07:48:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-14 13:58:36 -07:00
|
|
|
|
|
|
|
|
#[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()
|
|
|
|
|
}
|
|
|
|
|
}
|