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
pub trait Pixel {
type Encoding;
type RawEncoding;
fn pixel_format() -> PixelFormat;
}
pub trait ColorPixel: Pixel {}
pub trait DepthPixel: Pixel {}
pub trait RenderablePixel: Pixel {}
#[derive(Clone, Copy, Debug)]
pub struct PixelFormat {
pub encoding: Type,
pub format: Format
}
#[derive(Clone, Copy, Debug)]
pub enum Type {
Integral,
Unsigned,
Floating
}
#[derive(Clone, Copy, Debug)]
pub enum Format {
R(u8),
RG(u8, u8),
RGB(u8, u8, u8),
RGBA(u8, u8, u8, u8),
Depth(u8)
}
pub fn is_color_pixel(f: PixelFormat) -> bool {
match f.format {
Format::Depth(_) => false
, _ => true
}
}
pub fn is_depth_pixel(f: PixelFormat) -> bool {
!is_color_pixel(f)
}
#[derive(Clone, Copy, Debug)]
pub struct RGB8UI;
impl Pixel for RGB8UI {
type Encoding = (u8, u8, u8);
type RawEncoding = u8;
fn pixel_format() -> PixelFormat {
PixelFormat {
encoding: Type::Unsigned
, format: Format::RGB(8, 8, 8)
}
}
}
impl ColorPixel for RGB8UI {}
#[derive(Clone, Copy, Debug)]
pub struct RGBA8UI;
impl Pixel for RGBA8UI {
type Encoding = (u8, u8, u8, u8);
type RawEncoding = u8;
fn pixel_format() -> PixelFormat {
PixelFormat {
encoding: Type::Unsigned
, format: Format::RGBA(8, 8, 8, 8)
}
}
}
impl ColorPixel for RGBA8UI {}
impl RenderablePixel for RGBA8UI {}
#[derive(Clone, Copy, Debug)]
pub struct RGB32F;
impl Pixel for RGB32F {
type Encoding = (f32, f32, f32);
type RawEncoding = f32;
fn pixel_format() -> PixelFormat {
PixelFormat {
encoding: Type::Floating
, format: Format::RGB(32, 32, 32)
}
}
}
impl ColorPixel for RGB32F {}
#[derive(Clone, Copy, Debug)]
pub struct RGBA32F;
impl Pixel for RGBA32F {
type Encoding = (f32, f32, f32, f32);
type RawEncoding = f32;
fn pixel_format() -> PixelFormat {
PixelFormat {
encoding: Type::Floating
, format: Format::RGBA(32, 32, 32, 32)
}
}
}
impl ColorPixel for RGBA32F {}
impl RenderablePixel for RGBA32F {}
#[derive(Clone, Copy, Debug)]
pub struct Depth32F;
impl Pixel for Depth32F {
type Encoding = f32;
type RawEncoding = f32;
fn pixel_format() -> PixelFormat {
PixelFormat {
encoding: Type::Floating
, format: Format::Depth(32)
}
}
}
impl DepthPixel for Depth32F {}