diff options
author | 2020-02-26 12:34:34 +0100 | |
---|---|---|
committer | 2020-02-26 12:34:34 +0100 | |
commit | 59d45a5440aaa46c7dc8f3dc70c8518167c10418 (patch) | |
tree | 2b5ad3d2c577e9ebb7fcac7452a74680174f8108 /wgpu/src/image/raster.rs | |
parent | 82f0a49062d10f3cbf202a5379c061a2509ec97b (diff) | |
download | iced-59d45a5440aaa46c7dc8f3dc70c8518167c10418.tar.gz iced-59d45a5440aaa46c7dc8f3dc70c8518167c10418.tar.bz2 iced-59d45a5440aaa46c7dc8f3dc70c8518167c10418.zip |
Refactor texture atlas
- Split into multiple modules
- Rename some concepts
- Change API details
Diffstat (limited to 'wgpu/src/image/raster.rs')
-rw-r--r-- | wgpu/src/image/raster.rs | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/wgpu/src/image/raster.rs b/wgpu/src/image/raster.rs index 884dd65a..071d53c8 100644 --- a/wgpu/src/image/raster.rs +++ b/wgpu/src/image/raster.rs @@ -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) { |