1 // Copyright 2016 GFX developers 2 // 3 // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or 4 // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 // copied, modified, or distributed except according to those terms. 7 8 use cocoa_foundation::foundation::NSUInteger; 9 10 #[repr(u64)] 11 #[allow(non_camel_case_types)] 12 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] 13 pub enum MTLVertexFormat { 14 Invalid = 0, 15 UChar2 = 1, 16 UChar3 = 2, 17 UChar4 = 3, 18 Char2 = 4, 19 Char3 = 5, 20 Char4 = 6, 21 UChar2Normalized = 7, 22 UChar3Normalized = 8, 23 UChar4Normalized = 9, 24 Char2Normalized = 10, 25 Char3Normalized = 11, 26 Char4Normalized = 12, 27 UShort2 = 13, 28 UShort3 = 14, 29 UShort4 = 15, 30 Short2 = 16, 31 Short3 = 17, 32 Short4 = 18, 33 UShort2Normalized = 19, 34 UShort3Normalized = 20, 35 UShort4Normalized = 21, 36 Short2Normalized = 22, 37 Short3Normalized = 23, 38 Short4Normalized = 24, 39 Half2 = 25, 40 Half3 = 26, 41 Half4 = 27, 42 Float = 28, 43 Float2 = 29, 44 Float3 = 30, 45 Float4 = 31, 46 Int = 32, 47 Int2 = 33, 48 Int3 = 34, 49 Int4 = 35, 50 UInt = 36, 51 UInt2 = 37, 52 UInt3 = 38, 53 UInt4 = 39, 54 Int1010102Normalized = 40, 55 UInt1010102Normalized = 41, 56 UChar4Normalized_BGRA = 42, 57 UChar = 45, 58 Char = 46, 59 UCharNormalized = 47, 60 CharNormalized = 48, 61 UShort = 49, 62 Short = 50, 63 UShortNormalized = 51, 64 ShortNormalized = 52, 65 Half = 53, 66 } 67 68 #[repr(u64)] 69 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] 70 pub enum MTLVertexStepFunction { 71 Constant = 0, 72 PerVertex = 1, 73 PerInstance = 2, 74 PerPatch = 3, 75 PerPatchControlPoint = 4, 76 } 77 78 pub enum MTLVertexBufferLayoutDescriptor {} 79 80 foreign_obj_type! { 81 type CType = MTLVertexBufferLayoutDescriptor; 82 pub struct VertexBufferLayoutDescriptor; 83 pub struct VertexBufferLayoutDescriptorRef; 84 } 85 86 impl VertexBufferLayoutDescriptor { new() -> Self87 pub fn new() -> Self { 88 unsafe { 89 let class = class!(MTLVertexBufferLayoutDescriptor); 90 msg_send![class, new] 91 } 92 } 93 } 94 95 impl VertexBufferLayoutDescriptorRef { stride(&self) -> NSUInteger96 pub fn stride(&self) -> NSUInteger { 97 unsafe { msg_send![self, stride] } 98 } 99 set_stride(&self, stride: NSUInteger)100 pub fn set_stride(&self, stride: NSUInteger) { 101 unsafe { msg_send![self, setStride: stride] } 102 } 103 step_function(&self) -> MTLVertexStepFunction104 pub fn step_function(&self) -> MTLVertexStepFunction { 105 unsafe { msg_send![self, stepFunction] } 106 } 107 set_step_function(&self, func: MTLVertexStepFunction)108 pub fn set_step_function(&self, func: MTLVertexStepFunction) { 109 unsafe { msg_send![self, setStepFunction: func] } 110 } 111 step_rate(&self) -> NSUInteger112 pub fn step_rate(&self) -> NSUInteger { 113 unsafe { msg_send![self, stepRate] } 114 } 115 set_step_rate(&self, step_rate: NSUInteger)116 pub fn set_step_rate(&self, step_rate: NSUInteger) { 117 unsafe { msg_send![self, setStepRate: step_rate] } 118 } 119 } 120 121 pub enum MTLVertexBufferLayoutDescriptorArray {} 122 123 foreign_obj_type! { 124 type CType = MTLVertexBufferLayoutDescriptorArray; 125 pub struct VertexBufferLayoutDescriptorArray; 126 pub struct VertexBufferLayoutDescriptorArrayRef; 127 } 128 129 impl VertexBufferLayoutDescriptorArrayRef { object_at(&self, index: NSUInteger) -> Option<&VertexBufferLayoutDescriptorRef>130 pub fn object_at(&self, index: NSUInteger) -> Option<&VertexBufferLayoutDescriptorRef> { 131 unsafe { msg_send![self, objectAtIndexedSubscript: index] } 132 } 133 set_object_at( &self, index: NSUInteger, layout: Option<&VertexBufferLayoutDescriptorRef>, )134 pub fn set_object_at( 135 &self, 136 index: NSUInteger, 137 layout: Option<&VertexBufferLayoutDescriptorRef>, 138 ) { 139 unsafe { 140 msg_send![self, setObject:layout 141 atIndexedSubscript:index] 142 } 143 } 144 } 145 146 pub enum MTLVertexAttributeDescriptor {} 147 148 foreign_obj_type! { 149 type CType = MTLVertexAttributeDescriptor; 150 pub struct VertexAttributeDescriptor; 151 pub struct VertexAttributeDescriptorRef; 152 } 153 154 impl VertexAttributeDescriptor { new() -> Self155 pub fn new() -> Self { 156 unsafe { 157 let class = class!(MTLVertexAttributeDescriptor); 158 msg_send![class, new] 159 } 160 } 161 } 162 163 impl VertexAttributeDescriptorRef { format(&self) -> MTLVertexFormat164 pub fn format(&self) -> MTLVertexFormat { 165 unsafe { msg_send![self, format] } 166 } 167 set_format(&self, format: MTLVertexFormat)168 pub fn set_format(&self, format: MTLVertexFormat) { 169 unsafe { msg_send![self, setFormat: format] } 170 } 171 offset(&self) -> NSUInteger172 pub fn offset(&self) -> NSUInteger { 173 unsafe { msg_send![self, offset] } 174 } 175 set_offset(&self, offset: NSUInteger)176 pub fn set_offset(&self, offset: NSUInteger) { 177 unsafe { msg_send![self, setOffset: offset] } 178 } 179 buffer_index(&self) -> NSUInteger180 pub fn buffer_index(&self) -> NSUInteger { 181 unsafe { msg_send![self, bufferIndex] } 182 } 183 set_buffer_index(&self, index: NSUInteger)184 pub fn set_buffer_index(&self, index: NSUInteger) { 185 unsafe { msg_send![self, setBufferIndex: index] } 186 } 187 } 188 189 pub enum MTLVertexAttributeDescriptorArray {} 190 191 foreign_obj_type! { 192 type CType = MTLVertexAttributeDescriptorArray; 193 pub struct VertexAttributeDescriptorArray; 194 pub struct VertexAttributeDescriptorArrayRef; 195 } 196 197 impl VertexAttributeDescriptorArrayRef { object_at(&self, index: NSUInteger) -> Option<&VertexAttributeDescriptorRef>198 pub fn object_at(&self, index: NSUInteger) -> Option<&VertexAttributeDescriptorRef> { 199 unsafe { msg_send![self, objectAtIndexedSubscript: index] } 200 } 201 set_object_at( &self, index: NSUInteger, attribute: Option<&VertexAttributeDescriptorRef>, )202 pub fn set_object_at( 203 &self, 204 index: NSUInteger, 205 attribute: Option<&VertexAttributeDescriptorRef>, 206 ) { 207 unsafe { 208 msg_send![self, setObject:attribute 209 atIndexedSubscript:index] 210 } 211 } 212 } 213 214 pub enum MTLVertexDescriptor {} 215 216 foreign_obj_type! { 217 type CType = MTLVertexDescriptor; 218 pub struct VertexDescriptor; 219 pub struct VertexDescriptorRef; 220 } 221 222 impl VertexDescriptor { new<'a>() -> &'a VertexDescriptorRef223 pub fn new<'a>() -> &'a VertexDescriptorRef { 224 unsafe { 225 let class = class!(MTLVertexDescriptor); 226 msg_send![class, vertexDescriptor] 227 } 228 } 229 } 230 231 impl VertexDescriptorRef { layouts(&self) -> &VertexBufferLayoutDescriptorArrayRef232 pub fn layouts(&self) -> &VertexBufferLayoutDescriptorArrayRef { 233 unsafe { msg_send![self, layouts] } 234 } 235 attributes(&self) -> &VertexAttributeDescriptorArrayRef236 pub fn attributes(&self) -> &VertexAttributeDescriptorArrayRef { 237 unsafe { msg_send![self, attributes] } 238 } 239 240 #[cfg(feature = "private")] serialize_descriptor(&self) -> *mut std::ffi::c_void241 pub unsafe fn serialize_descriptor(&self) -> *mut std::ffi::c_void { 242 msg_send![self, newSerializedDescriptor] 243 } 244 reset(&self)245 pub fn reset(&self) { 246 unsafe { msg_send![self, reset] } 247 } 248 } 249