gloss_renderer/forward_renderer/render_platform/
bind_group_collection.rs1use std::collections::HashMap;
2
3use easy_wgpu::{
4 bind_group::{BindGroupDesc, BindGroupWrapper},
5 bind_group_layout::BindGroupLayoutDesc,
6 buffer::Buffer,
7 gpu::Gpu,
8};
9use gloss_hecs::Entity;
10use smallvec::SmallVec;
11use wgpu::BindGroupLayout;
12
13use crate::scene::Scene;
14
15pub trait BindGroupCollection {
18 fn new(gpu: &Gpu) -> Self;
19 fn build_layout_desc() -> BindGroupLayoutDesc;
20
21 fn update_if_stale(&mut self, ent_name: &str, entries: SmallVec<[wgpu::BindGroupEntry<'_>; 16]>, offset_in_ubo: u32, gpu: &Gpu) {
22 if !self.get_mut_entity2binds().contains_key(ent_name) || self.get_mut_entity2binds()[ent_name].0.is_stale(&entries) {
25 let bg = BindGroupDesc::new("local_bg", entries).into_bind_group_wrapper(gpu.device(), self.get_layout());
26 let bg_and_offset = (bg, offset_in_ubo);
27 self.get_mut_entity2binds().insert(ent_name.to_string(), bg_and_offset);
28 }
29
30 self.get_mut_entity2binds()
33 .entry(ent_name.to_string())
34 .and_modify(|r| r.1 = offset_in_ubo);
35 }
36 fn update_bind_group(&mut self, _entity: Entity, gpu: &Gpu, mesh_name: &str, ubo: &Buffer, offset_in_ubo: u32, _scene: &Scene);
37
38 fn get_layout(&self) -> &BindGroupLayout;
40 fn get_mut_entity2binds(&mut self) -> &mut HashMap<String, (BindGroupWrapper, u32)>;
41}