diff options
| author | Micha White <botahamec@outlook.com> | 2022-10-20 20:39:44 -0400 |
|---|---|---|
| committer | Micha White <botahamec@outlook.com> | 2022-10-20 20:39:44 -0400 |
| commit | 93347346e8bd8f7412ae03a0858dd307a1df2e0d (patch) | |
| tree | 17805956857c76b5fed3f47a821fcdf6141cf7a6 /alligator_render/src/vertex.rs | |
| parent | e337741969160603f06a7f2b30cda375eeef99fb (diff) | |
Moved files into workspace
Diffstat (limited to 'alligator_render/src/vertex.rs')
| -rw-r--r-- | alligator_render/src/vertex.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/alligator_render/src/vertex.rs b/alligator_render/src/vertex.rs new file mode 100644 index 0000000..570eec4 --- /dev/null +++ b/alligator_render/src/vertex.rs @@ -0,0 +1,39 @@ +use std::mem::size_of; + +use bytemuck::{Pod, Zeroable}; + +/// The vertices needed to form a square +pub const SQUARE: [Vertex; 6] = [ + Vertex::new(-0.5, -0.5), + Vertex::new(0.5, -0.5), + Vertex::new(-0.5, 0.5), + Vertex::new(0.5, 0.5), + Vertex::new(-0.5, 0.5), + Vertex::new(0.5, -0.5), +]; + +/// A vertex that is usable by the alligator shader +#[repr(C)] +#[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)] +pub struct Vertex { + position: [f32; 2], +} + +impl Vertex { + // whenever this is updated, please also update `sprite.wgsl` + pub(crate) const ATTRIBUTES: [wgpu::VertexAttribute; 1] = + wgpu::vertex_attr_array![0 => Float32x2]; + + /// Create a new vertex + const fn new(x: f32, y: f32) -> Self { + Self { position: [x, y] } + } + + pub(crate) const fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { + wgpu::VertexBufferLayout { + array_stride: size_of::<Self>() as wgpu::BufferAddress, + step_mode: wgpu::VertexStepMode::Vertex, + attributes: &Self::ATTRIBUTES, + } + } +} |
