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
use amethyst_core::specs::prelude::SystemData;
use error::Result;
use pipe::{Effect, NewEffect, Target};
use types::{Encoder, Factory};
pub trait PassData<'a> {
type Data: SystemData<'a> + Send;
}
pub trait Pass: for<'a> PassData<'a> {
fn compile(&mut self, effect: NewEffect) -> Result<Effect>;
fn apply<'a, 'b: 'a>(
&'a mut self,
encoder: &mut Encoder,
effect: &mut Effect,
factory: Factory,
data: <Self as PassData<'b>>::Data,
);
}
#[derive(Clone, Debug)]
pub struct CompiledPass<P> {
effect: Effect,
inner: P,
}
impl<P> CompiledPass<P>
where
P: Pass,
{
pub(super) fn compile(
mut pass: P,
fac: &mut Factory,
out: &Target,
multisampling: u16,
) -> Result<Self> {
let effect = pass.compile(NewEffect::new(fac, out, multisampling))?;
Ok(CompiledPass {
effect,
inner: pass,
})
}
}
impl<P> CompiledPass<P> {
pub fn apply<'a, 'b: 'a>(
&'a mut self,
encoder: &mut Encoder,
factory: Factory,
data: <P as PassData<'b>>::Data,
) where
P: Pass,
{
self.inner.apply(encoder, &mut self.effect, factory, data)
}
pub fn new_target(&mut self, target: &Target) {
self.effect.data.out_colors.clear();
self.effect
.data
.out_colors
.extend(target.color_bufs().iter().map(|cb| &cb.as_output).cloned());
self.effect.data.out_blends.clear();
self.effect
.data
.out_blends
.extend(target.color_bufs().iter().map(|cb| &cb.as_output).cloned());
self.effect.data.out_depth = target.depth_buf().map(|db| (db.as_output.clone(), (0, 0)));
}
}