use ash::vk;
use crate::{hotham_error::HothamError, resources::VulkanContext};
use anyhow::Result;
#[derive(Debug, Clone)]
pub struct Frame {
pub fence: vk::Fence,
pub command_buffer: vk::CommandBuffer,
pub framebuffer: vk::Framebuffer,
pub swapchain_image_view: vk::ImageView,
}
impl Frame {
pub(crate) fn new(
vulkan_context: &VulkanContext,
render_pass: vk::RenderPass,
swapchain_resolution: vk::Extent2D,
swapchain_image_view: vk::ImageView,
depth_image_view: vk::ImageView,
colour_image_view: vk::ImageView,
) -> Result<Self> {
let device = &vulkan_context.device;
let command_pool = vulkan_context.command_pool;
let fence = unsafe {
device.create_fence(
&vk::FenceCreateInfo::builder().flags(vk::FenceCreateFlags::SIGNALED),
None,
)
}?;
let command_buffer = unsafe {
device.allocate_command_buffers(
&vk::CommandBufferAllocateInfo::builder()
.command_buffer_count(1)
.level(vk::CommandBufferLevel::PRIMARY)
.command_pool(command_pool),
)
}?
.pop()
.ok_or(HothamError::EmptyListError)?;
let attachments = [colour_image_view, depth_image_view, swapchain_image_view];
let frame_buffer_create_info = vk::FramebufferCreateInfo::builder()
.render_pass(render_pass)
.attachments(&attachments)
.width(swapchain_resolution.width)
.height(swapchain_resolution.height)
.layers(1);
let frame_buffer = unsafe { device.create_framebuffer(&frame_buffer_create_info, None) }?;
Ok(Self {
fence,
command_buffer,
framebuffer: frame_buffer,
swapchain_image_view,
})
}
}