vkobject_rs/
rendertarget.rs

1
2use crate::prelude::*;
3use std::{
4	sync::{Arc, Mutex},
5};
6
7/// The resources for a texture to become a render-target texture
8#[derive(Debug)]
9pub struct RenderTargetProps {
10	/// The render pass object
11	pub renderpass: Arc<VulkanRenderPass>,
12
13	/// The framebuffer object
14	pub framebuffer: VulkanFramebuffer,
15
16	/// The extent of the render target
17	pub(crate) extent: VkExtent2D,
18
19	/// The attachment textures
20	pub attachments: Vec<Arc<VulkanTexture>>,
21
22	/// The semaphore for waiting the render target to be ready
23	pub acquire_semaphore: Arc<Mutex<VulkanSemaphore>>,
24
25	/// The semaphore indicating that the render commands were runned
26	pub release_semaphore: Arc<VulkanSemaphore>,
27}
28
29impl RenderTargetProps {
30	pub fn new(device: Arc<VulkanDevice>, extent: &VkExtent2D, renderpass: Option<Arc<VulkanRenderPass>>, attachments: &[Arc<VulkanTexture>]) -> Result<Self, VulkanError> {
31		let renderpass_attachments: Vec<VulkanRenderPassAttachment> = attachments.iter().map(|t| {
32			VulkanRenderPassAttachment::new(t.format, t.type_size.is_depth_stencil())
33		}).collect();
34		let renderpass = if let Some(renderpass) = renderpass {
35			renderpass.clone()
36		} else {
37			Arc::new(VulkanRenderPass::new(device.clone(), &renderpass_attachments)?)
38		};
39		let framebuffer = VulkanFramebuffer::new(device.clone(), extent, &renderpass, attachments)?;
40		Ok(Self {
41			renderpass,
42			framebuffer,
43			attachments: attachments.to_vec(),
44			extent: *extent,
45			acquire_semaphore: Arc::new(Mutex::new(VulkanSemaphore::new(device.clone())?)),
46			release_semaphore: Arc::new(VulkanSemaphore::new(device.clone())?),
47		})
48	}
49
50	pub fn get_extent(&self) -> &VkExtent2D {
51		&self.extent
52	}
53
54	pub(crate) fn get_vk_renderpass(&self) -> VkRenderPass {
55		self.renderpass.get_vk_renderpass()
56	}
57
58	pub(crate) fn get_vk_framebuffer(&self) -> VkFramebuffer {
59		self.framebuffer.get_vk_framebuffer()
60	}
61}
62
63impl Drop for RenderTargetProps {
64	fn drop(&mut self) {
65		let device = self.renderpass.device.clone();
66		device.vkcore.vkQueueWaitIdle(device.get_vk_queue()).unwrap();
67	}
68}
69
70unsafe impl Send for RenderTargetProps {}
71unsafe impl Sync for RenderTargetProps {}