diff --git a/src/commandbuffer.rs b/src/commandbuffer.rs index 028354ee..a59c6995 100644 --- a/src/commandbuffer.rs +++ b/src/commandbuffer.rs @@ -112,33 +112,33 @@ impl CommandBufferRef { unsafe { msg_send![self, addCompletedHandler: block] } } - pub fn new_blit_command_encoder(&self) -> &BlitCommandEncoderRef { - unsafe { msg_send![self, blitCommandEncoder] } + pub fn new_blit_command_encoder(&self) -> Id { + unsafe { msg_send_id![self, blitCommandEncoder] } } - pub fn new_compute_command_encoder(&self) -> &ComputeCommandEncoderRef { - unsafe { msg_send![self, computeCommandEncoder] } + pub fn new_compute_command_encoder(&self) -> Id { + unsafe { msg_send_id![self, computeCommandEncoder] } } pub fn new_render_command_encoder( &self, descriptor: &RenderPassDescriptorRef, - ) -> &RenderCommandEncoderRef { - unsafe { msg_send![self, renderCommandEncoderWithDescriptor: descriptor] } + ) -> Id { + unsafe { msg_send_id![self, renderCommandEncoderWithDescriptor: descriptor] } } pub fn new_parallel_render_command_encoder( &self, descriptor: &RenderPassDescriptorRef, - ) -> &ParallelRenderCommandEncoderRef { - unsafe { msg_send![self, parallelRenderCommandEncoderWithDescriptor: descriptor] } + ) -> Id { + unsafe { msg_send_id![self, parallelRenderCommandEncoderWithDescriptor: descriptor] } } pub fn compute_command_encoder_with_dispatch_type( &self, ty: MTLDispatchType, - ) -> &ComputeCommandEncoderRef { - unsafe { msg_send![self, computeCommandEncoderWithDispatchType: ty] } + ) -> Id { + unsafe { msg_send_id![self, computeCommandEncoderWithDispatchType: ty] } } pub fn encode_signal_event(&self, event: &EventRef, new_value: u64) { diff --git a/src/device.rs b/src/device.rs index 4906f45a..38e191fd 100644 --- a/src/device.rs +++ b/src/device.rs @@ -1977,9 +1977,9 @@ impl DeviceRef { unsafe { msg_send![self, supportsPullModelInterpolation] } } - pub fn new_argument_encoder(&self, arguments: &[&ArgumentDescriptorRef]) -> ArgumentEncoder { + pub fn new_argument_encoder(&self, arguments: &[&ArgumentDescriptorRef]) -> Id { let arguments: &ArrayRef = Array::from_slice(arguments); - unsafe { msg_send![self, newArgumentEncoderWithArguments: arguments] } + unsafe { msg_send_id![self, newArgumentEncoderWithArguments: arguments] } } pub fn new_heap(&self, descriptor: &HeapDescriptorRef) -> Heap { diff --git a/src/encoder.rs b/src/encoder.rs index 7ac209aa..e2ba6559 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -10,8 +10,9 @@ use super::*; use std::ops::Range; use objc2::encode::{Encode, Encoding}; -use objc2::foundation::{NSInteger, NSRange, NSString, NSUInteger}; +use objc2::foundation::{NSObject, NSInteger, NSRange, NSString, NSUInteger}; use objc2::rc::{Id, Shared}; +use objc2::{extern_protocol, ProtocolType}; #[repr(u64)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] @@ -198,15 +199,17 @@ unsafe impl RefEncode for VertexAmplificationViewMapping { const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING); } -pub enum MTLCommandEncoder {} - -foreign_obj_type! { - type CType = MTLCommandEncoder; +extern_protocol!( + #[derive(Debug, PartialEq, Eq, Hash)] pub struct CommandEncoder; - pub struct CommandEncoderRef; -} -impl CommandEncoderRef { + unsafe impl ProtocolType for CommandEncoder { + type Super = NSObject; + const NAME: &'static str = "MTLCommandEncoder"; + } +); + +impl CommandEncoder { pub fn label(&self) -> Id { unsafe { msg_send_id![self, label] } } @@ -235,31 +238,35 @@ impl CommandEncoderRef { } } -pub enum MTLParallelRenderCommandEncoder {} - -foreign_obj_type! { - type CType = MTLParallelRenderCommandEncoder; +extern_protocol!( + #[derive(Debug, PartialEq, Eq, Hash)] pub struct ParallelRenderCommandEncoder; - pub struct ParallelRenderCommandEncoderRef; - type ParentType = CommandEncoderRef; -} -impl ParallelRenderCommandEncoderRef { - pub fn render_command_encoder(&self) -> &RenderCommandEncoderRef { - unsafe { msg_send![self, renderCommandEncoder] } + unsafe impl ProtocolType for ParallelRenderCommandEncoder { + #[inherits(NSObject)] + type Super = CommandEncoder; + const NAME: &'static str = "MTLParallelRenderCommandEncoder"; } -} +); -pub enum MTLRenderCommandEncoder {} +impl ParallelRenderCommandEncoder { + pub fn render_command_encoder(&self) -> Id { + unsafe { msg_send_id![self, renderCommandEncoder] } + } +} -foreign_obj_type! { - type CType = MTLRenderCommandEncoder; +extern_protocol!( + #[derive(Debug, PartialEq, Eq, Hash)] pub struct RenderCommandEncoder; - pub struct RenderCommandEncoderRef; - type ParentType = CommandEncoderRef; -} -impl RenderCommandEncoderRef { + unsafe impl ProtocolType for RenderCommandEncoder { + #[inherits(NSObject)] + type Super = CommandEncoder; + const NAME: &'static str = "MTLRenderCommandEncoder"; + } +); + +impl RenderCommandEncoder { pub fn set_render_pipeline_state(&self, pipeline_state: &RenderPipelineStateRef) { unsafe { msg_send![self, setRenderPipelineState: pipeline_state] } } @@ -879,16 +886,18 @@ impl RenderCommandEncoderRef { } } -pub enum MTLBlitCommandEncoder {} - -foreign_obj_type! { - type CType = MTLBlitCommandEncoder; +extern_protocol!( + #[derive(Debug, PartialEq, Eq, Hash)] pub struct BlitCommandEncoder; - pub struct BlitCommandEncoderRef; - type ParentType = CommandEncoderRef; -} -impl BlitCommandEncoderRef { + unsafe impl ProtocolType for BlitCommandEncoder { + #[inherits(NSObject)] + type Super = CommandEncoder; + const NAME: &'static str = "MTLBlitCommandEncoder"; + } +); + +impl BlitCommandEncoder { pub fn synchronize_resource(&self, resource: &Resource) { unsafe { msg_send![self, synchronizeResource: resource] } } @@ -1059,16 +1068,18 @@ impl BlitCommandEncoderRef { } } -pub enum MTLComputeCommandEncoder {} - -foreign_obj_type! { - type CType = MTLComputeCommandEncoder; +extern_protocol!( + #[derive(Debug, PartialEq, Eq, Hash)] pub struct ComputeCommandEncoder; - pub struct ComputeCommandEncoderRef; - type ParentType = CommandEncoderRef; -} -impl ComputeCommandEncoderRef { + unsafe impl ProtocolType for ComputeCommandEncoder { + #[inherits(NSObject)] + type Super = CommandEncoder; + const NAME: &'static str = "MTLComputeCommandEncoder"; + } +); + +impl ComputeCommandEncoder { pub fn set_compute_pipeline_state(&self, state: &ComputePipelineStateRef) { unsafe { msg_send![self, setComputePipelineState: state] } } @@ -1298,15 +1309,17 @@ impl ComputeCommandEncoderRef { } } -pub enum MTLArgumentEncoder {} - -foreign_obj_type! { - type CType = MTLArgumentEncoder; +extern_protocol!( + #[derive(Debug, PartialEq, Eq, Hash)] pub struct ArgumentEncoder; - pub struct ArgumentEncoderRef; -} -impl ArgumentEncoderRef { + unsafe impl ProtocolType for ArgumentEncoder { + type Super = NSObject; + const NAME: &'static str = "MTLArgumentEncoder"; + } +); + +impl ArgumentEncoder { pub fn encoded_length(&self) -> NSUInteger { unsafe { msg_send![self, encodedLength] } } @@ -1438,10 +1451,7 @@ impl ArgumentEncoderRef { unsafe { msg_send![self, constantDataAtIndex: at_index] } } - pub fn new_argument_encoder_for_buffer(&self, index: NSUInteger) -> ArgumentEncoder { - unsafe { - let ptr = msg_send![self, newArgumentEncoderForBufferAtIndex: index]; - ArgumentEncoder::from_ptr(ptr) - } + pub fn new_argument_encoder_for_buffer(&self, index: NSUInteger) -> Id { + unsafe { msg_send_id![self, newArgumentEncoderForBufferAtIndex: index] } } } diff --git a/src/library.rs b/src/library.rs index a985c8d0..86fbbd3c 100644 --- a/src/library.rs +++ b/src/library.rs @@ -304,10 +304,9 @@ impl FunctionRef { unsafe { msg_send![self, stageInputAttributes] } } - pub fn new_argument_encoder(&self, buffer_index: NSUInteger) -> ArgumentEncoder { + pub fn new_argument_encoder(&self, buffer_index: NSUInteger) -> Id { unsafe { - let ptr = msg_send![self, newArgumentEncoderWithBufferIndex: buffer_index]; - ArgumentEncoder::from_ptr(ptr) + msg_send_id![self, newArgumentEncoderWithBufferIndex: buffer_index] } }