Skip to main content

bedrock/resources/
swapchain_image.rs

1use bedrock_vk::{self as brvk, VkRawHandle};
2
3use crate::*;
4
5/// Opaque handle to a image object, backed by Swapchain.
6#[derive(VkHandle, VkObject)]
7#[VkObject(type = brvk::VkImage::OBJECT_TYPE)]
8pub struct SwapchainImage<Swapchain>(
9    pub(crate) brvk::VkImage,
10    pub(crate) Swapchain,
11    pub(crate) brvk::VkFormat,
12    pub(crate) brvk::VkExtent3D,
13);
14unsafe impl<Swapchain: Sync> Sync for SwapchainImage<Swapchain> {}
15unsafe impl<Swapchain: Send> Send for SwapchainImage<Swapchain> {}
16impl<Swapchain: DeviceChildHandle> DeviceChildHandle for SwapchainImage<Swapchain> {
17    #[inline(always)]
18    fn device_handle(&self) -> brvk::VkDevice {
19        self.1.device_handle()
20    }
21}
22impl<Swapchain: DeviceChild> DeviceChild for SwapchainImage<Swapchain> {
23    type ConcreteDevice = Swapchain::ConcreteDevice;
24
25    #[inline(always)]
26    fn device(&self) -> &Self::ConcreteDevice {
27        self.1.device()
28    }
29}
30impl<Swapchain: crate::Swapchain> Image for SwapchainImage<Swapchain> {
31    #[inline(always)]
32    fn format(&self) -> brvk::VkFormat {
33        self.2
34    }
35
36    #[inline(always)]
37    fn size(&self) -> &brvk::VkExtent3D {
38        &self.3
39    }
40
41    #[inline(always)]
42    fn dimension(&self) -> brvk::VkImageViewType {
43        brvk::VK_IMAGE_VIEW_TYPE_2D
44    }
45}
46impl<Swapchain: Clone> SwapchainImage<&'_ Swapchain> {
47    /// Clones parent reference
48    #[inline(always)]
49    pub fn clone_parent(self) -> SwapchainImage<Swapchain> {
50        SwapchainImage(self.0, self.1.clone(), self.2, self.3)
51    }
52}
53impl<Swapchain> SwapchainImage<Swapchain> {
54    /// Purges the construct
55    pub const fn unmanage(self) -> (brvk::VkImage, Swapchain, brvk::VkFormat, brvk::VkExtent3D) {
56        let image = unsafe { core::ptr::read(&self.0) };
57        let swapchain = unsafe { core::ptr::read(&self.1) };
58        let format = unsafe { core::ptr::read(&self.2) };
59        let extent = unsafe { core::ptr::read(&self.3) };
60        core::mem::forget(self);
61
62        (image, swapchain, format, extent)
63    }
64}