// Copyright (c) 2021 The vulkano developers // Licensed under the Apache License, Version 2.0 // or the MIT // license , // at your option. All files in the project carrying such // notice may not be copied, modified, or distributed except // according to those terms. use crate::buffer::Subbuffer; use std::mem; /// A collection of vertex buffers. pub trait VertexBuffersCollection { /// Converts `self` into a list of buffers. // TODO: better than a Vec fn into_vec(self) -> Vec>; } impl VertexBuffersCollection for () { #[inline] fn into_vec(self) -> Vec> { Vec::new() } } impl VertexBuffersCollection for Subbuffer { fn into_vec(self) -> Vec> { vec![self.into_bytes()] } } impl VertexBuffersCollection for Vec> { fn into_vec(self) -> Vec> { assert!(mem::size_of::>() == mem::size_of::>()); assert!(mem::align_of::>() == mem::align_of::>()); // SAFETY: All `Subbuffer`s share the same layout. unsafe { mem::transmute::>, Vec>>(self) } } } impl VertexBuffersCollection for [Subbuffer; N] { fn into_vec(self) -> Vec> { self.into_iter().map(Subbuffer::into_bytes).collect() } } macro_rules! impl_collection { ($first:ident $(, $others:ident)*) => ( impl<$first: ?Sized $(, $others: ?Sized)*> VertexBuffersCollection for (Subbuffer<$first>, $(Subbuffer<$others>),*) { #[inline] #[allow(non_snake_case)] fn into_vec(self) -> Vec> { let ($first, $($others,)*) = self; vec![$first.into_bytes() $(, $others.into_bytes())*] } } impl_collection!($($others),*); ); () => {} } impl_collection!(Z, Y, X, W, V, U, T, S, R, Q, P, O, N, M, L, K, J, I, H, G, F, E, D, C, B, A);