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
use gfx;
use mopa;
pub trait Target: mopa::Any {}
mopafy!(Target);
pub type ColorFormat = gfx::format::Rgba8;
pub type DepthFormat = gfx::format::DepthStencil;
pub struct ColorBuffer<R: gfx::Resources> {
pub color: gfx::handle::RenderTargetView<R, ColorFormat>,
pub output_depth: gfx::handle::DepthStencilView<R, DepthFormat>,
}
impl<R: gfx::Resources> Target for ColorBuffer<R> {}
pub struct GeometryBuffer<R: gfx::Resources> {
pub normal: gfx::handle::RenderTargetView<R, [f32; 4]>,
pub ka: gfx::handle::RenderTargetView<R, ColorFormat>,
pub kd: gfx::handle::RenderTargetView<R, ColorFormat>,
pub ks: gfx::handle::RenderTargetView<R, ColorFormat>,
pub depth: gfx::handle::DepthStencilView<R, DepthFormat>,
pub texture_normal: gfx::handle::ShaderResourceView<R, [f32; 4]>,
pub texture_ka: gfx::handle::ShaderResourceView<R, [f32; 4]>,
pub texture_kd: gfx::handle::ShaderResourceView<R, [f32; 4]>,
pub texture_ks: gfx::handle::ShaderResourceView<R, [f32; 4]>,
pub texture_depth: gfx::handle::ShaderResourceView<R, f32>,
}
impl<R: gfx::Resources> GeometryBuffer<R> {
pub fn new<F>(factory: &mut F, (width, height): (u16, u16)) -> Self
where F: gfx::Factory<R>
{
let (_, texture_normal, normal) = factory.create_render_target(width, height).unwrap();
let (_, texture_ka, ka) = factory.create_render_target(width, height).unwrap();
let (_, texture_kd, kd) = factory.create_render_target(width, height).unwrap();
let (_, texture_ks, ks) = factory.create_render_target(width, height).unwrap();
let (_, texture_depth, depth) = factory.create_depth_stencil(width, height).unwrap();
GeometryBuffer {
normal: normal,
ka: ka,
kd: kd,
ks: ks,
depth: depth,
texture_normal: texture_normal,
texture_ka: texture_ka,
texture_kd: texture_kd,
texture_ks: texture_ks,
texture_depth: texture_depth,
}
}
}
impl<R: gfx::Resources> Target for GeometryBuffer<R> {}