use core::ops::Range;
use objc2::{Message, extern_protocol, msg_send, runtime::ProtocolObject};
use objc2_foundation::NSRange;
use crate::util::opt_ref_slice_as_ptr;
use crate::{MTLFunctionHandle, MTLResource, MTLResourceID};
extern_protocol!(
pub unsafe trait MTLVisibleFunctionTable: MTLResource {
#[unsafe(method(gpuResourceID))]
#[unsafe(method_family = none)]
fn gpu_resource_id(&self) -> MTLResourceID;
#[unsafe(method(setFunction:atIndex:))]
#[unsafe(method_family = none)]
fn set_function_at_index(
&self,
function: Option<&ProtocolObject<dyn MTLFunctionHandle>>,
index: usize,
);
}
);
pub trait MTLVisibleFunctionTableExt: MTLVisibleFunctionTable + Message {
fn set_functions(
&self,
functions: &[Option<&ProtocolObject<dyn MTLFunctionHandle>>],
range: Range<usize>,
) where
Self: Sized,
{
let ptr = opt_ref_slice_as_ptr(functions);
unsafe { msg_send![self, setFunctions: ptr, withRange: NSRange::from(range)] }
}
}
impl<T: MTLVisibleFunctionTable + Message> MTLVisibleFunctionTableExt for T {}