Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make iced_wgpu::mesh::Indexed use Arc<[_]> instead of Vec<_> #2703

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions examples/geometry/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions graphics/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -70,12 +71,12 @@ impl Mesh {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Indexed<T> {
/// The vertices of the mesh
pub vertices: Vec<T>,
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<u32>,
pub indices: Arc<[u32]>,
}

/// A two-dimensional vertex with a color.
Expand Down
8 changes: 4 additions & 4 deletions wgpu/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading