Skip to main content

mtl_gpu/argument/
texture_reference_type.rs

1//! A texture reference type for reflection.
2
3use std::ffi::c_void;
4use std::ptr::NonNull;
5
6use mtl_foundation::Referencing;
7use mtl_sys::{msg_send_0, sel};
8
9use crate::enums::{BindingAccess, DataType, TextureType};
10
11/// A texture reference type for reflection.
12///
13/// C++ equivalent: `MTL::TextureReferenceType`
14#[repr(transparent)]
15pub struct TextureReferenceType(pub(crate) NonNull<c_void>);
16
17impl TextureReferenceType {
18    /// Create from a raw pointer.
19    ///
20    /// # Safety
21    ///
22    /// The pointer must be a valid Metal TextureReferenceType.
23    #[inline]
24    pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
25        NonNull::new(ptr).map(Self)
26    }
27
28    /// Get the raw pointer.
29    #[inline]
30    pub fn as_raw(&self) -> *mut c_void {
31        self.0.as_ptr()
32    }
33
34    /// Get the data type.
35    ///
36    /// C++ equivalent: `DataType dataType() const`
37    #[inline]
38    pub fn data_type(&self) -> DataType {
39        unsafe { msg_send_0(self.as_ptr(), sel!(dataType)) }
40    }
41
42    /// Get the access mode.
43    ///
44    /// C++ equivalent: `BindingAccess access() const`
45    #[inline]
46    pub fn access(&self) -> BindingAccess {
47        unsafe { msg_send_0(self.as_ptr(), sel!(access)) }
48    }
49
50    /// Check if this is a depth texture.
51    ///
52    /// C++ equivalent: `bool isDepthTexture() const`
53    #[inline]
54    pub fn is_depth_texture(&self) -> bool {
55        unsafe { msg_send_0(self.as_ptr(), sel!(isDepthTexture)) }
56    }
57
58    /// Get the texture data type.
59    ///
60    /// C++ equivalent: `DataType textureDataType() const`
61    #[inline]
62    pub fn texture_data_type(&self) -> DataType {
63        unsafe { msg_send_0(self.as_ptr(), sel!(textureDataType)) }
64    }
65
66    /// Get the texture type.
67    ///
68    /// C++ equivalent: `TextureType textureType() const`
69    #[inline]
70    pub fn texture_type(&self) -> TextureType {
71        unsafe { msg_send_0(self.as_ptr(), sel!(textureType)) }
72    }
73}
74
75impl Clone for TextureReferenceType {
76    fn clone(&self) -> Self {
77        unsafe {
78            msg_send_0::<*mut c_void>(self.as_ptr(), sel!(retain));
79        }
80        Self(self.0)
81    }
82}
83
84impl Drop for TextureReferenceType {
85    fn drop(&mut self) {
86        unsafe {
87            msg_send_0::<()>(self.as_ptr(), sel!(release));
88        }
89    }
90}
91
92impl Referencing for TextureReferenceType {
93    #[inline]
94    fn as_ptr(&self) -> *const c_void {
95        self.0.as_ptr()
96    }
97}
98
99unsafe impl Send for TextureReferenceType {}
100unsafe impl Sync for TextureReferenceType {}