bezier/src/vertex.rs

29 lines
784 B
Rust
Raw Normal View History

2024-06-06 22:40:28 +07:00
#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub struct Vertex {
position: [f32; 2],
color: [f32; 3],
}
impl Vertex {
pub fn new(position: [f32; 2], color: [f32; 3]) -> Vertex {
Vertex {position, color}
}
pub fn new_white(position: [f32; 2]) -> Vertex {
Vertex {position, color: [1.0, 1.0, 1.0]}
}
const ATTRIBS: [wgpu::VertexAttribute; 2] = wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x3];
pub const fn desc() -> wgpu::VertexBufferLayout<'static> {
use std::mem;
wgpu::VertexBufferLayout {
array_stride: mem::size_of::<Self>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &Self::ATTRIBS,
}
}
}