You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

71 lines
1.5 KiB

use crate::render::{Device, ImageView, RenderPass};
use ash::{version::DeviceV1_0, vk};
use std::rc::Rc;
pub struct Framebuffer {
handle: vk::Framebuffer,
pub device: Rc<Device>,
pub render_pass: Rc<RenderPass>,
pub image_view: Rc<ImageView>,
}
impl Framebuffer {
pub fn create(
device: Rc<Device>,
render_pass: Rc<RenderPass>,
image_view: Rc<ImageView>,
image_extent: vk::Extent2D,
) -> Result<Rc<Self>, vk::Result> {
let attachments = [**image_view];
let create_info = vk::FramebufferCreateInfo {
render_pass: **render_pass,
attachment_count: attachments.len() as u32,
p_attachments: attachments.as_ptr(),
width: image_extent.width,
height: image_extent.height,
layers: 1,
..Default::default()
};
let handle = unsafe { device.create_framebuffer(&create_info, None)? };
Ok(Rc::new(Self { handle, device, render_pass, image_view }))
}
pub fn create_all(
device: Rc<Device>,
render_pass: Rc<RenderPass>,
image_views: &[Rc<ImageView>],
extent: vk::Extent2D,
) -> Result<Vec<Rc<Self>>, vk::Result> {
image_views
.iter()
.map(|image_view| {
Self::create(
device.clone(),
render_pass.clone(),
image_view.clone(),
extent,
)
})
.collect()
}
}
impl Drop for Framebuffer {
fn drop(&mut self) {
unsafe {
self.device.destroy_framebuffer(self.handle, None);
}
}
}
impl std::ops::Deref for Framebuffer {
type Target = vk::Framebuffer;
fn deref(&self) -> &Self::Target {
&self.handle
}
}
// EOF