From 3645d34d6a1ba1247238e830e9eefd52d9e5b986 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 21 Mar 2024 22:27:17 +0100 Subject: Implement composable, type-safe renderer fallback --- graphics/src/mesh.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'graphics/src/mesh.rs') diff --git a/graphics/src/mesh.rs b/graphics/src/mesh.rs index 041986cf..5be3ee5b 100644 --- a/graphics/src/mesh.rs +++ b/graphics/src/mesh.rs @@ -1,6 +1,6 @@ //! Draw triangles! use crate::color; -use crate::core::{Rectangle, Size}; +use crate::core::{self, Rectangle, Size}; use crate::gradient; use crate::Damage; @@ -74,3 +74,7 @@ pub struct GradientVertex2D { /// The packed vertex data of the gradient. pub gradient: gradient::Packed, } + +pub trait Renderer: core::Renderer { + fn draw_mesh(&mut self, mesh: Mesh); +} -- cgit From 85800c99ab285efd244c0addfdcf3c732a98de1d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 22 Mar 2024 01:53:48 +0100 Subject: Fix broken links in documentation --- graphics/src/mesh.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'graphics/src/mesh.rs') diff --git a/graphics/src/mesh.rs b/graphics/src/mesh.rs index 5be3ee5b..d671f494 100644 --- a/graphics/src/mesh.rs +++ b/graphics/src/mesh.rs @@ -75,6 +75,8 @@ pub struct GradientVertex2D { pub gradient: gradient::Packed, } +/// A renderer capable of drawing a [`Mesh`]. pub trait Renderer: core::Renderer { + /// Draws the given [`Mesh`]. fn draw_mesh(&mut self, mesh: Mesh); } -- cgit From 1f13a91361258a1607c71f4840a26a6437f88612 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 22 Mar 2024 05:27:31 +0100 Subject: Make `iced_tiny_skia` optional with a `tiny-skia` feature --- graphics/src/mesh.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'graphics/src/mesh.rs') diff --git a/graphics/src/mesh.rs b/graphics/src/mesh.rs index d671f494..20692b07 100644 --- a/graphics/src/mesh.rs +++ b/graphics/src/mesh.rs @@ -1,6 +1,6 @@ //! Draw triangles! use crate::color; -use crate::core::{self, Rectangle, Size}; +use crate::core::{Rectangle, Size}; use crate::gradient; use crate::Damage; @@ -76,7 +76,7 @@ pub struct GradientVertex2D { } /// A renderer capable of drawing a [`Mesh`]. -pub trait Renderer: core::Renderer { +pub trait Renderer { /// Draws the given [`Mesh`]. fn draw_mesh(&mut self, mesh: Mesh); } -- cgit From b05e61f5c8ae61c9f3c7cc08cded53901ebbccfd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 3 Apr 2024 21:07:54 +0200 Subject: Redesign `iced_wgpu` layering architecture --- graphics/src/mesh.rs | 90 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 12 deletions(-) (limited to 'graphics/src/mesh.rs') diff --git a/graphics/src/mesh.rs b/graphics/src/mesh.rs index 20692b07..d3e7ffaf 100644 --- a/graphics/src/mesh.rs +++ b/graphics/src/mesh.rs @@ -1,8 +1,7 @@ //! Draw triangles! use crate::color; -use crate::core::{Rectangle, Size}; +use crate::core::{Rectangle, Size, Transformation}; use crate::gradient; -use crate::Damage; use bytemuck::{Pod, Zeroable}; @@ -14,9 +13,10 @@ pub enum Mesh { /// The vertices and indices of the mesh. buffers: Indexed, - /// The size of the drawable region of the mesh. - /// - /// Any geometry that falls out of this region will be clipped. + /// The [`Transformation`] for the vertices of the [`Mesh`]. + transformation: Transformation, + + /// The [`Size`] of the [`Mesh`]. size: Size, }, /// A mesh with a gradient. @@ -24,19 +24,44 @@ pub enum Mesh { /// The vertices and indices of the mesh. buffers: Indexed, - /// The size of the drawable region of the mesh. - /// - /// Any geometry that falls out of this region will be clipped. + /// The [`Transformation`] for the vertices of the [`Mesh`]. + transformation: Transformation, + + /// The [`Size`] of the [`Mesh`]. size: Size, }, } -impl Damage for Mesh { - fn bounds(&self) -> Rectangle { +impl Mesh { + /// Returns the indices of the [`Mesh`]. + pub fn indices(&self) -> &[u32] { + match self { + Self::Solid { buffers, .. } => &buffers.indices, + Self::Gradient { buffers, .. } => &buffers.indices, + } + } + + /// Returns the [`Transformation`] of the [`Mesh`]. + pub fn transformation(&self) -> Transformation { + match self { + Self::Solid { transformation, .. } + | Self::Gradient { transformation, .. } => *transformation, + } + } + + /// Returns the clip bounds of the [`Mesh`]. + pub fn clip_bounds(&self) -> Rectangle { match self { - Self::Solid { size, .. } | Self::Gradient { size, .. } => { - Rectangle::with_size(*size) + Self::Solid { + size, + transformation, + .. } + | Self::Gradient { + size, + transformation, + .. + } => Rectangle::with_size(*size) * *transformation, } } } @@ -75,6 +100,47 @@ pub struct GradientVertex2D { pub gradient: gradient::Packed, } +/// The result of counting the attributes of a set of meshes. +#[derive(Debug, Clone, Copy, Default)] +pub struct AttributeCount { + /// The total amount of solid vertices. + pub solid_vertices: usize, + + /// The total amount of solid meshes. + pub solids: usize, + + /// The total amount of gradient vertices. + pub gradient_vertices: usize, + + /// The total amount of gradient meshes. + pub gradients: usize, + + /// The total amount of indices. + pub indices: usize, +} + +/// Returns the number of total vertices & total indices of all [`Mesh`]es. +pub fn attribute_count_of(meshes: &[Mesh]) -> AttributeCount { + meshes + .iter() + .fold(AttributeCount::default(), |mut count, mesh| { + match mesh { + Mesh::Solid { buffers, .. } => { + count.solids += 1; + count.solid_vertices += buffers.vertices.len(); + count.indices += buffers.indices.len(); + } + Mesh::Gradient { buffers, .. } => { + count.gradients += 1; + count.gradient_vertices += buffers.vertices.len(); + count.indices += buffers.indices.len(); + } + } + + count + }) +} + /// A renderer capable of drawing a [`Mesh`]. pub trait Renderer { /// Draws the given [`Mesh`]. -- cgit From 6d3e1d835e1688fbc58622a03a784ed25ed3f0e1 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 5 Apr 2024 23:59:21 +0200 Subject: Decouple caching from layering and simplify everything --- graphics/src/mesh.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'graphics/src/mesh.rs') diff --git a/graphics/src/mesh.rs b/graphics/src/mesh.rs index d3e7ffaf..76602319 100644 --- a/graphics/src/mesh.rs +++ b/graphics/src/mesh.rs @@ -1,6 +1,6 @@ //! Draw triangles! use crate::color; -use crate::core::{Rectangle, Size, Transformation}; +use crate::core::{Rectangle, Transformation}; use crate::gradient; use bytemuck::{Pod, Zeroable}; @@ -16,8 +16,8 @@ pub enum Mesh { /// The [`Transformation`] for the vertices of the [`Mesh`]. transformation: Transformation, - /// The [`Size`] of the [`Mesh`]. - size: Size, + /// The clip bounds of the [`Mesh`]. + clip_bounds: Rectangle, }, /// A mesh with a gradient. Gradient { @@ -27,8 +27,8 @@ pub enum Mesh { /// The [`Transformation`] for the vertices of the [`Mesh`]. transformation: Transformation, - /// The [`Size`] of the [`Mesh`]. - size: Size, + /// The clip bounds of the [`Mesh`]. + clip_bounds: Rectangle, }, } @@ -53,15 +53,15 @@ impl Mesh { pub fn clip_bounds(&self) -> Rectangle { match self { Self::Solid { - size, + clip_bounds, transformation, .. } | Self::Gradient { - size, + clip_bounds, transformation, .. - } => Rectangle::with_size(*size) * *transformation, + } => *clip_bounds * *transformation, } } } -- cgit