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
26#[doc(hidden)]
27pub mod prelude {
28 pub use crate::assets::*;
29 pub use crate::compute::*;
30 pub use crate::core::*;
31 pub use crate::passes::*;
32 pub use crate::sync::*;
33 pub use crate::utils::*;
34}
35
36pub mod wgpu_utils {
37 pub use wde_wgpu::bind_group::{BindGroup, BindGroupBuilder, BindGroupLayout};
38 pub use wde_wgpu::buffer::AsyncReadback;
39 pub use wde_wgpu::command_buffer::{
40 CommandBuffer, RenderPassBuilder, RenderPassColorAttachment, RenderPassDepth
41 };
42 pub use wde_wgpu::memory::{
43 GpuAllocation, GpuAllocationInfo, GpuMemory, GpuMemoryCategory, GpuMemoryTotal
44 };
45}
46
47pub mod assets;
48pub mod compute;
49pub mod core;
50pub mod passes;
51pub mod sync;
52pub mod utils;
53
54use crate::{
55 assets::AssetsPlugin,
56 core::{RenderCorePlugin, WindowIcon},
57 utils::UtilsPlugin
58};
59use bevy::prelude::*;
60
61/// The main renderer plugin. Also responsible for creating the primary window.
62pub struct RenderPlugin {
63 /// Title shown in the window's title bar.
64 pub window_title: String,
65 /// Initial size (width, height) of the window, in logical pixels.
66 pub window_resolution: (u32, u32),
67 /// Icon shown in the OS taskbar/title bar. See [`WindowIcon::from_bytes`].
68 pub window_icon: Option<WindowIcon>
69}
70impl Default for RenderPlugin {
71 fn default() -> Self {
72 Self {
73 window_title: "WaterDropEngine".into(),
74 window_resolution: (600, 500),
75 window_icon: None
76 }
77 }
78}
79impl Plugin for RenderPlugin {
80 fn build(&self, app: &mut App) {
81 // First, add the core plugin
82 app.add_plugins(RenderCorePlugin {
83 window_title: self.window_title.clone(),
84 window_resolution: self.window_resolution,
85 window_icon: self.window_icon.clone()
86 });
87
88 // Finally, add the other plugins
89 app.add_plugins((
90 UtilsPlugin,
91 AssetsPlugin,
92 crate::passes::RenderGraphDebugPlugin,
93 crate::passes::PipelineStatusPlugin
94 ));
95 }
96}