bort_vk/
image_access.rs

1use crate::{DeviceOwned, ImageDimensions, MemoryError};
2use ash::vk;
3use std::{error, fmt};
4
5// ~~ Image Access ~~
6
7/// Unifies different types of images
8pub trait ImageAccess: DeviceOwned + Send + Sync {
9    fn handle(&self) -> vk::Image;
10    fn dimensions(&self) -> ImageDimensions;
11}
12
13// ~~ Image Access Error ~~
14
15#[derive(Debug, Clone)]
16pub enum ImageAccessError {
17    /// `requested_coordinates` and `image_dimensions` are different enum variants
18    IncompatibleDimensions {
19        requested_coordinates: ImageDimensions,
20        image_dimensions: ImageDimensions,
21    },
22    InvalidDimensions {
23        requested_coordinates: ImageDimensions,
24        image_dimensions: ImageDimensions,
25    },
26    MemoryError(MemoryError),
27}
28
29impl fmt::Display for ImageAccessError {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        match self {
32            Self::MemoryError(e) => e.fmt(f),
33            Self::IncompatibleDimensions {
34                requested_coordinates,
35                image_dimensions,
36            } => {
37                write!(
38                    f,
39                    "incompatible coordinate/dimension types: requested coordinates = {:?}, image dimensions = {:?}",
40                    requested_coordinates, image_dimensions
41                )
42            }
43            Self::InvalidDimensions {
44                requested_coordinates,
45                image_dimensions,
46            } => {
47                write!(
48                    f,
49                    "invalid coordinates/dimensions: requested coordinates = {:?}, image dimensions = {:?}",
50                    requested_coordinates, image_dimensions
51                )
52            }
53        }
54    }
55}
56
57impl error::Error for ImageAccessError {
58    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
59        match self {
60            Self::MemoryError(e) => Some(e),
61            Self::IncompatibleDimensions { .. } => None,
62            Self::InvalidDimensions { .. } => None,
63        }
64    }
65}