Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant texture copies in TextureCopyNode #871

Merged
merged 4 commits into from
Nov 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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