mtl_gpu/pass/
depth_attachment.rs1use std::ffi::c_void;
4use std::ptr::NonNull;
5
6use mtl_foundation::Referencing;
7use mtl_sys::{msg_send_0, msg_send_1, sel};
8
9use crate::Texture;
10use crate::enums::{LoadAction, MultisampleDepthResolveFilter, StoreAction};
11
12#[repr(transparent)]
16pub struct RenderPassDepthAttachmentDescriptor(NonNull<c_void>);
17
18impl RenderPassDepthAttachmentDescriptor {
19 #[inline]
25 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
26 NonNull::new(ptr).map(Self)
27 }
28
29 #[inline]
31 pub fn as_raw(&self) -> *mut c_void {
32 self.0.as_ptr()
33 }
34
35 #[inline]
39 pub fn clear_depth(&self) -> f64 {
40 unsafe { msg_send_0(self.as_ptr(), sel!(clearDepth)) }
41 }
42
43 #[inline]
47 pub fn set_clear_depth(&self, depth: f64) {
48 unsafe {
49 msg_send_1::<(), f64>(self.as_ptr(), sel!(setClearDepth:), depth);
50 }
51 }
52
53 #[inline]
57 pub fn depth_resolve_filter(&self) -> MultisampleDepthResolveFilter {
58 unsafe { msg_send_0(self.as_ptr(), sel!(depthResolveFilter)) }
59 }
60
61 #[inline]
65 pub fn set_depth_resolve_filter(&self, filter: MultisampleDepthResolveFilter) {
66 unsafe {
67 msg_send_1::<(), MultisampleDepthResolveFilter>(
68 self.as_ptr(),
69 sel!(setDepthResolveFilter:),
70 filter,
71 );
72 }
73 }
74
75 pub fn texture(&self) -> Option<Texture> {
78 unsafe {
79 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(texture));
80 if ptr.is_null() {
81 return None;
82 }
83 let _: *mut c_void = msg_send_0(ptr, sel!(retain));
84 Texture::from_raw(ptr)
85 }
86 }
87
88 pub fn set_texture(&self, texture: Option<&Texture>) {
90 unsafe {
91 let ptr = texture.map_or(std::ptr::null(), |t| t.as_ptr());
92 msg_send_1::<(), *const c_void>(self.as_ptr(), sel!(setTexture:), ptr);
93 }
94 }
95
96 #[inline]
98 pub fn load_action(&self) -> LoadAction {
99 unsafe { msg_send_0(self.as_ptr(), sel!(loadAction)) }
100 }
101
102 #[inline]
104 pub fn set_load_action(&self, load_action: LoadAction) {
105 unsafe {
106 msg_send_1::<(), LoadAction>(self.as_ptr(), sel!(setLoadAction:), load_action);
107 }
108 }
109
110 #[inline]
112 pub fn store_action(&self) -> StoreAction {
113 unsafe { msg_send_0(self.as_ptr(), sel!(storeAction)) }
114 }
115
116 #[inline]
118 pub fn set_store_action(&self, store_action: StoreAction) {
119 unsafe {
120 msg_send_1::<(), StoreAction>(self.as_ptr(), sel!(setStoreAction:), store_action);
121 }
122 }
123}
124
125impl Referencing for RenderPassDepthAttachmentDescriptor {
126 #[inline]
127 fn as_ptr(&self) -> *const c_void {
128 self.0.as_ptr()
129 }
130}