mtl_gpu/pass/
attachment.rs1use std::ffi::c_void;
4use std::ptr::NonNull;
5
6use mtl_foundation::{Referencing, UInteger};
7use mtl_sys::{msg_send_0, msg_send_1, sel};
8
9use crate::Texture;
10use crate::enums::{LoadAction, StoreAction, StoreActionOptions};
11
12#[repr(transparent)]
16pub struct RenderPassAttachmentDescriptor(pub(crate) NonNull<c_void>);
17
18impl RenderPassAttachmentDescriptor {
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 pub fn texture(&self) -> Option<Texture> {
43 unsafe {
44 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(texture));
45 if ptr.is_null() {
46 return None;
47 }
48 let _: *mut c_void = msg_send_0(ptr, sel!(retain));
49 Texture::from_raw(ptr)
50 }
51 }
52
53 pub fn set_texture(&self, texture: Option<&Texture>) {
57 unsafe {
58 let ptr = texture.map_or(std::ptr::null(), |t| t.as_ptr());
59 msg_send_1::<(), *const c_void>(self.as_ptr(), sel!(setTexture:), ptr);
60 }
61 }
62
63 #[inline]
67 pub fn level(&self) -> UInteger {
68 unsafe { msg_send_0(self.as_ptr(), sel!(level)) }
69 }
70
71 #[inline]
75 pub fn set_level(&self, level: UInteger) {
76 unsafe {
77 msg_send_1::<(), UInteger>(self.as_ptr(), sel!(setLevel:), level);
78 }
79 }
80
81 #[inline]
85 pub fn slice(&self) -> UInteger {
86 unsafe { msg_send_0(self.as_ptr(), sel!(slice)) }
87 }
88
89 #[inline]
93 pub fn set_slice(&self, slice: UInteger) {
94 unsafe {
95 msg_send_1::<(), UInteger>(self.as_ptr(), sel!(setSlice:), slice);
96 }
97 }
98
99 #[inline]
103 pub fn depth_plane(&self) -> UInteger {
104 unsafe { msg_send_0(self.as_ptr(), sel!(depthPlane)) }
105 }
106
107 #[inline]
111 pub fn set_depth_plane(&self, depth_plane: UInteger) {
112 unsafe {
113 msg_send_1::<(), UInteger>(self.as_ptr(), sel!(setDepthPlane:), depth_plane);
114 }
115 }
116
117 #[inline]
121 pub fn load_action(&self) -> LoadAction {
122 unsafe { msg_send_0(self.as_ptr(), sel!(loadAction)) }
123 }
124
125 #[inline]
129 pub fn set_load_action(&self, load_action: LoadAction) {
130 unsafe {
131 msg_send_1::<(), LoadAction>(self.as_ptr(), sel!(setLoadAction:), load_action);
132 }
133 }
134
135 #[inline]
139 pub fn store_action(&self) -> StoreAction {
140 unsafe { msg_send_0(self.as_ptr(), sel!(storeAction)) }
141 }
142
143 #[inline]
147 pub fn set_store_action(&self, store_action: StoreAction) {
148 unsafe {
149 msg_send_1::<(), StoreAction>(self.as_ptr(), sel!(setStoreAction:), store_action);
150 }
151 }
152
153 #[inline]
157 pub fn store_action_options(&self) -> StoreActionOptions {
158 unsafe { msg_send_0(self.as_ptr(), sel!(storeActionOptions)) }
159 }
160
161 #[inline]
165 pub fn set_store_action_options(&self, options: StoreActionOptions) {
166 unsafe {
167 msg_send_1::<(), StoreActionOptions>(
168 self.as_ptr(),
169 sel!(setStoreActionOptions:),
170 options,
171 );
172 }
173 }
174
175 pub fn resolve_texture(&self) -> Option<Texture> {
179 unsafe {
180 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(resolveTexture));
181 if ptr.is_null() {
182 return None;
183 }
184 let _: *mut c_void = msg_send_0(ptr, sel!(retain));
185 Texture::from_raw(ptr)
186 }
187 }
188
189 pub fn set_resolve_texture(&self, texture: Option<&Texture>) {
193 unsafe {
194 let ptr = texture.map_or(std::ptr::null(), |t| t.as_ptr());
195 msg_send_1::<(), *const c_void>(self.as_ptr(), sel!(setResolveTexture:), ptr);
196 }
197 }
198
199 #[inline]
203 pub fn resolve_level(&self) -> UInteger {
204 unsafe { msg_send_0(self.as_ptr(), sel!(resolveLevel)) }
205 }
206
207 #[inline]
211 pub fn set_resolve_level(&self, level: UInteger) {
212 unsafe {
213 msg_send_1::<(), UInteger>(self.as_ptr(), sel!(setResolveLevel:), level);
214 }
215 }
216
217 #[inline]
221 pub fn resolve_slice(&self) -> UInteger {
222 unsafe { msg_send_0(self.as_ptr(), sel!(resolveSlice)) }
223 }
224
225 #[inline]
229 pub fn set_resolve_slice(&self, slice: UInteger) {
230 unsafe {
231 msg_send_1::<(), UInteger>(self.as_ptr(), sel!(setResolveSlice:), slice);
232 }
233 }
234
235 #[inline]
239 pub fn resolve_depth_plane(&self) -> UInteger {
240 unsafe { msg_send_0(self.as_ptr(), sel!(resolveDepthPlane)) }
241 }
242
243 #[inline]
247 pub fn set_resolve_depth_plane(&self, depth_plane: UInteger) {
248 unsafe {
249 msg_send_1::<(), UInteger>(self.as_ptr(), sel!(setResolveDepthPlane:), depth_plane);
250 }
251 }
252}
253
254impl Referencing for RenderPassAttachmentDescriptor {
255 #[inline]
256 fn as_ptr(&self) -> *const c_void {
257 self.0.as_ptr()
258 }
259}