summaryrefslogtreecommitdiff
path: root/src/vertex.rs
diff options
context:
space:
mode:
authorMicha White <botahamec@outlook.com>2022-09-18 15:30:56 -0400
committerMicha White <botahamec@outlook.com>2022-09-18 15:30:56 -0400
commitd613b20803f41eeb4f6ae27003d5bfa371502930 (patch)
tree233f1906d0150b4fce80af3fb63dceeb70f308da /src/vertex.rs
parentffee09ada476b3a350f331718d60fa806b564bad (diff)
Created a vertex buffer
Diffstat (limited to 'src/vertex.rs')
-rw-r--r--src/vertex.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/vertex.rs b/src/vertex.rs
new file mode 100644
index 0000000..7735801
--- /dev/null
+++ b/src/vertex.rs
@@ -0,0 +1,34 @@
+use std::mem::size_of;
+
+use bytemuck::{Pod, Zeroable};
+
+pub const SQUARE: [Vertex; 4] = [
+ Vertex::new(-0.5, -0.5),
+ Vertex::new(0.5, -0.5),
+ Vertex::new(-0.5, 0.5),
+ Vertex::new(0.5, 0.5),
+];
+
+#[repr(C)]
+#[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)]
+pub struct Vertex {
+ position: [f32; 2],
+}
+
+impl Vertex {
+ const fn new(x: f32, y: f32) -> Self {
+ Self { position: [x, y] }
+ }
+}
+
+impl Vertex {
+ const ATTRIBUTES: [wgpu::VertexAttribute; 1] = wgpu::vertex_attr_array![0 => Float32x2];
+
+ 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,
+ }
+ }
+}