| 1 |
use core::{num::NonZeroU32, ops::Range}; |
| 2 |
|
| 3 |
#[cfg(feature = "deserialize")] |
| 4 |
use serde::Deserialize; |
| 5 |
#[cfg(feature = "serialize")] |
| 6 |
use serde::Serialize; |
| 7 |
|
| 8 |
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
| 9 |
#[cfg_attr(feature = "serialize", derive(Serialize))] |
| 10 |
#[cfg_attr(feature = "deserialize", derive(Deserialize))] |
| 11 |
pub enum Coord { |
| 12 |
Normalized, |
| 13 |
Pixel, |
| 14 |
} |
| 15 |
|
| 16 |
impl Default for Coord { |
| 17 |
fn default() -> Self { |
| 18 |
Self::Normalized |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
impl Coord { |
| 23 |
pub const fn as_str(&self) -> &'static str { |
| 24 |
match *self { |
| 25 |
Self::Normalized => "normalized", |
| 26 |
Self::Pixel => "pixel", |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
| 32 |
#[cfg_attr(feature = "serialize", derive(Serialize))] |
| 33 |
#[cfg_attr(feature = "deserialize", derive(Deserialize))] |
| 34 |
pub enum Address { |
| 35 |
Repeat, |
| 36 |
MirroredRepeat, |
| 37 |
ClampToEdge, |
| 38 |
ClampToZero, |
| 39 |
ClampToBorder, |
| 40 |
} |
| 41 |
|
| 42 |
impl Default for Address { |
| 43 |
fn default() -> Self { |
| 44 |
Self::ClampToEdge |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
impl Address { |
| 49 |
pub const fn as_str(&self) -> &'static str { |
| 50 |
match *self { |
| 51 |
Self::Repeat => "repeat", |
| 52 |
Self::MirroredRepeat => "mirrored_repeat", |
| 53 |
Self::ClampToEdge => "clamp_to_edge", |
| 54 |
Self::ClampToZero => "clamp_to_zero", |
| 55 |
Self::ClampToBorder => "clamp_to_border", |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
| 61 |
#[cfg_attr(feature = "serialize", derive(Serialize))] |
| 62 |
#[cfg_attr(feature = "deserialize", derive(Deserialize))] |
| 63 |
pub enum BorderColor { |
| 64 |
TransparentBlack, |
| 65 |
OpaqueBlack, |
| 66 |
OpaqueWhite, |
| 67 |
} |
| 68 |
|
| 69 |
impl Default for BorderColor { |
| 70 |
fn default() -> Self { |
| 71 |
Self::TransparentBlack |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
impl BorderColor { |
| 76 |
pub const fn as_str(&self) -> &'static str { |
| 77 |
match *self { |
| 78 |
Self::TransparentBlack => "transparent_black", |
| 79 |
Self::OpaqueBlack => "opaque_black", |
| 80 |
Self::OpaqueWhite => "opaque_white", |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
| 86 |
#[cfg_attr(feature = "serialize", derive(Serialize))] |
| 87 |
#[cfg_attr(feature = "deserialize", derive(Deserialize))] |
| 88 |
pub enum Filter { |
| 89 |
Nearest, |
| 90 |
Linear, |
| 91 |
} |
| 92 |
|
| 93 |
impl Filter { |
| 94 |
pub const fn as_str(&self) -> &'static str { |
| 95 |
match *self { |
| 96 |
Self::Nearest => "nearest", |
| 97 |
Self::Linear => "linear", |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
impl Default for Filter { |
| 103 |
fn default() -> Self { |
| 104 |
Self::Nearest |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
| 109 |
#[cfg_attr(feature = "serialize", derive(Serialize))] |
| 110 |
#[cfg_attr(feature = "deserialize", derive(Deserialize))] |
| 111 |
pub enum CompareFunc { |
| 112 |
Never, |
| 113 |
Less, |
| 114 |
LessEqual, |
| 115 |
Greater, |
| 116 |
GreaterEqual, |
| 117 |
Equal, |
| 118 |
NotEqual, |
| 119 |
Always, |
| 120 |
} |
| 121 |
|
| 122 |
impl Default for CompareFunc { |
| 123 |
fn default() -> Self { |
| 124 |
Self::Never |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
impl CompareFunc { |
| 129 |
pub const fn as_str(&self) -> &'static str { |
| 130 |
match *self { |
| 131 |
Self::Never => "never", |
| 132 |
Self::Less => "less", |
| 133 |
Self::LessEqual => "less_equal", |
| 134 |
Self::Greater => "greater", |
| 135 |
Self::GreaterEqual => "greater_equal", |
| 136 |
Self::Equal => "equal", |
| 137 |
Self::NotEqual => "not_equal", |
| 138 |
Self::Always => "always", |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
#[derive(Clone, Debug, Default, PartialEq)] |
| 144 |
#[cfg_attr(feature = "serialize", derive(Serialize))] |
| 145 |
#[cfg_attr(feature = "deserialize", derive(Deserialize))] |
| 146 |
pub struct InlineSampler { |
| 147 |
pub coord: Coord, |
| 148 |
pub address: [Address; 3], |
| 149 |
pub border_color: BorderColor, |
| 150 |
pub mag_filter: Filter, |
| 151 |
pub min_filter: Filter, |
| 152 |
pub mip_filter: Option<Filter>, |
| 153 |
pub lod_clamp: Option<Range<f32>>, |
| 154 |
pub max_anisotropy: Option<NonZeroU32>, |
| 155 |
pub compare_func: CompareFunc, |
| 156 |
} |
| 157 |
|
| 158 |
impl Eq for InlineSampler {} |
| 159 |
|
| 160 |
#[allow(renamed_and_removed_lints)] |
| 161 |
#[allow(clippy::derive_hash_xor_eq)] |
| 162 |
impl core::hash::Hash for InlineSampler { |
| 163 |
fn hash<H: core::hash::Hasher>(&self, hasher: &mut H) { |
| 164 |
self.coord.hash(hasher); |
| 165 |
self.address.hash(hasher); |
| 166 |
self.border_color.hash(hasher); |
| 167 |
self.mag_filter.hash(hasher); |
| 168 |
self.min_filter.hash(hasher); |
| 169 |
self.mip_filter.hash(hasher); |
| 170 |
self.lod_clamp |
| 171 |
.as_ref() |
| 172 |
.map(|range| (range.start.to_bits(), range.end.to_bits())) |
| 173 |
.hash(hasher); |
| 174 |
self.max_anisotropy.hash(hasher); |
| 175 |
self.compare_func.hash(hasher); |
| 176 |
} |
| 177 |
} |