TexturePool

Struct TexturePool 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn len(&self) -> usize

Number of user textures (excludes the fallback).

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,