pub struct TexturePool {
textures: Vec<Arc<UserTexture>>,
by_name: HashMap<String, usize>,
fallback: Arc<UserTexture>,
}Expand description
Texture pool. Hold one per renderer; the comp pipeline borrows it whenever a preset’s user shader needs to bind disk-loaded textures.
Fields§
§textures: Vec<Arc<UserTexture>>All loaded textures in disk-walk order. The order is stable across
runs as long as the underlying filesystem returns the same listing —
used by pick_rand to make sampler_rand0X deterministic.
by_name: HashMap<String, usize>Lookup by canonicalised name.
fallback: Arc<UserTexture>1×1 opaque white. Bound into unfilled slots and returned when a preset references a name that isn’t on disk. Keeps every user shader compileable + drawable even when the texture pool is empty.
Implementations§
Source§impl TexturePool
impl TexturePool
Sourcepub fn new(device: &Device, queue: &Queue) -> Self
pub fn new(device: &Device, queue: &Queue) -> Self
Build a pool with only the 1×1 white fallback. Tests and headless CI
paths use this; the real engine calls from_dirs after.
Sourcepub fn from_dirs(device: &Device, queue: &Queue, dirs: &[PathBuf]) -> Self
pub fn from_dirs(device: &Device, queue: &Queue, dirs: &[PathBuf]) -> Self
Build a pool by scanning each directory in dirs for image files.
Earlier directories shadow later ones — pass user dirs before system
dirs if you want overrides.
Decode errors are logged and the offending file skipped; missing directories are silently treated as empty.
Sourcepub fn scan_dir(&mut self, device: &Device, queue: &Queue, dir: &Path)
pub fn scan_dir(&mut self, device: &Device, queue: &Queue, dir: &Path)
Append textures from one directory. Doesn’t recurse — flat layout
matches MD2’s Textures/ convention.
Sourcepub fn get(&self, name: &str) -> Option<&Arc<UserTexture>>
pub fn get(&self, name: &str) -> Option<&Arc<UserTexture>>
Lookup by canonicalised name. name is compared against the lowercase
stem of the source filename — get("clouds") matches both
clouds.png and Clouds.PNG.
Sourcepub fn fallback(&self) -> &Arc<UserTexture>
pub fn fallback(&self) -> &Arc<UserTexture>
Always-non-None fallback — bound into unfilled user-texture slots so the comp pass’s bind group is complete even when the pool is empty or a preset references a name we don’t have.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
true when the pool has no user textures (only the fallback). The
renderer uses this to skip the disk-load scan path entirely on
sampler_rand0X resolution.
Sourcepub fn pick_rand(
&self,
seed: u64,
prefix: Option<&str>,
) -> Option<&Arc<UserTexture>>
pub fn pick_rand( &self, seed: u64, prefix: Option<&str>, ) -> Option<&Arc<UserTexture>>
Deterministic-per-seed pick from the pool, optionally filtered by
name prefix. Returns None when no texture matches (caller can
substitute the fallback).
MD2’s sampler_rand0X slots want a stable choice for the lifetime
of a preset but a different choice across presets. The caller seeds
with hash(preset_name) ^ slot_index to achieve that.
Auto Trait Implementations§
impl Freeze for TexturePool
impl !RefUnwindSafe for TexturePool
impl Send for TexturePool
impl Sync for TexturePool
impl Unpin for TexturePool
impl !UnwindSafe for TexturePool
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
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