Skip to content

Commit

Permalink
Remove redundant texture copies in TextureCopyNode (#871)
Browse files Browse the repository at this point in the history
Remove redundant texture syncs in TextureCopyNode
  • Loading branch information
4-rodrigo-salazar authored Nov 17, 2020
1 parent fcf9d52 commit 3fca8c6
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
use bevy_app::prelude::{EventReader, Events};
use bevy_asset::{AssetEvent, Assets};
use bevy_ecs::{Resources, World};
use bevy_utils::{AHashExt, HashSet};

#[derive(Default)]
pub struct TextureCopyNode {
Expand All @@ -23,10 +24,15 @@ impl Node for TextureCopyNode {
) {
let texture_events = resources.get::<Events<AssetEvent<Texture>>>().unwrap();
let textures = resources.get::<Assets<Texture>>().unwrap();
let mut copied_textures = HashSet::new();
for event in self.texture_event_reader.iter(&texture_events) {
match event {
AssetEvent::Created { handle } | AssetEvent::Modified { handle } => {
if let Some(texture) = textures.get(handle) {
if copied_textures.contains(&handle.id) {
continue;
}

let texture_descriptor: TextureDescriptor = texture.into();
let width = texture.size.x() as usize;
let aligned_width = render_context
Expand Down Expand Up @@ -67,6 +73,8 @@ impl Node for TextureCopyNode {
texture_descriptor.size,
);
render_context.resources().remove_buffer(texture_buffer);

copied_textures.insert(&handle.id);
}
}
AssetEvent::Removed { .. } => {}
Expand Down

0 comments on commit 3fca8c6

Please sign in to comment.