Skip to main content

hexga_engine_render/
stencil.rs

1use super::*;
2
3
4#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5#[cfg_attr(feature = "hexga_io", derive(Save, Load))]
6#[derive(Debug, Copy, Clone, PartialEq)]
7pub struct StencilState {
8    pub front: StencilFaceState,
9    pub back: StencilFaceState,
10}
11
12
13#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
14#[cfg_attr(feature = "hexga_io", derive(Save, Load))]
15#[derive(Debug, Copy, Clone, PartialEq, Eq)]
16pub struct StencilFaceState {
17    /// Operation to use when stencil test fails
18    pub fail_op: StencilOp,
19
20    /// Operation to use when stencil test passes, but depth test fails
21    pub depth_fail_op: StencilOp,
22
23    /// Operation to use when both stencil and depth test pass,
24    /// or when stencil pass and no depth or depth disabled
25    pub pass_op: StencilOp,
26
27    /// Used for stencil testing with test_ref and test_mask: if (test_ref & test_mask) *test_func* (*stencil* && test_mask)
28    /// Default is Always, which means "always pass"
29    pub test_func: StencilCompareFunc,
30
31    /// Default value: 0
32    pub test_ref: i32,
33
34    /// Default value: all 1s
35    pub test_mask: u32,
36
37    /// Specifies a bit mask to enable or disable writing of individual bits in the stencil planes
38    /// Default value: all 1s
39    pub write_mask: u32,
40}
41
42/// Operations performed on current stencil value when comparison test passes or fails.
43#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
44#[cfg_attr(feature = "hexga_io", derive(Save, Load))]
45#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
46pub enum StencilOp {
47    /// Default value
48    Keep,
49    Zero,
50    Replace,
51    IncrementClamp,
52    DecrementClamp,
53    Invert,
54    IncrementWrap,
55    DecrementWrap,
56}
57
58/// Depth and stencil compare function
59#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
60#[cfg_attr(feature = "hexga_io", derive(Save, Load))]
61#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
62pub enum StencilCompareFunc {
63    /// Default value
64    Always,
65    Never,
66    Less,
67    Equal,
68    LessOrEqual,
69    Greater,
70    NotEqual,
71    GreaterOrEqual,
72}
73