No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

69 líneas
1.5KB

  1. use crate::render::{Device, OwnedImage};
  2. use ash::{version::DeviceV1_0, vk};
  3. use std::rc::Rc;
  4. pub struct ImageView {
  5. handle: vk::ImageView,
  6. pub device: Rc<Device>,
  7. pub image: Rc<OwnedImage>,
  8. }
  9. impl ImageView {
  10. pub fn create(
  11. device: Rc<Device>,
  12. image: Rc<OwnedImage>,
  13. format: vk::Format,
  14. ) -> Result<Rc<Self>, vk::Result> {
  15. let create_info = vk::ImageViewCreateInfo {
  16. format,
  17. image: **image,
  18. view_type: vk::ImageViewType::TYPE_2D,
  19. components: vk::ComponentMapping {
  20. r: vk::ComponentSwizzle::IDENTITY,
  21. g: vk::ComponentSwizzle::IDENTITY,
  22. b: vk::ComponentSwizzle::IDENTITY,
  23. a: vk::ComponentSwizzle::IDENTITY,
  24. },
  25. subresource_range: vk::ImageSubresourceRange {
  26. aspect_mask: vk::ImageAspectFlags::COLOR,
  27. base_mip_level: 0,
  28. level_count: 1,
  29. base_array_layer: 0,
  30. layer_count: 1,
  31. },
  32. ..Default::default()
  33. };
  34. let handle = unsafe { device.create_image_view(&create_info, None)? };
  35. Ok(Rc::new(Self { handle, device, image }))
  36. }
  37. pub fn create_all(
  38. device: Rc<Device>,
  39. images: &[Rc<OwnedImage>],
  40. format: vk::Format,
  41. ) -> Result<Vec<Rc<Self>>, vk::Result> {
  42. images
  43. .iter()
  44. .map(|image| Self::create(device.clone(), image.clone(), format))
  45. .collect()
  46. }
  47. }
  48. impl Drop for ImageView {
  49. fn drop(&mut self) {
  50. unsafe {
  51. self.device.destroy_image_view(self.handle, None);
  52. }
  53. }
  54. }
  55. impl std::ops::Deref for ImageView {
  56. type Target = vk::ImageView;
  57. fn deref(&self) -> &Self::Target {
  58. &self.handle
  59. }
  60. }
  61. // EOF