aboutsummaryrefslogtreecommitdiff
path: root/stockton-skeleton/src/texture/block.rs
blob: 1b195c23240b9578a63d54024f3bc4408fb2a24c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use super::{loader::BlockRef, repo::BLOCK_SIZE};
use crate::{buffers::image::SampledImage, mem::MemoryPool, types::*};

use arrayvec::ArrayVec;
use std::{iter::once, mem::ManuallyDrop};

/// A block of loaded textures
pub struct TexturesBlock<TP: MemoryPool> {
    pub id: BlockRef,
    pub descriptor_set: ManuallyDrop<RDescriptorSet>,
    pub imgs: ArrayVec<[SampledImage<TP>; BLOCK_SIZE]>,
}

impl<TP: MemoryPool> TexturesBlock<TP> {
    /// Destroy all Vulkan objects. Must be called before dropping.
    pub fn deactivate(
        mut self,
        device: &mut DeviceT,
        tex_alloc: &mut TP,
        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_with_device_pool(device, tex_alloc))
                .for_each(|_| {});
        }
    }
}