use crate::resources::GpuMesh;
use crate::resources::handle::SlotStore;
crate::resources::handle::slot_handle! {
pub struct MeshId;
}
pub(crate) struct MeshStore {
store: SlotStore<GpuMesh, MeshId>,
}
impl MeshStore {
pub fn new() -> Self {
Self {
store: SlotStore::default(),
}
}
pub fn insert(&mut self, mesh: GpuMesh) -> MeshId {
let bytes = mesh.gpu_byte_size();
self.store.insert(mesh, bytes)
}
pub fn get(&self, id: MeshId) -> Option<&GpuMesh> {
self.store.get(id)
}
pub fn get_mut(&mut self, id: MeshId) -> Option<&mut GpuMesh> {
self.store.get_mut(id)
}
pub fn replace(&mut self, id: MeshId, mesh: GpuMesh) -> crate::error::ViewportResult<()> {
let bytes = mesh.gpu_byte_size();
match self.store.replace(id, mesh, bytes) {
Some(_) => Ok(()),
None => Err(crate::error::ViewportError::SlotEmpty { index: id.index() }),
}
}
pub fn remove(&mut self, id: MeshId) -> bool {
self.store.remove(id).is_some()
}
pub fn len(&self) -> usize {
self.store.len()
}
pub fn slot_count(&self) -> usize {
self.store.slot_count()
}
pub fn allocated_bytes(&self) -> u64 {
self.store.allocated_bytes()
}
pub fn contains(&self, id: MeshId) -> bool {
self.store.contains(id)
}
pub fn iter_mut(&mut self) -> impl Iterator<Item = (MeshId, &mut GpuMesh)> {
self.store.iter_mut()
}
}