mtl_gpu/mtl4/acceleration_structure/
primitive_descriptor.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::MotionBorderMode;
10
11#[repr(transparent)]
15pub struct PrimitiveAccelerationStructureDescriptor(NonNull<c_void>);
16
17impl PrimitiveAccelerationStructureDescriptor {
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 = mtl_sys::Class::get("MTL4PrimitiveAccelerationStructureDescriptor")?;
34 let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
35 if ptr.is_null() {
36 return None;
37 }
38 let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
39 Self::from_raw(ptr)
40 }
41 }
42
43 pub fn geometry_descriptors_raw(&self) -> *mut c_void {
47 unsafe { msg_send_0(self.as_ptr(), sel!(geometryDescriptors)) }
48 }
49
50 pub fn set_geometry_descriptors_raw(&self, descriptors: *const c_void) {
54 unsafe {
55 let _: () = msg_send_1(self.as_ptr(), sel!(setGeometryDescriptors:), descriptors);
56 }
57 }
58
59 pub fn motion_end_border_mode(&self) -> MotionBorderMode {
63 unsafe { msg_send_0(self.as_ptr(), sel!(motionEndBorderMode)) }
64 }
65
66 pub fn set_motion_end_border_mode(&self, mode: MotionBorderMode) {
70 unsafe {
71 let _: () = msg_send_1(self.as_ptr(), sel!(setMotionEndBorderMode:), mode);
72 }
73 }
74
75 pub fn motion_end_time(&self) -> f32 {
79 unsafe { msg_send_0(self.as_ptr(), sel!(motionEndTime)) }
80 }
81
82 pub fn set_motion_end_time(&self, time: f32) {
86 unsafe {
87 let _: () = msg_send_1(self.as_ptr(), sel!(setMotionEndTime:), time);
88 }
89 }
90
91 pub fn motion_keyframe_count(&self) -> UInteger {
95 unsafe { msg_send_0(self.as_ptr(), sel!(motionKeyframeCount)) }
96 }
97
98 pub fn set_motion_keyframe_count(&self, count: UInteger) {
102 unsafe {
103 let _: () = msg_send_1(self.as_ptr(), sel!(setMotionKeyframeCount:), count);
104 }
105 }
106
107 pub fn motion_start_border_mode(&self) -> MotionBorderMode {
111 unsafe { msg_send_0(self.as_ptr(), sel!(motionStartBorderMode)) }
112 }
113
114 pub fn set_motion_start_border_mode(&self, mode: MotionBorderMode) {
118 unsafe {
119 let _: () = msg_send_1(self.as_ptr(), sel!(setMotionStartBorderMode:), mode);
120 }
121 }
122
123 pub fn motion_start_time(&self) -> f32 {
127 unsafe { msg_send_0(self.as_ptr(), sel!(motionStartTime)) }
128 }
129
130 pub fn set_motion_start_time(&self, time: f32) {
134 unsafe {
135 let _: () = msg_send_1(self.as_ptr(), sel!(setMotionStartTime:), time);
136 }
137 }
138}
139
140impl Default for PrimitiveAccelerationStructureDescriptor {
141 fn default() -> Self {
142 Self::new().expect("Failed to create MTL4PrimitiveAccelerationStructureDescriptor")
143 }
144}
145
146impl Clone for PrimitiveAccelerationStructureDescriptor {
147 fn clone(&self) -> Self {
148 unsafe {
149 mtl_sys::msg_send_0::<*mut c_void>(self.as_ptr(), mtl_sys::sel!(retain));
150 }
151 Self(self.0)
152 }
153}
154
155impl Drop for PrimitiveAccelerationStructureDescriptor {
156 fn drop(&mut self) {
157 unsafe {
158 mtl_sys::msg_send_0::<()>(self.as_ptr(), mtl_sys::sel!(release));
159 }
160 }
161}
162
163impl Referencing for PrimitiveAccelerationStructureDescriptor {
164 #[inline]
165 fn as_ptr(&self) -> *const c_void {
166 self.0.as_ptr()
167 }
168}
169
170unsafe impl Send for PrimitiveAccelerationStructureDescriptor {}
171unsafe impl Sync for PrimitiveAccelerationStructureDescriptor {}
172
173impl std::fmt::Debug for PrimitiveAccelerationStructureDescriptor {
174 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
175 f.debug_struct("PrimitiveAccelerationStructureDescriptor")
176 .field("motion_keyframe_count", &self.motion_keyframe_count())
177 .finish()
178 }
179}