diff --git a/examples/window/main.rs b/examples/window/main.rs index f53978bc..6852c7e3 100644 --- a/examples/window/main.rs +++ b/examples/window/main.rs @@ -34,9 +34,9 @@ fn prepare_pipeline_state<'a>(device: &DeviceRef, library: &LibraryRef) -> Rende pipeline_state_descriptor.set_vertex_function(Some(&vert)); pipeline_state_descriptor.set_fragment_function(Some(&frag)); pipeline_state_descriptor - .color_attachments() - .object_at(0) - .unwrap() + .color_attachments()[0] + // .object_at(0) + // .unwrap() .set_pixel_format(MTLPixelFormat::BGRA8Unorm); device @@ -44,10 +44,16 @@ fn prepare_pipeline_state<'a>(device: &DeviceRef, library: &LibraryRef) -> Rende .unwrap() } +fn ppd(desc: &mut RenderPassDescriptorRef) { + // let color_attachment = &desc.color_attachments()[0]; + desc.color_attachments()[0] = desc.color_attachments()[0].to_owned(); +} + fn prepare_render_pass_descriptor(descriptor: &RenderPassDescriptorRef, texture: &TextureRef) { //descriptor.color_attachments().set_object_at(0, MTLRenderPassColorAttachmentDescriptor::alloc()); //let color_attachment: MTLRenderPassColorAttachmentDescriptor = unsafe { msg_send![descriptor.color_attachments().0, _descriptorAtIndex:0] };//descriptor.color_attachments().object_at(0); - let color_attachment = descriptor.color_attachments().object_at(0).unwrap(); + let color_attachment = &descriptor.color_attachments()[0]; + color_attachment.set_texture(Some(texture)); color_attachment.set_load_action(MTLLoadAction::Clear); @@ -133,9 +139,9 @@ fn main() { encoder.end_encoding(); render_pass_descriptor - .color_attachments() - .object_at(0) - .unwrap() + .color_attachments()[0] + // .object_at(0) + // .unwrap() .set_load_action(MTLLoadAction::DontCare); let encoder = command_buffer.new_render_command_encoder(&render_pass_descriptor); diff --git a/src/pipeline/compute.rs b/src/pipeline/compute.rs index 3ffefe43..608833a4 100644 --- a/src/pipeline/compute.rs +++ b/src/pipeline/compute.rs @@ -261,13 +261,28 @@ foreign_obj_type! { pub struct AttributeDescriptorArrayRef; } -impl AttributeDescriptorArrayRef { - pub fn object_at(&self, index: usize) -> Option<&AttributeDescriptorRef> { +// impl AttributeDescriptorArrayRef { +// pub fn object_at(&self, index: NSUInteger) -> Option<&AttributeDescriptorRef> { +// unsafe { msg_send![self, objectAtIndexedSubscript: index] } +// } + +// pub fn set_object_at(&self, index: NSUInteger, buffer_desc: Option<&AttributeDescriptorRef>) { +// unsafe { msg_send![self, setObject:buffer_desc atIndexedSubscript:index] } +// } +// } + + +impl std::ops::Index for AttributeDescriptorArrayRef { + type Output = AttributeDescriptor; + + fn index(&self, index: NSUInteger) -> &Self::Output { unsafe { msg_send![self, objectAtIndexedSubscript: index] } } +} - pub fn set_object_at(&self, index: usize, buffer_desc: Option<&AttributeDescriptorRef>) { - unsafe { msg_send![self, setObject:buffer_desc atIndexedSubscript:index] } +impl std::ops::IndexMut for AttributeDescriptorArrayRef { + fn index_mut(&mut self, index: NSUInteger) -> &mut Self::Output { + unsafe { msg_send![self, objectAtIndexedSubscript: index] } } } @@ -313,13 +328,17 @@ foreign_obj_type! { pub struct BufferLayoutDescriptorArrayRef; } -impl BufferLayoutDescriptorArrayRef { - pub fn object_at(&self, index: usize) -> Option<&BufferLayoutDescriptorRef> { +impl std::ops::Index for BufferLayoutDescriptorArrayRef { + type Output = BufferLayoutDescriptor; + + fn index(&self, index: NSUInteger) -> &Self::Output { unsafe { msg_send![self, objectAtIndexedSubscript: index] } } +} - pub fn set_object_at(&self, index: usize, buffer_desc: Option<&BufferLayoutDescriptorRef>) { - unsafe { msg_send![self, setObject:buffer_desc atIndexedSubscript:index] } +impl std::ops::IndexMut for BufferLayoutDescriptorArrayRef { + fn index_mut(&mut self, index: NSUInteger) -> &mut Self::Output { + unsafe { msg_send![self, objectAtIndexedSubscript: index] } } } diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index 91f336fc..0cc62805 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -37,13 +37,27 @@ foreign_obj_type! { pub struct PipelineBufferDescriptorArrayRef; } -impl PipelineBufferDescriptorArrayRef { - pub fn object_at(&self, index: NSUInteger) -> Option<&PipelineBufferDescriptorRef> { +// impl PipelineBufferDescriptorArrayRef { +// pub fn object_at(&self, index: NSUInteger) -> Option<&PipelineBufferDescriptorRef> { +// unsafe { msg_send![self, objectAtIndexedSubscript: index] } +// } + +// pub fn set_object_at(&self, index: NSUInteger, buffer_desc: Option<&PipelineBufferDescriptorRef>) { +// unsafe { msg_send![self, setObject:buffer_desc atIndexedSubscript:index] } +// } +// } + +impl std::ops::Index for PipelineBufferDescriptorArrayRef { + type Output = PipelineBufferDescriptor; + + fn index(&self, index: NSUInteger) -> &Self::Output { unsafe { msg_send![self, objectAtIndexedSubscript: index] } } +} - pub fn set_object_at(&self, index: NSUInteger, buffer_desc: Option<&PipelineBufferDescriptorRef>) { - unsafe { msg_send![self, setObject:buffer_desc atIndexedSubscript:index] } +impl std::ops::IndexMut for PipelineBufferDescriptorArrayRef { + fn index_mut(&mut self, index: NSUInteger) -> &mut Self::Output { + unsafe { msg_send![self, objectAtIndexedSubscript: index] } } } diff --git a/src/pipeline/render.rs b/src/pipeline/render.rs index b3efe594..788fac13 100644 --- a/src/pipeline/render.rs +++ b/src/pipeline/render.rs @@ -403,19 +403,34 @@ foreign_obj_type! { pub struct RenderPipelineColorAttachmentDescriptorArrayRef; } -impl RenderPipelineColorAttachmentDescriptorArrayRef { - pub fn object_at(&self, index: NSUInteger) -> Option<&RenderPipelineColorAttachmentDescriptorRef> { +// impl RenderPipelineColorAttachmentDescriptorArrayRef { +// pub fn object_at(&self, index: NSUInteger) -> Option<&RenderPipelineColorAttachmentDescriptorRef> { +// unsafe { msg_send![self, objectAtIndexedSubscript: index] } +// } + +// pub fn set_object_at( +// &self, +// index: NSUInteger, +// attachment: Option<&RenderPipelineColorAttachmentDescriptorRef>, +// ) { +// unsafe { +// msg_send![self, setObject:attachment +// atIndexedSubscript:index] +// } +// } +// } + + +impl std::ops::Index for RenderPipelineColorAttachmentDescriptorArrayRef { + type Output = RenderPipelineColorAttachmentDescriptor; + + fn index(&self, index: NSUInteger) -> &Self::Output { unsafe { msg_send![self, objectAtIndexedSubscript: index] } } +} - pub fn set_object_at( - &self, - index: NSUInteger, - attachment: Option<&RenderPipelineColorAttachmentDescriptorRef>, - ) { - unsafe { - msg_send![self, setObject:attachment - atIndexedSubscript:index] - } +impl std::ops::IndexMut for RenderPipelineColorAttachmentDescriptorArrayRef { + fn index_mut(&mut self, index: NSUInteger) -> &mut Self::Output { + unsafe { msg_send![self, objectAtIndexedSubscript: index] } } -} +} \ No newline at end of file diff --git a/src/renderpass.rs b/src/renderpass.rs index 2c0f8e33..cd34f695 100644 --- a/src/renderpass.rs +++ b/src/renderpass.rs @@ -231,20 +231,39 @@ foreign_obj_type! { pub struct RenderPassColorAttachmentDescriptorArrayRef; } -impl RenderPassColorAttachmentDescriptorArrayRef { - pub fn object_at(&self, index: usize) -> Option<&RenderPassColorAttachmentDescriptorRef> { + +// impl RenderPassColorAttachmentDescriptorArrayRef { +// // #[deprecated( +// // since = "0.17.3", +// // note = "Use Index trait methods instead" +// // )] +// pub fn object_at(&self, index: NSUInteger) -> Option<&RenderPassColorAttachmentDescriptorRef> { +// unsafe { msg_send![self, objectAtIndexedSubscript: index] } +// } + +// pub fn set_object_at( +// &self, +// index: usize, +// attachment: Option<&RenderPassColorAttachmentDescriptorRef>, +// ) { +// unsafe { +// msg_send![self, setObject:attachment +// atIndexedSubscript:index] +// } +// } +// } + +impl std::ops::Index for RenderPassColorAttachmentDescriptorArrayRef { + type Output = RenderPassColorAttachmentDescriptorRef; + + fn index(&self, index: NSUInteger) -> &Self::Output { unsafe { msg_send![self, objectAtIndexedSubscript: index] } } +} - pub fn set_object_at( - &self, - index: usize, - attachment: Option<&RenderPassColorAttachmentDescriptorRef>, - ) { - unsafe { - msg_send![self, setObject:attachment - atIndexedSubscript:index] - } +impl std::ops::IndexMut for RenderPassColorAttachmentDescriptorArrayRef { + fn index_mut(&mut self, index: NSUInteger) -> &mut Self::Output { + unsafe { msg_send![self, objectAtIndexedSubscript: index] } } } diff --git a/src/vertexdescriptor.rs b/src/vertexdescriptor.rs index 610c9c81..32f88854 100644 --- a/src/vertexdescriptor.rs +++ b/src/vertexdescriptor.rs @@ -125,16 +125,17 @@ foreign_obj_type! { pub struct VertexBufferLayoutDescriptorArrayRef; } -impl VertexBufferLayoutDescriptorArrayRef { - pub fn object_at(&self, index: NSUInteger) -> Option<&VertexBufferLayoutDescriptorRef> { +impl std::ops::Index for VertexBufferLayoutDescriptorArrayRef { + type Output = VertexBufferLayoutDescriptor; + + fn index(&self, index: NSUInteger) -> &Self::Output { unsafe { msg_send![self, objectAtIndexedSubscript: index] } } +} - pub fn set_object_at(&self, index: NSUInteger, layout: Option<&VertexBufferLayoutDescriptorRef>) { - unsafe { - msg_send![self, setObject:layout - atIndexedSubscript:index] - } +impl std::ops::IndexMut for VertexBufferLayoutDescriptorArrayRef { + fn index_mut(&mut self, index: NSUInteger) -> &mut Self::Output { + unsafe { msg_send![self, objectAtIndexedSubscript: index] } } }