use bytemuck::{Pod, Zeroable};
pub trait VertexDesc: Sized {
fn attribs() -> &'static [wgpu::VertexAttribute];
fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
use std::mem;
wgpu::VertexBufferLayout {
array_stride: mem::size_of::<Self>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: Self::attribs(),
}
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Pod, Zeroable)]
pub struct SpriteVertex {
pub position: [f32; 3],
pub tex_coords: [f32; 2],
pub tint: [f32; 4],
}
impl VertexDesc for SpriteVertex {
fn attribs() -> &'static [wgpu::VertexAttribute] {
static SPRITE_ATTRIBS: [wgpu::VertexAttribute; 3] =
wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x2, 2 => Float32x4];
&SPRITE_ATTRIBS
}
}