summaryrefslogtreecommitdiffstats
path: root/graphics/src/layer/mesh.rs
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/src/layer/mesh.rs')
-rw-r--r--graphics/src/layer/mesh.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/graphics/src/layer/mesh.rs b/graphics/src/layer/mesh.rs
new file mode 100644
index 00000000..0946317e
--- /dev/null
+++ b/graphics/src/layer/mesh.rs
@@ -0,0 +1,51 @@
+//! A collection of triangle primitives.
+
+use crate::{Color, Point, Rectangle, triangle};
+use crate::gradient::Gradient;
+
+/// A mesh of triangles.
+#[derive(Debug, Clone, Copy)]
+pub struct Mesh<'a> {
+ /// The origin of the vertices of the [`Mesh`].
+ pub origin: Point,
+
+ /// The vertex and index buffers of the [`Mesh`].
+ pub buffers: &'a triangle::Mesh2D,
+
+ /// The clipping bounds of the [`Mesh`].
+ pub clip_bounds: Rectangle<f32>,
+
+ /// The shader of the [`Mesh`].
+ pub style: &'a Style,
+}
+
+#[derive(Debug, Clone)]
+/// Supported shaders for primitives.
+pub enum Style {
+ /// Fill a primitive with a solid color.
+ Solid(Color),
+ /// Fill a primitive with an interpolated color.
+ Gradient(Gradient)
+}
+
+impl <'a> Into<Style> for Gradient {
+ fn into(self) -> Style {
+ match self {
+ Gradient::Linear(linear) => {
+ Style::Gradient(Gradient::Linear(linear))
+ }
+ }
+ }
+}
+
+/// Returns the number of total vertices & total indices of all [`Mesh`]es.
+pub fn attribute_count_of<'a>(meshes: &'a [Mesh<'a>]) -> (usize, usize) {
+ meshes
+ .iter()
+ .map(|Mesh { buffers, .. }| {
+ (buffers.vertices.len(), buffers.indices.len())
+ })
+ .fold((0, 0), |(total_v, total_i), (v, i)| {
+ (total_v + v, total_i + i)
+ })
+}