render_graph_demo/
render_graph_demo.rs

1//! Render Graph Demo - Multi-Pass Rendering Pipeline
2//!
3//! Demonstrates the render graph system for complex rendering pipelines:
4//! - Declaring render passes
5//! - Resource dependencies
6//! - Automatic pass ordering and optimization
7//! - Multi-target rendering
8//! - Post-processing chains
9//!
10//! **Note:** This demonstrates the Render Graph API structure.
11
12use astrelis_core::logging;
13use astrelis_render::{Color, GraphicsContext, RenderTarget, RenderableWindow, WindowContextDescriptor, wgpu};
14use astrelis_winit::{
15    FrameTime, WindowId,
16    app::{App, AppCtx, run_app},
17    event::EventBatch,
18    window::{WinitPhysicalSize, WindowBackend, WindowDescriptor},
19};
20use std::sync::Arc;
21
22struct RenderGraphDemo {
23    _context: Arc<GraphicsContext>,
24    window: RenderableWindow,
25    window_id: WindowId,
26}
27
28fn main() {
29    logging::init();
30
31    run_app(|ctx| {
32        let graphics_ctx = GraphicsContext::new_owned_sync_or_panic();
33
34        let window = ctx
35            .create_window(WindowDescriptor {
36                title: "Render Graph Demo - Multi-Pass Rendering".to_string(),
37                size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
38                ..Default::default()
39            })
40            .expect("Failed to create window");
41
42        let window = RenderableWindow::new_with_descriptor(
43            window,
44            graphics_ctx.clone(),
45            WindowContextDescriptor {
46                format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
47                ..Default::default()
48            },
49        ).expect("Failed to create renderable window");
50
51        let window_id = window.id();
52
53        println!("\n═══════════════════════════════════════════════════════");
54        println!("  🔀 RENDER GRAPH DEMO - Multi-Pass Rendering");
55        println!("═══════════════════════════════════════════════════════");
56        println!("\n  RENDER GRAPH FEATURES:");
57        println!("    • Declarative pass definition");
58        println!("    • Automatic dependency resolution");
59        println!("    • Resource lifetime management");
60        println!("    • Parallel pass execution");
61        println!("    • Automatic optimization");
62        println!("\n  EXAMPLE PIPELINE:");
63        println!("    1. Shadow Pass → depth texture");
64        println!("    2. Geometry Pass → color + normal + depth");
65        println!("    3. Lighting Pass → lit scene");
66        println!("    4. Post-Processing → bloom, tone mapping");
67        println!("    5. UI Pass → final composite");
68        println!("\n  Render Graph API Usage:");
69        println!("    let mut graph = RenderGraph::new();");
70        println!("    graph.add_pass(\"shadow\", shadow_pass_descriptor);");
71        println!("    graph.add_pass(\"geometry\", geometry_pass_descriptor);");
72        println!("    graph.add_dependency(\"lighting\", \"geometry\");");
73        println!("    graph.compile();");
74        println!("    graph.execute(&mut encoder);");
75        println!("═══════════════════════════════════════════════════════\n");
76
77        tracing::info!("Render graph demo initialized");
78
79        Box::new(RenderGraphDemo {
80            _context: graphics_ctx,
81            window,
82            window_id,
83        })
84    });
85}
86
87impl App for RenderGraphDemo {
88    fn update(&mut self, _ctx: &mut AppCtx, _time: &FrameTime) {}
89
90    fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
91        if window_id != self.window_id {
92            return;
93        }
94
95        events.dispatch(|event| {
96            if let astrelis_winit::event::Event::WindowResized(size) = event {
97                self.window.resized(*size);
98                astrelis_winit::event::HandleStatus::consumed()
99            } else {
100                astrelis_winit::event::HandleStatus::ignored()
101            }
102        });
103
104        let mut frame = self.window.begin_drawing();
105        frame.clear_and_render(
106            RenderTarget::Surface,
107            Color::from_rgb_u8(20, 30, 40),
108            |_pass| {},
109        );
110        frame.finish();
111    }
112}