From 06249f52890114de2cf1add8312a449d5ca2ec38 Mon Sep 17 00:00:00 2001 From: edwloef Date: Thu, 19 Dec 2024 17:51:42 +0100 Subject: [PATCH] make `iced_wgpu::mesh::Indexed` use `Arc<[_]>` instead of `Vec<_>` --- examples/geometry/src/main.rs | 10 ++++++---- graphics/src/mesh.rs | 5 +++-- wgpu/src/geometry.rs | 8 ++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/examples/geometry/src/main.rs b/examples/geometry/src/main.rs index d53ae6a563..8aa831b0af 100644 --- a/examples/geometry/src/main.rs +++ b/examples/geometry/src/main.rs @@ -83,7 +83,7 @@ mod rainbow { let mesh = Mesh::Solid { buffers: mesh::Indexed { - vertices: vec![ + vertices: [ SolidVertex2D { position: posn_center, color: color::pack([1.0, 1.0, 1.0, 1.0]), @@ -120,8 +120,9 @@ mod rainbow { position: posn_l, color: color::pack(color_v), }, - ], - indices: vec![ + ] + .into(), + indices: [ 0, 1, 2, // TL 0, 2, 3, // T 0, 3, 4, // TR @@ -130,7 +131,8 @@ mod rainbow { 0, 6, 7, // B 0, 7, 8, // BL 0, 8, 1, // L - ], + ] + .into(), }, transformation: Transformation::IDENTITY, clip_bounds: Rectangle::INFINITE, diff --git a/graphics/src/mesh.rs b/graphics/src/mesh.rs index 7660231930..41afe22640 100644 --- a/graphics/src/mesh.rs +++ b/graphics/src/mesh.rs @@ -4,6 +4,7 @@ use crate::core::{Rectangle, Transformation}; use crate::gradient; use bytemuck::{Pod, Zeroable}; +use std::sync::Arc; /// A low-level primitive to render a mesh of triangles. #[derive(Debug, Clone, PartialEq)] @@ -70,12 +71,12 @@ impl Mesh { #[derive(Clone, Debug, PartialEq, Eq)] pub struct Indexed { /// The vertices of the mesh - pub vertices: Vec, + pub vertices: Arc<[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, + pub indices: Arc<[u32]>, } /// A two-dimensional vertex with a color. diff --git a/wgpu/src/geometry.rs b/wgpu/src/geometry.rs index d2ffda53e1..d1749fbbce 100644 --- a/wgpu/src/geometry.rs +++ b/wgpu/src/geometry.rs @@ -527,8 +527,8 @@ impl BufferStack { Buffer::Solid(buffer) if !buffer.indices.is_empty() => { Some(Mesh::Solid { buffers: mesh::Indexed { - vertices: buffer.vertices, - indices: buffer.indices, + vertices: Arc::from(buffer.vertices), + indices: Arc::from(buffer.indices), }, clip_bounds, transformation: Transformation::IDENTITY, @@ -537,8 +537,8 @@ impl BufferStack { Buffer::Gradient(buffer) if !buffer.indices.is_empty() => { Some(Mesh::Gradient { buffers: mesh::Indexed { - vertices: buffer.vertices, - indices: buffer.indices, + vertices: Arc::from(buffer.vertices), + indices: Arc::from(buffer.indices), }, clip_bounds, transformation: Transformation::IDENTITY,