nsi_sys/
lib.rs

1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4//! Auto-generated Rust bindings for *Illumination Research*’s *Nodal
5//! Scene Interface* – ɴsɪ.
6//!
7//! You should not need to use this crate directly except for two
8//! reasons. You are likely either:
9//! * a masochist who wants to use the C-API directly from Rust.
10//! * Not happy with my high level Rust binding (see below) – consider
11//!   opening an issue [here](https://github.com/virtualritz/nsi/issues)
12//!   instead.
13//! * writing a renderer that exposes an ɴsɪ C-API.
14//!
15//! # High Level Bindings
16//!
17//! There are high level Rust bindings for this API in the
18//! [ɴsɪ crate](https://crates.io/crates/nsi/).
19//!
20//! ## Differences From The C API
21//!
22//! All `enum`s have been rustified – they were mapped to actual Rust `enum`s.
23//!
24//! Postfixes were stripped on `enum` and `struct` type names. E.g.:
25//!
26//! [`NSIParam_t`](https://github.com/virtualritz/nsi-sys/blob/f1f05da59b558f9dd18f7afd37aa82d72b73b7da/include/nsi.h#L69-L77)
27//! ⟶ [`NSIParam`]
28//!
29//! Prefixes and postfixes were stripped on `enum` variants. E.g.:
30//!
31//! [`NSIType_t`](https://github.com/virtualritz/nsi-sys/blob/f1f05da59b558f9dd18f7afd37aa82d72b73b7da/include/nsi.h#L27-L41)`::NSITypeInvalid`
32//! ⟶ [`NSIType`]`::Invalid`
33//!
34//! Rationale: make code using the bindings a bit less convoluted resp. easier
35//! to read.
36//!
37//! Finally, [`NSIParamFlags`] is a [`bitflags`](https://docs.rs/bitflags)
38//! `struct` that wraps the `NSIParam*` flags from the C-API for ergonomics.
39//!
40//! # Compile- vs. Runtime
41//!
42//! The crate builds as-is, with default features.
43//!
44//! However, at runtime this crate requires a library/renderer that
45//! implements the ɴsɪ C-API to link against. Currently the only
46//! renderer that does is [*3Delight*](https://www.3delight.com/).
47//!
48//! # Features
49//!
50//! * `download_lib3delight` – Fetches the dynamic library version of *3Delight
51//!   2.1.2* for *Linux*, *macOS* or *Windows*.
52//!
53//!   This can be used as a fallback, to build against, if you do not have the
54//!   renderer installed on your system. But it is an old version of 3Delight
55//!   and foremost a CI feature.
56//!
57//!   It is instead suggested that you [download a *3Delight*
58//!   package](https://www.3delight.com/download) for your platform & install
59//!   it. This will set the `DELIGHT` environment variable that the build
60//!   script is looking for to find a locally installed library to link
61//!   against. Free version renders with up to 12 cores.
62//!
63//!   This will also install *3Delight Display* which you can render to,
64//!   progressively – useful for debugging.
65//!
66//! * `link_lib3delight` – Links against the dynamic library version of
67//!   3Delight. Requires the `DELIGHT` environment variable to be set.
68//!
69//! * `omit_functions` – Omit generating bindings for the API's functions. This
70//!   is for the case where you want to expose your own C-API hooks from your
71//!   renderer.
72use bitflags::bitflags;
73use std::os::raw::c_int;
74
75mod c_api {
76    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
77}
78
79pub use c_api::{
80    NSIContext, NSIErrorHandler, NSIErrorLevel, NSIHandle, NSIParam,
81    NSIProcedural, NSIProceduralExecute, NSIProceduralLoad,
82    NSIProceduralUnload, NSIRenderStopped, NSIReport, NSIStoppingStatus,
83    NSIType, NSI_ALL_ATTRIBUTES, NSI_ALL_NODES, NSI_SCENE_GLOBAL,
84    NSI_SCENE_ROOT, NSI_VERSION,
85};
86
87#[cfg(not(feature = "omit_functions"))]
88pub use c_api::{
89    NSIBegin, NSIConnect, NSICreate, NSIDelete, NSIDeleteAttribute,
90    NSIDisconnect, NSIEnd, NSIEvaluate, NSIRenderControl, NSISetAttribute,
91    NSISetAttributeAtTime,
92};
93
94bitflags! {
95    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
96    pub struct NSIParamFlags: c_int {
97        const InterpolateLinear = c_api::NSIParamInterpolateLinear as _;
98        const IsArray = c_api::NSIParamIsArray as _;
99        const PerFace = c_api::NSIParamPerFace as _;
100        const PerVertex = c_api::NSIParamPerVertex as _;
101    }
102}
103
104impl From<i32> for NSIErrorLevel {
105    fn from(level: i32) -> Self {
106        match level {
107            0 => NSIErrorLevel::Message,
108            1 => NSIErrorLevel::Info,
109            2 => NSIErrorLevel::Warning,
110            _ => NSIErrorLevel::Error,
111        }
112    }
113}