Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
Store textures in Arc for easier cloning in blood canvas, things are …
Browse files Browse the repository at this point in the history
…FAST now
  • Loading branch information
darthdeus committed Jan 20, 2024
1 parent 4ad683c commit e8fb562
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions comfy-core/src/asset_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl AssetLoader {

pub fn parse_texture_byte_queue(
&mut self,
texture_image_map: Arc<Mutex<HashMap<TextureHandle, RgbaImage>>>,
texture_image_map: Arc<Mutex<HashMap<TextureHandle, Arc<RgbaImage>>>>,
) {
let _span = span!("parse_texture_byte_queue");

Expand All @@ -101,7 +101,7 @@ impl AssetLoader {
Ok(image) => {
image_map
.lock()
.insert(request.handle, image.to_rgba8());
.insert(request.handle, Arc::new(image.to_rgba8()));

inc_assets_loaded(1);

Expand Down
5 changes: 3 additions & 2 deletions comfy-core/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ pub struct Assets {
pub textures: HashMap<String, TextureHandle>,
// pub texture_load_bytes_queue: Vec<String>,
// TODO: private & fix?
pub texture_image_map: Arc<Mutex<HashMap<TextureHandle, image::RgbaImage>>>,
pub texture_image_map:
Arc<Mutex<HashMap<TextureHandle, Arc<image::RgbaImage>>>>,

pub sound_ids: HashMap<String, Sound>,
pub sounds: Arc<Mutex<HashMap<Sound, StaticSoundData>>>,
Expand Down Expand Up @@ -318,7 +319,7 @@ impl Assets {
pub fn load_image_data(
path: &str,
texture: TextureHandle,
) -> Option<RgbaImage> {
) -> Option<Arc<RgbaImage>> {
let assets = ASSETS.borrow();

let image_map = assets.texture_image_map.lock();
Expand Down
2 changes: 1 addition & 1 deletion comfy-wgpu/src/blood_canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl TextureCreator for WgpuTextureCreator {

let assets = ASSETS.borrow_mut();
let mut image_map = assets.texture_image_map.lock();
image_map.insert(handle, image.clone());
image_map.insert(handle, Arc::new(image.clone()));

handle
}
Expand Down
6 changes: 5 additions & 1 deletion comfy-wgpu/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ pub fn load_texture_with_image(
);

ASSETS.borrow_mut().insert_handle(name, handle);
ASSETS.borrow_mut().texture_image_map.lock().insert(handle, img.to_rgba8());
ASSETS
.borrow_mut()
.texture_image_map
.lock()
.insert(handle, Arc::new(img.to_rgba8()));
textures.insert(handle, BindableTexture { bind_group, texture });
}

Expand Down

0 comments on commit e8fb562

Please sign in to comment.