Debian Codegraph @

third_party/rust/metal/src/depthstencil.rs

raw
1 // Copyright 2016 GFX developers
2 //
3 // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4 // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5 // http://opensource.org/licenses/MIT>, at your option. This file may not be
6 // copied, modified, or distributed except according to those terms.
7
8 use crate::DeviceRef;
9 use objc::runtime::{NO, YES};
10
11 /// See <https://developer.apple.com/documentation/metal/mtlcomparefunction>
12 #[repr(u64)]
13 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
14 pub enum MTLCompareFunction {
15 Never = 0,
16 Less = 1,
17 Equal = 2,
18 LessEqual = 3,
19 Greater = 4,
20 NotEqual = 5,
21 GreaterEqual = 6,
22 Always = 7,
23 }
24
25 /// See <https://developer.apple.com/documentation/metal/mtlstenciloperation>
26 #[repr(u64)]
27 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
28 pub enum MTLStencilOperation {
29 Keep = 0,
30 Zero = 1,
31 Replace = 2,
32 IncrementClamp = 3,
33 DecrementClamp = 4,
34 Invert = 5,
35 IncrementWrap = 6,
36 DecrementWrap = 7,
37 }
38
39 /// See <https://developer.apple.com/documentation/metal/mtlstencildescriptor>
40 pub enum MTLStencilDescriptor {}
41
42 foreign_obj_type! {
43 type CType = MTLStencilDescriptor;
44 pub struct StencilDescriptor;
45 }
46
47 impl StencilDescriptor {
48 pub fn new() -> Self {
49 unsafe {
50 let class = class!(MTLStencilDescriptor);
51 msg_send![class, new]
52 }
53 }
54 }
55
56 impl StencilDescriptorRef {
57 pub fn stencil_compare_function(&self) -> MTLCompareFunction {
58 unsafe { msg_send![self, stencilCompareFunction] }
59 }
60
61 pub fn set_stencil_compare_function(&self, func: MTLCompareFunction) {
62 unsafe { msg_send![self, setStencilCompareFunction: func] }
63 }
64
65 pub fn stencil_failure_operation(&self) -> MTLStencilOperation {
66 unsafe { msg_send![self, stencilFailureOperation] }
67 }
68
69 pub fn set_stencil_failure_operation(&self, operation: MTLStencilOperation) {
70 unsafe { msg_send![self, setStencilFailureOperation: operation] }
71 }
72
73 pub fn depth_failure_operation(&self) -> MTLStencilOperation {
74 unsafe { msg_send![self, depthFailureOperation] }
75 }
76
77 pub fn set_depth_failure_operation(&self, operation: MTLStencilOperation) {
78 unsafe { msg_send![self, setDepthFailureOperation: operation] }
79 }
80
81 pub fn depth_stencil_pass_operation(&self) -> MTLStencilOperation {
82 unsafe { msg_send![self, depthStencilPassOperation] }
83 }
84
85 pub fn set_depth_stencil_pass_operation(&self, operation: MTLStencilOperation) {
86 unsafe { msg_send![self, setDepthStencilPassOperation: operation] }
87 }
88
89 pub fn read_mask(&self) -> u32 {
90 unsafe { msg_send![self, readMask] }
91 }
92
93 pub fn set_read_mask(&self, mask: u32) {
94 unsafe { msg_send![self, setReadMask: mask] }
95 }
96
97 pub fn write_mask(&self) -> u32 {
98 unsafe { msg_send![self, writeMask] }
99 }
100
101 pub fn set_write_mask(&self, mask: u32) {
102 unsafe { msg_send![self, setWriteMask: mask] }
103 }
104 }
105
106 /// See <https://developer.apple.com/documentation/metal/mtldepthstencildescriptor>
107 pub enum MTLDepthStencilDescriptor {}
108
109 foreign_obj_type! {
110 type CType = MTLDepthStencilDescriptor;
111 pub struct DepthStencilDescriptor;
112 }
113
114 impl DepthStencilDescriptor {
115 pub fn new() -> Self {
116 unsafe {
117 let class = class!(MTLDepthStencilDescriptor);
118 msg_send![class, new]
119 }
120 }
121 }
122
123 impl DepthStencilDescriptorRef {
124 pub fn depth_compare_function(&self) -> MTLCompareFunction {
125 unsafe { msg_send![self, depthCompareFunction] }
126 }
127
128 pub fn set_depth_compare_function(&self, func: MTLCompareFunction) {
129 unsafe { msg_send![self, setDepthCompareFunction: func] }
130 }
131
132 pub fn depth_write_enabled(&self) -> bool {
133 unsafe { msg_send_bool![self, isDepthWriteEnabled] }
134 }
135
136 pub fn set_depth_write_enabled(&self, enabled: bool) {
137 unsafe { msg_send![self, setDepthWriteEnabled: enabled] }
138 }
139
140 pub fn front_face_stencil(&self) -> Option<&StencilDescriptorRef> {
141 unsafe { msg_send![self, frontFaceStencil] }
142 }
143
144 pub fn set_front_face_stencil(&self, descriptor: Option<&StencilDescriptorRef>) {
145 unsafe { msg_send![self, setFrontFaceStencil: descriptor] }
146 }
147
148 pub fn back_face_stencil(&self) -> Option<&StencilDescriptorRef> {
149 unsafe { msg_send![self, backFaceStencil] }
150 }
151
152 pub fn set_back_face_stencil(&self, descriptor: Option<&StencilDescriptorRef>) {
153 unsafe { msg_send![self, setBackFaceStencil: descriptor] }
154 }
155
156 pub fn label(&self) -> &str {
157 unsafe {
158 let label = msg_send![self, label];
159 crate::nsstring_as_str(label)
160 }
161 }
162
163 pub fn set_label(&self, label: &str) {
164 unsafe {
165 let nslabel = crate::nsstring_from_str(label);
166 let () = msg_send![self, setLabel: nslabel];
167 }
168 }
169 }
170
171 /// See <https://developer.apple.com/documentation/metal/mtldepthstencilstate>
172 pub enum MTLDepthStencilState {}
173
174 foreign_obj_type! {
175 type CType = MTLDepthStencilState;
176 pub struct DepthStencilState;
177 }
178
179 impl DepthStencilStateRef {
180 pub fn device(&self) -> &DeviceRef {
181 unsafe { msg_send![self, device] }
182 }
183
184 pub fn label(&self) -> &str {
185 unsafe {
186 let label = msg_send![self, label];
187 crate::nsstring_as_str(label)
188 }
189 }
190 }