mtl_gpu/mtl4/acceleration_structure/
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 AccelerationStructureTriangleGeometryDescriptor(NonNull<c_void>);
18
19impl AccelerationStructureTriangleGeometryDescriptor {
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("MTL4AccelerationStructureTriangleGeometryDescriptor")?;
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 {
50 unsafe { msg_send_0(self.as_ptr(), sel!(indexBuffer)) }
51 }
52
53 pub fn set_index_buffer(&self, buffer: BufferRange) {
57 unsafe {
58 let _: () = msg_send_1(self.as_ptr(), sel!(setIndexBuffer:), buffer);
59 }
60 }
61
62 pub fn index_type(&self) -> IndexType {
66 unsafe { msg_send_0(self.as_ptr(), sel!(indexType)) }
67 }
68
69 pub fn set_index_type(&self, index_type: IndexType) {
73 unsafe {
74 let _: () = msg_send_1(self.as_ptr(), sel!(setIndexType:), index_type);
75 }
76 }
77
78 pub fn transformation_matrix_buffer(&self) -> BufferRange {
82 unsafe { msg_send_0(self.as_ptr(), sel!(transformationMatrixBuffer)) }
83 }
84
85 pub fn set_transformation_matrix_buffer(&self, buffer: BufferRange) {
89 unsafe {
90 let _: () = msg_send_1(self.as_ptr(), sel!(setTransformationMatrixBuffer:), buffer);
91 }
92 }
93
94 pub fn transformation_matrix_layout(&self) -> MatrixLayout {
98 unsafe { msg_send_0(self.as_ptr(), sel!(transformationMatrixLayout)) }
99 }
100
101 pub fn set_transformation_matrix_layout(&self, layout: MatrixLayout) {
105 unsafe {
106 let _: () = msg_send_1(self.as_ptr(), sel!(setTransformationMatrixLayout:), layout);
107 }
108 }
109
110 pub fn triangle_count(&self) -> UInteger {
114 unsafe { msg_send_0(self.as_ptr(), sel!(triangleCount)) }
115 }
116
117 pub fn set_triangle_count(&self, count: UInteger) {
121 unsafe {
122 let _: () = msg_send_1(self.as_ptr(), sel!(setTriangleCount:), count);
123 }
124 }
125
126 pub fn vertex_buffer(&self) -> BufferRange {
130 unsafe { msg_send_0(self.as_ptr(), sel!(vertexBuffer)) }
131 }
132
133 pub fn set_vertex_buffer(&self, buffer: BufferRange) {
137 unsafe {
138 let _: () = msg_send_1(self.as_ptr(), sel!(setVertexBuffer:), buffer);
139 }
140 }
141
142 pub fn vertex_format(&self) -> AttributeFormat {
146 unsafe { msg_send_0(self.as_ptr(), sel!(vertexFormat)) }
147 }
148
149 pub fn set_vertex_format(&self, format: AttributeFormat) {
153 unsafe {
154 let _: () = msg_send_1(self.as_ptr(), sel!(setVertexFormat:), format);
155 }
156 }
157
158 pub fn vertex_stride(&self) -> UInteger {
162 unsafe { msg_send_0(self.as_ptr(), sel!(vertexStride)) }
163 }
164
165 pub fn set_vertex_stride(&self, stride: UInteger) {
169 unsafe {
170 let _: () = msg_send_1(self.as_ptr(), sel!(setVertexStride:), stride);
171 }
172 }
173}
174
175impl Default for AccelerationStructureTriangleGeometryDescriptor {
176 fn default() -> Self {
177 Self::new().expect("Failed to create MTL4AccelerationStructureTriangleGeometryDescriptor")
178 }
179}
180
181impl Clone for AccelerationStructureTriangleGeometryDescriptor {
182 fn clone(&self) -> Self {
183 unsafe {
184 mtl_sys::msg_send_0::<*mut c_void>(self.as_ptr(), mtl_sys::sel!(retain));
185 }
186 Self(self.0)
187 }
188}
189
190impl Drop for AccelerationStructureTriangleGeometryDescriptor {
191 fn drop(&mut self) {
192 unsafe {
193 mtl_sys::msg_send_0::<()>(self.as_ptr(), mtl_sys::sel!(release));
194 }
195 }
196}
197
198impl Referencing for AccelerationStructureTriangleGeometryDescriptor {
199 #[inline]
200 fn as_ptr(&self) -> *const c_void {
201 self.0.as_ptr()
202 }
203}
204
205unsafe impl Send for AccelerationStructureTriangleGeometryDescriptor {}
206unsafe impl Sync for AccelerationStructureTriangleGeometryDescriptor {}
207
208impl std::fmt::Debug for AccelerationStructureTriangleGeometryDescriptor {
209 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
210 f.debug_struct("AccelerationStructureTriangleGeometryDescriptor")
211 .field("triangle_count", &self.triangle_count())
212 .finish()
213 }
214}