use bytemuck::{Pod, Zeroable};
use wgpu::{BufferAddress, VertexAttribute, VertexBufferLayout, VertexFormat, VertexStepMode};

pub type Vector3 = [f32; 3];
pub type RGBColor = Vector3;

#[repr(C)]
#[derive(PartialEq, Copy, Clone, Debug, Zeroable, Pod)]
pub struct Vertex {
    pub position: Vector3,
    pub color: RGBColor
}

impl Vertex {
    pub fn descriptor() -> VertexBufferLayout<'static> {
        VertexBufferLayout {
            array_stride: std::mem::size_of::<Vertex>() as BufferAddress,
            step_mode: VertexStepMode::Vertex,
            attributes: &[
                VertexAttribute {
                    format: VertexFormat::Float32x3,
                    offset: 0,
                    shader_location: 0,
                },
                VertexAttribute {
                    format: VertexFormat::Float32x3,
                    offset: std::mem::size_of::<Vector3>() as BufferAddress,
                    shader_location: 1,
                }
            ],
        }
    }
}

/*
C--D
|  |
A--B

ABC <-> BCD
 */

pub const VERTICES: &[Vertex] = &[

    Vertex { position: [-1.0, -1.0, 0.0], color: [1.0, 0.0, 0.0] }, // A
    Vertex { position: [1.0, -1.0, 0.0], color: [0.0, 1.0, 0.0] }, // B
    Vertex { position: [-1.0, 1.0, 0.0], color: [0.0, 0.0, 1.0] }, // C
    Vertex { position: [1.0, 1.0, 0.0], color: [1.0, 1.0, 1.0] }, // D
];

pub const INDICES: &[u16] = &[
    0, 1, 2,
    3, 2, 1
];



