pub struct ResourceRegistry { /* private fields */ }Expand description
Shared registry of GPU textures and shaders, with generation-checked handles and reference counting.
Slots are recycled via a free list when their reference count reaches zero. The generation counter prevents stale handles from aliasing new allocations.
Implementations§
Source§impl ResourceRegistry
impl ResourceRegistry
Sourcepub fn alloc_texture(&mut self, name: String) -> TextureHandle
pub fn alloc_texture(&mut self, name: String) -> TextureHandle
Allocate a texture slot with an initial reference count of 1.
Sourcepub fn retain_texture(&mut self, h: TextureHandle) -> bool
pub fn retain_texture(&mut self, h: TextureHandle) -> bool
Increment the reference count of h.
Returns false if the handle is stale (generation mismatch or
out-of-bounds); returns true on success.
Sourcepub fn release_texture(&mut self, h: TextureHandle)
pub fn release_texture(&mut self, h: TextureHandle)
Decrement the reference count of h.
When the count reaches zero the slot’s generation is bumped and the slot is pushed onto the free list for reuse. Stale or already-freed handles are silently ignored.
Sourcepub fn get_texture(&self, h: TextureHandle) -> Option<&str>
pub fn get_texture(&self, h: TextureHandle) -> Option<&str>
Return the name associated with h, or None if stale.
Sourcepub fn alloc_shader(&mut self, name: String) -> ShaderHandle
pub fn alloc_shader(&mut self, name: String) -> ShaderHandle
Allocate a shader slot with an initial reference count of 1.
Sourcepub fn retain_shader(&mut self, h: ShaderHandle) -> bool
pub fn retain_shader(&mut self, h: ShaderHandle) -> bool
Increment the reference count of h.
Returns false if the handle is stale; returns true on success.
Sourcepub fn release_shader(&mut self, h: ShaderHandle)
pub fn release_shader(&mut self, h: ShaderHandle)
Decrement the reference count of h.
When the count reaches zero the slot is freed and the generation is bumped. Stale handles are silently ignored.
Sourcepub fn get_shader(&self, h: ShaderHandle) -> Option<&str>
pub fn get_shader(&self, h: ShaderHandle) -> Option<&str>
Return the name associated with h, or None if stale.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ResourceRegistry
impl RefUnwindSafe for ResourceRegistry
impl Send for ResourceRegistry
impl Sync for ResourceRegistry
impl Unpin for ResourceRegistry
impl UnsafeUnpin for ResourceRegistry
impl UnwindSafe for ResourceRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more