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
use glium;
use glium::Surface;
use glium::uniforms::Uniforms;
use shapes::{Shape, IndexType};
use shapes::mould::Mould;
use {Screen, ScreenType};
use errors::ProcessingErr;
impl<'a> Screen<'a> {
/// Create a new framebuffer from a texture. This is necessary if you want
/// to draw to a texture, which is useful in combination with shaders that
/// perform some post-processing on the texture. In the case that you will also
/// use a shader for post-processing, you will also need to use a Mould.
#[inline]
pub fn framebuffer(
&self,
fbtex: &'a glium::texture::Texture2d,
) -> Result<glium::framebuffer::SimpleFrameBuffer, ProcessingErr> {
match self.display {
ScreenType::Window(ref d) => {
glium::framebuffer::SimpleFrameBuffer::new(d, fbtex).map_err(|e| ProcessingErr::FBNoCreate(e))
}
ScreenType::Headless(ref d) => {
glium::framebuffer::SimpleFrameBuffer::new(d, fbtex).map_err(|e| ProcessingErr::FBNoCreate(e))
}
}
}
/// Erase the framebuffer and set it to the given color.
#[inline]
pub fn clear_framebuffer(
&self,
framebuffer: &mut glium::framebuffer::SimpleFrameBuffer,
r: f32,
g: f32,
b: f32,
a: f32,
) {
framebuffer.clear_color_srgb(r, g, b, a);
}
/// Draw the given shape onto the given framebuffer.
#[inline]
pub fn draw_onto_framebuffer<S: Shape>(
&self,
shape: &S,
framebuffer: &mut glium::framebuffer::SimpleFrameBuffer,
) -> Result<(), ProcessingErr> {
// see if there is a decent way to use this
// let mut t = self.draw_params.clone();
// t.depth.write = false;
let t = glium::draw_parameters::DrawParameters {
depth: glium::Depth {
write: false,
test: glium::DepthTest::Overwrite,
..Default::default()
},
multisampling: false,
smooth: None,
..Default::default()
};
if let Some(tex) = shape.get_texture() {
let prog = &self.shader_bank[1];
let u = create_uniforms!{self, tex: *tex};
if self.fill_stuff {
match *shape.fill_indices() {
&IndexType::Buffer { ind: ref ib } => {
framebuffer
.draw(*shape.fill_buffer(), ib, prog, &u, &t)
.map_err(|e| ProcessingErr::FBDrawFailed(e))?
}
&IndexType::NoBuffer { ind: ref ib } => {
framebuffer
.draw(*shape.fill_buffer(), ib, prog, &u, &t)
.map_err(|e| ProcessingErr::FBDrawFailed(e))?
}
}
};
if self.stroke_stuff {
match *shape.stroke_indices() {
&IndexType::NoBuffer { ind: ref ib } => {
framebuffer
.draw(*shape.stroke_buffer(), ib, prog, &u, &t)
.map_err(|e| ProcessingErr::FBDrawFailed(e))?
}
_ => {}
}
};
} else {
let prog = &self.shader_bank[0];
let u = create_uniforms!{self};
if self.fill_stuff {
match *shape.fill_indices() {
&IndexType::Buffer { ind: ref ib } => {
framebuffer
.draw(*shape.fill_buffer(), ib, prog, &u, &t)
.map_err(|e| ProcessingErr::FBDrawFailed(e))?
}
&IndexType::NoBuffer { ind: ref ib } => {
framebuffer
.draw(*shape.fill_buffer(), ib, prog, &u, &t)
.map_err(|e| ProcessingErr::FBDrawFailed(e))?
}
}
};
if self.stroke_stuff {
match *shape.stroke_indices() {
&IndexType::NoBuffer { ind: ref ib } => {
framebuffer
.draw(*shape.stroke_buffer(), ib, prog, &u, &t)
.map_err(|e| ProcessingErr::FBDrawFailed(e))?
}
_ => {}
}
};
}
Ok(())
// if self.drew_points {
// self.draw_params.smooth = Some(glium::draw_parameters::Smooth::Nicest);
// self.drew_points = false;
// }
}
/// Draw a Mould (i.e., a shape plus a custom shader) onto the given framebuffer.
#[inline]
pub fn draw_mould_onto_framebuffer<S: Shape, U: Uniforms>(
&self,
mould: &Mould<U, S>,
framebuffer: &mut glium::framebuffer::SimpleFrameBuffer,
) -> Result<(), ProcessingErr> {
let shader = mould.get_shader();
let shape = mould.get_shape();
let prog = &self.shader_bank[shader.get_idx()];
let uniforms = shader.get_uniforms();
// let t = glium::draw_parameters::DrawParameters {
// depth: glium::Depth {
// write: false,
// test: glium::DepthTest::Overwrite,
// ..Default::default()
// },
// multisampling: false,
// smooth: None,
// ..Default::default()
// };
if self.fill_stuff {
match *shape.fill_indices() {
&IndexType::Buffer { ind: ref ib } => {
framebuffer
.draw(
*shape.fill_buffer(),
ib,
prog,
uniforms,
&Default::default(),
)
.map_err(|e| ProcessingErr::FBDrawFailed(e))?
}
&IndexType::NoBuffer { ind: ref ib } => {
framebuffer
.draw(
*shape.fill_buffer(),
ib,
prog,
uniforms,
&Default::default(),
)
.map_err(|e| ProcessingErr::FBDrawFailed(e))?
}
}
};
if self.stroke_stuff {
match *shape.stroke_indices() {
&IndexType::NoBuffer { ind: ref ib } => {
framebuffer
.draw(
*shape.stroke_buffer(),
ib,
&prog,
uniforms,
&Default::default(),
)
.map_err(|e| ProcessingErr::FBDrawFailed(e))?
}
_ => {}
}
};
Ok(())
}
}