tessera_ui/renderer/
drawer.rs

1//! Graphics rendering pipeline management.
2//!
3//! This module provides the drawing infrastructure for the unified command system,
4//! 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 operations,
17/// maintaining a registry of pipelines and dispatching draw commands to the appropriate
18/// 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        render_pass: &mut wgpu::RenderPass<'_>,
48        scene_texture_view: &wgpu::TextureView,
49    ) {
50        self.pipeline_registry.begin_all_passes(
51            gpu,
52            queue,
53            config,
54            render_pass,
55            scene_texture_view,
56        );
57    }
58
59    /// Finalize all pipelines at the end of each render pass.
60    ///
61    /// This method calls the `end_pass` method on all registered pipelines,
62    /// allowing them to perform cleanup or final operations.
63    pub fn end_pass(
64        &mut self,
65        gpu: &wgpu::Device,
66        queue: &wgpu::Queue,
67        config: &wgpu::SurfaceConfiguration,
68        render_pass: &mut wgpu::RenderPass<'_>,
69        scene_texture_view: &wgpu::TextureView,
70    ) {
71        self.pipeline_registry
72            .end_all_passes(gpu, queue, config, render_pass, scene_texture_view);
73    }
74
75    /// Submit a draw command to the appropriate pipeline for rendering.
76    ///
77    /// This method dispatches the command to the correct pipeline based on its type,
78    /// providing all necessary context including GPU resources, render pass, and
79    /// positioning information.
80    ///
81    /// # Arguments
82    /// * `cmd` - The draw command to execute
83    /// * `size` - Size of the component being drawn
84    /// * `start_pos` - Position where drawing should begin
85    /// * `scene_texture_view` - Optional background texture for sampling
86    /// * `compute_texture_view` - Compute pipeline output texture
87    pub fn submit(
88        &mut self,
89        context: ErasedDrawContext<'_, '_>,
90        commands: &[(&dyn DrawCommand, PxSize, PxPosition)],
91    ) {
92        self.pipeline_registry.dispatch(context, commands);
93    }
94}