tessera_ui/renderer/
drawer.rs

1//! Graphics rendering pipeline management.
2//!
3//! This module provides the drawing infrastructure for the unified command
4//! system, handling graphics pipeline registration and command dispatch.
5
6pub mod command;
7pub mod pipeline;
8
9use crate::{PxPosition, px::PxSize};
10
11pub use command::DrawCommand;
12pub use pipeline::{DrawablePipeline, ErasedDrawContext, PipelineRegistry};
13
14/// Drawer manages graphics pipelines and processes draw commands.
15///
16/// The Drawer acts as the central coordinator for all graphics rendering
17/// operations, maintaining a registry of pipelines and dispatching draw
18/// commands to the appropriate pipeline implementations.
19pub struct Drawer {
20    /// Registry containing all registered graphics pipelines
21    pub pipeline_registry: PipelineRegistry,
22}
23
24impl Default for Drawer {
25    fn default() -> Self {
26        Self::new()
27    }
28}
29
30impl Drawer {
31    /// Create a new drawer
32    pub fn new() -> Self {
33        Self {
34            pipeline_registry: PipelineRegistry::new(),
35        }
36    }
37
38    /// Initialize all pipelines at the beginning of each render pass.
39    ///
40    /// This method calls the `begin_pass` method on all registered pipelines,
41    /// allowing them to set up per-pass state such as uniform buffers.
42    pub fn begin_pass(
43        &mut self,
44        gpu: &wgpu::Device,
45        queue: &wgpu::Queue,
46        config: &wgpu::SurfaceConfiguration,
47        target_size: PxSize,
48        render_pass: &mut wgpu::RenderPass<'_>,
49        scene_texture_view: &wgpu::TextureView,
50    ) {
51        self.pipeline_registry.begin_all_passes(
52            gpu,
53            queue,
54            config,
55            target_size,
56            render_pass,
57            scene_texture_view,
58        );
59    }
60
61    /// Finalize all pipelines at the end of each render pass.
62    ///
63    /// This method calls the `end_pass` method on all registered pipelines,
64    /// allowing them to perform cleanup or final operations.
65    pub fn end_pass(
66        &mut self,
67        gpu: &wgpu::Device,
68        queue: &wgpu::Queue,
69        config: &wgpu::SurfaceConfiguration,
70        target_size: PxSize,
71        render_pass: &mut wgpu::RenderPass<'_>,
72        scene_texture_view: &wgpu::TextureView,
73    ) {
74        self.pipeline_registry.end_all_passes(
75            gpu,
76            queue,
77            config,
78            target_size,
79            render_pass,
80            scene_texture_view,
81        );
82    }
83
84    /// Submit a draw command to the appropriate pipeline for rendering.
85    ///
86    /// This method dispatches the command to the correct pipeline based on its
87    /// type, providing all necessary context including GPU resources,
88    /// render pass, and positioning information.
89    ///
90    /// # Arguments
91    /// * `cmd` - The draw command to execute
92    /// * `size` - Size of the component being drawn
93    /// * `start_pos` - Position where drawing should begin
94    /// * `scene_texture_view` - Optional background texture for sampling
95    /// * `compute_texture_view` - Compute pipeline output texture
96    pub fn submit(
97        &mut self,
98        context: ErasedDrawContext<'_, '_>,
99        commands: &[(&dyn DrawCommand, PxSize, PxPosition)],
100    ) {
101        self.pipeline_registry.dispatch(context, commands);
102    }
103}