aboutsummaryrefslogtreecommitdiff
path: root/stockton-skeleton/src/texture/block.rs
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:23 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:23 +0100
commit0353181306702c40ad0fe482b5c2b159b46794a4 (patch)
tree33acc6a9e8ea4705884cf93b78cf869008f71832 /stockton-skeleton/src/texture/block.rs
parent664f0b0777ba96298b29f0c753d52a81cbb233f1 (diff)
refactor(all): rename some crates
Diffstat (limited to 'stockton-skeleton/src/texture/block.rs')
-rw-r--r--stockton-skeleton/src/texture/block.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/stockton-skeleton/src/texture/block.rs b/stockton-skeleton/src/texture/block.rs
new file mode 100644
index 0000000..5ac3a94
--- /dev/null
+++ b/stockton-skeleton/src/texture/block.rs
@@ -0,0 +1,62 @@
+use super::{loader::BlockRef, repo::BLOCK_SIZE};
+use crate::types::*;
+
+use arrayvec::ArrayVec;
+use rendy_memory::{Allocator, Block};
+use std::{iter::once, mem::ManuallyDrop};
+
+pub struct TexturesBlock<B: Block<back::Backend>> {
+ pub id: BlockRef,
+ pub descriptor_set: ManuallyDrop<RDescriptorSet>,
+ pub imgs: ArrayVec<[LoadedImage<B>; BLOCK_SIZE]>,
+}
+
+impl<B: Block<back::Backend>> TexturesBlock<B> {
+ pub fn deactivate<T: Allocator<back::Backend, Block = B>>(
+ mut self,
+ device: &mut DeviceT,
+ 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<B: Block<back::Backend>> {
+ pub mem: ManuallyDrop<B>,
+ pub img: ManuallyDrop<ImageT>,
+ pub img_view: ManuallyDrop<ImageViewT>,
+ pub sampler: ManuallyDrop<SamplerT>,
+ pub row_size: usize,
+ pub height: u32,
+ pub width: u32,
+}
+
+impl<B: Block<back::Backend>> LoadedImage<B> {
+ pub fn deactivate<T: Allocator<back::Backend, Block = B>>(
+ self,
+ device: &mut DeviceT,
+ 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));
+ }
+ }
+}