pub mod assemble;
pub mod command_buffer;
pub mod effects;
pub mod output;
pub mod rasterize;
pub mod renderer;
pub mod shade;
pub mod vertex;
use embedded_graphics_core::pixelcolor::Rgb565;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Stage {
Vertex,
Assemble,
Rasterize,
Shade,
Output,
}
impl Stage {
pub const ORDER: [Stage; 5] = [
Stage::Vertex,
Stage::Assemble,
Stage::Rasterize,
Stage::Shade,
Stage::Output,
];
#[must_use]
pub const fn index(self) -> usize {
self as usize
}
#[must_use]
pub const fn next(self) -> Option<Stage> {
match self {
Stage::Vertex => Some(Stage::Assemble),
Stage::Assemble => Some(Stage::Rasterize),
Stage::Rasterize => Some(Stage::Shade),
Stage::Shade => Some(Stage::Output),
Stage::Output => None,
}
}
}
pub trait StageKind {
const STAGE: Stage;
}
pub type ClipVertex = nalgebra::Vector4<f32>;
pub type ScreenPrimitive = assemble::primitive::DrawPrimitive;
pub type FragmentColor = Rgb565;
impl StageKind for vertex::camera::Camera {
const STAGE: Stage = Stage::Vertex;
}
impl StageKind for assemble::primitive::DrawPrimitive {
const STAGE: Stage = Stage::Assemble;
}
impl<'a> StageKind for rasterize::draw::state::RasterState<'a> {
const STAGE: Stage = Stage::Rasterize;
}
impl StageKind for shade::shader::FlatColorShader {
const STAGE: Stage = Stage::Shade;
}
impl StageKind for crate::error::DisplayError {
const STAGE: Stage = Stage::Output;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn stage_order_is_sequential() {
assert_eq!(Stage::ORDER.len(), 5);
for pair in Stage::ORDER.windows(2) {
assert_eq!(pair[0].next(), Some(pair[1]));
assert!(pair[0] < pair[1]);
}
assert_eq!(Stage::Output.next(), None);
assert_eq!(Stage::Vertex.index(), 0);
assert_eq!(Stage::Output.index(), 4);
}
#[test]
fn principal_types_declare_their_stage() {
assert_eq!(vertex::camera::Camera::STAGE, Stage::Vertex);
assert_eq!(
<assemble::primitive::DrawPrimitive as StageKind>::STAGE,
Stage::Assemble
);
assert_eq!(
<shade::shader::FlatColorShader as StageKind>::STAGE,
Stage::Shade
);
assert_eq!(
<crate::error::DisplayError as StageKind>::STAGE,
Stage::Output
);
}
}