mtl_gpu/mtl4/acceleration_structure/
motion_triangle_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 crate::{AttributeFormat, IndexType, MatrixLayout};
10
11use super::BufferRange;
12
13#[repr(transparent)]
17pub struct AccelerationStructureMotionTriangleGeometryDescriptor(NonNull<c_void>);
18
19impl AccelerationStructureMotionTriangleGeometryDescriptor {
20 #[inline]
22 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
23 NonNull::new(ptr).map(Self)
24 }
25
26 #[inline]
28 pub fn as_raw(&self) -> *mut c_void {
29 self.0.as_ptr()
30 }
31
32 pub fn new() -> Option<Self> {
34 unsafe {
35 let class =
36 mtl_sys::Class::get("MTL4AccelerationStructureMotionTriangleGeometryDescriptor")?;
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 pub fn index_buffer(&self) -> BufferRange {
48 unsafe { msg_send_0(self.as_ptr(), sel!(indexBuffer)) }
49 }
50
51 pub fn set_index_buffer(&self, buffer: BufferRange) {
53 unsafe {
54 let _: () = msg_send_1(self.as_ptr(), sel!(setIndexBuffer:), buffer);
55 }
56 }
57
58 pub fn index_type(&self) -> IndexType {
60 unsafe { msg_send_0(self.as_ptr(), sel!(indexType)) }
61 }
62
63 pub fn set_index_type(&self, index_type: IndexType) {
65 unsafe {
66 let _: () = msg_send_1(self.as_ptr(), sel!(setIndexType:), index_type);
67 }
68 }
69
70 pub fn transformation_matrix_buffer(&self) -> BufferRange {
72 unsafe { msg_send_0(self.as_ptr(), sel!(transformationMatrixBuffer)) }
73 }
74
75 pub fn set_transformation_matrix_buffer(&self, buffer: BufferRange) {
77 unsafe {
78 let _: () = msg_send_1(self.as_ptr(), sel!(setTransformationMatrixBuffer:), buffer);
79 }
80 }
81
82 pub fn transformation_matrix_layout(&self) -> MatrixLayout {
84 unsafe { msg_send_0(self.as_ptr(), sel!(transformationMatrixLayout)) }
85 }
86
87 pub fn set_transformation_matrix_layout(&self, layout: MatrixLayout) {
89 unsafe {
90 let _: () = msg_send_1(self.as_ptr(), sel!(setTransformationMatrixLayout:), layout);
91 }
92 }
93
94 pub fn triangle_count(&self) -> UInteger {
96 unsafe { msg_send_0(self.as_ptr(), sel!(triangleCount)) }
97 }
98
99 pub fn set_triangle_count(&self, count: UInteger) {
101 unsafe {
102 let _: () = msg_send_1(self.as_ptr(), sel!(setTriangleCount:), count);
103 }
104 }
105
106 pub fn vertex_buffers(&self) -> BufferRange {
108 unsafe { msg_send_0(self.as_ptr(), sel!(vertexBuffers)) }
109 }
110
111 pub fn set_vertex_buffers(&self, buffers: BufferRange) {
113 unsafe {
114 let _: () = msg_send_1(self.as_ptr(), sel!(setVertexBuffers:), buffers);
115 }
116 }
117
118 pub fn vertex_format(&self) -> AttributeFormat {
120 unsafe { msg_send_0(self.as_ptr(), sel!(vertexFormat)) }
121 }
122
123 pub fn set_vertex_format(&self, format: AttributeFormat) {
125 unsafe {
126 let _: () = msg_send_1(self.as_ptr(), sel!(setVertexFormat:), format);
127 }
128 }
129
130 pub fn vertex_stride(&self) -> UInteger {
132 unsafe { msg_send_0(self.as_ptr(), sel!(vertexStride)) }
133 }
134
135 pub fn set_vertex_stride(&self, stride: UInteger) {
137 unsafe {
138 let _: () = msg_send_1(self.as_ptr(), sel!(setVertexStride:), stride);
139 }
140 }
141}
142
143impl Default for AccelerationStructureMotionTriangleGeometryDescriptor {
144 fn default() -> Self {
145 Self::new()
146 .expect("Failed to create MTL4AccelerationStructureMotionTriangleGeometryDescriptor")
147 }
148}
149
150impl Clone for AccelerationStructureMotionTriangleGeometryDescriptor {
151 fn clone(&self) -> Self {
152 unsafe {
153 mtl_sys::msg_send_0::<*mut c_void>(self.as_ptr(), mtl_sys::sel!(retain));
154 }
155 Self(self.0)
156 }
157}
158
159impl Drop for AccelerationStructureMotionTriangleGeometryDescriptor {
160 fn drop(&mut self) {
161 unsafe {
162 mtl_sys::msg_send_0::<()>(self.as_ptr(), mtl_sys::sel!(release));
163 }
164 }
165}
166
167impl Referencing for AccelerationStructureMotionTriangleGeometryDescriptor {
168 #[inline]
169 fn as_ptr(&self) -> *const c_void {
170 self.0.as_ptr()
171 }
172}
173
174unsafe impl Send for AccelerationStructureMotionTriangleGeometryDescriptor {}
175unsafe impl Sync for AccelerationStructureMotionTriangleGeometryDescriptor {}
176
177impl std::fmt::Debug for AccelerationStructureMotionTriangleGeometryDescriptor {
178 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
179 f.debug_struct("AccelerationStructureMotionTriangleGeometryDescriptor")
180 .field("triangle_count", &self.triangle_count())
181 .finish()
182 }
183}