use core::{ffi::c_float, ptr::NonNull};
use objc2::{
ClassType, extern_class, extern_conformance, extern_methods, msg_send,
rc::{Allocated, Retained},
runtime::NSObject,
};
use objc2_foundation::{CopyingHelper, NSCopying, NSObjectProtocol};
use super::MTLRasterizationRateSampleArray;
use crate::types::MTLSize;
extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTLRasterizationRateLayerDescriptor;
);
extern_conformance!(
unsafe impl NSCopying for MTLRasterizationRateLayerDescriptor {}
);
unsafe impl CopyingHelper for MTLRasterizationRateLayerDescriptor {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTLRasterizationRateLayerDescriptor {}
);
impl MTLRasterizationRateLayerDescriptor {
extern_methods!(
#[unsafe(method(initWithSampleCount:))]
#[unsafe(method_family = init)]
pub fn init_with_sample_count(
this: Allocated<Self>,
sample_count: MTLSize,
) -> Retained<Self>;
#[unsafe(method(initWithSampleCount:horizontal:vertical:))]
#[unsafe(method_family = init)]
pub fn init_with_sample_count_horizontal_vertical(
this: Allocated<Self>,
sample_count: MTLSize,
horizontal: NonNull<c_float>,
vertical: NonNull<c_float>,
) -> Retained<Self>;
#[unsafe(method(sampleCount))]
#[unsafe(method_family = none)]
pub fn sample_count(&self) -> MTLSize;
#[unsafe(method(maxSampleCount))]
#[unsafe(method_family = none)]
pub fn max_sample_count(&self) -> MTLSize;
#[unsafe(method(horizontalSampleStorage))]
#[unsafe(method_family = none)]
pub fn horizontal_sample_storage(&self) -> NonNull<c_float>;
#[unsafe(method(verticalSampleStorage))]
#[unsafe(method_family = none)]
pub fn vertical_sample_storage(&self) -> NonNull<c_float>;
#[unsafe(method(horizontal))]
#[unsafe(method_family = none)]
pub fn horizontal(&self) -> Retained<MTLRasterizationRateSampleArray>;
#[unsafe(method(vertical))]
#[unsafe(method_family = none)]
pub fn vertical(&self) -> Retained<MTLRasterizationRateSampleArray>;
#[unsafe(method(setSampleCount:))]
#[unsafe(method_family = none)]
pub fn set_sample_count(
&self,
sample_count: MTLSize,
);
);
}
impl MTLRasterizationRateLayerDescriptor {
pub fn new_with_sample_count_horizontal_vertical(
sample_count: MTLSize,
horizontal: &[f32],
vertical: &[f32],
) -> Retained<Self> {
assert_eq!(horizontal.len(), sample_count.width, "horizontal sample count does not match sample_count.width");
assert_eq!(vertical.len(), sample_count.height, "vertical sample count does not match sample_count.height");
let horizontal = NonNull::from(horizontal).cast::<c_float>();
let vertical = NonNull::from(vertical).cast::<c_float>();
let allocated: Allocated<Self> = unsafe { msg_send![Self::class(), alloc] };
Self::init_with_sample_count_horizontal_vertical(allocated, sample_count, horizontal, vertical)
}
}