ombre 0.6.7

Shadowy game and graphics library for Rust
Documentation
//! Graphics pipeline types.
use super::*;

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct PipelineId(id::Id);

impl PipelineId {
    /// Get the next pipeline id.
    pub fn next() -> Self {
        Self(id::next())
    }
}

#[derive(Debug, Clone, Copy, Default)]
pub struct BlendState {
    /// Color blending.
    pub rgb: Option<BlendEquation>,
    /// Alpha blending.
    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 {
    /// One 32-bit wide float (equivalent to `f32`)
    Float1,
    /// Two 32-bit wide floats (equivalent to `[f32; 2]`)
    Float2,
    /// Three 32-bit wide floats (equivalent to `[f32; 3]`)
    Float3,
    /// Four 32-bit wide floats (equivalent to `[f32; 4]`)
    Float4,
    /// One unsigned 8-bit integer (equivalent to `u8`)
    Byte1,
    /// Two unsigned 8-bit integers (equivalent to `[u8; 2]`)
    Byte2,
    /// Three unsigned 8-bit integers (equivalent to `[u8; 3]`)
    Byte3,
    /// Four unsigned 8-bit integers (equivalent to `[u8; 4]`)
    Byte4,
    /// One unsigned 16-bit integer (equivalent to `u16`)
    Short1,
    /// Two unsigned 16-bit integers (equivalent to `[u16; 2]`)
    Short2,
    /// Tree unsigned 16-bit integers (equivalent to `[u16; 3]`)
    Short3,
    /// Four unsigned 16-bit integers (equivalent to `[u16; 4]`)
    Short4,
    /// One unsigned 32-bit integers (equivalent to `[u32; 1]`)
    Int1,
    /// Two unsigned 32-bit integers (equivalent to `[u32; 2]`)
    Int2,
    /// Three unsigned 32-bit integers (equivalent to `[u32; 3]`)
    Int3,
    /// Four unsigned 32-bit integers (equivalent to `[u32; 4]`)
    Int4,
}

impl VertexFormat {
    /// Number of components in this vertex format.
    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,
        }
    }

    /// Size in bytes.
    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,
            }
    }
}

/// Specify whether front- or back-facing polygons can be culled.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
pub enum CullMode {
    #[default]
    Nothing,
    Front,
    Back,
}

/// Define front- and back-facing polygons.
#[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,
}