mtl_gpu/mtl4/acceleration_structure/
bounding_box_geometry.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 super::BufferRange;
10
11#[repr(transparent)]
15pub struct AccelerationStructureBoundingBoxGeometryDescriptor(NonNull<c_void>);
16
17impl AccelerationStructureBoundingBoxGeometryDescriptor {
18 #[inline]
20 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
21 NonNull::new(ptr).map(Self)
22 }
23
24 #[inline]
26 pub fn as_raw(&self) -> *mut c_void {
27 self.0.as_ptr()
28 }
29
30 pub fn new() -> Option<Self> {
32 unsafe {
33 let class =
34 mtl_sys::Class::get("MTL4AccelerationStructureBoundingBoxGeometryDescriptor")?;
35 let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
36 if ptr.is_null() {
37 return None;
38 }
39 let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
40 Self::from_raw(ptr)
41 }
42 }
43
44 pub fn bounding_box_buffer(&self) -> BufferRange {
48 unsafe { msg_send_0(self.as_ptr(), sel!(boundingBoxBuffer)) }
49 }
50
51 pub fn set_bounding_box_buffer(&self, buffer: BufferRange) {
55 unsafe {
56 let _: () = msg_send_1(self.as_ptr(), sel!(setBoundingBoxBuffer:), buffer);
57 }
58 }
59
60 pub fn bounding_box_count(&self) -> UInteger {
64 unsafe { msg_send_0(self.as_ptr(), sel!(boundingBoxCount)) }
65 }
66
67 pub fn set_bounding_box_count(&self, count: UInteger) {
71 unsafe {
72 let _: () = msg_send_1(self.as_ptr(), sel!(setBoundingBoxCount:), count);
73 }
74 }
75
76 pub fn bounding_box_stride(&self) -> UInteger {
80 unsafe { msg_send_0(self.as_ptr(), sel!(boundingBoxStride)) }
81 }
82
83 pub fn set_bounding_box_stride(&self, stride: UInteger) {
87 unsafe {
88 let _: () = msg_send_1(self.as_ptr(), sel!(setBoundingBoxStride:), stride);
89 }
90 }
91}
92
93impl Default for AccelerationStructureBoundingBoxGeometryDescriptor {
94 fn default() -> Self {
95 Self::new()
96 .expect("Failed to create MTL4AccelerationStructureBoundingBoxGeometryDescriptor")
97 }
98}
99
100impl Clone for AccelerationStructureBoundingBoxGeometryDescriptor {
101 fn clone(&self) -> Self {
102 unsafe {
103 mtl_sys::msg_send_0::<*mut c_void>(self.as_ptr(), mtl_sys::sel!(retain));
104 }
105 Self(self.0)
106 }
107}
108
109impl Drop for AccelerationStructureBoundingBoxGeometryDescriptor {
110 fn drop(&mut self) {
111 unsafe {
112 mtl_sys::msg_send_0::<()>(self.as_ptr(), mtl_sys::sel!(release));
113 }
114 }
115}
116
117impl Referencing for AccelerationStructureBoundingBoxGeometryDescriptor {
118 #[inline]
119 fn as_ptr(&self) -> *const c_void {
120 self.0.as_ptr()
121 }
122}
123
124unsafe impl Send for AccelerationStructureBoundingBoxGeometryDescriptor {}
125unsafe impl Sync for AccelerationStructureBoundingBoxGeometryDescriptor {}
126
127impl std::fmt::Debug for AccelerationStructureBoundingBoxGeometryDescriptor {
128 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
129 f.debug_struct("AccelerationStructureBoundingBoxGeometryDescriptor")
130 .field("bounding_box_count", &self.bounding_box_count())
131 .finish()
132 }
133}