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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use super::*;

#[derive(Default, Debug, Clone)]
pub struct PassStep {
    pub(crate) step_dependency: PassStepDependency,

    pub(crate) vertex_buffers: Vec<VertexBufferId>,
    pub(crate) index_buffer: Option<IndexBufferId>,

    pub(crate) programs: Vec<ProgramId>,

    pub(crate) write_colors: Vec<PassLocalAttachment>,
    pub(crate) write_depth: Option<PassLocalAttachment>,

    pub(crate) wait_for_color_from: Option<(PassStepDependency, ShaderStage)>,
    pub(crate) wait_for_depth_from: Option<(PassStepDependency, ShaderStage)>,

    pub(crate) read_attachment: Vec<PassLocalAttachment>,
}

impl PassStep {
    pub fn add_vertex_buffer(&mut self, vbo: VertexBufferId) -> &mut Self {
        self.vertex_buffers.push(vbo);
        self
    }

    pub fn set_index_buffer(&mut self, ibo: IndexBufferId) -> &mut Self {
        self.index_buffer = Some(ibo);
        self
    }

    pub fn add_program(&mut self, program: ProgramId) -> &mut Self {
        self.programs.push(program);
        self
    }

    /// Wait for a specific step to finish rendering.
    /// The dependency can be obtained with `step.get_step_dependency()`.
    pub fn set_wait_for_color_from_step(
        &mut self,
        dependency: PassStepDependency,
        shader_usage: ShaderStage,
    ) -> &mut Self {
        self.wait_for_color_from = Some((dependency, shader_usage));
        self
    }

    /// Wait for a specific step to complete depth testing.
    /// The dependency can be obtained with `step.get_step_dependency()`.
    pub fn set_wait_for_depth_from_step(
        &mut self,
        dependency: PassStepDependency,
        shader_usage: ShaderStage,
    ) -> &mut Self {
        self.wait_for_depth_from = Some((dependency, shader_usage));
        self
    }

    /// Add a [`PassLocalAttachment`] to draw into.
    pub fn add_write_color(&mut self, local_attachment: PassLocalAttachment) -> &mut Self {
        self.write_colors.push(local_attachment);
        self
    }

    /// Add a [`PassLocalAttachment`] to use for depth testing.
    pub fn set_write_depth(&mut self, local_attachment: PassLocalAttachment) -> &mut Self {
        self.write_depth = Some(local_attachment);
        self
    }

    /// Denote that a [`PassLocalAttachment`] is used as input.
    pub fn read_local_attachment(&mut self, local_attachment: PassLocalAttachment) -> &mut Self {
        self.read_attachment.push(local_attachment);
        self
    }

    /// Get a [`PassStepDependency`] to have another step wait for this one to complete.
    pub fn get_step_dependency(&self) -> PassStepDependency {
        self.step_dependency
    }
}