Module texture_pool

Module texture_pool 

Source
Expand description

User-loaded texture pool for the comp pass.

MilkDrop 2 lets preset authors reference image files on disk via sampler sampler_<NAME>; declarations in the comp shader, then sample them through tex2D(sampler_<NAME>, uv). The image filename (stem) becomes the sampler name — clouds.pngsampler_clouds. Authors also reference sampler_rand00..15 to pull a deterministic-per-preset random texture from whatever’s on disk, optionally filtered by name prefix (sampler_rand02_smalltiled → only smalltiled*.png).

This module owns the disk-loaded GPU textures. The comp pipeline reads through it at preset load time to populate the 8 user-texture binding slots. Lookup is by canonicalised name (lowercase stem, no extension); presets in the wild mix case freely (sampler_Worms vs sampler_worms).

Pool population is best-effort:

  • Missing directory → empty pool (engine continues with the fallback 1×1 white texture). Logged once at debug level.
  • Unreadable / undecodable file → skipped with a warn log; rest of the directory loads.
  • Name collisions across directories → first hit wins; later directories only fill gaps. Matches MD2’s “search path” semantics.

Structs§

TexturePool
Texture pool. Hold one per renderer; the comp pipeline borrows it whenever a preset’s user shader needs to bind disk-loaded textures.
UserTexture
One GPU-resident user texture.

Functions§

canonical_stem 🔒
default_texture_dirs
XDG-default search paths for user textures. The renderer’s caller (CLI / GUI) typically extends this with config-driven dirs.
load_texture_file 🔒
make_fallback_texture 🔒
upload_rgba8 🔒