Skip to main content

mtl_gpu/enums/
depth_stencil.rs

1//! Depth and stencil enumerations.
2//!
3//! Corresponds to `Metal/MTLDepthStencil.hpp`.
4
5use mtl_foundation::UInteger;
6
7/// Compare function for depth/stencil testing.
8///
9/// C++ equivalent: `MTL::CompareFunction`
10#[repr(transparent)]
11#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
12pub struct CompareFunction(pub UInteger);
13
14impl CompareFunction {
15    pub const NEVER: Self = Self(0);
16    pub const LESS: Self = Self(1);
17    pub const EQUAL: Self = Self(2);
18    pub const LESS_EQUAL: Self = Self(3);
19    pub const GREATER: Self = Self(4);
20    pub const NOT_EQUAL: Self = Self(5);
21    pub const GREATER_EQUAL: Self = Self(6);
22    pub const ALWAYS: Self = Self(7);
23}
24
25/// Stencil operation.
26///
27/// C++ equivalent: `MTL::StencilOperation`
28#[repr(transparent)]
29#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
30pub struct StencilOperation(pub UInteger);
31
32impl StencilOperation {
33    pub const KEEP: Self = Self(0);
34    pub const ZERO: Self = Self(1);
35    pub const REPLACE: Self = Self(2);
36    pub const INCREMENT_CLAMP: Self = Self(3);
37    pub const DECREMENT_CLAMP: Self = Self(4);
38    pub const INVERT: Self = Self(5);
39    pub const INCREMENT_WRAP: Self = Self(6);
40    pub const DECREMENT_WRAP: Self = Self(7);
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_compare_function_values() {
49        assert_eq!(CompareFunction::NEVER.0, 0);
50        assert_eq!(CompareFunction::LESS.0, 1);
51        assert_eq!(CompareFunction::ALWAYS.0, 7);
52    }
53
54    #[test]
55    fn test_stencil_operation_values() {
56        assert_eq!(StencilOperation::KEEP.0, 0);
57        assert_eq!(StencilOperation::DECREMENT_WRAP.0, 7);
58    }
59}