Remove redundant texture copies in TextureCopyNode (#871)
Remove redundant texture syncs in TextureCopyNode
This commit is contained in:
		
							parent
							
								
									fcf9d525e1
								
							
						
					
					
						commit
						3fca8c60bb
					
				| @ -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 { | ||||
| @ -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 | ||||
| @ -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 { .. } => {} | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 rod-salazar
						rod-salazar