Skip to main content

mtl_gpu/mtl4/acceleration_structure/
motion_bounding_box_geometry.rs

1//! Descriptor for motion bounding box geometry in an acceleration structure.
2
3use 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/// Descriptor for motion bounding box geometry in an acceleration structure.
12///
13/// C++ equivalent: `MTL4::AccelerationStructureMotionBoundingBoxGeometryDescriptor`
14#[repr(transparent)]
15pub struct AccelerationStructureMotionBoundingBoxGeometryDescriptor(NonNull<c_void>);
16
17impl AccelerationStructureMotionBoundingBoxGeometryDescriptor {
18    /// Create from a raw pointer.
19    #[inline]
20    pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
21        NonNull::new(ptr).map(Self)
22    }
23
24    /// Get the raw pointer.
25    #[inline]
26    pub fn as_raw(&self) -> *mut c_void {
27        self.0.as_ptr()
28    }
29
30    /// Create a new motion bounding box geometry descriptor.
31    pub fn new() -> Option<Self> {
32        unsafe {
33            let class = mtl_sys::Class::get(
34                "MTL4AccelerationStructureMotionBoundingBoxGeometryDescriptor",
35            )?;
36            let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
37            if ptr.is_null() {
38                return None;
39            }
40            let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
41            Self::from_raw(ptr)
42        }
43    }
44
45    /// Get the bounding box buffers (for motion keyframes).
46    pub fn bounding_box_buffers(&self) -> BufferRange {
47        unsafe { msg_send_0(self.as_ptr(), sel!(boundingBoxBuffers)) }
48    }
49
50    /// Set the bounding box buffers (for motion keyframes).
51    pub fn set_bounding_box_buffers(&self, buffers: BufferRange) {
52        unsafe {
53            let _: () = msg_send_1(self.as_ptr(), sel!(setBoundingBoxBuffers:), buffers);
54        }
55    }
56
57    /// Get the bounding box count.
58    pub fn bounding_box_count(&self) -> UInteger {
59        unsafe { msg_send_0(self.as_ptr(), sel!(boundingBoxCount)) }
60    }
61
62    /// Set the bounding box count.
63    pub fn set_bounding_box_count(&self, count: UInteger) {
64        unsafe {
65            let _: () = msg_send_1(self.as_ptr(), sel!(setBoundingBoxCount:), count);
66        }
67    }
68
69    /// Get the bounding box stride.
70    pub fn bounding_box_stride(&self) -> UInteger {
71        unsafe { msg_send_0(self.as_ptr(), sel!(boundingBoxStride)) }
72    }
73
74    /// Set the bounding box stride.
75    pub fn set_bounding_box_stride(&self, stride: UInteger) {
76        unsafe {
77            let _: () = msg_send_1(self.as_ptr(), sel!(setBoundingBoxStride:), stride);
78        }
79    }
80}
81
82impl Default for AccelerationStructureMotionBoundingBoxGeometryDescriptor {
83    fn default() -> Self {
84        Self::new()
85            .expect("Failed to create MTL4AccelerationStructureMotionBoundingBoxGeometryDescriptor")
86    }
87}
88
89impl Clone for AccelerationStructureMotionBoundingBoxGeometryDescriptor {
90    fn clone(&self) -> Self {
91        unsafe {
92            mtl_sys::msg_send_0::<*mut c_void>(self.as_ptr(), mtl_sys::sel!(retain));
93        }
94        Self(self.0)
95    }
96}
97
98impl Drop for AccelerationStructureMotionBoundingBoxGeometryDescriptor {
99    fn drop(&mut self) {
100        unsafe {
101            mtl_sys::msg_send_0::<()>(self.as_ptr(), mtl_sys::sel!(release));
102        }
103    }
104}
105
106impl Referencing for AccelerationStructureMotionBoundingBoxGeometryDescriptor {
107    #[inline]
108    fn as_ptr(&self) -> *const c_void {
109        self.0.as_ptr()
110    }
111}
112
113unsafe impl Send for AccelerationStructureMotionBoundingBoxGeometryDescriptor {}
114unsafe impl Sync for AccelerationStructureMotionBoundingBoxGeometryDescriptor {}
115
116impl std::fmt::Debug for AccelerationStructureMotionBoundingBoxGeometryDescriptor {
117    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
118        f.debug_struct("AccelerationStructureMotionBoundingBoxGeometryDescriptor")
119            .field("bounding_box_count", &self.bounding_box_count())
120            .finish()
121    }
122}