objc2-gl-kit 0.3.2

Bindings to the GLKit framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;
#[cfg(feature = "objc2-model-io")]
use objc2_model_io::*;
#[cfg(feature = "objc2-open-gl")]
#[cfg(target_os = "macos")]
use objc2_open_gl::*;

use crate::*;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/glkit/kglkmodelerrordomain?language=objc)
    pub static kGLKModelErrorDomain: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/glkit/kglkmodelerrorkey?language=objc)
    pub static kGLKModelErrorKey: &'static NSString;
}

extern_class!(
    /// Allocator passed to MDLAsset init method to load vertex and index data directly into OpenGL buffer object
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/glkit/glkmeshbufferallocator?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct GLKMeshBufferAllocator;
);

#[cfg(feature = "objc2-model-io")]
extern_conformance!(
    unsafe impl MDLMeshBufferAllocator for GLKMeshBufferAllocator {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for GLKMeshBufferAllocator {}
);

impl GLKMeshBufferAllocator {
    extern_methods!();
}

/// Methods declared on superclass `NSObject`.
impl GLKMeshBufferAllocator {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// Mesh buffers created when  needs to allocate memory to back vertex or index data
    ///
    /// Memory backing these buffer are OpenGL buffers. Model I/O will load index and vertex data from from a model asset directly in to the OpenGL buffer object.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/glkit/glkmeshbuffer?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct GLKMeshBuffer;
);

#[cfg(feature = "objc2-model-io")]
extern_conformance!(
    unsafe impl MDLMeshBuffer for GLKMeshBuffer {}
);

extern_conformance!(
    unsafe impl NSCopying for GLKMeshBuffer {}
);

unsafe impl CopyingHelper for GLKMeshBuffer {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for GLKMeshBuffer {}
);

impl GLKMeshBuffer {
    extern_methods!(
        /// Size in bytes of the buffer allocation
        #[unsafe(method(length))]
        #[unsafe(method_family = none)]
        pub unsafe fn length(&self) -> NSUInteger;

        /// Allocator object used to create this buffer.
        ///
        /// This allcoator used for copy and relayout operations (such as when a new vertex descriptor is applied to a vertex buffer)
        #[unsafe(method(allocator))]
        #[unsafe(method_family = none)]
        pub unsafe fn allocator(&self) -> Retained<GLKMeshBufferAllocator>;

        #[cfg(feature = "objc2-open-gl")]
        #[cfg(target_os = "macos")]
        /// glBufferName for buffer object backing vertex/index data
        ///
        /// Many GLKMeshBuffers may reference the same OpenGL buffer object, but each with its own offset.  (i.e. Many GLKMeshBuffers may be suballocated from a single OpenGL buffer object)
        #[unsafe(method(glBufferName))]
        #[unsafe(method_family = none)]
        pub unsafe fn glBufferName(&self) -> GLuint;

        /// Byte offset of the data within the OpenGL buffer
        #[unsafe(method(offset))]
        #[unsafe(method_family = none)]
        pub unsafe fn offset(&self) -> NSUInteger;

        #[cfg(feature = "objc2-model-io")]
        /// Zone from which this buffer was created (if it was created witha zone)
        ///
        /// A single GL buffer is allocated for each zone.  Each zone could have many GLKMeshBuffers, each with it's own offset.  If a GLKMeshBufferAllocator is used, Model I/O will attempt to load all vertex and indexData of a single model into a single zone.  So although there maybe many GLKMeshBuffers for a model they will be backed with the same contigous GL buffer.
        #[unsafe(method(zone))]
        #[unsafe(method_family = none)]
        pub unsafe fn zone(&self) -> Option<Retained<ProtocolObject<dyn MDLMeshBufferZone>>>;

        #[cfg(feature = "objc2-model-io")]
        /// the intended type of the buffer
        #[unsafe(method(type))]
        #[unsafe(method_family = none)]
        pub unsafe fn r#type(&self) -> MDLMeshBufferType;
    );
}

/// Methods declared on superclass `NSObject`.
impl GLKMeshBuffer {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/glkit/glksubmesh?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct GLKSubmesh;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for GLKSubmesh {}
);

impl GLKSubmesh {
    extern_methods!(
        /// Must be initialized by a GLKMesh object
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Option<Retained<Self>>;

        #[cfg(feature = "objc2-open-gl")]
        #[cfg(target_os = "macos")]
        /// Type of data in the elementBuffer (aka indexBuffer)
        ///
        /// This value should be used for the type parameter of glDrawElements
        #[unsafe(method(type))]
        #[unsafe(method_family = none)]
        pub unsafe fn r#type(&self) -> GLenum;

        #[cfg(feature = "objc2-open-gl")]
        #[cfg(target_os = "macos")]
        /// Primitive type mode value of data in the elementBuffer (aka indexBuffer)
        ///
        /// This value should be used for the mode parameter in glDrawElements
        #[unsafe(method(mode))]
        #[unsafe(method_family = none)]
        pub unsafe fn mode(&self) -> GLenum;

        #[cfg(feature = "objc2-open-gl")]
        #[cfg(target_os = "macos")]
        /// Number of elements (aka indicies) in the elementBuffer (aka indexBuffer)
        ///
        /// This value should be used for the count parameter in glDrawElements
        #[unsafe(method(elementCount))]
        #[unsafe(method_family = none)]
        pub unsafe fn elementCount(&self) -> GLsizei;

        /// Name of buffer object with index data
        ///
        /// The buffer name to be used with DrawElements
        #[unsafe(method(elementBuffer))]
        #[unsafe(method_family = none)]
        pub unsafe fn elementBuffer(&self) -> Retained<GLKMeshBuffer>;

        /// Parent GLKit mesh containing vertex data of this object
        ///
        /// Buffer of this parent mesh should be set in the encoder before a drawIndexedPrimitives call is made
        #[unsafe(method(mesh))]
        #[unsafe(method_family = none)]
        pub unsafe fn mesh(&self) -> Option<Retained<GLKMesh>>;

        /// Name from the original MDLSubmesh object.
        ///
        /// Although not directly used by this object, the application may use this to identify the submesh in it renderer/scene/world.
        #[unsafe(method(name))]
        #[unsafe(method_family = none)]
        pub unsafe fn name(&self) -> Retained<NSString>;
    );
}

/// Methods declared on superclass `NSObject`.
impl GLKSubmesh {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/glkit/glkmesh?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct GLKMesh;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for GLKMesh {}
);

impl GLKMesh {
    extern_methods!(
        /// Must initialize with a mesh
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Option<Retained<Self>>;

        #[cfg(feature = "objc2-model-io")]
        /// Initialize the mesh and the mesh's submeshes
        ///
        /// This does NOT initialize any meshes that are children of the Model I/O mesh
        /// Pointer to an NSError object which will be set if an error occurred
        ///
        /// Parameter `mesh`: Model I/O Mesh from which to create this GLKit mesh
        #[unsafe(method(initWithMesh:error:_))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithMesh_error(
            this: Allocated<Self>,
            mesh: &MDLMesh,
        ) -> Result<Retained<Self>, Retained<NSError>>;

        #[cfg(feature = "objc2-model-io")]
        /// Initialize all meshes in a Model I/O asset.
        ///
        /// Returns: An array of GLKit meshes built an asset
        ///
        /// Parameter `asset`: Model I/O asset from which to create GLKit meshes
        ///
        /// Parameter `sourceMeshes`: Model I/O meshes corresponding the newly created GLKMeshes
        ///
        /// Parameter `error`: Pointer to an NSError object set if an error occurred
        ///
        /// Parameter `return`: GLKit meshes created from the Model I/O asset
        ///
        /// A convenience method to create GLKit meshes from each mesh in a Model/IO asset.  Resulting meshes are returned while Model I/O meshes from which they were generated will appear in the sourceMeshes array.
        #[unsafe(method(newMeshesFromAsset:sourceMeshes:error:_))]
        #[unsafe(method_family = new)]
        pub unsafe fn newMeshesFromAsset_sourceMeshes_error(
            asset: &MDLAsset,
            source_meshes: Option<&mut Option<Retained<NSArray<MDLMesh>>>>,
        ) -> Result<Retained<NSArray<GLKMesh>>, Retained<NSError>>;

        /// Number of verticies in the vertexBuffers
        #[unsafe(method(vertexCount))]
        #[unsafe(method_family = none)]
        pub unsafe fn vertexCount(&self) -> NSUInteger;

        /// Array of buffers in which mesh vertex data resides
        #[unsafe(method(vertexBuffers))]
        #[unsafe(method_family = none)]
        pub unsafe fn vertexBuffers(&self) -> Retained<NSArray<GLKMeshBuffer>>;

        #[cfg(feature = "objc2-model-io")]
        /// Model I/O vertex descriptor specifying the layout of data in vertexBuffers
        ///
        /// This is not directly used by this object, but the application can use this information to determine rendering state or setup a vertex attribute object.
        #[unsafe(method(vertexDescriptor))]
        #[unsafe(method_family = none)]
        pub unsafe fn vertexDescriptor(&self) -> Retained<MDLVertexDescriptor>;

        /// Submeshes containing index buffers to rendering mesh verticies.
        ///
        /// Submeshes may also contain texture materials to apply when rendering this object
        #[unsafe(method(submeshes))]
        #[unsafe(method_family = none)]
        pub unsafe fn submeshes(&self) -> Retained<NSArray<GLKSubmesh>>;

        /// Name of the mesh copies from the originating Model I/O mesh
        ///
        /// Can be used by the app to identiry the mesh in it's scene/world/renderer etc.
        #[unsafe(method(name))]
        #[unsafe(method_family = none)]
        pub unsafe fn name(&self) -> Retained<NSString>;
    );
}

/// Methods declared on superclass `NSObject`.
impl GLKMesh {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

/// Structure for parameters to use in glVertexAttribPointer given a MDLVertexForamt
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/glkit/glkvertexattributeparameters?language=objc)
#[cfg(feature = "objc2-open-gl")]
#[cfg(target_os = "macos")]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct GLKVertexAttributeParameters {
    pub r#type: GLenum,
    pub size: GLint,
    pub normalized: GLboolean,
}

#[cfg(feature = "objc2-open-gl")]
#[cfg(target_os = "macos")]
unsafe impl Encode for GLKVertexAttributeParameters {
    const ENCODING: Encoding = Encoding::Struct(
        "_GLKVertexAttributeParameters",
        &[<GLenum>::ENCODING, <GLint>::ENCODING, <GLboolean>::ENCODING],
    );
}

#[cfg(feature = "objc2-open-gl")]
#[cfg(target_os = "macos")]
unsafe impl RefEncode for GLKVertexAttributeParameters {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern "C-unwind" {
    /// Returns parameters to use in a call to glVertexAttribPointer given a MDLVertexFormat
    #[cfg(all(feature = "objc2-model-io", feature = "objc2-open-gl"))]
    #[cfg(target_os = "macos")]
    pub fn GLKVertexAttributeParametersFromModelIO(
        vertex_format: MDLVertexFormat,
    ) -> GLKVertexAttributeParameters;
}