aleatico 0.1.1

stub package for furmint engine graphics
Documentation
/// Structure representing a raw vertex in the memory
#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub struct ColoredVertex {
    /// Vertex position
    pub position: [f32; 3],
    /// Vertex color
    pub color: [f32; 3],
}

/// Structure representing a raw textured vertex in the memory
#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub struct TexturedVertex {
    /// Vertex position
    pub position: [f32; 3],
    /// Vertex texture coordinates
    pub tex_coords: [f32; 2],
}

/// Trait that a vertex should implement to be used in a [`crate::renderer::resources::pipelines::Pipeline`]
pub trait DescribableVertex<'a> {
    /// Return a buffer layout for this vertex
    fn desc() -> wgpu::VertexBufferLayout<'a>;
}

impl<'a> DescribableVertex<'a> for ColoredVertex {
    fn desc() -> wgpu::VertexBufferLayout<'static> {
        wgpu::VertexBufferLayout {
            array_stride: size_of::<ColoredVertex>() as wgpu::BufferAddress,
            step_mode: wgpu::VertexStepMode::Vertex,
            attributes: &[
                wgpu::VertexAttribute {
                    offset: 0,
                    shader_location: 0,
                    format: wgpu::VertexFormat::Float32x3,
                },
                wgpu::VertexAttribute {
                    offset: size_of::<[f32; 3]>() as wgpu::BufferAddress,
                    shader_location: 1,
                    format: wgpu::VertexFormat::Float32x3,
                },
            ],
        }
    }
}

impl<'a> DescribableVertex<'a> for TexturedVertex {
    fn desc() -> wgpu::VertexBufferLayout<'static> {
        wgpu::VertexBufferLayout {
            array_stride: size_of::<TexturedVertex>() as wgpu::BufferAddress,
            step_mode: wgpu::VertexStepMode::Vertex,
            attributes: &[
                wgpu::VertexAttribute {
                    offset: 0,
                    shader_location: 0,
                    format: wgpu::VertexFormat::Float32x3,
                },
                wgpu::VertexAttribute {
                    offset: size_of::<[f32; 3]>() as wgpu::BufferAddress,
                    shader_location: 1,
                    format: wgpu::VertexFormat::Float32x2, // NEW!
                },
            ],
        }
    }
}