mtl_gpu/pass/
color_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};
11use crate::types::ClearColor;
12
13#[repr(transparent)]
17pub struct RenderPassColorAttachmentDescriptor(NonNull<c_void>);
18
19impl RenderPassColorAttachmentDescriptor {
20 #[inline]
26 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
27 NonNull::new(ptr).map(Self)
28 }
29
30 #[inline]
32 pub fn as_raw(&self) -> *mut c_void {
33 self.0.as_ptr()
34 }
35
36 #[inline]
40 pub fn clear_color(&self) -> ClearColor {
41 unsafe { msg_send_0(self.as_ptr(), sel!(clearColor)) }
42 }
43
44 #[inline]
48 pub fn set_clear_color(&self, color: ClearColor) {
49 unsafe {
50 msg_send_1::<(), ClearColor>(self.as_ptr(), sel!(setClearColor:), color);
51 }
52 }
53
54 pub fn texture(&self) -> Option<Texture> {
57 unsafe {
58 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(texture));
59 if ptr.is_null() {
60 return None;
61 }
62 let _: *mut c_void = msg_send_0(ptr, sel!(retain));
63 Texture::from_raw(ptr)
64 }
65 }
66
67 pub fn set_texture(&self, texture: Option<&Texture>) {
69 unsafe {
70 let ptr = texture.map_or(std::ptr::null(), |t| t.as_ptr());
71 msg_send_1::<(), *const c_void>(self.as_ptr(), sel!(setTexture:), ptr);
72 }
73 }
74
75 #[inline]
77 pub fn load_action(&self) -> LoadAction {
78 unsafe { msg_send_0(self.as_ptr(), sel!(loadAction)) }
79 }
80
81 #[inline]
83 pub fn set_load_action(&self, load_action: LoadAction) {
84 unsafe {
85 msg_send_1::<(), LoadAction>(self.as_ptr(), sel!(setLoadAction:), load_action);
86 }
87 }
88
89 #[inline]
91 pub fn store_action(&self) -> StoreAction {
92 unsafe { msg_send_0(self.as_ptr(), sel!(storeAction)) }
93 }
94
95 #[inline]
97 pub fn set_store_action(&self, store_action: StoreAction) {
98 unsafe {
99 msg_send_1::<(), StoreAction>(self.as_ptr(), sel!(setStoreAction:), store_action);
100 }
101 }
102
103 #[inline]
105 pub fn level(&self) -> UInteger {
106 unsafe { msg_send_0(self.as_ptr(), sel!(level)) }
107 }
108
109 #[inline]
111 pub fn set_level(&self, level: UInteger) {
112 unsafe {
113 msg_send_1::<(), UInteger>(self.as_ptr(), sel!(setLevel:), level);
114 }
115 }
116
117 #[inline]
119 pub fn slice(&self) -> UInteger {
120 unsafe { msg_send_0(self.as_ptr(), sel!(slice)) }
121 }
122
123 #[inline]
125 pub fn set_slice(&self, slice: UInteger) {
126 unsafe {
127 msg_send_1::<(), UInteger>(self.as_ptr(), sel!(setSlice:), slice);
128 }
129 }
130}
131
132impl Referencing for RenderPassColorAttachmentDescriptor {
133 #[inline]
134 fn as_ptr(&self) -> *const c_void {
135 self.0.as_ptr()
136 }
137}
138
139#[repr(transparent)]
143pub struct RenderPassColorAttachmentDescriptorArray(NonNull<c_void>);
144
145impl RenderPassColorAttachmentDescriptorArray {
146 #[inline]
152 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
153 NonNull::new(ptr).map(Self)
154 }
155
156 #[inline]
158 pub fn as_raw(&self) -> *mut c_void {
159 self.0.as_ptr()
160 }
161
162 pub fn object_at(&self, index: UInteger) -> Option<RenderPassColorAttachmentDescriptor> {
166 unsafe {
167 let ptr: *mut c_void =
168 msg_send_1(self.as_ptr(), sel!(objectAtIndexedSubscript:), index);
169 RenderPassColorAttachmentDescriptor::from_raw(ptr)
170 }
171 }
172
173 pub fn set_object_at(
177 &self,
178 attachment: Option<&RenderPassColorAttachmentDescriptor>,
179 index: UInteger,
180 ) {
181 unsafe {
182 let ptr = attachment.map_or(std::ptr::null(), |a| a.as_ptr());
183 mtl_sys::msg_send_2::<(), *const c_void, UInteger>(
184 self.as_ptr(),
185 sel!(setObject: atIndexedSubscript:),
186 ptr,
187 index,
188 );
189 }
190 }
191}
192
193impl Referencing for RenderPassColorAttachmentDescriptorArray {
194 #[inline]
195 fn as_ptr(&self) -> *const c_void {
196 self.0.as_ptr()
197 }
198}