all_is_cubes_render/lib.rs
1//! Raytracer and rendering abstractions for the all-is-cubes engine.
2//!
3//! ## Package features
4//!
5//! This package, `all-is-cubes-render`, defines the following feature flags:
6//!
7//! * `"auto-threads"`:
8//! Enable use of threads for parallel and background processing, including via
9//! [`rayon`]’s global thread pool.
10//! This feature does not affect the public API (except via enabling other features),
11//! only performance and dependencies.
12//! * `"raytracer"`:
13//! Enables the [`raytracer`] module.
14//! * `"std"` (enabled by default):
15//! If disabled, the library becomes `no_std` compatible, at this cost:
16//! * [`raytracer::RtRenderer`] does not implement [`headless::HeadlessRenderer`].
17
18#![no_std]
19// Crate-specific lint settings. (General settings can be found in the workspace manifest.)
20#![forbid(unsafe_code)]
21
22#[cfg(any(feature = "std", test))]
23#[cfg_attr(test, macro_use)]
24extern crate std;
25#[allow(unused_imports)]
26#[macro_use]
27extern crate alloc;
28
29// -------------------------------------------------------------------------------------------------
30
31pub mod camera;
32
33mod flaws;
34pub use flaws::Flaws;
35
36mod headless;
37#[doc(hidden)]
38pub use headless::info_text_drawable;
39pub use headless::{HeadlessRenderer, Rendering};
40
41#[cfg(feature = "raytracer")]
42pub mod raytracer;
43
44// -------------------------------------------------------------------------------------------------
45
46/// An error indicating that a [`HeadlessRenderer`] or other renderer failed to operate.
47#[derive(Clone, Debug, Eq, Hash, PartialEq, displaydoc::Display)]
48#[non_exhaustive]
49pub enum RenderError {
50 /// A component of the [`Universe`] that is to be rendered was not available
51 /// for reading.
52 ///
53 /// [`Universe`]: all_is_cubes::universe::Universe
54 #[displaydoc("scene to be rendered was not available for reading")]
55 Read(all_is_cubes::universe::HandleError),
56 // TODO: add errors for out of memory, lost GPU, etc.
57}
58
59#[cfg(feature = "std")]
60impl core::error::Error for RenderError {
61 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
62 match self {
63 RenderError::Read(e) => Some(e),
64 }
65 }
66}