Skip to main content

mtl_gpu/mtl4/acceleration_structure/
curve_geometry.rs

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