use crate::color::Rgba8;
use crate::gfx::ColorMode;
use crate::math::Vec2F;
use bytemuck::{Pod, Zeroable};
use wgpu::{BufferAddress, VertexAttribute, VertexBufferLayout, VertexFormat, VertexStepMode};
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Zeroable, Pod)]
pub struct Vertex {
pub pos: Vec2F,
pub tex: Vec2F,
pub col: Rgba8,
pub mode: ColorMode,
}
impl Vertex {
pub(crate) const LAYOUT: VertexBufferLayout<'static> = VertexBufferLayout {
array_stride: size_of::<Self>() as BufferAddress,
step_mode: VertexStepMode::Vertex,
attributes: &[
VertexAttribute {
format: VertexFormat::Float32x2,
offset: 0,
shader_location: 0,
},
VertexAttribute {
format: VertexFormat::Float32x2,
offset: 8,
shader_location: 1,
},
VertexAttribute {
format: VertexFormat::Unorm8x4,
offset: 16,
shader_location: 2,
},
VertexAttribute {
format: VertexFormat::Unorm8x4,
offset: 20,
shader_location: 3,
},
],
};
#[inline]
pub const fn new(pos: Vec2F, tex: Vec2F, col: Rgba8, mode: ColorMode) -> Self {
Self {
pos,
tex,
col,
mode,
}
}
#[inline]
pub const fn simple(pos: Vec2F, tex: Vec2F) -> Self {
Self::new(pos, tex, Rgba8::WHITE, ColorMode::MULT)
}
#[inline]
pub const fn mult(pos: Vec2F, tex: Vec2F, col: Rgba8) -> Self {
Self::new(pos, tex, col, ColorMode::MULT)
}
#[inline]
pub const fn wash(pos: Vec2F, tex: Vec2F, col: Rgba8) -> Self {
Self::new(pos, tex, col, ColorMode::WASH)
}
#[inline]
pub const fn veto(pos: Vec2F, col: Rgba8) -> Self {
Self::new(pos, Vec2F::ZERO, col, ColorMode::VETO)
}
#[inline]
pub const fn misc(pos: Vec2F, tex: Vec2F, col: Rgba8) -> Self {
Self::new(pos, tex, col, ColorMode::MISC)
}
}