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
use super::*;
use glyph_brush::delegate_glyph_brush_builder_fns;
pub struct GlyphBrushBuilder<'a, H = DefaultSectionHasher> {
inner: glyph_brush::GlyphBrushBuilder<'a, H>,
depth_test: gfx::state::Depth,
texture_filter_method: texture::FilterMethod,
}
impl<'a> GlyphBrushBuilder<'a> {
#[inline]
pub fn using_font_bytes<B: Into<SharedBytes<'a>>>(font_0_data: B) -> Self {
Self::using_font(Font::from_bytes(font_0_data).unwrap())
}
#[inline]
pub fn using_fonts_bytes<B, V>(font_data: V) -> Self
where
B: Into<SharedBytes<'a>>,
V: Into<Vec<B>>,
{
Self::using_fonts(
font_data
.into()
.into_iter()
.map(|data| Font::from_bytes(data).unwrap())
.collect::<Vec<_>>(),
)
}
#[inline]
pub fn using_font(font_0: Font<'a>) -> Self {
Self::using_fonts(vec![font_0])
}
pub fn using_fonts<V: Into<Vec<Font<'a>>>>(fonts: V) -> Self {
GlyphBrushBuilder {
inner: glyph_brush::GlyphBrushBuilder::using_fonts(fonts),
depth_test: gfx::preset::depth::PASS_TEST,
texture_filter_method: texture::FilterMethod::Bilinear,
}
}
}
impl<'a, H: BuildHasher> GlyphBrushBuilder<'a, H> {
delegate_glyph_brush_builder_fns!(inner);
pub fn depth_test(mut self, depth_test: gfx::state::Depth) -> Self {
self.depth_test = depth_test;
self
}
pub fn texture_filter_method(mut self, filter_method: texture::FilterMethod) -> Self {
self.texture_filter_method = filter_method;
self
}
pub fn section_hasher<T: BuildHasher>(self, section_hasher: T) -> GlyphBrushBuilder<'a, T> {
GlyphBrushBuilder {
inner: self.inner.section_hasher(section_hasher),
depth_test: self.depth_test,
texture_filter_method: self.texture_filter_method,
}
}
pub fn build<R, F>(self, mut factory: F) -> GlyphBrush<'a, R, F, H>
where
R: gfx::Resources,
F: gfx::Factory<R>,
{
let (cache_width, cache_height) = self.inner.initial_cache_size;
let font_cache_tex = create_texture(&mut factory, cache_width, cache_height).unwrap();
let program = factory
.link_program(
include_bytes!("shader/vert.glsl"),
include_bytes!("shader/frag.glsl"),
)
.unwrap();
GlyphBrush {
font_cache_tex,
texture_filter_method: self.texture_filter_method,
glyph_brush: self.inner.build(),
factory,
program,
draw_cache: None,
depth_test: self.depth_test,
}
}
}