delight_sys/
lib.rs

1#![allow(non_snake_case)]
2#![allow(dead_code)]
3//! Auto-generated Rust bindings for *Illumination Research*'s 3Delight
4//! renderer's utility API.
5//!
6//! You should not need to use this crate directly except for two
7//! reasons. You are likely either:
8//!
9//! * a masochist who wants to use the C-API directly from Rust.
10//!
11//! * Not happy with my high level Rust binding (see below) – consider
12//!   opening an issue [here](https://github.com/virtualritz/delight-helpers/issues)
13//!   instead.
14//!
15//! ## High Level Bindings
16//!
17//! There are high level Rust bindings for this API in the
18//! [`delight` crate](https://crates.io/crates/delight/).
19//!
20//! ## Compile- vs. Runtime
21//!
22//! The crate builds as-is, with default features.
23//!
24//! However, at runtime this crate requires a library/renderer that
25//! implements the resp. C-API to link against. Currently the only
26//! renderer that does is [*3Delight*](https://www.3delight.com/).
27//!
28//! ## Cargo Features
29//!
30//! * `download_lib3delight` -- Fetches the dynamic library version of
31//!   3Delight for Linux, macOS or Windows. This can be used as a fallback, to
32//!   build against, if you do not have the renderer installed on your system.
33//!   But it is an old version of 3Delight and foremost a CI feature.
34//!
35//!   It is instead suggested that you download a 3Delight package for your
36//!   platform & install it. This will set the `DELIGHT` environment variable
37//!   that the build script is looking for to find a locally installed library
38//!   to link against.
39//!
40//!   This will also install *3Delight Display* which you can render to,
41//!   progressively -- useful for debugging.
42//!
43//!   The free version renders with up to 12 cores.
44//!
45//! * `link_lib3delight` -- Statucally link against `lib3dlight`` during build.
46//!
47//!   This requires a 3Delight installation unless `download_lib3delight` is
48//!   set. See also next section.
49//!
50//! ## Linking Style
51//!
52//! The 3Delight dynamic library (`lib3delight`) can either be linked to,
53//! during build, or loaded at runtime.
54//!
55//! * By default `lib3deligh` is loaded at runtime. This has several
56//!   advantages:
57//!
58//!   1. If you ship your application or library you can ship it without the
59//!      library. It can still run and will print an informative error if the
60//!      library cannot be loaded.
61//!
62//!   2. A user can install an updated version of the renderer and stuff will
63//!      ‘just work’.
64//!
65//! * Dynamically link against `lib3delight`.
66//!
67//!   * The feature is called `link_lib3delight`. You should disable default
68//!     features (they are not needed/used) in this case:
69//!
70//!     ```toml
71//!     [dependencies]
72//!     delight-sys = {
73//!         version = "0.8",
74//!         default-features = false,
75//!         features = ["link_lib3delight"]
76//!     }
77//!     ```
78//!
79//!   * `lib3delight` becomes a dependency. If it cannot be found by the
80//!     system's dynamic linker at runtime, your lib/app will not load/start.
81use lazy_static::lazy_static;
82use std::os::raw::{c_char, c_int};
83
84// Crate features -----------------------------------------------------
85
86#[cfg(not(feature = "link_lib3delight"))]
87mod dynamic;
88#[cfg(feature = "link_lib3delight")]
89mod linked;
90
91#[cfg(not(feature = "link_lib3delight"))]
92use self::dynamic as api;
93#[cfg(feature = "link_lib3delight")]
94use self::linked as api;
95
96// API initalization/on-demand loading of lib3delight -----------------
97lazy_static! {
98    pub static ref DL_API: api::ApiImpl = api::ApiImpl::new().expect("Could not load lib3delight");
99}
100
101pub trait Api {
102    fn DlGetVersionString(&self) -> *const c_char;
103    fn DlGetLibNameAndVersionString(&self) -> *const c_char;
104    fn DlGetCopyrightString(&self) -> *const c_char;
105    fn DlGetInstallRoot(&self) -> *const c_char;
106    fn DlIsFreeLibrary(&self) -> c_int;
107}