mod simple;
pub use self::simple::*;
use {
crate::{
command::{QueueId, RenderPassEncoder},
factory::Factory,
graph::GraphContext,
node::{
render::{pass::SubpassBuilder, PrepareResult},
BufferAccess, DescBuilder, ImageAccess, NodeBuffer, NodeImage,
},
BufferId, ImageId, NodeId,
},
rendy_core::hal::Backend,
};
pub trait RenderGroupDesc<B: Backend, T: ?Sized>: std::fmt::Debug {
fn builder(self) -> DescBuilder<B, T, Self>
where
Self: Sized,
{
DescBuilder {
desc: self,
buffers: Vec::new(),
images: Vec::new(),
dependencies: Vec::new(),
marker: std::marker::PhantomData,
}
}
fn buffers(&self) -> Vec<BufferAccess> {
Vec::new()
}
fn images(&self) -> Vec<ImageAccess> {
Vec::new()
}
fn colors(&self) -> usize {
1
}
fn depth(&self) -> bool {
true
}
fn build<'a>(
self,
ctx: &GraphContext<B>,
factory: &mut Factory<B>,
queue: QueueId,
aux: &T,
framebuffer_width: u32,
framebuffer_height: u32,
subpass: rendy_core::hal::pass::Subpass<'_, B>,
buffers: Vec<NodeBuffer>,
images: Vec<NodeImage>,
) -> Result<Box<dyn RenderGroup<B, T>>, rendy_core::hal::pso::CreationError>;
}
pub trait RenderGroup<B: Backend, T: ?Sized>: std::fmt::Debug + Send + Sync {
fn prepare(
&mut self,
factory: &Factory<B>,
queue: QueueId,
index: usize,
subpass: rendy_core::hal::pass::Subpass<'_, B>,
aux: &T,
) -> PrepareResult;
fn draw_inline(
&mut self,
encoder: RenderPassEncoder<'_, B>,
index: usize,
subpass: rendy_core::hal::pass::Subpass<'_, B>,
aux: &T,
);
fn dispose(self: Box<Self>, factory: &mut Factory<B>, aux: &T);
}
pub trait RenderGroupBuilder<B: Backend, T: ?Sized>: std::fmt::Debug {
fn into_subpass(self) -> SubpassBuilder<B, T>
where
Self: Sized + 'static,
{
SubpassBuilder::new().with_group(self)
}
fn colors(&self) -> usize;
fn depth(&self) -> bool;
fn buffers(&self) -> Vec<(BufferId, BufferAccess)>;
fn images(&self) -> Vec<(ImageId, ImageAccess)>;
fn dependencies(&self) -> Vec<NodeId>;
fn build<'a>(
self: Box<Self>,
ctx: &GraphContext<B>,
factory: &mut Factory<B>,
queue: QueueId,
aux: &T,
framebuffer_width: u32,
framebuffer_height: u32,
subpass: rendy_core::hal::pass::Subpass<'_, B>,
buffers: Vec<NodeBuffer>,
images: Vec<NodeImage>,
) -> Result<Box<dyn RenderGroup<B, T>>, rendy_core::hal::pso::CreationError>;
}
impl<B, T, D> RenderGroupBuilder<B, T> for DescBuilder<B, T, D>
where
B: Backend,
T: ?Sized,
D: RenderGroupDesc<B, T>,
{
fn colors(&self) -> usize {
self.desc.colors()
}
fn depth(&self) -> bool {
self.desc.depth()
}
fn buffers(&self) -> Vec<(BufferId, BufferAccess)> {
self.buffers
.iter()
.cloned()
.zip(self.desc.buffers())
.collect()
}
fn images(&self) -> Vec<(ImageId, ImageAccess)> {
self.images
.iter()
.cloned()
.zip(self.desc.images())
.collect()
}
fn dependencies(&self) -> Vec<NodeId> {
self.dependencies.clone()
}
fn build<'a>(
self: Box<Self>,
ctx: &GraphContext<B>,
factory: &mut Factory<B>,
queue: QueueId,
aux: &T,
framebuffer_width: u32,
framebuffer_height: u32,
subpass: rendy_core::hal::pass::Subpass<'_, B>,
buffers: Vec<NodeBuffer>,
images: Vec<NodeImage>,
) -> Result<Box<dyn RenderGroup<B, T>>, rendy_core::hal::pso::CreationError> {
self.desc.build(
ctx,
factory,
queue,
aux,
framebuffer_width,
framebuffer_height,
subpass,
buffers,
images,
)
}
}