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;
7mod pipeline;
8
9use crate::{PxPosition, px::PxSize};
10
11pub use command::{BarrierRequirement, DrawCommand};
12pub use pipeline::{DrawablePipeline, 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 ) {
49 self.pipeline_registry
50 .begin_all_passes(gpu, queue, config, render_pass);
51 }
52
53 /// Finalize all pipelines at the end of each render pass.
54 ///
55 /// This method calls the `end_pass` method on all registered pipelines,
56 /// allowing them to perform cleanup or final operations.
57 pub fn end_pass(
58 &mut self,
59 gpu: &wgpu::Device,
60 queue: &wgpu::Queue,
61 config: &wgpu::SurfaceConfiguration,
62 render_pass: &mut wgpu::RenderPass<'_>,
63 ) {
64 self.pipeline_registry
65 .end_all_passes(gpu, queue, config, render_pass);
66 }
67
68 /// Submit a draw command to the appropriate pipeline for rendering.
69 ///
70 /// This method dispatches the command to the correct pipeline based on its type,
71 /// providing all necessary context including GPU resources, render pass, and
72 /// positioning information.
73 ///
74 /// # Arguments
75 /// * `cmd` - The draw command to execute
76 /// * `size` - Size of the component being drawn
77 /// * `start_pos` - Position where drawing should begin
78 /// * `scene_texture_view` - Optional background texture for sampling
79 /// * `compute_texture_view` - Compute pipeline output texture
80 pub fn submit(
81 &mut self,
82 gpu: &wgpu::Device,
83 queue: &wgpu::Queue,
84 config: &wgpu::SurfaceConfiguration,
85 render_pass: &mut wgpu::RenderPass<'_>,
86 cmd: &dyn DrawCommand,
87 size: PxSize,
88 start_pos: PxPosition,
89 scene_texture_view: &wgpu::TextureView,
90 ) {
91 self.pipeline_registry.dispatch(
92 gpu,
93 queue,
94 config,
95 render_pass,
96 cmd,
97 size,
98 start_pos,
99 scene_texture_view,
100 );
101 }
102}