Skip to main content

apple_mps/generated/
ray.rs

1use crate::ffi;
2use core::ffi::c_void;
3use core::ptr;
4
5macro_rules! opaque_generated_handle {
6    ($name:ident) => {
7        pub struct $name {
8            ptr: *mut c_void,
9        }
10
11        unsafe impl Send for $name {}
12        unsafe impl Sync for $name {}
13
14        impl Drop for $name {
15            fn drop(&mut self) {
16                if !self.ptr.is_null() {
17                    unsafe { ffi::mps_object_release(self.ptr) };
18                    self.ptr = ptr::null_mut();
19                }
20            }
21        }
22
23        impl $name {
24            #[must_use]
25            pub const fn as_ptr(&self) -> *mut c_void {
26                self.ptr
27            }
28
29            /// # Safety
30            ///
31            /// `ptr` must be a valid Objective-C object of the matching MPS type or protocol.
32            #[must_use]
33            pub unsafe fn retained_from_raw(ptr: *mut c_void) -> Option<Self> {
34                let retained = unsafe { ffi::mps_object_retain(ptr) };
35                if retained.is_null() {
36                    None
37                } else {
38                    Some(Self { ptr: retained })
39                }
40            }
41        }
42    };
43}
44
45macro_rules! raw_value_type {
46    ($name:ident, $raw:ty) => {
47        #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
48        #[repr(transparent)]
49        pub struct $name(pub $raw);
50
51        impl $name {
52            #[must_use]
53            pub const fn from_raw(raw: $raw) -> Self {
54                Self(raw)
55            }
56
57            #[must_use]
58            pub const fn as_raw(self) -> $raw {
59                self.0
60            }
61        }
62
63        impl From<$raw> for $name {
64            fn from(value: $raw) -> Self {
65                Self(value)
66            }
67        }
68
69        impl From<$name> for $raw {
70            fn from(value: $name) -> Self {
71                value.0
72            }
73        }
74    };
75}
76
77raw_value_type!(AccelerationStructureUsage, usize);
78raw_value_type!(RayMaskOptions, usize);
79raw_value_type!(TemporalWeighting, usize);
80raw_value_type!(TransformType, usize);
81raw_value_type!(AccelerationStructureStatus, usize);
82raw_value_type!(BoundingBoxIntersectionTestType, usize);
83raw_value_type!(PolygonType, usize);
84raw_value_type!(RayMaskOperator, usize);
85raw_value_type!(TriangleIntersectionTestType, usize);
86opaque_generated_handle!(SVGFDefaultTextureAllocator);
87opaque_generated_handle!(SVGFDenoiser);
88opaque_generated_handle!(TemporalAA);
89opaque_generated_handle!(AccelerationStructure);
90opaque_generated_handle!(AccelerationStructureGroup);
91opaque_generated_handle!(InstanceAccelerationStructure);
92opaque_generated_handle!(PolygonBuffer);
93opaque_generated_handle!(QuadrilateralAccelerationStructure);
94opaque_generated_handle!(TriangleAccelerationStructure);
95opaque_generated_handle!(SVGFTextureAllocator);