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.

72 line
1.5KB

  1. use crate::render::{Device, ImageView, RenderPass};
  2. use ash::{version::DeviceV1_0, vk};
  3. use std::rc::Rc;
  4. pub struct Framebuffer {
  5. handle: vk::Framebuffer,
  6. pub device: Rc<Device>,
  7. pub render_pass: Rc<RenderPass>,
  8. pub image_view: Rc<ImageView>,
  9. }
  10. impl Framebuffer {
  11. pub fn create(
  12. device: Rc<Device>,
  13. render_pass: Rc<RenderPass>,
  14. image_view: Rc<ImageView>,
  15. image_extent: vk::Extent2D,
  16. ) -> Result<Rc<Self>, vk::Result> {
  17. let attachments = [**image_view];
  18. let create_info = vk::FramebufferCreateInfo {
  19. render_pass: **render_pass,
  20. attachment_count: attachments.len() as u32,
  21. p_attachments: attachments.as_ptr(),
  22. width: image_extent.width,
  23. height: image_extent.height,
  24. layers: 1,
  25. ..Default::default()
  26. };
  27. let handle = unsafe { device.create_framebuffer(&create_info, None)? };
  28. Ok(Rc::new(Self { handle, device, render_pass, image_view }))
  29. }
  30. pub fn create_all(
  31. device: Rc<Device>,
  32. render_pass: Rc<RenderPass>,
  33. image_views: &[Rc<ImageView>],
  34. extent: vk::Extent2D,
  35. ) -> Result<Vec<Rc<Self>>, vk::Result> {
  36. image_views
  37. .iter()
  38. .map(|image_view| {
  39. Self::create(
  40. device.clone(),
  41. render_pass.clone(),
  42. image_view.clone(),
  43. extent,
  44. )
  45. })
  46. .collect()
  47. }
  48. }
  49. impl Drop for Framebuffer {
  50. fn drop(&mut self) {
  51. unsafe {
  52. self.device.destroy_framebuffer(self.handle, None);
  53. }
  54. }
  55. }
  56. impl std::ops::Deref for Framebuffer {
  57. type Target = vk::Framebuffer;
  58. fn deref(&self) -> &Self::Target {
  59. &self.handle
  60. }
  61. }
  62. // EOF