use super::{loader::BlockRef, repo::BLOCK_SIZE}; use crate::types::*; use arrayvec::ArrayVec; use hal::prelude::*; use rendy_memory::{Allocator, Block}; use std::{iter::once, mem::ManuallyDrop}; pub struct TexturesBlock> { pub id: BlockRef, pub descriptor_set: ManuallyDrop, pub imgs: ArrayVec<[LoadedImage; BLOCK_SIZE]>, } impl> TexturesBlock { pub fn deactivate>( mut self, device: &mut Device, tex_alloc: &mut T, desc_alloc: &mut DescriptorAllocator, ) { unsafe { use std::ptr::read; // Descriptor set desc_alloc.free(once(read(&*self.descriptor_set))); // Images self.imgs .drain(..) .map(|x| x.deactivate(device, tex_alloc)) .for_each(|_| {}); } } } pub struct LoadedImage> { pub mem: ManuallyDrop, pub img: ManuallyDrop, pub img_view: ManuallyDrop, pub sampler: ManuallyDrop, pub row_size: usize, pub height: u32, pub width: u32, } impl> LoadedImage { pub fn deactivate>( self, device: &mut Device, alloc: &mut T, ) { unsafe { use std::ptr::read; device.destroy_image_view(read(&*self.img_view)); device.destroy_image(read(&*self.img)); device.destroy_sampler(read(&*self.sampler)); alloc.free(device, read(&*self.mem)); } } }