use super::*;
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct PipelineId(id::Id);
impl PipelineId {
pub fn next() -> Self {
Self(id::next())
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct BlendState {
pub rgb: Option<BlendEquation>,
pub alpha: Option<BlendEquation>,
}
#[derive(Debug, Clone, Copy)]
pub struct ColorState {
pub mask: Rgba<bool>,
pub blend: BlendState,
}
impl Default for ColorState {
fn default() -> Self {
Self {
mask: Rgba::new(true, true, true, true),
blend: BlendState::default(),
}
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct DepthState {
pub compare: Comparison,
pub offset: Option<(f32, f32)>,
}
#[derive(Debug, Clone, Default)]
pub struct PipelineDescriptor<'a> {
pub layout: &'a [BufferLayout<'a>],
pub depth: Option<DepthState>,
pub stencil: Option<StencilState>,
pub color: Option<ColorState>,
pub culling: CullMode,
pub winding: FaceWinding,
pub primitive: Primitive,
}
#[derive(Clone, Debug)]
pub struct BufferLayout<'a> {
pub stride: Option<i32>,
pub step: VertexStep,
pub step_rate: i32,
pub attrs: &'a [VertexAttribute],
}
impl<'a> Default for BufferLayout<'a> {
fn default() -> BufferLayout<'a> {
BufferLayout {
stride: None,
step: VertexStep::default(),
step_rate: 1,
attrs: &[],
}
}
}
#[derive(Clone, Copy, PartialEq, Debug, Default)]
pub enum VertexStep {
#[default]
PerVertex,
PerInstance,
}
#[derive(Clone, Debug)]
pub struct VertexAttribute {
pub name: &'static str,
pub format: VertexFormat,
}
impl VertexAttribute {
pub const fn new(name: &'static str, format: VertexFormat) -> VertexAttribute {
VertexAttribute { name, format }
}
}
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum VertexFormat {
Float1,
Float2,
Float3,
Float4,
Byte1,
Byte2,
Byte3,
Byte4,
Short1,
Short2,
Short3,
Short4,
Int1,
Int2,
Int3,
Int4,
}
impl VertexFormat {
pub const fn components(&self) -> usize {
match self {
VertexFormat::Float1 => 1,
VertexFormat::Float2 => 2,
VertexFormat::Float3 => 3,
VertexFormat::Float4 => 4,
VertexFormat::Byte1 => 1,
VertexFormat::Byte2 => 2,
VertexFormat::Byte3 => 3,
VertexFormat::Byte4 => 4,
VertexFormat::Short1 => 1,
VertexFormat::Short2 => 2,
VertexFormat::Short3 => 3,
VertexFormat::Short4 => 4,
VertexFormat::Int1 => 1,
VertexFormat::Int2 => 2,
VertexFormat::Int3 => 3,
VertexFormat::Int4 => 4,
}
}
pub const fn size(&self) -> usize {
self.components()
* match self {
VertexFormat::Float1
| VertexFormat::Float2
| VertexFormat::Float3
| VertexFormat::Float4 => 4,
VertexFormat::Byte1
| VertexFormat::Byte2
| VertexFormat::Byte3
| VertexFormat::Byte4 => 1,
VertexFormat::Short1
| VertexFormat::Short2
| VertexFormat::Short3
| VertexFormat::Short4 => 2,
VertexFormat::Int1
| VertexFormat::Int2
| VertexFormat::Int3
| VertexFormat::Int4 => 4,
}
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
pub enum CullMode {
#[default]
Nothing,
Front,
Back,
}
#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
pub enum FaceWinding {
#[default]
CounterClockwise,
Clockwise,
}
#[derive(Debug, PartialEq, Clone, Copy, Default)]
pub enum Primitive {
#[default]
Triangles,
Lines,
}