1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
mod lines;
mod triangles;

// Reexports
pub use self::lines::Lines;
pub use self::triangles::Triangles;

use crate::{Pipeline, Target};

#[derive(Copy, Clone, Debug)]
pub enum DepthStrategy {
    IfLessWrite,
    IfMoreWrite,
    IfLessNoWrite,
    IfMoreNoWrite,
    None,
}

/// This trait is for internal use only.
pub trait BackfaceMode {
    const ENABLED: bool;
}

/// Implies that reversed polygons should not be culled from the rendering pipeline.
pub struct BackfaceCullingDisabled;

impl BackfaceMode for BackfaceCullingDisabled {
    const ENABLED: bool = false;
}

/// Implies that reversed polygons should be culled from the rendering pipeline.
pub struct BackfaceCullingEnabled;

impl BackfaceMode for BackfaceCullingEnabled {
    const ENABLED: bool = true;
}

/// Represents a rasterization algorithm.
pub trait Rasterizer {
    /// The type of input required during rasterization.
    ///
    /// For most rasterization algorithms, this is the information that corresponds to a vertex
    /// position.
    type Input;

    /// The type of any supplementary data required by the rasterization algorithm.
    ///
    /// Examples of supplementary data include depth buffers, stencil buffers, etc.
    type Supplement;

    /// Rasterize the provided vertex data and write the resulting fragment information to the
    /// target.
    fn draw<P: Pipeline, T: Target<Item = P::Pixel>>(
        pipeline: &P,
        vertices: &[P::Vertex],
        target: &mut T,
        supplement: Self::Supplement,
    );
}