summaryrefslogtreecommitdiffstats
path: root/src/vertex.rs
blob: aab7d02ff0f0556eac0770d3117fa3582455387d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub struct Vertex
{
    pub position: [f32;3],
    pub uv: [f32;2]
}

impl Vertex
{
    const ATTRIBS: [wgpu::VertexAttribute;2] =
        wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x2];

    pub fn descr()
    -> 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
        }
    }
}

pub const QUAD_VERTICES: &[Vertex] = &[
    Vertex { position: [ -1.0, -1.0, 0.0 ], uv: [ 0.0, 1.0 ] },
    Vertex { position: [  1.0, -1.0, 0.0 ], uv: [ 1.0, 1.0 ] },
    Vertex { position: [  1.0,  1.0, 0.0 ], uv: [ 1.0, 0.0 ] },
    Vertex { position: [  1.0,  1.0, 0.0 ], uv: [ 1.0, 0.0 ] },
    Vertex { position: [ -1.0,  1.0, 0.0 ], uv: [ 0.0, 0.0 ] },
    Vertex { position: [ -1.0, -1.0, 0.0 ], uv: [ 0.0, 1.0 ] }
];