use objc2::{
extern_class, extern_conformance, extern_methods, msg_send,
rc::{Allocated, Retained},
runtime::{NSObject, ProtocolObject},
};
use objc2_foundation::{CopyingHelper, NSArray, NSCopying, NSObjectProtocol, NSString};
use crate::{
MTLBinaryArchive, MTLDynamicLibrary, MTLLinkedFunctions, MTLPipelineBufferDescriptorArray, MTLPixelFormat,
MTLPrimitiveTopologyClass, MTLRenderPipelineColorAttachmentDescriptorArray, MTLShaderValidation,
MTLTessellationControlPointIndexType, MTLTessellationFactorFormat, MTLTessellationFactorStepFunction,
MTLTessellationPartitionMode, MTLVertexDescriptor, MTLWinding, library::MTLFunction,
};
extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTLRenderPipelineDescriptor;
);
extern_conformance!(
unsafe impl NSCopying for MTLRenderPipelineDescriptor {}
);
unsafe impl CopyingHelper for MTLRenderPipelineDescriptor {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTLRenderPipelineDescriptor {}
);
impl MTLRenderPipelineDescriptor {
extern_methods!(
#[unsafe(method(vertexFunction))]
#[unsafe(method_family = none)]
pub fn vertex_function(&self) -> Option<Retained<ProtocolObject<dyn MTLFunction>>>;
#[unsafe(method(setVertexFunction:))]
#[unsafe(method_family = none)]
pub fn set_vertex_function(
&self,
function: Option<&ProtocolObject<dyn MTLFunction>>,
);
#[unsafe(method(fragmentFunction))]
#[unsafe(method_family = none)]
pub fn fragment_function(&self) -> Option<Retained<ProtocolObject<dyn MTLFunction>>>;
#[unsafe(method(setFragmentFunction:))]
#[unsafe(method_family = none)]
pub fn set_fragment_function(
&self,
function: Option<&ProtocolObject<dyn MTLFunction>>,
);
#[unsafe(method(vertexBuffers))]
#[unsafe(method_family = none)]
pub fn vertex_buffers(&self) -> Retained<MTLPipelineBufferDescriptorArray>;
#[unsafe(method(fragmentBuffers))]
#[unsafe(method_family = none)]
pub fn fragment_buffers(&self) -> Retained<MTLPipelineBufferDescriptorArray>;
#[unsafe(method(vertexLinkedFunctions))]
#[unsafe(method_family = none)]
pub fn vertex_linked_functions(&self) -> Retained<MTLLinkedFunctions>;
#[unsafe(method(setVertexLinkedFunctions:))]
#[unsafe(method_family = none)]
pub fn set_vertex_linked_functions(
&self,
functions: Option<&MTLLinkedFunctions>,
);
#[unsafe(method(fragmentLinkedFunctions))]
#[unsafe(method_family = none)]
pub fn fragment_linked_functions(&self) -> Retained<MTLLinkedFunctions>;
#[unsafe(method(setFragmentLinkedFunctions:))]
#[unsafe(method_family = none)]
pub fn set_fragment_linked_functions(
&self,
functions: Option<&MTLLinkedFunctions>,
);
#[unsafe(method(supportAddingVertexBinaryFunctions))]
#[unsafe(method_family = none)]
pub fn support_adding_vertex_binary_functions(&self) -> bool;
#[unsafe(method(setSupportAddingVertexBinaryFunctions:))]
#[unsafe(method_family = none)]
pub fn set_support_adding_vertex_binary_functions(
&self,
val: bool,
);
#[unsafe(method(supportAddingFragmentBinaryFunctions))]
#[unsafe(method_family = none)]
pub fn support_adding_fragment_binary_functions(&self) -> bool;
#[unsafe(method(setSupportAddingFragmentBinaryFunctions:))]
#[unsafe(method_family = none)]
pub fn set_support_adding_fragment_binary_functions(
&self,
val: bool,
);
#[unsafe(method(maxVertexCallStackDepth))]
#[unsafe(method_family = none)]
pub fn max_vertex_call_stack_depth(&self) -> usize;
#[unsafe(method(setMaxVertexCallStackDepth:))]
#[unsafe(method_family = none)]
pub fn set_max_vertex_call_stack_depth(
&self,
depth: usize,
);
#[unsafe(method(maxFragmentCallStackDepth))]
#[unsafe(method_family = none)]
pub fn max_fragment_call_stack_depth(&self) -> usize;
#[unsafe(method(setMaxFragmentCallStackDepth:))]
#[unsafe(method_family = none)]
pub fn set_max_fragment_call_stack_depth(
&self,
depth: usize,
);
#[deprecated = "use raster_sample_count"]
#[unsafe(method(sampleCount))]
#[unsafe(method_family = none)]
pub fn sample_count(&self) -> usize;
#[deprecated = "use set_raster_sample_count"]
#[unsafe(method(setSampleCount:))]
#[unsafe(method_family = none)]
pub fn set_sample_count(
&self,
sample_count: usize,
);
#[unsafe(method(rasterSampleCount))]
#[unsafe(method_family = none)]
pub fn raster_sample_count(&self) -> usize;
#[unsafe(method(setRasterSampleCount:))]
#[unsafe(method_family = none)]
pub fn set_raster_sample_count(
&self,
raster_sample_count: usize,
);
#[unsafe(method(isAlphaToCoverageEnabled))]
#[unsafe(method_family = none)]
pub fn is_alpha_to_coverage_enabled(&self) -> bool;
#[unsafe(method(setAlphaToCoverageEnabled:))]
#[unsafe(method_family = none)]
pub fn set_alpha_to_coverage_enabled(
&self,
enabled: bool,
);
#[unsafe(method(isAlphaToOneEnabled))]
#[unsafe(method_family = none)]
pub fn is_alpha_to_one_enabled(&self) -> bool;
#[unsafe(method(setAlphaToOneEnabled:))]
#[unsafe(method_family = none)]
pub fn set_alpha_to_one_enabled(
&self,
enabled: bool,
);
#[unsafe(method(isRasterizationEnabled))]
#[unsafe(method_family = none)]
pub fn is_rasterization_enabled(&self) -> bool;
#[unsafe(method(setRasterizationEnabled:))]
#[unsafe(method_family = none)]
pub fn set_rasterization_enabled(
&self,
enabled: bool,
);
#[unsafe(method(maxVertexAmplificationCount))]
#[unsafe(method_family = none)]
pub fn max_vertex_amplification_count(&self) -> usize;
#[unsafe(method(setMaxVertexAmplificationCount:))]
#[unsafe(method_family = none)]
pub fn set_max_vertex_amplification_count(
&self,
value: usize,
);
#[unsafe(method(colorAttachments))]
#[unsafe(method_family = none)]
pub fn color_attachments(&self) -> Retained<MTLRenderPipelineColorAttachmentDescriptorArray>;
#[unsafe(method(depthAttachmentPixelFormat))]
#[unsafe(method_family = none)]
pub fn depth_attachment_pixel_format(&self) -> MTLPixelFormat;
#[unsafe(method(setDepthAttachmentPixelFormat:))]
#[unsafe(method_family = none)]
pub fn set_depth_attachment_pixel_format(
&self,
fmt: MTLPixelFormat,
);
#[unsafe(method(stencilAttachmentPixelFormat))]
#[unsafe(method_family = none)]
pub fn stencil_attachment_pixel_format(&self) -> MTLPixelFormat;
#[unsafe(method(setStencilAttachmentPixelFormat:))]
#[unsafe(method_family = none)]
pub fn set_stencil_attachment_pixel_format(
&self,
fmt: MTLPixelFormat,
);
#[unsafe(method(inputPrimitiveTopology))]
#[unsafe(method_family = none)]
pub fn input_primitive_topology(&self) -> MTLPrimitiveTopologyClass;
#[unsafe(method(setInputPrimitiveTopology:))]
#[unsafe(method_family = none)]
pub fn set_input_primitive_topology(
&self,
topo: MTLPrimitiveTopologyClass,
);
#[unsafe(method(tessellationPartitionMode))]
#[unsafe(method_family = none)]
pub fn tessellation_partition_mode(&self) -> MTLTessellationPartitionMode;
#[unsafe(method(setTessellationPartitionMode:))]
#[unsafe(method_family = none)]
pub fn set_tessellation_partition_mode(
&self,
mode: MTLTessellationPartitionMode,
);
#[unsafe(method(maxTessellationFactor))]
#[unsafe(method_family = none)]
pub fn max_tessellation_factor(&self) -> usize;
#[unsafe(method(setMaxTessellationFactor:))]
#[unsafe(method_family = none)]
pub fn set_max_tessellation_factor(
&self,
factor: usize,
);
#[unsafe(method(isTessellationFactorScaleEnabled))]
#[unsafe(method_family = none)]
pub fn is_tessellation_factor_scale_enabled(&self) -> bool;
#[unsafe(method(setTessellationFactorScaleEnabled:))]
#[unsafe(method_family = none)]
pub fn set_tessellation_factor_scale_enabled(
&self,
enabled: bool,
);
#[unsafe(method(tessellationFactorFormat))]
#[unsafe(method_family = none)]
pub fn tessellation_factor_format(&self) -> MTLTessellationFactorFormat;
#[unsafe(method(setTessellationFactorFormat:))]
#[unsafe(method_family = none)]
pub fn set_tessellation_factor_format(
&self,
format: MTLTessellationFactorFormat,
);
#[unsafe(method(tessellationControlPointIndexType))]
#[unsafe(method_family = none)]
pub fn tessellation_control_point_index_type(&self) -> MTLTessellationControlPointIndexType;
#[unsafe(method(setTessellationControlPointIndexType:))]
#[unsafe(method_family = none)]
pub fn set_tessellation_control_point_index_type(
&self,
index_type: MTLTessellationControlPointIndexType,
);
#[unsafe(method(tessellationFactorStepFunction))]
#[unsafe(method_family = none)]
pub fn tessellation_factor_step_function(&self) -> MTLTessellationFactorStepFunction;
#[unsafe(method(setTessellationFactorStepFunction:))]
#[unsafe(method_family = none)]
pub fn set_tessellation_factor_step_function(
&self,
step_function: MTLTessellationFactorStepFunction,
);
#[unsafe(method(tessellationOutputWindingOrder))]
#[unsafe(method_family = none)]
pub fn tessellation_output_winding_order(&self) -> MTLWinding;
#[unsafe(method(setTessellationOutputWindingOrder:))]
#[unsafe(method_family = none)]
pub fn set_tessellation_output_winding_order(
&self,
winding: MTLWinding,
);
#[unsafe(method(vertexDescriptor))]
#[unsafe(method_family = none)]
pub fn vertex_descriptor(&self) -> Option<Retained<MTLVertexDescriptor>>;
#[unsafe(method(setVertexDescriptor:))]
#[unsafe(method_family = none)]
pub fn set_vertex_descriptor(
&self,
vertex_descriptor: Option<&MTLVertexDescriptor>,
);
#[unsafe(method(supportIndirectCommandBuffers))]
#[unsafe(method_family = none)]
pub fn support_indirect_command_buffers(&self) -> bool;
#[unsafe(method(setSupportIndirectCommandBuffers:))]
#[unsafe(method_family = none)]
pub fn set_support_indirect_command_buffers(
&self,
enabled: bool,
);
#[unsafe(method(reset))]
#[unsafe(method_family = none)]
pub fn reset(&self);
#[unsafe(method(shaderValidation))]
#[unsafe(method_family = none)]
pub fn shader_validation(&self) -> MTLShaderValidation;
#[unsafe(method(setShaderValidation:))]
#[unsafe(method_family = none)]
pub fn set_shader_validation(
&self,
v: MTLShaderValidation,
);
);
}
impl MTLRenderPipelineDescriptor {
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>;
);
}
impl MTLRenderPipelineDescriptor {
pub fn vertex_preloaded_libraries(&self) -> Box<[Retained<ProtocolObject<dyn MTLDynamicLibrary>>]> {
let libraries: Retained<NSArray<ProtocolObject<dyn MTLDynamicLibrary>>> =
unsafe { msg_send![self, vertexPreloadedLibraries] };
libraries.to_vec().into_boxed_slice()
}
pub fn set_vertex_preloaded_libraries(
&self,
libraries: &[&ProtocolObject<dyn MTLDynamicLibrary>],
) {
let libraries = NSArray::from_slice(libraries);
unsafe {
let _: () = msg_send![self, setVertexPreloadedLibraries: &*libraries];
}
}
pub fn fragment_preloaded_libraries(&self) -> Box<[Retained<ProtocolObject<dyn MTLDynamicLibrary>>]> {
let libraries: Retained<NSArray<ProtocolObject<dyn MTLDynamicLibrary>>> =
unsafe { msg_send![self, fragmentPreloadedLibraries] };
libraries.to_vec().into_boxed_slice()
}
pub fn set_fragment_preloaded_libraries(
&self,
libraries: &[&ProtocolObject<dyn MTLDynamicLibrary>],
) {
let libraries = NSArray::from_slice(libraries);
unsafe {
let _: () = msg_send![self, setFragmentPreloadedLibraries: &*libraries];
}
}
pub fn binary_archives(&self) -> Option<Box<[Retained<ProtocolObject<dyn MTLBinaryArchive>>]>> {
let archives: Option<Retained<NSArray<ProtocolObject<dyn MTLBinaryArchive>>>> =
unsafe { msg_send![self, binaryArchives] };
archives.map(|archives| archives.to_vec().into_boxed_slice())
}
pub fn set_binary_archives(
&self,
archives: Option<&[&ProtocolObject<dyn MTLBinaryArchive>]>,
) {
let archives = archives.map(NSArray::from_slice);
unsafe {
let _: () = msg_send![self, setBinaryArchives: archives.as_deref()];
}
}
pub fn label(&self) -> Option<String> {
let s: Option<Retained<NSString>> = unsafe { msg_send![self, label] };
s.map(|s| s.to_string())
}
pub fn set_label(
&self,
label: Option<&str>,
) {
unsafe {
let _: () = msg_send![self, setLabel: label.map(NSString::from_str).as_deref()];
}
}
}
#[cfg(test)]
mod tests {
use objc2::{rc::Retained, runtime::ProtocolObject};
use super::MTLRenderPipelineDescriptor;
use crate::{MTLBinaryArchive, MTLDynamicLibrary};
#[test]
fn collection_methods_have_rust_native_signatures() {
let _: fn(&MTLRenderPipelineDescriptor) -> Box<[Retained<ProtocolObject<dyn MTLDynamicLibrary>>]> =
MTLRenderPipelineDescriptor::vertex_preloaded_libraries;
let _: fn(&MTLRenderPipelineDescriptor) -> Option<Box<[Retained<ProtocolObject<dyn MTLBinaryArchive>>]>> =
MTLRenderPipelineDescriptor::binary_archives;
}
}