Skip to main content

wde_renderer/
lib.rs

1//! The main renderer plugin and related utilities.
2//!
3//! This crate provides the main rendering plugin for the engine, as well as core types and utilities for defining render pipelines, render passes and related resources. It is designed to be flexible and extensible, allowing users to define their own render pipelines and passes while providing a solid foundation of core functionality.
4//! It is an overlay over [`wde_wgpu`](wde_wgpu) that integrates it with the engine's asset system, ECS and render graph.
5//!
6//! The renderer flow is composed of the following stages:
7//! ```text
8//! |--------------------------------------------------------------------|
9//! |      |         |          Main World Update                        |
10//! | Sync | Extract |---------------------------------------------------|
11//! |      |         |         Render World Update                       |
12//! |--------------------------------------------------------------------|
13//! ```
14//! Where:
15//! - The **Sync** stage is responsible for synchronizing entities between the main and render worlds (see the [`sync`](crate::sync) module for more details).
16//! - The **Extract** stage is responsible for extracting resources, queries and entities from the main world to the render world, so that they can be used by the render passes (see the [`core`](crate::core) and [`sync`](crate::sync) modules for more details).
17//! - The **Main World Update** and **Render World Update** stages are responsible for running the systems in the main and render worlds, respectively.
18//!
19//! The main components of this crate are:
20//! - The [`assets`](crate::assets) module that defines the render pipeline asset system and related types.
21//! - The [`core`](crate::core) module that defines core types and resources for the renderer, such as the render graph and pipeline manager.
22//! - The [`passes`](crate::passes) module that defines the traits and types for render passes and sub-passes, as well as a simple render graph implementation.
23//! - The [`sync`](crate::sync) module that provides utilities to automatically extract resources, query and entities from the main to the render world.
24//! - The [`utils`](crate::utils) module that provides utility resources and systems, such as the depth texture and meshes for rendering.
25
26extern crate self as wde_renderer;
27
28#[doc(hidden)]
29pub mod prelude {
30    pub use crate::assets::*;
31    pub use crate::compute::*;
32    pub use crate::core::*;
33    pub use crate::passes::*;
34    pub use crate::sync::*;
35    pub use crate::utils::*;
36
37    // Re-export the macros
38    pub use wde_renderer_macros::*;
39}
40
41pub mod wgpu_utils {
42    pub use wde_wgpu::buffer::AsyncReadback;
43    pub use wde_wgpu::command_buffer::{
44        CommandBuffer, RenderPassBuilder, RenderPassColorAttachment, RenderPassDepth
45    };
46}
47
48pub mod assets;
49pub mod compute;
50pub mod core;
51pub mod passes;
52pub mod sync;
53pub mod utils;
54
55use crate::{
56    assets::AssetsPlugin,
57    core::{RenderCorePlugin, WindowIcon},
58    sync::SyncPlugin,
59    utils::UtilsPlugin
60};
61use bevy::prelude::*;
62
63/// The main renderer plugin. Also responsible for creating the primary window.
64pub struct RenderPlugin {
65    /// Title shown in the window's title bar.
66    pub window_title: String,
67    /// Initial size (width, height) of the window, in logical pixels.
68    pub window_resolution: (u32, u32),
69    /// Icon shown in the OS taskbar/title bar. See [`WindowIcon::from_bytes`].
70    pub window_icon: Option<WindowIcon>
71}
72impl Default for RenderPlugin {
73    fn default() -> Self {
74        Self {
75            window_title: "WaterDropEngine".into(),
76            window_resolution: (600, 500),
77            window_icon: None
78        }
79    }
80}
81impl Plugin for RenderPlugin {
82    fn build(&self, app: &mut App) {
83        // First, add the core plugin
84        app.add_plugins(RenderCorePlugin {
85            window_title: self.window_title.clone(),
86            window_resolution: self.window_resolution,
87            window_icon: self.window_icon.clone()
88        });
89
90        // Finally, add the other plugins
91        app.add_plugins((SyncPlugin, UtilsPlugin, AssetsPlugin));
92    }
93}