Refactor texture atlas
- Split into multiple modules - Rename some concepts - Change API details
This commit is contained in:
parent
82f0a49062
commit
59d45a5440
11 changed files with 647 additions and 667 deletions
|
|
@ -1,12 +1,10 @@
|
|||
use crate::image::{TextureArray, ImageAllocation};
|
||||
use crate::texture::atlas::{self, Atlas};
|
||||
use iced_native::image;
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
pub enum Memory {
|
||||
Host(::image::ImageBuffer<::image::Bgra<u8>, Vec<u8>>),
|
||||
Device(ImageAllocation),
|
||||
Device(atlas::Entry),
|
||||
NotFound,
|
||||
Invalid,
|
||||
}
|
||||
|
|
@ -15,7 +13,7 @@ impl Memory {
|
|||
pub fn dimensions(&self) -> (u32, u32) {
|
||||
match self {
|
||||
Memory::Host(image) => image.dimensions(),
|
||||
Memory::Device(allocation) => allocation.size(),
|
||||
Memory::Device(entry) => entry.size(),
|
||||
Memory::NotFound => (1, 1),
|
||||
Memory::Invalid => (1, 1),
|
||||
}
|
||||
|
|
@ -78,17 +76,26 @@ impl Cache {
|
|||
handle: &image::Handle,
|
||||
device: &wgpu::Device,
|
||||
encoder: &mut wgpu::CommandEncoder,
|
||||
atlas_array: &mut TextureArray,
|
||||
) -> &Memory {
|
||||
atlas: &mut Atlas,
|
||||
) -> Option<&atlas::Entry> {
|
||||
let memory = self.load(handle);
|
||||
|
||||
if let Memory::Host(image) = memory {
|
||||
let allocation = atlas_array.upload(image, device, encoder);
|
||||
let (width, height) = image.dimensions();
|
||||
|
||||
let allocation =
|
||||
atlas.upload(width, height, &image, device, encoder)?;
|
||||
|
||||
dbg!("Uploaded");
|
||||
|
||||
*memory = Memory::Device(allocation);
|
||||
}
|
||||
|
||||
memory
|
||||
if let Memory::Device(allocation) = memory {
|
||||
Some(allocation)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn trim(&mut self) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue