I'd be interested in hearing what results you get with this. My renderer already does a pretty good job of minimizing texture switches, but if you are just chucking textures at the GPU, this could make a big difference:
http://blitzmax.com/codearcs/codearcs.php?code=2147
http://blitzmax.com/codearcs/codearcs.php?code=2147