rendy_graph/node/render/group/
mod.rs1mod simple;
2
3pub use self::simple::*;
4
5use {
6 crate::{
7 command::{QueueId, RenderPassEncoder},
8 factory::Factory,
9 graph::GraphContext,
10 node::{
11 render::{pass::SubpassBuilder, PrepareResult},
12 BufferAccess, DescBuilder, ImageAccess, NodeBuffer, NodeImage,
13 },
14 BufferId, ImageId, NodeId,
15 },
16 rendy_core::hal::Backend,
17};
18
19pub trait RenderGroupDesc<B: Backend, T: ?Sized>: std::fmt::Debug {
21 fn builder(self) -> DescBuilder<B, T, Self>
23 where
24 Self: Sized,
25 {
26 DescBuilder {
27 desc: self,
28 buffers: Vec::new(),
29 images: Vec::new(),
30 dependencies: Vec::new(),
31 marker: std::marker::PhantomData,
32 }
33 }
34
35 fn buffers(&self) -> Vec<BufferAccess> {
37 Vec::new()
38 }
39
40 fn images(&self) -> Vec<ImageAccess> {
42 Vec::new()
43 }
44
45 fn colors(&self) -> usize {
47 1
48 }
49
50 fn depth(&self) -> bool {
52 true
53 }
54
55 fn build<'a>(
57 self,
58 ctx: &GraphContext<B>,
59 factory: &mut Factory<B>,
60 queue: QueueId,
61 aux: &T,
62 framebuffer_width: u32,
63 framebuffer_height: u32,
64 subpass: rendy_core::hal::pass::Subpass<'_, B>,
65 buffers: Vec<NodeBuffer>,
66 images: Vec<NodeImage>,
67 ) -> Result<Box<dyn RenderGroup<B, T>>, rendy_core::hal::pso::CreationError>;
68}
69
70pub trait RenderGroup<B: Backend, T: ?Sized>: std::fmt::Debug + Send + Sync {
72 fn prepare(
74 &mut self,
75 factory: &Factory<B>,
76 queue: QueueId,
77 index: usize,
78 subpass: rendy_core::hal::pass::Subpass<'_, B>,
79 aux: &T,
80 ) -> PrepareResult;
81
82 fn draw_inline(
84 &mut self,
85 encoder: RenderPassEncoder<'_, B>,
86 index: usize,
87 subpass: rendy_core::hal::pass::Subpass<'_, B>,
88 aux: &T,
89 );
90
91 fn dispose(self: Box<Self>, factory: &mut Factory<B>, aux: &T);
93}
94
95pub trait RenderGroupBuilder<B: Backend, T: ?Sized>: std::fmt::Debug {
97 fn into_subpass(self) -> SubpassBuilder<B, T>
99 where
100 Self: Sized + 'static,
101 {
102 SubpassBuilder::new().with_group(self)
103 }
104
105 fn colors(&self) -> usize;
107
108 fn depth(&self) -> bool;
110
111 fn buffers(&self) -> Vec<(BufferId, BufferAccess)>;
113
114 fn images(&self) -> Vec<(ImageId, ImageAccess)>;
116
117 fn dependencies(&self) -> Vec<NodeId>;
119
120 fn build<'a>(
122 self: Box<Self>,
123 ctx: &GraphContext<B>,
124 factory: &mut Factory<B>,
125 queue: QueueId,
126 aux: &T,
127 framebuffer_width: u32,
128 framebuffer_height: u32,
129 subpass: rendy_core::hal::pass::Subpass<'_, B>,
130 buffers: Vec<NodeBuffer>,
131 images: Vec<NodeImage>,
132 ) -> Result<Box<dyn RenderGroup<B, T>>, rendy_core::hal::pso::CreationError>;
133}
134
135impl<B, T, D> RenderGroupBuilder<B, T> for DescBuilder<B, T, D>
136where
137 B: Backend,
138 T: ?Sized,
139 D: RenderGroupDesc<B, T>,
140{
141 fn colors(&self) -> usize {
142 self.desc.colors()
143 }
144
145 fn depth(&self) -> bool {
146 self.desc.depth()
147 }
148
149 fn buffers(&self) -> Vec<(BufferId, BufferAccess)> {
150 self.buffers
151 .iter()
152 .cloned()
153 .zip(self.desc.buffers())
154 .collect()
155 }
156
157 fn images(&self) -> Vec<(ImageId, ImageAccess)> {
158 self.images
159 .iter()
160 .cloned()
161 .zip(self.desc.images())
162 .collect()
163 }
164
165 fn dependencies(&self) -> Vec<NodeId> {
166 self.dependencies.clone()
167 }
168
169 fn build<'a>(
170 self: Box<Self>,
171 ctx: &GraphContext<B>,
172 factory: &mut Factory<B>,
173 queue: QueueId,
174 aux: &T,
175 framebuffer_width: u32,
176 framebuffer_height: u32,
177 subpass: rendy_core::hal::pass::Subpass<'_, B>,
178 buffers: Vec<NodeBuffer>,
179 images: Vec<NodeImage>,
180 ) -> Result<Box<dyn RenderGroup<B, T>>, rendy_core::hal::pso::CreationError> {
181 self.desc.build(
182 ctx,
183 factory,
184 queue,
185 aux,
186 framebuffer_width,
187 framebuffer_height,
188 subpass,
189 buffers,
190 images,
191 )
192 }
193}