Skip to main content

spatialrust_render_wgpu/
lib.rs

1//! Explicit wgpu backend for SpatialRust visualization contracts.
2//!
3//! Geometry enters this crate only through caller-requested upload methods.
4//! Uploads return a byte-exact transfer receipt, and device buffers remain
5//! resident until explicitly recycled or dropped.
6
7#![deny(unsafe_code)]
8#![warn(missing_docs)]
9
10mod error;
11#[cfg(feature = "wgpu")]
12mod geometry;
13#[cfg(feature = "wgpu")]
14mod render;
15#[cfg(feature = "wgpu")]
16mod runtime;
17
18pub use error::{RenderError, RenderResult};
19#[cfg(feature = "wgpu")]
20pub use geometry::{GpuGeometry, GpuGeometryKind};
21#[cfg(feature = "wgpu")]
22pub use render::{
23    GpuRenderTarget, HeadlessRender, PickResult, ReadbackImage, RenderOptions, RenderReceipt,
24    RENDER_TARGET_FORMAT,
25};
26#[cfg(feature = "wgpu")]
27pub use runtime::WgpuRenderer;
28
29// Native GPU tests share device initialization while keeping distinct renderers.
30// Retain the previous construction path for wasm test compilation.
31#[cfg(all(test, feature = "wgpu"))]
32fn test_runtime() -> Result<std::sync::Arc<spatialrust_gpu::WgpuRuntime>, String> {
33    #[cfg(not(target_arch = "wasm32"))]
34    {
35        spatialrust_gpu::WgpuRuntime::shared().map_err(|error| error.to_string())
36    }
37    #[cfg(target_arch = "wasm32")]
38    {
39        spatialrust_gpu::WgpuRuntime::new_headless()
40            .map(std::sync::Arc::new)
41            .map_err(|error| error.to_string())
42    }
43}