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