Skip to main content

par_term_render/renderer/shaders/
mod.rs

1//! Shader management for the renderer.
2//!
3//! Manages two independent shader renderers:
4//!
5//! - **Background shader** (`custom_shader_renderer`) — full-screen post-processing
6//!   effect rendered before the terminal cell grid, compatible with Ghostty/Shadertoy GLSL.
7//! - **Cursor shader** (`cursor_shader_renderer`) — cursor overlay effect rendered after
8//!   the cell grid, enabling glow, trail, and other cursor effects.
9//!
10//! ## Sub-modules
11//!
12//! - [`background`] — init and `impl Renderer` methods for the background shader
13//! - [`cursor`] — init and `impl Renderer` methods for the cursor shader
14//! - [`shared`] — `impl Renderer` methods that update both renderers (mouse, cursor state, etc.)
15
16pub(super) mod background;
17pub(super) mod cursor;
18pub(super) mod shared;
19
20use crate::cell_renderer::CellRenderer;
21use crate::custom_shader_renderer::CustomShaderRenderer;
22
23/// Parameters for initialising the background custom shader renderer.
24pub struct CustomShaderInitParams<'a> {
25    pub size_width: u32,
26    pub size_height: u32,
27    pub window_padding: f32,
28    pub path: Option<&'a str>,
29    pub enabled: bool,
30    pub animation: bool,
31    pub animation_speed: f32,
32    pub window_opacity: f32,
33    pub full_content: bool,
34    pub brightness: f32,
35    pub channel_paths: &'a [Option<std::path::PathBuf>; 4],
36    pub cubemap_path: Option<&'a std::path::Path>,
37    pub use_background_as_channel0: bool,
38}
39
40/// Parameters for initialising the cursor shader renderer.
41pub struct CursorShaderInitParams<'a> {
42    pub size_width: u32,
43    pub size_height: u32,
44    pub window_padding: f32,
45    pub path: Option<&'a str>,
46    pub enabled: bool,
47    pub animation: bool,
48    pub animation_speed: f32,
49    pub window_opacity: f32,
50}
51
52/// Parameters for enabling/updating the background custom shader at runtime.
53pub struct CustomShaderEnableParams<'a> {
54    pub enabled: bool,
55    pub shader_path: Option<&'a str>,
56    pub window_opacity: f32,
57    pub animation_enabled: bool,
58    pub animation_speed: f32,
59    pub full_content: bool,
60    pub brightness: f32,
61    pub channel_paths: &'a [Option<std::path::PathBuf>; 4],
62    pub cubemap_path: Option<&'a std::path::Path>,
63}
64
65/// Initialize the custom (background) shader renderer if configured.
66///
67/// Returns `(renderer, shader_path)` where both are `Some` if initialization succeeded.
68pub(super) fn init_custom_shader(
69    cell_renderer: &CellRenderer,
70    params: CustomShaderInitParams<'_>,
71) -> (Option<CustomShaderRenderer>, Option<String>) {
72    background::init_custom_shader(cell_renderer, params)
73}
74
75/// Initialize the cursor shader renderer if configured.
76///
77/// Returns `(renderer, shader_path)` where both are `Some` if initialization succeeded.
78pub(super) fn init_cursor_shader(
79    cell_renderer: &CellRenderer,
80    params: CursorShaderInitParams<'_>,
81) -> (Option<CustomShaderRenderer>, Option<String>) {
82    cursor::init_cursor_shader(cell_renderer, params)
83}