rafx_framework/render_features/
render_feature_flag_mask.rs

1use crate::render_features::registry::{
2    RenderFeatureFlagMaskInnerType, MAX_RENDER_FEATURE_FLAG_COUNT,
3};
4use crate::render_features::{RenderFeatureFlag, RenderFeatureFlagIndex};
5
6#[derive(Default)]
7pub struct RenderFeatureFlagMaskBuilder(RenderFeatureFlagMaskInnerType);
8
9impl RenderFeatureFlagMaskBuilder {
10    pub fn add_render_feature_flag<RenderFeatureFlagT: RenderFeatureFlag>(
11        mut self
12    ) -> RenderFeatureFlagMaskBuilder {
13        let index = RenderFeatureFlagT::feature_flag_index();
14        assert!(
15            index < MAX_RENDER_FEATURE_FLAG_COUNT,
16            "feature flag {} is not registered",
17            RenderFeatureFlagT::feature_flag_debug_name()
18        );
19        self.0 |= 1 << RenderFeatureFlagT::feature_flag_index();
20        self
21    }
22
23    pub fn build(self) -> RenderFeatureFlagMask {
24        RenderFeatureFlagMask(self.0)
25    }
26}
27
28#[derive(Copy, Clone, Debug)]
29pub struct RenderFeatureFlagMask(RenderFeatureFlagMaskInnerType);
30
31impl RenderFeatureFlagMask {
32    pub fn is_included<RenderFeatureFlagT: RenderFeatureFlag>(&self) -> bool {
33        let index = RenderFeatureFlagT::feature_flag_index();
34        assert!(
35            index < MAX_RENDER_FEATURE_FLAG_COUNT,
36            "feature flag {} is not registered",
37            RenderFeatureFlagT::feature_flag_debug_name()
38        );
39
40        self.is_included_index_unchecked(index)
41    }
42
43    #[inline(always)]
44    pub fn is_included_index(
45        &self,
46        index: RenderFeatureFlagIndex,
47    ) -> bool {
48        assert!(
49            index < MAX_RENDER_FEATURE_FLAG_COUNT,
50            "feature flag index {} is invalid (did you forget to register a feature flag?)",
51            index
52        );
53
54        self.is_included_index_unchecked(index)
55    }
56
57    pub fn empty() -> Self {
58        RenderFeatureFlagMask(0)
59    }
60
61    #[inline(always)]
62    fn is_included_index_unchecked(
63        &self,
64        index: RenderFeatureFlagIndex,
65    ) -> bool {
66        (self.0 & 1 << index) != 0
67    }
68}