Skip to main content

polyscope_render/
lib.rs

1//! Rendering backend for polyscope-rs.
2//!
3//! This crate provides the wgpu-based rendering engine, including:
4//! - GPU resource management (buffers, textures, pipelines)
5//! - Shader compilation and management (WGSL)
6//! - Material and color map systems
7//! - Camera and view management
8
9// Type casts in graphics code: These lints flag intentional conversions between
10// GPU types (u32 indices, f32 coordinates) and CPU types (usize, f64). The values
11// involved are bounded (mesh vertices, texture dimensions, pixel coordinates) and
12// will not overflow in practice. Suppressing at crate level to avoid noise.
13#![allow(clippy::cast_possible_truncation)]
14#![allow(clippy::cast_sign_loss)]
15#![allow(clippy::cast_precision_loss)]
16#![allow(clippy::cast_possible_wrap)]
17// Documentation lints: Detailed error/panic docs will be added as the API stabilizes.
18#![allow(clippy::missing_errors_doc)]
19#![allow(clippy::missing_panics_doc)]
20// Function length: Rendering and initialization functions are legitimately complex.
21#![allow(clippy::too_many_lines)]
22// Method design: Some methods take &self for API consistency even when not using it.
23#![allow(clippy::unused_self)]
24// Variable naming: In graphics code, similar variable names (e.g., color1, color2) are common.
25#![allow(clippy::similar_names)]
26// Argument design: Some functions take ownership for API consistency.
27#![allow(clippy::needless_pass_by_value)]
28// Slice handling: Sometimes &mut Vec is needed for push/pop operations.
29#![allow(clippy::ptr_arg)]
30// Default initialization: Sometimes we need to modify fields after default.
31#![allow(clippy::field_reassign_with_default)]
32// Default access: In wgpu pipeline code, Default::default() is idiomatic.
33#![allow(clippy::default_trait_access)]
34// Lifetimes: Some patterns require explicit lifetimes for clarity.
35#![allow(clippy::needless_lifetimes)]
36// Control flow: Sometimes if-let-else is clearer than let-else.
37#![allow(clippy::manual_let_else)]
38// Function signatures: Complex rendering functions need many parameters.
39#![allow(clippy::too_many_arguments)]
40
41pub mod buffer;
42pub mod camera;
43pub mod color_maps;
44pub mod curve_network_render;
45pub mod depth_peel_pass;
46pub mod dual_quat;
47pub mod engine;
48pub mod error;
49pub mod ground_plane;
50pub mod materials;
51pub mod pick;
52pub mod point_cloud_render;
53pub mod reflection;
54pub mod reflection_pass;
55pub mod screenshot;
56pub mod shader;
57pub mod shadow_map;
58pub mod slice_mesh_render;
59pub mod slice_plane_render;
60pub mod ssaa_pass;
61pub mod ssao_pass;
62pub mod surface_mesh_render;
63pub mod tone_mapping;
64pub mod vector_render;
65pub mod volume_grid_render;
66
67pub use camera::{AxisDirection, Camera, NavigationStyle, ProjectionMode};
68pub use color_maps::{ColorMap, ColorMapRegistry};
69pub use curve_network_render::{CurveNetworkRenderData, CurveNetworkUniforms};
70pub use depth_peel_pass::DepthPeelPass;
71pub use engine::RenderEngine;
72pub use error::{RenderError, RenderResult};
73pub use ground_plane::{GroundPlaneRenderData, GroundPlaneUniforms};
74pub use materials::{Material, MaterialRegistry, MaterialUniforms};
75pub use pick::{
76    MeshPickUniforms, PickElementType, PickResult, PickUniforms, TubePickUniforms, color_to_index,
77    index_to_color,
78};
79pub use point_cloud_render::{PointCloudRenderData, PointUniforms};
80pub use reflection::{ground_reflection_matrix, reflection_matrix};
81pub use reflection_pass::{ReflectionPass, ReflectionUniforms};
82pub use screenshot::{ScreenshotError, ScreenshotOptions, save_image, save_to_buffer};
83pub use shader::{ShaderBuilder, ShaderProgram};
84pub use shadow_map::{LightUniforms, SHADOW_MAP_SIZE, ShadowMapPass};
85pub use slice_mesh_render::SliceMeshRenderData;
86pub use slice_plane_render::{
87    PlaneRenderUniforms, SlicePlaneRenderData, create_slice_plane_bind_group_layout,
88    create_slice_plane_pipeline,
89};
90pub use ssaa_pass::SsaaPass;
91pub use ssao_pass::{SsaoPass, SsaoUniforms};
92pub use surface_mesh_render::{MeshUniforms, SurfaceMeshRenderData};
93pub use tone_mapping::{ToneMapPass, ToneMapUniforms};
94pub use vector_render::{VectorRenderData, VectorUniforms};
95pub use volume_grid_render::{
96    GridcubePickUniforms, GridcubeRenderData, GridcubeUniforms, IsosurfaceRenderData,
97    SimpleMeshUniforms,
98};
99
100/// Render context passed to structures during drawing.
101pub struct RenderContext<'a> {
102    /// The wgpu device.
103    pub device: &'a wgpu::Device,
104    /// The wgpu queue.
105    pub queue: &'a wgpu::Queue,
106    /// The command encoder.
107    pub encoder: &'a mut wgpu::CommandEncoder,
108    /// The target texture view.
109    pub view: &'a wgpu::TextureView,
110    /// The depth texture view.
111    pub depth_view: &'a wgpu::TextureView,
112    /// The current camera.
113    pub camera: &'a Camera,
114    /// The material registry.
115    pub materials: &'a MaterialRegistry,
116    /// The color map registry.
117    pub color_maps: &'a ColorMapRegistry,
118}
119
120impl polyscope_core::structure::RenderContext for RenderContext<'_> {}