Skip to main content

mtl_gpu/mtl4/acceleration_structure/
motion_curve_geometry.rs

1//! Descriptor for motion curve 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 crate::{AttributeFormat, CurveBasis, CurveEndCaps, CurveType, IndexType};
10
11use super::BufferRange;
12
13/// Descriptor for motion curve geometry in an acceleration structure.
14///
15/// C++ equivalent: `MTL4::AccelerationStructureMotionCurveGeometryDescriptor`
16#[repr(transparent)]
17pub struct AccelerationStructureMotionCurveGeometryDescriptor(NonNull<c_void>);
18
19impl AccelerationStructureMotionCurveGeometryDescriptor {
20    /// Create from a raw pointer.
21    #[inline]
22    pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
23        NonNull::new(ptr).map(Self)
24    }
25
26    /// Get the raw pointer.
27    #[inline]
28    pub fn as_raw(&self) -> *mut c_void {
29        self.0.as_ptr()
30    }
31
32    /// Create a new motion curve geometry descriptor.
33    pub fn new() -> Option<Self> {
34        unsafe {
35            let class =
36                mtl_sys::Class::get("MTL4AccelerationStructureMotionCurveGeometryDescriptor")?;
37            let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
38            if ptr.is_null() {
39                return None;
40            }
41            let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
42            Self::from_raw(ptr)
43        }
44    }
45
46    /// Get the control point buffers (for motion keyframes).
47    pub fn control_point_buffers(&self) -> BufferRange {
48        unsafe { msg_send_0(self.as_ptr(), sel!(controlPointBuffers)) }
49    }
50
51    /// Set the control point buffers.
52    pub fn set_control_point_buffers(&self, buffers: BufferRange) {
53        unsafe {
54            let _: () = msg_send_1(self.as_ptr(), sel!(setControlPointBuffers:), buffers);
55        }
56    }
57
58    /// Get the control point count.
59    pub fn control_point_count(&self) -> UInteger {
60        unsafe { msg_send_0(self.as_ptr(), sel!(controlPointCount)) }
61    }
62
63    /// Set the control point count.
64    pub fn set_control_point_count(&self, count: UInteger) {
65        unsafe {
66            let _: () = msg_send_1(self.as_ptr(), sel!(setControlPointCount:), count);
67        }
68    }
69
70    /// Get the control point format.
71    pub fn control_point_format(&self) -> AttributeFormat {
72        unsafe { msg_send_0(self.as_ptr(), sel!(controlPointFormat)) }
73    }
74
75    /// Set the control point format.
76    pub fn set_control_point_format(&self, format: AttributeFormat) {
77        unsafe {
78            let _: () = msg_send_1(self.as_ptr(), sel!(setControlPointFormat:), format);
79        }
80    }
81
82    /// Get the control point stride.
83    pub fn control_point_stride(&self) -> UInteger {
84        unsafe { msg_send_0(self.as_ptr(), sel!(controlPointStride)) }
85    }
86
87    /// Set the control point stride.
88    pub fn set_control_point_stride(&self, stride: UInteger) {
89        unsafe {
90            let _: () = msg_send_1(self.as_ptr(), sel!(setControlPointStride:), stride);
91        }
92    }
93
94    /// Get the curve basis.
95    pub fn curve_basis(&self) -> CurveBasis {
96        unsafe { msg_send_0(self.as_ptr(), sel!(curveBasis)) }
97    }
98
99    /// Set the curve basis.
100    pub fn set_curve_basis(&self, basis: CurveBasis) {
101        unsafe {
102            let _: () = msg_send_1(self.as_ptr(), sel!(setCurveBasis:), basis);
103        }
104    }
105
106    /// Get the curve end caps.
107    pub fn curve_end_caps(&self) -> CurveEndCaps {
108        unsafe { msg_send_0(self.as_ptr(), sel!(curveEndCaps)) }
109    }
110
111    /// Set the curve end caps.
112    pub fn set_curve_end_caps(&self, end_caps: CurveEndCaps) {
113        unsafe {
114            let _: () = msg_send_1(self.as_ptr(), sel!(setCurveEndCaps:), end_caps);
115        }
116    }
117
118    /// Get the curve type.
119    pub fn curve_type(&self) -> CurveType {
120        unsafe { msg_send_0(self.as_ptr(), sel!(curveType)) }
121    }
122
123    /// Set the curve type.
124    pub fn set_curve_type(&self, curve_type: CurveType) {
125        unsafe {
126            let _: () = msg_send_1(self.as_ptr(), sel!(setCurveType:), curve_type);
127        }
128    }
129
130    /// Get the index buffer.
131    pub fn index_buffer(&self) -> BufferRange {
132        unsafe { msg_send_0(self.as_ptr(), sel!(indexBuffer)) }
133    }
134
135    /// Set the index buffer.
136    pub fn set_index_buffer(&self, buffer: BufferRange) {
137        unsafe {
138            let _: () = msg_send_1(self.as_ptr(), sel!(setIndexBuffer:), buffer);
139        }
140    }
141
142    /// Get the index type.
143    pub fn index_type(&self) -> IndexType {
144        unsafe { msg_send_0(self.as_ptr(), sel!(indexType)) }
145    }
146
147    /// Set the index type.
148    pub fn set_index_type(&self, index_type: IndexType) {
149        unsafe {
150            let _: () = msg_send_1(self.as_ptr(), sel!(setIndexType:), index_type);
151        }
152    }
153
154    /// Get the radius buffers (for motion keyframes).
155    pub fn radius_buffers(&self) -> BufferRange {
156        unsafe { msg_send_0(self.as_ptr(), sel!(radiusBuffers)) }
157    }
158
159    /// Set the radius buffers.
160    pub fn set_radius_buffers(&self, buffers: BufferRange) {
161        unsafe {
162            let _: () = msg_send_1(self.as_ptr(), sel!(setRadiusBuffers:), buffers);
163        }
164    }
165
166    /// Get the radius format.
167    pub fn radius_format(&self) -> AttributeFormat {
168        unsafe { msg_send_0(self.as_ptr(), sel!(radiusFormat)) }
169    }
170
171    /// Set the radius format.
172    pub fn set_radius_format(&self, format: AttributeFormat) {
173        unsafe {
174            let _: () = msg_send_1(self.as_ptr(), sel!(setRadiusFormat:), format);
175        }
176    }
177
178    /// Get the radius stride.
179    pub fn radius_stride(&self) -> UInteger {
180        unsafe { msg_send_0(self.as_ptr(), sel!(radiusStride)) }
181    }
182
183    /// Set the radius stride.
184    pub fn set_radius_stride(&self, stride: UInteger) {
185        unsafe {
186            let _: () = msg_send_1(self.as_ptr(), sel!(setRadiusStride:), stride);
187        }
188    }
189
190    /// Get the segment control point count.
191    pub fn segment_control_point_count(&self) -> UInteger {
192        unsafe { msg_send_0(self.as_ptr(), sel!(segmentControlPointCount)) }
193    }
194
195    /// Set the segment control point count.
196    pub fn set_segment_control_point_count(&self, count: UInteger) {
197        unsafe {
198            let _: () = msg_send_1(self.as_ptr(), sel!(setSegmentControlPointCount:), count);
199        }
200    }
201
202    /// Get the segment count.
203    pub fn segment_count(&self) -> UInteger {
204        unsafe { msg_send_0(self.as_ptr(), sel!(segmentCount)) }
205    }
206
207    /// Set the segment count.
208    pub fn set_segment_count(&self, count: UInteger) {
209        unsafe {
210            let _: () = msg_send_1(self.as_ptr(), sel!(setSegmentCount:), count);
211        }
212    }
213}
214
215impl Default for AccelerationStructureMotionCurveGeometryDescriptor {
216    fn default() -> Self {
217        Self::new()
218            .expect("Failed to create MTL4AccelerationStructureMotionCurveGeometryDescriptor")
219    }
220}
221
222impl Clone for AccelerationStructureMotionCurveGeometryDescriptor {
223    fn clone(&self) -> Self {
224        unsafe {
225            mtl_sys::msg_send_0::<*mut c_void>(self.as_ptr(), mtl_sys::sel!(retain));
226        }
227        Self(self.0)
228    }
229}
230
231impl Drop for AccelerationStructureMotionCurveGeometryDescriptor {
232    fn drop(&mut self) {
233        unsafe {
234            mtl_sys::msg_send_0::<()>(self.as_ptr(), mtl_sys::sel!(release));
235        }
236    }
237}
238
239impl Referencing for AccelerationStructureMotionCurveGeometryDescriptor {
240    #[inline]
241    fn as_ptr(&self) -> *const c_void {
242        self.0.as_ptr()
243    }
244}
245
246unsafe impl Send for AccelerationStructureMotionCurveGeometryDescriptor {}
247unsafe impl Sync for AccelerationStructureMotionCurveGeometryDescriptor {}
248
249impl std::fmt::Debug for AccelerationStructureMotionCurveGeometryDescriptor {
250    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
251        f.debug_struct("AccelerationStructureMotionCurveGeometryDescriptor")
252            .field("segment_count", &self.segment_count())
253            .finish()
254    }
255}