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