tirbofish/dropbear
main / crates / kino-ui / src / rendering / vertex.rs · 1515 bytes
crates/kino-ui/src/rendering/vertex.rs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use bytemuck::{Pod, Zeroable};
#[repr(C)]
#[derive(Copy, Clone, Pod, Zeroable, Debug)]
pub struct Vertex {
pub position: [f32; 2],
pub colour: [f32; 4],
pub tex_coord: [f32; 2],
}
impl Vertex {
pub fn new(
position: impl Into<[f32; 2]>,
colour: impl Into<[f32; 4]>,
tex_coord: impl Into<[f32; 2]>,
) -> Self {
Self {
position: position.into(),
colour: colour.into(),
tex_coord: tex_coord.into(),
}
}
pub fn desc() -> wgpu::VertexBufferLayout<'static> {
wgpu::VertexBufferLayout {
array_stride: size_of::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[
// position
wgpu::VertexAttribute {
format: wgpu::VertexFormat::Float32x2,
offset: 0,
shader_location: 0,
},
// colour
wgpu::VertexAttribute {
format: wgpu::VertexFormat::Float32x4,
offset: size_of::<[f32; 2]>() as wgpu::BufferAddress,
shader_location: 1,
},
// tex_coords
wgpu::VertexAttribute {
format: wgpu::VertexFormat::Float32x2,
offset: size_of::<[f32; 6]>() as wgpu::BufferAddress,
shader_location: 2,
},
],
}
}
}