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
use crate::definition::*;
use crate::core::*;
pub struct PhongForwardPipeline {
context: Context,
depth_texture: Option<DepthTargetTexture2D>
}
impl PhongForwardPipeline {
pub fn new(context: &Context) -> Result<Self, Error>
{
Ok(Self {
context: context.clone(),
depth_texture: Some(DepthTargetTexture2D::new(context, 1, 1,Wrapping::ClampToEdge,
Wrapping::ClampToEdge, DepthFormat::Depth32F)?)
})
}
pub fn depth_pass<F: FnOnce() -> Result<(), Error>>(&mut self, width: usize, height: usize, render_scene: F) -> Result<(), Error>
{
self.depth_texture = Some(DepthTargetTexture2D::new(&self.context, width, height,Wrapping::ClampToEdge,
Wrapping::ClampToEdge, DepthFormat::Depth32F)?);
RenderTarget::new_depth(&self.context,self.depth_texture.as_ref().unwrap())?
.write(&ClearState::depth(1.0), render_scene)?;
Ok(())
}
pub fn depth_texture(&self) -> &dyn Texture
{
self.depth_texture.as_ref().unwrap()
}
}