rafx_framework/render_features/
render_phase_mask.rs1use crate::render_features::registry::{RenderPhaseMaskInnerType, MAX_RENDER_PHASE_COUNT};
2use crate::render_features::{RenderPhase, RenderPhaseIndex};
3
4#[derive(Default)]
5pub struct RenderPhaseMaskBuilder(RenderPhaseMaskInnerType);
6
7impl RenderPhaseMaskBuilder {
8 pub fn add_render_phase<RenderPhaseT: RenderPhase>(mut self) -> RenderPhaseMaskBuilder {
9 let index = RenderPhaseT::render_phase_index();
10 assert!(
11 index < MAX_RENDER_PHASE_COUNT,
12 "render phase {} is not registered",
13 RenderPhaseT::render_phase_debug_name()
14 );
15 self.0 |= 1 << RenderPhaseT::render_phase_index();
16 self
17 }
18
19 pub fn build(self) -> RenderPhaseMask {
20 RenderPhaseMask(self.0)
21 }
22}
23
24#[derive(Copy, Clone, Debug)]
25pub struct RenderPhaseMask(RenderPhaseMaskInnerType);
26
27impl RenderPhaseMask {
28 pub fn is_included<RenderPhaseT: RenderPhase>(&self) -> bool {
29 let index = RenderPhaseT::render_phase_index();
30 assert!(
31 index < MAX_RENDER_PHASE_COUNT,
32 "render phase {} is not registered",
33 RenderPhaseT::render_phase_debug_name()
34 );
35
36 self.is_included_index_unchecked(index)
37 }
38
39 #[inline(always)]
40 pub fn is_included_index(
41 &self,
42 index: RenderPhaseIndex,
43 ) -> bool {
44 assert!(
45 index < MAX_RENDER_PHASE_COUNT,
46 "render phase index {} is invalid (did you forget to register a render phase?)",
47 index
48 );
49
50 self.is_included_index_unchecked(index)
51 }
52
53 pub fn empty() -> Self {
54 RenderPhaseMask(0)
55 }
56
57 #[inline(always)]
58 fn is_included_index_unchecked(
59 &self,
60 index: RenderPhaseIndex,
61 ) -> bool {
62 (self.0 & 1 << index) != 0
63 }
64}