diff --git a/crates/bevy_render_graph/src/std/copy.rs b/crates/bevy_render_graph/src/std/copy.rs index 8a76666c19e07..5eafb9478c2a1 100644 --- a/crates/bevy_render_graph/src/std/copy.rs +++ b/crates/bevy_render_graph/src/std/copy.rs @@ -14,6 +14,7 @@ use crate::{ use super::SrcDst; +///Performs a copy operation between two textures which must be of the same size and format. pub fn copy_texture_to_texture<'g>( graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Texture>, @@ -37,6 +38,9 @@ pub fn copy_texture_to_texture<'g>( ); } +///Performs a copy operation between a texture and a buffer. The copy must not overrun the +///destination buffer. If `layout` is `None` the graph will check if the buffer has an associated +///`ImageDataLayout` in its metadata. If not, the function will `panic!` pub fn copy_texture_to_buffer<'g>( graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Texture, Buffer>, @@ -48,7 +52,7 @@ pub fn copy_texture_to_buffer<'g>( let size = graph.meta(src_dst.src).size; let layout = layout .or(graph.meta(src_dst.dst).layout) - .expect("ImageDataLayout not provided"); + .expect("ImageDataLayout not provided for copy operation"); graph.add_node( Some("copy_texture_to_buffer".into()), @@ -66,6 +70,9 @@ pub fn copy_texture_to_buffer<'g>( ); } +///Performs a copy operation between a texture and a buffer. The copy must not overrun the +///destination texture. If `layout` is `None` the graph will check if the buffer has an associated +///`ImageDataLayout` in its metadata. If not, the function will `panic!` pub fn copy_buffer_to_texture<'g>( graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Buffer, Texture>, @@ -95,6 +102,7 @@ pub fn copy_buffer_to_texture<'g>( ); } +///Performs a copy operation between two buffers. The copy must not overrun the destination buffer. pub fn copy_buffer_to_buffer<'g>( graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Buffer>, @@ -120,48 +128,62 @@ pub fn copy_buffer_to_buffer<'g>( ); } -pub trait CopyTo: UsagesRenderResource { - fn copy_to<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self, Dst>); +///Denotes a resource whose data can be copied to others of type `Dst` +pub trait CopyResource: UsagesRenderResource { + ///Perfoms a copy from a resource of type `Self` to a resource of type `Dst` in the render + ///graph + fn copy_resource<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self, Dst>); } -impl CopyTo for Texture { - fn copy_to<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self>) { +impl CopyResource for Texture { + fn copy_resource<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self>) { copy_texture_to_texture(graph, src_dst); } } -impl CopyTo for Texture { - fn copy_to<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self, Buffer>) { +impl CopyResource for Texture { + fn copy_resource<'g>( + graph: &mut RenderGraphBuilder<'_, 'g>, + src_dst: SrcDst<'g, Self, Buffer>, + ) { copy_texture_to_buffer(graph, src_dst, None); } } -impl CopyTo for Buffer { - fn copy_to<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self, Texture>) { +impl CopyResource for Buffer { + fn copy_resource<'g>( + graph: &mut RenderGraphBuilder<'_, 'g>, + src_dst: SrcDst<'g, Self, Texture>, + ) { copy_buffer_to_texture(graph, src_dst, None); } } -impl CopyTo for Buffer { - fn copy_to<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self>) { +impl CopyResource for Buffer { + fn copy_resource<'g>(graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Self>) { copy_buffer_to_buffer(graph, src_dst); } } -pub fn copy_to<'g, Src: CopyTo, Dst: UsagesRenderResource>( +///Performs a copy operation between two resources. If copying between a texture and a buffer (or +///vice-versa) the buffer must have been created with an associated `ImageDataLayout` in its +///metadata. +pub fn copy<'g, Src: CopyResource, Dst: UsagesRenderResource>( graph: &mut RenderGraphBuilder<'_, 'g>, src_dst: SrcDst<'g, Src, Dst>, ) { - CopyTo::copy_to(graph, src_dst); + CopyResource::copy_resource(graph, src_dst); } -pub fn clone<'g, R: CopyTo>( +///Clones a resource by creating a new resource from the original's metadata, and performing a copy +///from the original resource to the new one. +pub fn clone<'g, R: CopyResource>( graph: &mut RenderGraphBuilder<'_, 'g>, resource: RenderHandle<'g, R>, ) -> RenderHandle<'g, R> { let meta = graph.meta(resource).clone(); let new_resource = graph.new_resource(meta); - copy_to( + copy( graph, SrcDst { src: resource, diff --git a/crates/bevy_render_graph/src/std/mod.rs b/crates/bevy_render_graph/src/std/mod.rs index 53b092b7da218..c1d6741830e98 100644 --- a/crates/bevy_render_graph/src/std/mod.rs +++ b/crates/bevy_render_graph/src/std/mod.rs @@ -1,3 +1,5 @@ +use bevy_app::{PluginGroup, PluginGroupBuilder}; + mod builder; mod copy; mod fullscreen; @@ -9,3 +11,12 @@ pub use copy::*; pub use fullscreen::*; pub use misc::*; pub use swap::*; + +///A set of minimal plugins that setup assets and behavior for the graph standard library. +pub struct DefaultRenderGraphPlugins; + +impl PluginGroup for DefaultRenderGraphPlugins { + fn build(self) -> PluginGroupBuilder { + PluginGroupBuilder::start::().add(FullscreenPlugin) + } +}