First half of buffers
This commit is contained in:
47
src/vertex.rs
Normal file
47
src/vertex.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
|
||||
pub struct Vertex {
|
||||
position: [f32; 3],
|
||||
color: [f32; 3],
|
||||
}
|
||||
|
||||
impl Vertex {
|
||||
pub fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
|
||||
wgpu::VertexBufferLayout {
|
||||
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
|
||||
step_mode: wgpu::InputStepMode::Vertex,
|
||||
// this oculd be shortened with:
|
||||
// attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3],
|
||||
attributes: &[
|
||||
wgpu::VertexAttribute {
|
||||
offset: 0,
|
||||
shader_location: 0,
|
||||
format: wgpu::VertexFormat::Float32x3,
|
||||
},
|
||||
wgpu::VertexAttribute {
|
||||
offset: std::mem::size_of::<[f32; 3]>() as wgpu::BufferAddress,
|
||||
shader_location: 1,
|
||||
format: wgpu::VertexFormat::Float32x3,
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const VERTICES: &[Vertex] = &[
|
||||
// Top
|
||||
Vertex {
|
||||
position: [0.0, 0.5, 0.0],
|
||||
color: [1.0, 0.0, 0.0],
|
||||
},
|
||||
// Left
|
||||
Vertex {
|
||||
position: [-0.5, -0.5, 0.0],
|
||||
color: [0.0, 1.0, 0.0],
|
||||
},
|
||||
// Right
|
||||
Vertex {
|
||||
position: [0.5, -0.5, 0.0],
|
||||
color: [0.0, 0.0, 1.0],
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user