objc2_model_io/generated/MDLMeshBuffer.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// Type of data a MDLMeshBuffer has been allocated for
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/modelio/mdlmeshbuffertype?language=objc)
13// NS_ENUM
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct MDLMeshBufferType(pub NSUInteger);
17impl MDLMeshBufferType {
18 #[doc(alias = "MDLMeshBufferTypeVertex")]
19 pub const Vertex: Self = Self(1);
20 #[doc(alias = "MDLMeshBufferTypeIndex")]
21 pub const Index: Self = Self(2);
22 #[doc(alias = "MDLMeshBufferTypeCustom")]
23 pub const Custom: Self = Self(3);
24}
25
26unsafe impl Encode for MDLMeshBufferType {
27 const ENCODING: Encoding = NSUInteger::ENCODING;
28}
29
30unsafe impl RefEncode for MDLMeshBufferType {
31 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
32}
33
34extern_class!(
35 /// Represents a reference to memory of a mapped MeshBuffer
36 ///
37 /// See also [Apple's documentation](https://developer.apple.com/documentation/modelio/mdlmeshbuffermap?language=objc)
38 #[unsafe(super(NSObject))]
39 #[derive(Debug, PartialEq, Eq, Hash)]
40 pub struct MDLMeshBufferMap;
41);
42
43unsafe impl NSObjectProtocol for MDLMeshBufferMap {}
44
45impl MDLMeshBufferMap {
46 extern_methods!(
47 #[cfg(feature = "block2")]
48 /// Called by implementor of MDLMeshBuffer protocol to create the map
49 /// and arrange for unmapping on deallocation.
50 #[unsafe(method(initWithBytes:deallocator:))]
51 #[unsafe(method_family = init)]
52 pub unsafe fn initWithBytes_deallocator(
53 this: Allocated<Self>,
54 bytes: NonNull<c_void>,
55 deallocator: Option<&block2::Block<dyn Fn()>>,
56 ) -> Retained<Self>;
57
58 /// Mutable pointer to data in a MDLMeshBuffer object.
59 #[unsafe(method(bytes))]
60 #[unsafe(method_family = none)]
61 pub unsafe fn bytes(&self) -> NonNull<c_void>;
62 );
63}
64
65/// Methods declared on superclass `NSObject`.
66impl MDLMeshBufferMap {
67 extern_methods!(
68 #[unsafe(method(init))]
69 #[unsafe(method_family = init)]
70 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
71
72 #[unsafe(method(new))]
73 #[unsafe(method_family = new)]
74 pub unsafe fn new() -> Retained<Self>;
75 );
76}
77
78extern_protocol!(
79 /// Used by ModelIO to represent a buffer to be filled with vertex and
80 /// index data
81 ///
82 /// Supports deep copy of data by conforming to the NSCopying protocol
83 ///
84 /// See also [Apple's documentation](https://developer.apple.com/documentation/modelio/mdlmeshbuffer?language=objc)
85 pub unsafe trait MDLMeshBuffer: NSObjectProtocol + NSCopying {
86 /// Fills buffer with data at offset
87 ///
88 /// Parameter `data`: Data to fill buffer with
89 ///
90 /// Parameter `offset`: Byte offset in buffer to begin filling data
91 ///
92 /// Fills data.length bytes of data. Will not write beyond length of
93 /// this buffer.
94 #[unsafe(method(fillData:offset:))]
95 #[unsafe(method_family = none)]
96 unsafe fn fillData_offset(&self, data: &NSData, offset: NSUInteger);
97
98 /// CPU access to buffer's memory
99 ///
100 /// Returns: An MDLMeshBufferMap object to read or modify a buffer's memory
101 ///
102 /// The buffer will remain mapped as long as the returned MDLMeshBufferMap
103 /// object exists. Mapping a buffer may impose restrictions on a system.
104 /// For instance, if the implementing class maps an OpenGL buffer, that
105 /// buffer may be unavailable for rendering while mapped, and cause a
106 /// draw failure. Precautions must be taken in such cases.
107 #[unsafe(method(map))]
108 #[unsafe(method_family = none)]
109 unsafe fn map(&self) -> Retained<MDLMeshBufferMap>;
110
111 /// Size in bytes of the buffer allocation
112 #[unsafe(method(length))]
113 #[unsafe(method_family = none)]
114 unsafe fn length(&self) -> NSUInteger;
115
116 /// Allocator object used to create this buffer.
117 ///
118 /// This allcoator used for copy and relayout operations (such as when
119 /// a new vertex descriptor is applied to a vertex buffer)
120 #[unsafe(method(allocator))]
121 #[unsafe(method_family = none)]
122 unsafe fn allocator(&self) -> Retained<ProtocolObject<dyn MDLMeshBufferAllocator>>;
123
124 /// Zone from which this buffer was created
125 ///
126 /// This zone will be used for copy and relayout operations (such as
127 /// when a new vertex descriptor is applied to a vertex buffer). If
128 /// the default zone is used this will be nil.
129 #[unsafe(method(zone))]
130 #[unsafe(method_family = none)]
131 unsafe fn zone(&self) -> Retained<ProtocolObject<dyn MDLMeshBufferZone>>;
132
133 /// the intended type of the buffer
134 #[unsafe(method(type))]
135 #[unsafe(method_family = none)]
136 unsafe fn r#type(&self) -> MDLMeshBufferType;
137 }
138);
139
140extern_class!(
141 /// A CPU memory backed mesh buffer
142 ///
143 /// See also [Apple's documentation](https://developer.apple.com/documentation/modelio/mdlmeshbufferdata?language=objc)
144 #[unsafe(super(NSObject))]
145 #[derive(Debug, PartialEq, Eq, Hash)]
146 pub struct MDLMeshBufferData;
147);
148
149unsafe impl MDLMeshBuffer for MDLMeshBufferData {}
150
151unsafe impl NSCopying for MDLMeshBufferData {}
152
153unsafe impl CopyingHelper for MDLMeshBufferData {
154 type Result = Self;
155}
156
157unsafe impl NSObjectProtocol for MDLMeshBufferData {}
158
159impl MDLMeshBufferData {
160 extern_methods!(
161 /// instantiate a new data backed mesh buffer
162 ///
163 /// Parameter `type`: the intended use of the buffer
164 ///
165 /// Parameter `length`: the size of buffer to allocate, in bytes
166 #[unsafe(method(initWithType:length:))]
167 #[unsafe(method_family = init)]
168 pub unsafe fn initWithType_length(
169 this: Allocated<Self>,
170 r#type: MDLMeshBufferType,
171 length: NSUInteger,
172 ) -> Retained<Self>;
173
174 /// instantiate a new data backed mesh buffer
175 ///
176 /// Parameter `type`: the intended use of the buffer
177 ///
178 /// Parameter `data`: the data to be used as a mesh buffer. It will be copied.
179 #[unsafe(method(initWithType:data:))]
180 #[unsafe(method_family = init)]
181 pub unsafe fn initWithType_data(
182 this: Allocated<Self>,
183 r#type: MDLMeshBufferType,
184 data: Option<&NSData>,
185 ) -> Retained<Self>;
186
187 #[unsafe(method(data))]
188 #[unsafe(method_family = none)]
189 pub unsafe fn data(&self) -> Retained<NSData>;
190 );
191}
192
193/// Methods declared on superclass `NSObject`.
194impl MDLMeshBufferData {
195 extern_methods!(
196 #[unsafe(method(init))]
197 #[unsafe(method_family = init)]
198 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
199
200 #[unsafe(method(new))]
201 #[unsafe(method_family = new)]
202 pub unsafe fn new() -> Retained<Self>;
203 );
204}
205
206extern_protocol!(
207 /// A reference to a logical pool of memory from which mesh buffers would
208 /// be allocated
209 ///
210 /// See also [Apple's documentation](https://developer.apple.com/documentation/modelio/mdlmeshbufferzone?language=objc)
211 pub unsafe trait MDLMeshBufferZone: NSObjectProtocol {
212 /// Total size of memory in the zone
213 #[unsafe(method(capacity))]
214 #[unsafe(method_family = none)]
215 unsafe fn capacity(&self) -> NSUInteger;
216
217 /// Allocator used to create the zone
218 #[unsafe(method(allocator))]
219 #[unsafe(method_family = none)]
220 unsafe fn allocator(&self) -> Retained<ProtocolObject<dyn MDLMeshBufferAllocator>>;
221 }
222);
223
224extern_protocol!(
225 /// Object for allocating buffers to back vertex and index data
226 ///
227 /// Accepted by MDLAsset init method. Implementor creates objects
228 /// implementing MDLMeshBuffer with memory to be filled with vertex and
229 /// index data during 3d file loading and parsing.
230 ///
231 /// See also [Apple's documentation](https://developer.apple.com/documentation/modelio/mdlmeshbufferallocator?language=objc)
232 pub unsafe trait MDLMeshBufferAllocator: NSObjectProtocol {
233 /// Create a zone which can be used to allocate MDLMeshBuffer objects
234 ///
235 /// Parameter `capacity`: Total size in bytes of all buffers which can be created from
236 /// this zone
237 #[unsafe(method(newZone:))]
238 #[unsafe(method_family = new)]
239 unsafe fn newZone(
240 &self,
241 capacity: NSUInteger,
242 ) -> Retained<ProtocolObject<dyn MDLMeshBufferZone>>;
243
244 /// Create a zone which can be used to allocate MDLMeshBuffer objects
245 ///
246 /// Parameter `sizes`: Sizes of each buffer to be created in this zone
247 ///
248 /// Parameter `types`: Type of each buffer to be created in this zone. Values to be of
249 /// MDLMeshBufferType
250 ///
251 /// Will create a zone from which MDLMeshBuffer objects can be
252 /// allocated. This will allocate a zone with enough capacity
253 /// for each of the buffers with sizes and types specified even taking
254 /// into any alignment restrictions necessary to use these buffers.
255 #[unsafe(method(newZoneForBuffersWithSize:andType:))]
256 #[unsafe(method_family = new)]
257 unsafe fn newZoneForBuffersWithSize_andType(
258 &self,
259 sizes: &NSArray<NSNumber>,
260 types: &NSArray<NSNumber>,
261 ) -> Retained<ProtocolObject<dyn MDLMeshBufferZone>>;
262
263 /// Create a buffer in a default zone
264 ///
265 /// Parameter `length`: Size of buffer to be created in bytes
266 ///
267 /// Parameter `type`: Type of data to be stored in this buffer
268 #[unsafe(method(newBuffer:type:))]
269 #[unsafe(method_family = new)]
270 unsafe fn newBuffer_type(
271 &self,
272 length: NSUInteger,
273 r#type: MDLMeshBufferType,
274 ) -> Retained<ProtocolObject<dyn MDLMeshBuffer>>;
275
276 /// Create a buffer in a default zone and fill with data in the supplied
277 /// NSData object
278 ///
279 /// Parameter `data`: Memory to fill the buffer with
280 ///
281 /// Parameter `type`: Type of data to be stored in this buffer
282 #[unsafe(method(newBufferWithData:type:))]
283 #[unsafe(method_family = new)]
284 unsafe fn newBufferWithData_type(
285 &self,
286 data: &NSData,
287 r#type: MDLMeshBufferType,
288 ) -> Retained<ProtocolObject<dyn MDLMeshBuffer>>;
289
290 /// Create a buffer from a given zone with the given length
291 ///
292 /// Returns: An object conforming to the MDLMeshBuffer protocol. Returns nil the
293 /// buffer could not be allocated in the zone given.
294 ///
295 /// Parameter `zone`: Zone from which to allocate the memory
296 ///
297 /// Parameter `type`: Type of data to be stored in this buffer
298 ///
299 /// An implementing MDLMeshBufferAllocator object may increase the size
300 /// of the zone if the buffer could not be allocated with the current
301 /// zone size. Alternatively the implementation may return nil if the
302 /// buffer could not be allocated.
303 #[unsafe(method(newBufferFromZone:length:type:))]
304 #[unsafe(method_family = new)]
305 unsafe fn newBufferFromZone_length_type(
306 &self,
307 zone: Option<&ProtocolObject<dyn MDLMeshBufferZone>>,
308 length: NSUInteger,
309 r#type: MDLMeshBufferType,
310 ) -> Option<Retained<ProtocolObject<dyn MDLMeshBuffer>>>;
311
312 /// Create a buffer from a given zone and fill with data in the supplied
313 /// NSData object
314 ///
315 /// Returns: An object conforming to the MDLMeshBuffer protocol. Returns nil the
316 /// buffer could not be allocated in the given zone
317 ///
318 /// Parameter `zone`: Zone from which to allocate the memory
319 ///
320 /// Parameter `data`: Values with which to fill the buffer
321 ///
322 /// Parameter `type`: Type of data to be stored in this buffer
323 ///
324 /// An implementing MDLMeshBufferAllocator object may increase the size
325 /// of the zone if the buffer could not be allocated with the current
326 /// zone size. Alternatively the implementation may return nil if the
327 /// buffer could not be allocated.
328 #[unsafe(method(newBufferFromZone:data:type:))]
329 #[unsafe(method_family = new)]
330 unsafe fn newBufferFromZone_data_type(
331 &self,
332 zone: Option<&ProtocolObject<dyn MDLMeshBufferZone>>,
333 data: &NSData,
334 r#type: MDLMeshBufferType,
335 ) -> Option<Retained<ProtocolObject<dyn MDLMeshBuffer>>>;
336 }
337);
338
339extern_class!(
340 /// An allocator to use when backing with an NSData is appropriate.
341 ///
342 /// See also [Apple's documentation](https://developer.apple.com/documentation/modelio/mdlmeshbufferdataallocator?language=objc)
343 #[unsafe(super(NSObject))]
344 #[derive(Debug, PartialEq, Eq, Hash)]
345 pub struct MDLMeshBufferDataAllocator;
346);
347
348unsafe impl MDLMeshBufferAllocator for MDLMeshBufferDataAllocator {}
349
350unsafe impl NSObjectProtocol for MDLMeshBufferDataAllocator {}
351
352impl MDLMeshBufferDataAllocator {
353 extern_methods!();
354}
355
356/// Methods declared on superclass `NSObject`.
357impl MDLMeshBufferDataAllocator {
358 extern_methods!(
359 #[unsafe(method(init))]
360 #[unsafe(method_family = init)]
361 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
362
363 #[unsafe(method(new))]
364 #[unsafe(method_family = new)]
365 pub unsafe fn new() -> Retained<Self>;
366 );
367}
368
369extern_class!(
370 /// A default zone that can be use for convenience
371 ///
372 /// See also [Apple's documentation](https://developer.apple.com/documentation/modelio/mdlmeshbufferzonedefault?language=objc)
373 #[unsafe(super(NSObject))]
374 #[derive(Debug, PartialEq, Eq, Hash)]
375 pub struct MDLMeshBufferZoneDefault;
376);
377
378unsafe impl MDLMeshBufferZone for MDLMeshBufferZoneDefault {}
379
380unsafe impl NSObjectProtocol for MDLMeshBufferZoneDefault {}
381
382impl MDLMeshBufferZoneDefault {
383 extern_methods!(
384 #[unsafe(method(capacity))]
385 #[unsafe(method_family = none)]
386 pub unsafe fn capacity(&self) -> NSUInteger;
387
388 #[unsafe(method(allocator))]
389 #[unsafe(method_family = none)]
390 pub unsafe fn allocator(&self) -> Retained<ProtocolObject<dyn MDLMeshBufferAllocator>>;
391 );
392}
393
394/// Methods declared on superclass `NSObject`.
395impl MDLMeshBufferZoneDefault {
396 extern_methods!(
397 #[unsafe(method(init))]
398 #[unsafe(method_family = init)]
399 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
400
401 #[unsafe(method(new))]
402 #[unsafe(method_family = new)]
403 pub unsafe fn new() -> Retained<Self>;
404 );
405}