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