Rework texture generating code, add texture grouping

What does this variable hold?  The code isn't self-describing.