aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLibravatar Silas Bartha <[email protected]>2024-06-03 21:39:43 -0400
committerLibravatar Silas Bartha <[email protected]>2024-06-03 21:39:43 -0400
commitef6c2954156b2b0cf4abfe583d8faaf546f4e7c4 (patch)
treef5da21c83771023d55036ad94ee52d8db992ffbd /src
parent0ac133c0c396c8b75892cb6e43a52ad973046e2d (diff)
Removed toolchain config
Diffstat (limited to 'src')
-rw-r--r--src/components.rs19
-rw-r--r--src/lib.rs28
-rw-r--r--src/nodes.rs22
-rw-r--r--src/render_assets.rs21
-rw-r--r--src/systems.rs22
5 files changed, 72 insertions, 40 deletions
diff --git a/src/components.rs b/src/components.rs
index 3179f0c..c1122d0 100644
--- a/src/components.rs
+++ b/src/components.rs
@@ -1,6 +1,6 @@
-use std::sync::{Mutex, Arc};
+use std::sync::{Arc, Mutex};
-use bevy::{prelude::*, render::extract_component::ExtractComponent, ecs::query::QueryItem};
+use bevy::{ecs::query::QueryItem, prelude::*, render::extract_component::ExtractComponent};
use crate::render_assets::FramebufferExtractSource;
@@ -8,20 +8,16 @@ use crate::render_assets::FramebufferExtractSource;
pub struct FramebufferExtractDestination(pub Arc<Mutex<Image>>);
impl ExtractComponent for FramebufferExtractDestination {
- type QueryData = (
- &'static Self,
- &'static Handle<FramebufferExtractSource>,
- );
+ type QueryData = (&'static Self, &'static Handle<FramebufferExtractSource>);
type QueryFilter = ();
type Out = (Self, Handle<FramebufferExtractSource>);
- fn extract_component((destination, source_handle): QueryItem<'_, Self::QueryData>) -> Option<Self::Out> {
- Some((
- destination.clone(),
- source_handle.clone(),
- ))
+ fn extract_component(
+ (destination, source_handle): QueryItem<'_, Self::QueryData>,
+ ) -> Option<Self::Out> {
+ Some((destination.clone(), source_handle.clone()))
}
}
@@ -30,4 +26,3 @@ pub struct ExtractFramebufferBundle {
pub source: Handle<FramebufferExtractSource>,
pub dest: FramebufferExtractDestination,
}
-
diff --git a/src/lib.rs b/src/lib.rs
index c112610..05f387d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,19 +1,24 @@
-use bevy::{prelude::*, render::{render_asset::RenderAssetPlugin, extract_component::ExtractComponentPlugin, RenderApp, Render, RenderSet, render_graph::RenderGraph, graph::CameraDriverLabel}};
+use bevy::{
+ prelude::*,
+ render::{
+ extract_component::ExtractComponentPlugin, graph::CameraDriverLabel,
+ render_asset::RenderAssetPlugin, render_graph::RenderGraph, Render, RenderApp, RenderSet,
+ },
+};
use components::FramebufferExtractDestination;
-use nodes::{FramebufferExtractNode, FramebufferExtractLabel};
+use nodes::{FramebufferExtractLabel, FramebufferExtractNode};
use render_assets::FramebufferExtractSource;
pub mod components;
-mod systems;
mod nodes;
pub mod render_assets;
+mod systems;
pub struct FramebufferExtractPlugin;
impl Plugin for FramebufferExtractPlugin {
fn build(&self, app: &mut App) {
- app
- .register_type::<FramebufferExtractSource>()
+ app.register_type::<FramebufferExtractSource>()
.init_asset::<FramebufferExtractSource>()
.register_asset_reflect::<FramebufferExtractSource>()
.add_plugins((
@@ -22,13 +27,12 @@ impl Plugin for FramebufferExtractPlugin {
));
let render_app = app.sub_app_mut(RenderApp);
- render_app
- .add_systems(
- Render,
- systems::extract_framebuffers
- .after(RenderSet::Render)
- .before(RenderSet::Cleanup),
- );
+ render_app.add_systems(
+ Render,
+ systems::extract_framebuffers
+ .after(RenderSet::Render)
+ .before(RenderSet::Cleanup),
+ );
let mut graph = render_app.world.resource_mut::<RenderGraph>();
graph.add_node(FramebufferExtractLabel, FramebufferExtractNode);
graph.add_node_edge(CameraDriverLabel, FramebufferExtractLabel);
diff --git a/src/nodes.rs b/src/nodes.rs
index d069798..9791ad1 100644
--- a/src/nodes.rs
+++ b/src/nodes.rs
@@ -1,4 +1,12 @@
-use bevy::{prelude::*, render::{render_graph::{Node, RenderGraphContext, NodeRunError, RenderLabel}, renderer::RenderContext, render_asset::RenderAssets, render_resource::{ImageCopyBuffer, ImageDataLayout}}};
+use bevy::{
+ prelude::*,
+ render::{
+ render_asset::RenderAssets,
+ render_graph::{Node, NodeRunError, RenderGraphContext, RenderLabel},
+ render_resource::{ImageCopyBuffer, ImageDataLayout},
+ renderer::RenderContext,
+ },
+};
use crate::render_assets::FramebufferExtractSource;
@@ -15,9 +23,15 @@ impl Node for FramebufferExtractNode {
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(())
+ 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(
diff --git a/src/render_assets.rs b/src/render_assets.rs
index 1615e01..0e2cd4d 100644
--- a/src/render_assets.rs
+++ b/src/render_assets.rs
@@ -1,4 +1,12 @@
-use bevy::{prelude::*, render::{render_asset::{RenderAsset, RenderAssets, RenderAssetUsages, PrepareAssetError}, render_resource::{Buffer, Extent3d, BufferUsages, BufferDescriptor, TextureFormat}, renderer::RenderDevice}, ecs::system::{lifetimeless::SRes, SystemParamItem}};
+use bevy::{
+ ecs::system::{lifetimeless::SRes, SystemParamItem},
+ prelude::*,
+ render::{
+ render_asset::{PrepareAssetError, RenderAsset, RenderAssetUsages, RenderAssets},
+ render_resource::{Buffer, BufferDescriptor, BufferUsages, Extent3d, TextureFormat},
+ renderer::RenderDevice,
+ },
+};
pub struct GpuFramebufferExtractSource {
pub buffer: Buffer,
@@ -24,19 +32,20 @@ impl RenderAsset for FramebufferExtractSource {
self,
(device, images): &mut SystemParamItem<Self::Param>,
) -> Result<Self::PreparedAsset, PrepareAssetError<Self>> {
-
let Some(gpu_image) = images.get(&self.0) else {
warn!("Failed to get GPU image");
- return Err(PrepareAssetError::RetryNextUpdate(self))
+ return Err(PrepareAssetError::RetryNextUpdate(self));
};
let size = gpu_image.texture.size();
let format = gpu_image.texture_format;
- let bytes_per_row = (size.width / format.block_dimensions().0) * format.block_copy_size(None).unwrap();
- let padded_bytes_per_row = RenderDevice::align_copy_bytes_per_row(bytes_per_row as usize) as u32;
+ let bytes_per_row =
+ (size.width / format.block_dimensions().0) * format.block_copy_size(None).unwrap();
+ let padded_bytes_per_row =
+ RenderDevice::align_copy_bytes_per_row(bytes_per_row as usize) as u32;
Ok(GpuFramebufferExtractSource {
- buffer: device.create_buffer(&BufferDescriptor {
+ buffer: device.create_buffer(&BufferDescriptor {
label: Some("framebuffer_extract_buffer"),
size: (size.height * padded_bytes_per_row) as u64,
usage: BufferUsages::COPY_DST | BufferUsages::MAP_READ,
diff --git a/src/systems.rs b/src/systems.rs
index 244b82f..74f8dc8 100644
--- a/src/systems.rs
+++ b/src/systems.rs
@@ -1,11 +1,21 @@
-use bevy::{prelude::*, render::{render_asset::{RenderAssets, RenderAssetUsages}, renderer::RenderDevice, render_resource::{MapMode, Maintain, Extent3d, TextureDimension}}};
+use bevy::{
+ prelude::*,
+ render::{
+ render_asset::{RenderAssetUsages, RenderAssets},
+ render_resource::{Extent3d, Maintain, MapMode, TextureDimension},
+ renderer::RenderDevice,
+ },
+};
use pollster::FutureExt;
-use crate::{render_assets::FramebufferExtractSource, components::FramebufferExtractDestination};
+use crate::{components::FramebufferExtractDestination, render_assets::FramebufferExtractSource};
pub fn extract_framebuffers(
- mut extract_bundles: Query<(&Handle<FramebufferExtractSource>, &mut FramebufferExtractDestination)>,
+ mut extract_bundles: Query<(
+ &Handle<FramebufferExtractSource>,
+ &mut FramebufferExtractDestination,
+ )>,
sources: Res<RenderAssets<FramebufferExtractSource>>,
device: Res<RenderDevice>,
) {
@@ -25,7 +35,7 @@ pub fn extract_framebuffers(
device.poll(Maintain::Wait);
rx.block_on().unwrap().unwrap();
}
-
+
slice.get_mapped_range().to_vec()
};
@@ -39,7 +49,8 @@ pub fn extract_framebuffers(
std::thread::spawn(move || {
if bytes_per_row != padded_bytes_per_row {
- let mut unpadded_bytes = Vec::<u8>::with_capacity(source_size.height as usize * bytes_per_row);
+ let mut unpadded_bytes =
+ Vec::<u8>::with_capacity(source_size.height as usize * bytes_per_row);
for padded_row in image_bytes.chunks(padded_bytes_per_row) {
unpadded_bytes.extend_from_slice(&padded_row[..bytes_per_row]);
}
@@ -59,5 +70,4 @@ pub fn extract_framebuffers(
);
});
}
-
}