texture freeing + render updates done a bit nicer

This commit is contained in:
2025-08-23 13:02:00 -04:00
parent 5fe63e311c
commit 6fbdf9fbc8
10 changed files with 176 additions and 108 deletions

27
src/util/refcount.rs Normal file
View File

@@ -0,0 +1,27 @@
use std::sync::{
Arc,
atomic::{AtomicU32, Ordering},
mpsc::Sender,
};
pub struct RefCounter(Arc<AtomicU32>);
impl RefCounter {
pub fn new() -> Self {
Self(Arc::new(0.into()))
}
pub fn refs(&self) -> u32 {
self.0.load(Ordering::Acquire)
}
pub fn drop(&mut self) -> bool {
let refs = self.0.fetch_sub(1, Ordering::Release);
refs == 0
}
}
impl Clone for RefCounter {
fn clone(&self) -> Self {
self.0.fetch_add(1, Ordering::Release);
Self(self.0.clone())
}
}