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.
 
 
 

68 lines
1.5 KiB

use crate::render::{Device, OwnedImage};
use ash::{version::DeviceV1_0, vk};
use std::rc::Rc;
pub struct ImageView {
handle: vk::ImageView,
pub device: Rc<Device>,
pub image: Rc<OwnedImage>,
}
impl ImageView {
pub fn create(
device: Rc<Device>,
image: Rc<OwnedImage>,
format: vk::Format,
) -> Result<Rc<Self>, vk::Result> {
let create_info = vk::ImageViewCreateInfo {
format,
image: **image,
view_type: vk::ImageViewType::TYPE_2D,
components: vk::ComponentMapping {
r: vk::ComponentSwizzle::IDENTITY,
g: vk::ComponentSwizzle::IDENTITY,
b: vk::ComponentSwizzle::IDENTITY,
a: vk::ComponentSwizzle::IDENTITY,
},
subresource_range: vk::ImageSubresourceRange {
aspect_mask: vk::ImageAspectFlags::COLOR,
base_mip_level: 0,
level_count: 1,
base_array_layer: 0,
layer_count: 1,
},
..Default::default()
};
let handle = unsafe { device.create_image_view(&create_info, None)? };
Ok(Rc::new(Self { handle, device, image }))
}
pub fn create_all(
device: Rc<Device>,
images: &[Rc<OwnedImage>],
format: vk::Format,
) -> Result<Vec<Rc<Self>>, vk::Result> {
images
.iter()
.map(|image| Self::create(device.clone(), image.clone(), format))
.collect()
}
}
impl Drop for ImageView {
fn drop(&mut self) {
unsafe {
self.device.destroy_image_view(self.handle, None);
}
}
}
impl std::ops::Deref for ImageView {
type Target = vk::ImageView;
fn deref(&self) -> &Self::Target {
&self.handle
}
}
// EOF