mtl_gpu/acceleration/motion_geometry/
bounding_box.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::Buffer;
10
11#[repr(transparent)]
15pub struct AccelerationStructureMotionBoundingBoxGeometryDescriptor(pub(crate) NonNull<c_void>);
16
17impl AccelerationStructureMotionBoundingBoxGeometryDescriptor {
18 pub fn new() -> Option<Self> {
22 unsafe {
23 let class = mtl_sys::Class::get(
24 "MTLAccelerationStructureMotionBoundingBoxGeometryDescriptor",
25 )?;
26 let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
27 if ptr.is_null() {
28 return None;
29 }
30 let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
31 Self::from_raw(ptr)
32 }
33 }
34
35 #[inline]
41 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
42 NonNull::new(ptr).map(Self)
43 }
44
45 #[inline]
47 pub fn as_raw(&self) -> *mut c_void {
48 self.0.as_ptr()
49 }
50
51 #[inline]
55 pub fn allow_duplicate_intersection_function_invocation(&self) -> bool {
56 unsafe {
57 msg_send_0(
58 self.as_ptr(),
59 sel!(allowDuplicateIntersectionFunctionInvocation),
60 )
61 }
62 }
63
64 #[inline]
66 pub fn set_allow_duplicate_intersection_function_invocation(&self, allow: bool) {
67 unsafe {
68 msg_send_1::<(), bool>(
69 self.as_ptr(),
70 sel!(setAllowDuplicateIntersectionFunctionInvocation:),
71 allow,
72 );
73 }
74 }
75
76 #[inline]
78 pub fn intersection_function_table_offset(&self) -> UInteger {
79 unsafe { msg_send_0(self.as_ptr(), sel!(intersectionFunctionTableOffset)) }
80 }
81
82 #[inline]
84 pub fn set_intersection_function_table_offset(&self, offset: UInteger) {
85 unsafe {
86 msg_send_1::<(), UInteger>(
87 self.as_ptr(),
88 sel!(setIntersectionFunctionTableOffset:),
89 offset,
90 );
91 }
92 }
93
94 #[inline]
96 pub fn opaque(&self) -> bool {
97 unsafe { msg_send_0(self.as_ptr(), sel!(opaque)) }
98 }
99
100 #[inline]
102 pub fn set_opaque(&self, opaque: bool) {
103 unsafe {
104 msg_send_1::<(), bool>(self.as_ptr(), sel!(setOpaque:), opaque);
105 }
106 }
107
108 pub fn label(&self) -> Option<String> {
110 unsafe {
111 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(label));
112 if ptr.is_null() {
113 return None;
114 }
115 let utf8_ptr: *const std::ffi::c_char =
116 mtl_sys::msg_send_0(ptr as *const c_void, sel!(UTF8String));
117 if utf8_ptr.is_null() {
118 return None;
119 }
120 let c_str = std::ffi::CStr::from_ptr(utf8_ptr);
121 Some(c_str.to_string_lossy().into_owned())
122 }
123 }
124
125 pub fn set_label(&self, label: &str) {
127 if let Some(ns_label) = mtl_foundation::String::from_str(label) {
128 unsafe {
129 msg_send_1::<(), *const c_void>(self.as_ptr(), sel!(setLabel:), ns_label.as_ptr());
130 }
131 }
132 }
133
134 pub fn primitive_data_buffer(&self) -> Option<Buffer> {
136 unsafe {
137 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(primitiveDataBuffer));
138 if ptr.is_null() {
139 return None;
140 }
141 let _: *mut c_void = msg_send_0(ptr, sel!(retain));
142 Buffer::from_raw(ptr)
143 }
144 }
145
146 pub fn set_primitive_data_buffer(&self, buffer: Option<&Buffer>) {
148 unsafe {
149 msg_send_1::<(), *const c_void>(
150 self.as_ptr(),
151 sel!(setPrimitiveDataBuffer:),
152 buffer.map_or(std::ptr::null(), |b| b.as_ptr()),
153 );
154 }
155 }
156
157 #[inline]
159 pub fn primitive_data_buffer_offset(&self) -> UInteger {
160 unsafe { msg_send_0(self.as_ptr(), sel!(primitiveDataBufferOffset)) }
161 }
162
163 #[inline]
165 pub fn set_primitive_data_buffer_offset(&self, offset: UInteger) {
166 unsafe {
167 msg_send_1::<(), UInteger>(self.as_ptr(), sel!(setPrimitiveDataBufferOffset:), offset);
168 }
169 }
170
171 #[inline]
173 pub fn primitive_data_element_size(&self) -> UInteger {
174 unsafe { msg_send_0(self.as_ptr(), sel!(primitiveDataElementSize)) }
175 }
176
177 #[inline]
179 pub fn set_primitive_data_element_size(&self, size: UInteger) {
180 unsafe {
181 msg_send_1::<(), UInteger>(self.as_ptr(), sel!(setPrimitiveDataElementSize:), size);
182 }
183 }
184
185 #[inline]
187 pub fn primitive_data_stride(&self) -> UInteger {
188 unsafe { msg_send_0(self.as_ptr(), sel!(primitiveDataStride)) }
189 }
190
191 #[inline]
193 pub fn set_primitive_data_stride(&self, stride: UInteger) {
194 unsafe {
195 msg_send_1::<(), UInteger>(self.as_ptr(), sel!(setPrimitiveDataStride:), stride);
196 }
197 }
198
199 #[inline]
205 pub fn bounding_box_count(&self) -> UInteger {
206 unsafe { msg_send_0(self.as_ptr(), sel!(boundingBoxCount)) }
207 }
208
209 #[inline]
213 pub fn set_bounding_box_count(&self, count: UInteger) {
214 unsafe {
215 msg_send_1::<(), UInteger>(self.as_ptr(), sel!(setBoundingBoxCount:), count);
216 }
217 }
218
219 #[inline]
223 pub fn bounding_box_stride(&self) -> UInteger {
224 unsafe { msg_send_0(self.as_ptr(), sel!(boundingBoxStride)) }
225 }
226
227 #[inline]
231 pub fn set_bounding_box_stride(&self, stride: UInteger) {
232 unsafe {
233 msg_send_1::<(), UInteger>(self.as_ptr(), sel!(setBoundingBoxStride:), stride);
234 }
235 }
236
237 #[inline]
246 pub fn bounding_box_buffers_ptr(&self) -> *const c_void {
247 unsafe { msg_send_0(self.as_ptr(), sel!(boundingBoxBuffers)) }
248 }
249
250 pub unsafe fn set_bounding_box_buffers_ptr(&self, bounding_box_buffers: *const c_void) {
258 unsafe {
259 msg_send_1::<(), *const c_void>(
260 self.as_ptr(),
261 sel!(setBoundingBoxBuffers:),
262 bounding_box_buffers,
263 );
264 }
265 }
266}
267
268impl Default for AccelerationStructureMotionBoundingBoxGeometryDescriptor {
269 fn default() -> Self {
270 Self::new().expect("failed to create motion bounding box geometry descriptor")
271 }
272}
273
274impl Clone for AccelerationStructureMotionBoundingBoxGeometryDescriptor {
275 fn clone(&self) -> Self {
276 unsafe {
277 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(copy));
278 Self::from_raw(ptr).expect("failed to copy motion bounding box geometry descriptor")
279 }
280 }
281}
282
283impl Drop for AccelerationStructureMotionBoundingBoxGeometryDescriptor {
284 fn drop(&mut self) {
285 unsafe {
286 msg_send_0::<()>(self.as_ptr(), sel!(release));
287 }
288 }
289}
290
291impl Referencing for AccelerationStructureMotionBoundingBoxGeometryDescriptor {
292 #[inline]
293 fn as_ptr(&self) -> *const c_void {
294 self.0.as_ptr()
295 }
296}
297
298unsafe impl Send for AccelerationStructureMotionBoundingBoxGeometryDescriptor {}
299unsafe impl Sync for AccelerationStructureMotionBoundingBoxGeometryDescriptor {}