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