aboutsummaryrefslogtreecommitdiff
path: root/src/nodes.rs
diff options
context:
space:
mode:
authorLibravatar Silas Bartha <silas@exvacuum.dev>2024-04-24 21:05:55 -0400
committerLibravatar Silas Bartha <silas@exvacuum.dev>2024-04-24 21:05:55 -0400
commit98d21d244bb92a1a8d35b1dff35d9c10bdcab19a (patch)
tree8d1729071750d879ca2123e69df2c6bfbf1857c5 /src/nodes.rs
Render Texture Extraction
Diffstat (limited to 'src/nodes.rs')
-rw-r--r--src/nodes.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/nodes.rs b/src/nodes.rs
new file mode 100644
index 0000000..bccd861
--- /dev/null
+++ b/src/nodes.rs
@@ -0,0 +1,38 @@
+use bevy::{prelude::*, render::{render_graph::{Node, RenderGraphContext, NodeRunError, RenderLabel}, renderer::RenderContext, render_asset::RenderAssets, render_resource::{ImageCopyBuffer, ImageDataLayout}}};
+
+use crate::render_assets::FramebufferExtractSource;
+
+#[derive(RenderLabel, Clone, PartialEq, Eq, Debug, Hash)]
+pub struct FramebufferExtractLabel;
+
+#[derive(Default)]
+pub struct FramebufferExtractNode;
+
+impl Node for FramebufferExtractNode {
+ fn run(
+ &self,
+ graph: &mut RenderGraphContext,
+ render_context: &mut RenderContext,
+ world: &World,
+ ) -> Result<(), NodeRunError> {
+ for (_, source) in world.resource::<RenderAssets<FramebufferExtractSource>>().iter() {
+ let Some(gpu_image) = world.resource::<RenderAssets<Image>>().get(&source.source_handle) else {
+ return Ok(())
+ };
+
+ render_context.command_encoder().copy_texture_to_buffer(
+ gpu_image.texture.as_image_copy(),
+ ImageCopyBuffer {
+ buffer: &source.buffer,
+ layout: ImageDataLayout {
+ offset: 0,
+ bytes_per_row: Some(source.padded_bytes_per_row),
+ rows_per_image: None,
+ },
+ },
+ source.source_size,
+ );
+ }
+ Ok(())
+ }
+}