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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#[cfg(feature = "opengl")]
pub mod gl;
#[cfg(feature = "vulkan")]
pub mod vk;
#[cfg(all(target_os = "windows", feature = "dxgi"))]
pub mod dxgi;
#[cfg(all(target_os = "windows", feature = "d3d11"))]
pub mod d3d11;
#[cfg(all(target_os = "windows", feature = "d3d12"))]
pub mod d3d12;
mod viewport;
pub use viewport::Viewport;
use num_traits::AsPrimitive;
use std::convert::Infallible;
use std::str::FromStr;
#[repr(u32)]
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum ImageFormat {
#[default]
Unknown = 0,
R8Unorm,
R8Uint,
R8Sint,
R8G8Unorm,
R8G8Uint,
R8G8Sint,
R8G8B8A8Unorm,
R8G8B8A8Uint,
R8G8B8A8Sint,
R8G8B8A8Srgb,
A2B10G10R10UnormPack32,
A2B10G10R10UintPack32,
R16Uint,
R16Sint,
R16Sfloat,
R16G16Uint,
R16G16Sint,
R16G16Sfloat,
R16G16B16A16Uint,
R16G16B16A16Sint,
R16G16B16A16Sfloat,
R32Uint,
R32Sint,
R32Sfloat,
R32G32Uint,
R32G32Sint,
R32G32Sfloat,
R32G32B32A32Uint,
R32G32B32A32Sint,
R32G32B32A32Sfloat,
}
#[repr(i32)]
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Hash)]
pub enum FilterMode {
Linear = 0,
#[default]
Nearest,
}
impl FromStr for WrapMode {
type Err = Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"clamp_to_border" => WrapMode::ClampToBorder,
"clamp_to_edge" => WrapMode::ClampToEdge,
"repeat" => WrapMode::Repeat,
"mirrored_repeat" => WrapMode::MirroredRepeat,
_ => WrapMode::ClampToBorder,
})
}
}
impl FromStr for FilterMode {
type Err = Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"linear" => FilterMode::Linear,
"nearest" => FilterMode::Nearest,
_ => FilterMode::Nearest,
})
}
}
#[repr(i32)]
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Hash)]
pub enum WrapMode {
#[default]
ClampToBorder = 0,
ClampToEdge,
Repeat,
MirroredRepeat,
}
impl FromStr for ImageFormat {
type Err = Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"UNKNOWN" => Self::Unknown,
"R8_UNORM" => Self::R8Unorm,
"R8_UINT" => Self::R8Uint,
"R8_SINT" => Self::R8Sint,
"R8G8_UNORM" => Self::R8G8Unorm,
"R8G8_UINT" => Self::R8Uint,
"R8G8_SINT" => Self::R8G8Sint,
"R8G8B8A8_UNORM" => Self::R8G8B8A8Unorm,
"R8G8B8A8_UINT" => Self::R8G8B8A8Uint,
"R8G8B8A8_SINT" => Self::R8G8B8A8Sint,
"R8G8B8A8_SRGB" => Self::R8G8B8A8Srgb,
"A2B10G10R10_UNORM_PACK32" => Self::A2B10G10R10UnormPack32,
"A2B10G10R10_UINT_PACK32" => Self::A2B10G10R10UintPack32,
"R16_UINT" => Self::R16Uint,
"R16_SINT" => Self::R16Sint,
"R16_SFLOAT" => Self::R16Sfloat,
"R16G16_UINT" => Self::R16G16Uint,
"R16G16_SINT" => Self::R16G16Sint,
"R16G16_SFLOAT" => Self::R16G16Sfloat,
"R16G16B16A16_UINT" => Self::R16G16B16A16Uint,
"R16G16B16A16_SINT" => Self::R16G16B16A16Sint,
"R16G16B16A16_SFLOAT" => Self::R16G16B16A16Sfloat,
"R32_UINT" => Self::R32Uint,
"R32_SINT" => Self::R32Sint,
"R32_SFLOAT" => Self::R32Sfloat,
"R32G32_UINT" => Self::R32G32Uint,
"R32G32_SINT" => Self::R32G32Sint,
"R32G32_SFLOAT" => Self::R32G32Sfloat,
"R32G32B32A32_UINT" => Self::R32G32B32A32Uint,
"R32G32B32A32_SINT" => Self::R32G32B32A32Sint,
"R32G32B32A32_SFLOAT" => Self::R32G32B32A32Sfloat,
_ => Self::Unknown,
})
}
}
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub struct Size<T> {
pub width: T,
pub height: T,
}
impl<T> Size<T> {
pub fn new(width: T, height: T) -> Self {
Size { width, height }
}
}
impl<T> From<Size<T>> for [f32; 4]
where
T: Copy + AsPrimitive<f32>,
{
fn from(value: Size<T>) -> Self {
[
value.width.as_(),
value.height.as_(),
1.0 / value.width.as_(),
1.0 / value.height.as_(),
]
}
}