Skip to main content

fui/
image_sampling.rs

1use crate::ffi::ImageSamplingKind;
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq)]
4pub enum ImageSamplingMode {
5    Linear,
6    Nearest,
7    LinearMipmapNearest,
8    LinearMipmapLinear,
9    CubicMitchell,
10    CubicCatmullRom,
11    Anisotropic,
12}
13
14impl ImageSamplingMode {
15    pub(crate) fn ffi_kind(self) -> ImageSamplingKind {
16        match self {
17            Self::Linear => ImageSamplingKind::Linear,
18            Self::Nearest => ImageSamplingKind::Nearest,
19            Self::LinearMipmapNearest => ImageSamplingKind::LinearMipmapNearest,
20            Self::LinearMipmapLinear => ImageSamplingKind::LinearMipmapLinear,
21            Self::CubicMitchell => ImageSamplingKind::CubicMitchell,
22            Self::CubicCatmullRom => ImageSamplingKind::CubicCatmullRom,
23            Self::Anisotropic => ImageSamplingKind::Anisotropic,
24        }
25    }
26}
27
28#[derive(Clone, Copy, Debug, PartialEq, Eq)]
29pub struct ImageSampling {
30    kind: ImageSamplingMode,
31    max_aniso: u32,
32}
33
34impl ImageSampling {
35    pub fn linear() -> Self {
36        Self::new(ImageSamplingMode::Linear, 0)
37    }
38
39    pub fn nearest() -> Self {
40        Self::new(ImageSamplingMode::Nearest, 0)
41    }
42
43    pub fn linear_mipmap_nearest() -> Self {
44        Self::new(ImageSamplingMode::LinearMipmapNearest, 0)
45    }
46
47    pub fn linear_mipmap_linear() -> Self {
48        Self::new(ImageSamplingMode::LinearMipmapLinear, 0)
49    }
50
51    pub fn cubic_mitchell() -> Self {
52        Self::new(ImageSamplingMode::CubicMitchell, 0)
53    }
54
55    pub fn cubic_catmull_rom() -> Self {
56        Self::new(ImageSamplingMode::CubicCatmullRom, 0)
57    }
58
59    pub fn anisotropic(max_aniso: u32) -> Self {
60        Self::new(ImageSamplingMode::Anisotropic, max_aniso)
61    }
62
63    pub fn new(kind: ImageSamplingMode, max_aniso: u32) -> Self {
64        Self { kind, max_aniso }
65    }
66
67    pub fn kind(self) -> ImageSamplingMode {
68        self.kind
69    }
70
71    pub(crate) fn ffi_kind(self) -> ImageSamplingKind {
72        self.kind.ffi_kind()
73    }
74
75    pub fn max_aniso(self) -> u32 {
76        self.max_aniso
77    }
78}