mtl_gpu/argument/
texture_reference_type.rs1use 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#[repr(transparent)]
15pub struct TextureReferenceType(pub(crate) NonNull<c_void>);
16
17impl TextureReferenceType {
18 #[inline]
24 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
25 NonNull::new(ptr).map(Self)
26 }
27
28 #[inline]
30 pub fn as_raw(&self) -> *mut c_void {
31 self.0.as_ptr()
32 }
33
34 #[inline]
38 pub fn data_type(&self) -> DataType {
39 unsafe { msg_send_0(self.as_ptr(), sel!(dataType)) }
40 }
41
42 #[inline]
46 pub fn access(&self) -> BindingAccess {
47 unsafe { msg_send_0(self.as_ptr(), sel!(access)) }
48 }
49
50 #[inline]
54 pub fn is_depth_texture(&self) -> bool {
55 unsafe { msg_send_0(self.as_ptr(), sel!(isDepthTexture)) }
56 }
57
58 #[inline]
62 pub fn texture_data_type(&self) -> DataType {
63 unsafe { msg_send_0(self.as_ptr(), sel!(textureDataType)) }
64 }
65
66 #[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 {}