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
pub mod forward;
pub mod deferred;

use std;
use gfx;
use mopa;

/// A `Pass` is an implementation of a Pass
pub trait Pass<R>
    where R: gfx::Resources
{
    /// The argument required for the Pass
    type Arg: ::PassDescription;
    /// The render Target
    type Target: ::Target;

    /// encode the pass into the encoder using the supplied argument
    /// frame and render target
    fn apply<C>(&self,
                arg: &Self::Arg,
                target: &Self::Target,
                pipeline: &::Pipeline,
                scene: &::Scene<R>,
                encoder: &mut gfx::Encoder<R, C>)
        where C: gfx::CommandBuffer<R>;
}

#[derive(Clone, Debug)]
/// Clear the frame buffer
pub struct Clear {
    /// the color to clear with
    pub color: [f32; 4],
}
impl PassDescription for Clear {}

impl Clear {
    /// Create a new boxed Clear Description
    pub fn new(color: [f32; 4]) -> Box<PassDescription> {
        Box::new(Clear { color: color })
    }
}

#[derive(Clone, Debug)]
/// Render the scene as a wireframe
pub struct Wireframe {
    /// The Camera to use
    pub camera: String,
    /// The scene to use
    pub scene: String,
}
impl PassDescription for Wireframe {}

impl Wireframe {
    /// Create a boxed Description of the Writeframe
    pub fn new<A, B>(camera: A, scene: B) -> Box<PassDescription>
        where String: From<A> + From<B>
    {
        Box::new(Wireframe {
            camera: String::from(camera),
            scene: String::from(scene),
        })
    }
}

#[derive(Clone, Debug)]
/// Render into the target without any shading applied
pub struct DrawFlat {
    /// The Camera to use
    pub camera: String,
    /// The scene to use
    pub scene: String,
}
impl PassDescription for DrawFlat {}

impl DrawFlat {
    /// Create a Boxed DrawFlat
    pub fn new<A, B>(camera: A, scene: B) -> Box<PassDescription>
        where String: From<A> + From<B>
    {
        Box::new(DrawFlat {
            camera: String::from(camera),
            scene: String::from(scene),
        })
    }
}

#[derive(Clone, Debug)]
/// Render only the depth layer leaving
/// all other Gbuffer layers unchanged
pub struct DepthPass {
    /// The Camera to use
    pub camera: String,
    /// The scene to use
    pub scene: String,
}

impl PassDescription for DepthPass {}

impl DepthPass {
    /// Create a Boxed DepthPass
    pub fn new<A, B>(camera: A, scene: B) -> Box<PassDescription>
        where String: From<A> + From<B>
    {
        Box::new(DepthPass {
            camera: String::from(camera),
            scene: String::from(scene),
        })
    }
}

#[derive(Clone, Debug)]
/// Render into the target without a standard
/// ambient/diffuse shading
pub struct DrawShaded {
    /// The Camera to use
    pub camera: String,
    /// The scene to use
    pub scene: String,
}
impl PassDescription for DrawShaded {}

impl DrawShaded {
    /// Create a Boxed DrawShaded
    pub fn new<A, B>(camera: A, scene: B) -> Box<PassDescription>
        where String: From<A> + From<B>
    {
        Box::new(DrawShaded {
            camera: String::from(camera),
            scene: String::from(scene),
        })
    }
}

#[derive(Clone, Debug)]
/// Blit a layer of the gbuffer into the target
pub struct BlitLayer {
    /// the gbuffer to blit from
    pub gbuffer: String,
    /// the layer of the buffer to blit from
    /// one of ka, kd or normal
    pub layer: String,
}
impl PassDescription for BlitLayer {}

impl BlitLayer {
    /// Create a boxed BlitLayer
    pub fn new<A, B>(gbuffer: A, layer: B) -> Box<PassDescription>
        where String: From<A> + From<B>
    {
        Box::new(BlitLayer {
            gbuffer: String::from(gbuffer),
            layer: String::from(layer),
        })
    }
}

#[derive(Clone, Debug)]
/// Do a lighting pass
pub struct Lighting {
    /// The Camera to use
    pub camera: String,
    /// The gbuffer to source the data
    pub gbuffer: String,
    /// the scene to get the lights from
    pub scene: String,
}
impl PassDescription for Lighting {}

impl Lighting {
    /// Box the Lighting Pass
    pub fn new<A, B, C>(camera: A, gbuffer: B, scene: C) -> Box<PassDescription>
        where String: From<A> + From<B> + From<C>
    {
        Box::new(Lighting {
            camera: String::from(camera),
            gbuffer: String::from(gbuffer),
            scene: String::from(scene),
        })
    }
}

/// Describes a render pass
pub trait PassDescription: mopa::Any + std::fmt::Debug {}
mopafy!(PassDescription);