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
use device::{Device, InstanceCount, Resources, VertexCount};
use device::draw::CommandBuffer;
use device::target::{ClearData, Mask, Mirror, Rect};
use render::{DrawError, Renderer, RenderFactory};
use render::batch::Batch;
use render::target::Output;
pub trait Stream<R: Resources> {
type CommandBuffer: CommandBuffer<R>;
type Output: Output<R>;
fn get_output(&self) -> &Self::Output;
fn access(&mut self) -> (&mut Renderer<R, Self::CommandBuffer>, &Self::Output);
fn get_aspect_ratio(&self) -> f32 {
let (w, h) = self.get_output().get_size();
w as f32 / h as f32
}
fn clear(&mut self, data: ClearData) {
let (ren, out) = self.access();
let mask = out.get_mask();
ren.clear(data, mask, out);
}
fn blit_on<I: Output<R>>(&mut self,
source: &I, source_rect: Rect, dest_rect: Rect,
mirror: Mirror, mask: Mask) {
let (ren, out) = self.access();
ren.blit(source, source_rect, out, dest_rect, mirror, mask);
}
fn blit_to<O: Output<R>>(&mut self,
destination: &O, dest_rect: Rect, source_rect: Rect,
mirror: Mirror, mask: Mask) {
let (ren, out) = self.access();
ren.blit(out, source_rect, destination, dest_rect, mirror, mask);
}
fn draw<B: Batch<R>>(&mut self, batch: &B)
-> Result<(), DrawError<B::Error>> {
let (ren, out) = self.access();
ren.draw(batch, out)
}
fn draw_instanced<B: Batch<R>>(&mut self, batch: &B,
count: InstanceCount, base: VertexCount)
-> Result<(), DrawError<B::Error>> {
let (ren, out) = self.access();
ren.draw_instanced(batch, count, base, out)
}
fn flush<D>(&mut self, device: &mut D) where
D: Device<Resources = R, CommandBuffer = Self::CommandBuffer>,
{
let (ren, _) = self.access();
device.submit(ren.as_buffer());
ren.reset();
}
}
impl<'a, R: Resources, C: CommandBuffer<R>, O: Output<R>>
Stream<R> for (&'a mut Renderer<R, C>, &'a O) {
type CommandBuffer = C;
type Output = O;
fn get_output(&self) -> &O {
&self.1
}
fn access(&mut self) -> (&mut Renderer<R, C>, &O) {
(&mut self.0, &self.1)
}
}
pub struct OwnedStream<
R: Resources,
C: CommandBuffer<R>,
O: Output<R>
>(pub Renderer<R, C>, pub O);
impl<R: Resources, C: CommandBuffer<R>, O: Output<R>>
Stream<R> for OwnedStream<R, C, O> {
type CommandBuffer = C;
type Output = O;
fn get_output(&self) -> &O {
&self.1
}
fn access(&mut self) -> (&mut Renderer<R, C>, &O) {
(&mut self.0, &self.1)
}
}
pub trait StreamFactory<R: Resources, C: CommandBuffer<R>>: RenderFactory<R, C> {
fn create_stream<O: Output<R>>(&mut self, output: O) -> OwnedStream<R, C, O> {
OwnedStream(self.create_renderer(), output)
}
}
impl<R: Resources, C: CommandBuffer<R>>
StreamFactory<R, C> for RenderFactory<R, C> {}