use core::ops::Range;
use objc2::{
extern_class, extern_conformance, extern_methods, msg_send,
rc::{Allocated, Retained},
runtime::NSObject,
};
use objc2_foundation::{CopyingHelper, NSCopying, NSObjectProtocol, NSRange};
use crate::{MTLPixelFormat, MTLTextureSwizzleChannels, MTLTextureType};
extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTLTextureViewDescriptor;
);
extern_conformance!(
unsafe impl NSCopying for MTLTextureViewDescriptor {}
);
unsafe impl CopyingHelper for MTLTextureViewDescriptor {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTLTextureViewDescriptor {}
);
impl MTLTextureViewDescriptor {
extern_methods!(
#[unsafe(method(pixelFormat))]
#[unsafe(method_family = none)]
pub fn pixel_format(&self) -> MTLPixelFormat;
#[unsafe(method(setPixelFormat:))]
#[unsafe(method_family = none)]
pub fn set_pixel_format(
&self,
pixel_format: MTLPixelFormat,
);
#[unsafe(method(textureType))]
#[unsafe(method_family = none)]
pub fn texture_type(&self) -> MTLTextureType;
#[unsafe(method(setTextureType:))]
#[unsafe(method_family = none)]
pub fn set_texture_type(
&self,
texture_type: MTLTextureType,
);
#[unsafe(method(swizzle))]
#[unsafe(method_family = none)]
pub fn swizzle(&self) -> MTLTextureSwizzleChannels;
#[unsafe(method(setSwizzle:))]
#[unsafe(method_family = none)]
pub fn set_swizzle(
&self,
swizzle: MTLTextureSwizzleChannels,
);
);
pub fn level_range(&self) -> Range<usize> {
let ns_range: NSRange = unsafe { msg_send![self, levelRange] };
ns_range.into()
}
pub fn set_level_range(
&self,
level_range: Range<usize>,
) {
unsafe {
let _: () = msg_send![self, setLevelRange: NSRange::from(level_range)];
}
}
pub fn slice_range(&self) -> Range<usize> {
let ns_range: NSRange = unsafe { msg_send![self, sliceRange] };
ns_range.into()
}
pub fn set_slice_range(
&self,
slice_range: Range<usize>,
) {
unsafe {
let _: () = msg_send![self, setSliceRange: NSRange::from(slice_range)];
}
}
}
impl MTLTextureViewDescriptor {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub fn new() -> Retained<Self>;
);
}