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
use std::ops;
use device;
use render::{batch, Renderer, RenderFactory};
use render::shade::ShaderParam;
pub struct Graphics<D: device::Device, F> {
pub device: D,
pub factory: F,
pub renderer: Renderer<D::Resources, D::CommandBuffer>,
context: batch::Context<D::Resources>,
}
impl<D: device::Device, F> ops::Deref for Graphics<D, F> {
type Target = batch::Context<D::Resources>;
fn deref(&self) -> &batch::Context<D::Resources> {
&self.context
}
}
impl<D: device::Device, F> ops::DerefMut for Graphics<D, F> {
fn deref_mut(&mut self) -> &mut batch::Context<D::Resources> {
&mut self.context
}
}
impl<D: device::Device, F: device::Factory<D::Resources>> Graphics<D, F> {
pub fn clear<O: ::Output<D::Resources>>(&mut self,
data: ::ClearData, mask: ::Mask, out: &O) {
self.renderer.clear(data, mask, out)
}
pub fn draw<'a,
T: ShaderParam<Resources = D::Resources>,
O: ::Output<D::Resources>,
>(
&'a mut self, batch: &'a batch::RefBatch<T>, out: &O)
-> Result<(), ::DrawError<batch::OutOfBounds>>
{
self.renderer.draw(&(batch, &self.context), out)
}
pub fn draw_core<'a,
T: ShaderParam<Resources = D::Resources>,
O: ::Output<D::Resources>,
>(
&'a mut self, core: &'a batch::CoreBatch<T>, slice: &'a ::Slice<D::Resources>,
params: &'a T, out: &O) -> Result<(), ::DrawError<batch::OutOfBounds>>
{
self.renderer.draw(&self.context.bind(core, slice, params), out)
}
pub fn end_frame(&mut self) {
self.device.submit(self.renderer.as_buffer());
self.renderer.reset();
}
pub fn cleanup(&mut self) {
self.device.after_frame();
self.factory.cleanup();
}
}
pub trait DeviceExt<D: device::Device, F> {
fn into_graphics(mut self) -> Graphics<D, F>;
}
impl<
D: device::Device,
F: device::Factory<D::Resources>,
> DeviceExt<D, F> for (D, F) {
fn into_graphics(mut self) -> Graphics<D, F> {
let rend = self.1.create_renderer();
Graphics {
device: self.0,
factory: self.1,
renderer: rend,
context: batch::Context::new(),
}
}
}