Function forsyth::order_vertices [−][src]
pub fn order_vertices<Index, Vertex>(
vertices: &[Vertex],
indices: &[Index]
) -> Result<(Vec<Vertex>, Vec<Index>), String> where
Index: Copy + Eq + TryInto<usize> + TryFrom<usize> + Hash,
Vertex: Copy,
Expand description
Orders a vertex buffer to maximize data locality.
The returned vertex buffer contains the referenced vertices from vertices
and is ordered to maximize data locality when being read sequentially.
The accompanying index buffer contains the mapped indices
to match the new vertex ordering.
This function can also be used to consolidate sparse index and vertex data as unreferenced vertices are not copied.
use forsyth::order_vertices; assert_eq!( order_vertices(&['d', 'c', 'b', 'a'], &[3, 2, 0, 2, 1, 0]), Ok((vec!['a', 'b', 'd', 'c'], vec![0, 1, 2, 1, 3, 2])) ); // Vertices not referenced by any index are removed assert_eq!( order_vertices(&['x', 'x', 'a', 'b', 'y', 'c'], &[2, 3, 5]), Ok((vec!['a', 'b', 'c'], vec![0, 1, 2])) ); // Indices must be in valid range assert_eq!( order_vertices(&['a', 'b', 'c'], &[0_i8, 1, 99]), Err("index does not point into vertex array (out-of-bounds)".to_string()) ); assert_eq!( order_vertices(&['a', 'b', 'c'], &[0_i8, -1, 2]), Err("failed to convert Index to usize".to_string()) );