use crate::Scene;
use crate::content::identity::MaterialId;
use crate::view::pipelines::{GeometryPass, GeometryPipelines, Variant};
pub(crate) struct Binder<'a> {
pipelines: &'a GeometryPipelines,
kind: GeometryPass,
by_variant: [Option<&'a wgpu::RenderPipeline>; Variant::COUNT],
variant: Option<Variant>,
material: Option<MaterialId>,
}
impl<'a> Binder<'a> {
pub fn new(pipelines: &'a GeometryPipelines, kind: GeometryPass) -> Self {
Self {
pipelines,
kind,
by_variant: [None; Variant::COUNT],
variant: None,
material: None,
}
}
pub fn bind(
&mut self,
pass: &mut wgpu::RenderPass<'_>,
scene: &Scene,
variant: Variant,
material: MaterialId,
) {
if self.variant != Some(variant) {
let pipeline = *self.by_variant[variant.index()]
.get_or_insert_with(|| self.pipelines.get(self.kind, variant));
pass.set_pipeline(pipeline);
self.variant = Some(variant);
}
if self.material != Some(material) {
pass.set_bind_group(2, &scene.drawn_material(material).group, &[]);
self.material = Some(material);
}
}
pub fn forget_pipeline(&mut self) {
self.variant = None;
}
}