#![forbid(unsafe_code)]
pub mod cpu;
pub mod lighting;
mod math;
pub mod output_cache;
pub mod shader;
pub mod uniforms;
#[cfg(feature = "wgpu")]
pub mod wgpu_executor;
#[cfg(test)]
mod test_scenes;
pub use cpu::{CpuRasterizer, CpuRenderOptions, Scene3DImage};
pub use output_cache::Scene3DOutputCache;
use ferroui_base::logging::{LogArea, LogEventLevel, Logger};
use ferroui_base::{PixelSize, Rect};
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
static SCENES_DRAWN_ON_CPU: AtomicU64 = AtomicU64::new(0);
static SCENES_DRAWN_ON_CPU_REPORTED: AtomicBool = AtomicBool::new(false);
static LIGHTS_LEFT_OUT: AtomicU64 = AtomicU64::new(0);
static LIGHTS_LEFT_OUT_REPORTED: AtomicBool = AtomicBool::new(false);
static UNSAMPLED_BRUSHES: AtomicU64 = AtomicU64::new(0);
static UNSAMPLED_BRUSHES_REPORTED: AtomicBool = AtomicBool::new(false);
pub fn scenes_drawn_on_cpu() -> u64 {
SCENES_DRAWN_ON_CPU.load(Ordering::Relaxed)
}
pub fn report_scene_drawn_on_cpu(backend: &str) {
SCENES_DRAWN_ON_CPU.fetch_add(1, Ordering::Relaxed);
if SCENES_DRAWN_ON_CPU_REPORTED.swap(true, Ordering::Relaxed) {
return;
}
if let Some(logger) = Logger::try_get(LogEventLevel::Warning, LogArea::VISUAL) {
logger.log(
None,
&format!(
"A 3D scene (Viewport3D) is drawn by the CPU reference on a GPU surface of {backend}: the backend has no \
GPU executor for 3D scenes there yet, or its executor failed (docs/porting/media3d.md, \
docs/porting/gpu-rendering.md)."
),
);
}
}
pub fn lights_left_out() -> u64 {
LIGHTS_LEFT_OUT.load(Ordering::Relaxed)
}
pub(crate) fn note_lights_left_out(count: usize) {
LIGHTS_LEFT_OUT.fetch_add(count as u64, Ordering::Relaxed);
if LIGHTS_LEFT_OUT_REPORTED.swap(true, Ordering::Relaxed) {
return;
}
if let Some(logger) = Logger::try_get(LogEventLevel::Warning, LogArea::VISUAL) {
logger.log(
None,
"A 3D scene has more than 16 lights: the lights after the 16th in tree order are left out \
(docs/porting/media3d.md, section 6.1).",
);
}
}
pub fn layers_with_unsampled_brushes() -> u64 {
UNSAMPLED_BRUSHES.load(Ordering::Relaxed)
}
pub(crate) fn note_unsampled_brush() {
UNSAMPLED_BRUSHES.fetch_add(1, Ordering::Relaxed);
if UNSAMPLED_BRUSHES_REPORTED.swap(true, Ordering::Relaxed) {
return;
}
if let Some(logger) = Logger::try_get(LogEventLevel::Warning, LogArea::VISUAL) {
logger.log(
None,
"A material of a 3D scene paints with a brush the 3D renderer cannot sample yet (only solid colour brushes \
are drawn before step D6): the layer is drawn with its Color (docs/porting/media3d.md).",
);
}
}
pub fn scene_pixel_size(bounds: Rect, x_axis: (f64, f64), y_axis: (f64, f64)) -> (PixelSize, f64) {
let x_scale = x_axis.0.hypot(x_axis.1);
let y_scale = y_axis.0.hypot(y_axis.1);
let side = |length: f64| {
if length.is_finite() {
(length - 1e-6).ceil().clamp(1.0, f64::from(cpu::MAX_SIDE)) as i32
} else {
1
}
};
let size = PixelSize::new(side(bounds.width * x_scale), side(bounds.height * y_scale));
let scale = x_scale.max(y_scale);
(size, if scale.is_finite() && scale > 0.0 { scale } else { 1.0 })
}