summaryrefslogtreecommitdiffstats
path: root/graphics/src/mesh.rs
diff options
context:
space:
mode:
authorLibravatar Bingus <shankern@protonmail.com>2023-07-12 12:23:18 -0700
committerLibravatar Bingus <shankern@protonmail.com>2023-07-12 12:23:18 -0700
commit633f405f3f78bc7f82d2b2061491b0e011137451 (patch)
tree5ebfc1f45d216a5c14a90492563599e6969eab4d /graphics/src/mesh.rs
parent41836dd80d0534608e7aedfbf2319c540a23de1a (diff)
parent21bd51426d900e271206f314e0c915dd41065521 (diff)
downloadiced-633f405f3f78bc7f82d2b2061491b0e011137451.tar.gz
iced-633f405f3f78bc7f82d2b2061491b0e011137451.tar.bz2
iced-633f405f3f78bc7f82d2b2061491b0e011137451.zip
Merge remote-tracking branch 'origin/master' into feat/multi-window-support
# Conflicts: # Cargo.toml # core/src/window/icon.rs # core/src/window/id.rs # core/src/window/position.rs # core/src/window/settings.rs # examples/integration/src/main.rs # examples/integration_opengl/src/main.rs # glutin/src/application.rs # native/src/subscription.rs # native/src/window.rs # runtime/src/window/action.rs # src/lib.rs # src/window.rs # winit/Cargo.toml # winit/src/application.rs # winit/src/icon.rs # winit/src/settings.rs # winit/src/window.rs
Diffstat (limited to 'graphics/src/mesh.rs')
-rw-r--r--graphics/src/mesh.rs76
1 files changed, 76 insertions, 0 deletions
diff --git a/graphics/src/mesh.rs b/graphics/src/mesh.rs
new file mode 100644
index 00000000..cfb5a60f
--- /dev/null
+++ b/graphics/src/mesh.rs
@@ -0,0 +1,76 @@
+//! Draw triangles!
+use crate::color;
+use crate::core::{Rectangle, Size};
+use crate::gradient;
+use crate::Damage;
+
+use bytemuck::{Pod, Zeroable};
+
+/// A low-level primitive to render a mesh of triangles.
+#[derive(Debug, Clone, PartialEq)]
+pub enum Mesh {
+ /// A mesh with a solid color.
+ Solid {
+ /// The vertices and indices of the mesh.
+ buffers: Indexed<SolidVertex2D>,
+
+ /// The size of the drawable region of the mesh.
+ ///
+ /// Any geometry that falls out of this region will be clipped.
+ size: Size,
+ },
+ /// A mesh with a gradient.
+ Gradient {
+ /// The vertices and indices of the mesh.
+ buffers: Indexed<GradientVertex2D>,
+
+ /// The size of the drawable region of the mesh.
+ ///
+ /// Any geometry that falls out of this region will be clipped.
+ size: Size,
+ },
+}
+
+impl Damage for Mesh {
+ fn bounds(&self) -> Rectangle {
+ match self {
+ Self::Solid { size, .. } | Self::Gradient { size, .. } => {
+ Rectangle::with_size(*size)
+ }
+ }
+ }
+}
+
+/// A set of [`Vertex2D`] and indices representing a list of triangles.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct Indexed<T> {
+ /// The vertices of the mesh
+ pub vertices: Vec<T>,
+
+ /// The list of vertex indices that defines the triangles of the mesh.
+ ///
+ /// Therefore, this list should always have a length that is a multiple of 3.
+ pub indices: Vec<u32>,
+}
+
+/// A two-dimensional vertex with a color.
+#[derive(Copy, Clone, Debug, PartialEq, Zeroable, Pod)]
+#[repr(C)]
+pub struct SolidVertex2D {
+ /// The vertex position in 2D space.
+ pub position: [f32; 2],
+
+ /// The color of the vertex in __linear__ RGBA.
+ pub color: color::Packed,
+}
+
+/// A vertex which contains 2D position & packed gradient data.
+#[derive(Copy, Clone, Debug, PartialEq, Zeroable, Pod)]
+#[repr(C)]
+pub struct GradientVertex2D {
+ /// The vertex position in 2D space.
+ pub position: [f32; 2],
+
+ /// The packed vertex data of the gradient.
+ pub gradient: gradient::Packed,
+}