mepeyew/context/
pass_step.rs

1use super::*;
2
3#[derive(Default, Debug, Clone)]
4pub struct PassStep {
5    pub(crate) step_dependency: PassStepDependency,
6
7    pub(crate) vertex_buffers: Vec<VertexBufferId>,
8    pub(crate) index_buffer: Option<IndexBufferId>,
9
10    pub(crate) programs: Vec<ProgramId>,
11
12    pub(crate) write_colors: Vec<PassLocalAttachment>,
13    pub(crate) write_depth: Option<PassLocalAttachment>,
14
15    pub(crate) wait_for_color_from: Option<(PassStepDependency, ShaderStage)>,
16    pub(crate) wait_for_depth_from: Option<(PassStepDependency, ShaderStage)>,
17
18    pub(crate) read_attachment: Vec<PassLocalAttachment>,
19}
20
21impl PassStep {
22    pub fn add_vertex_buffer(&mut self, vbo: VertexBufferId) -> &mut Self {
23        self.vertex_buffers.push(vbo);
24        self
25    }
26
27    pub fn set_index_buffer(&mut self, ibo: IndexBufferId) -> &mut Self {
28        self.index_buffer = Some(ibo);
29        self
30    }
31
32    pub fn add_program(&mut self, program: ProgramId) -> &mut Self {
33        self.programs.push(program);
34        self
35    }
36
37    /// Wait for a specific step to finish rendering.
38    /// The dependency can be obtained with `step.get_step_dependency()`.
39    pub fn set_wait_for_color_from_step(
40        &mut self,
41        dependency: PassStepDependency,
42        shader_usage: ShaderStage,
43    ) -> &mut Self {
44        self.wait_for_color_from = Some((dependency, shader_usage));
45        self
46    }
47
48    /// Wait for a specific step to complete depth testing.
49    /// The dependency can be obtained with `step.get_step_dependency()`.
50    pub fn set_wait_for_depth_from_step(
51        &mut self,
52        dependency: PassStepDependency,
53        shader_usage: ShaderStage,
54    ) -> &mut Self {
55        self.wait_for_depth_from = Some((dependency, shader_usage));
56        self
57    }
58
59    /// Add a [`PassLocalAttachment`] to draw into.
60    pub fn add_write_color(&mut self, local_attachment: PassLocalAttachment) -> &mut Self {
61        self.write_colors.push(local_attachment);
62        self
63    }
64
65    /// Add a [`PassLocalAttachment`] to use for depth testing.
66    pub fn set_write_depth(&mut self, local_attachment: PassLocalAttachment) -> &mut Self {
67        self.write_depth = Some(local_attachment);
68        self
69    }
70
71    /// Denote that a [`PassLocalAttachment`] is used as input.
72    pub fn read_local_attachment(&mut self, local_attachment: PassLocalAttachment) -> &mut Self {
73        self.read_attachment.push(local_attachment);
74        self
75    }
76
77    /// Get a [`PassStepDependency`] to have another step wait for this one to complete.
78    pub fn get_step_dependency(&self) -> PassStepDependency {
79        self.step_dependency
80    }
81}