Skip to main content

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