Skip to main content

pebble/graphics/render/
targets.rs

1use crate::graphics::pipeline::texture_view::TextureView;
2
3pub struct ColorTarget<'a> {
4    pub(crate) attachment: Option<&'a TextureView>,
5    pub(crate) clear: [f32; 4]
6}
7
8pub struct ColorTargetBuilder<'a> {
9    target: ColorTarget<'a>
10}
11
12impl<'a> ColorTargetBuilder<'a> {
13    pub fn new() -> Self {
14        Self {
15            target: ColorTarget {
16                attachment: None,
17                clear: [0.0, 0.0, 0.0, 1.0]
18            }
19        }
20    }
21
22    pub fn with_attachment(mut self, view: &'a TextureView) -> Self {
23        self.target.attachment = Some(view);
24        self
25    }
26
27    pub fn with_clear(mut self, clear: [f32; 4]) -> Self {
28        self.target.clear = clear;
29        self
30    }
31
32    pub fn build(self) -> ColorTarget<'a> {
33        self.target
34    }
35}
36
37pub struct DepthTarget<'a> {
38    pub(crate) attachment: &'a TextureView,
39    pub(crate) clear: Option<f32>,
40}
41
42pub struct DepthTargetBuilder<'a> {
43    target: DepthTarget<'a>
44}
45
46impl<'a> DepthTargetBuilder<'a> {
47    pub fn new(view: &'a TextureView) -> Self {
48        Self {
49            target: DepthTarget {
50                attachment: view,
51                clear: Some(1.0)
52            }
53        }
54    }
55
56    pub fn with_clear(mut self, clear: f32) -> Self {
57        self.target.clear = Some(clear);
58        self
59    }
60
61    pub fn build(self) -> DepthTarget<'a> {
62        self.target
63    }
64}
65
66pub struct Pass<'a> {
67    pub(crate) colors: Vec<ColorTarget<'a>>,
68    pub(crate) depth: Option<DepthTarget<'a>>
69}
70
71pub struct PassBuilder<'a> {
72    targets: Vec<ColorTarget<'a>>,
73    depth: Option<DepthTarget<'a>>,
74}
75
76impl<'a> PassBuilder<'a> {
77    pub fn new() -> Self {
78        Self { targets: Vec::new(), depth: None }
79    }
80
81    pub fn with_target(mut self, target: ColorTarget<'a>) -> Self {
82        self.targets.push(target);
83        self
84    }
85
86    pub fn with_depth(mut self, depth: DepthTarget<'a>) -> Self {
87        self.depth = Some(depth);
88        self
89    }
90
91    pub fn build(self) -> Pass<'a> {
92        Pass {
93            colors: self.targets,
94            depth: self.depth,
95        }
96    }
97}