+#include <msp/core/hash.h>
#include "texture.h"
#include "texturing.h"
#include "texunit.h"
unbind();
}
+int Texturing::find_free_unit(const string &name_hint) const
+{
+ unsigned max_unit = TexUnit::get_n_units();
+ // Leave some space for effect textures
+ max_unit -= min(max_unit/4, 8U);
+ unsigned initial_unit = (name_hint.empty() ? 0 : hash32(name_hint)%max_unit);
+ unsigned unit = initial_unit;
+ while(get_attached_texture(unit))
+ {
+ unit = (unit+1)%max_unit;
+ if(unit==initial_unit)
+ return -1;
+ }
+
+ return unit;
+}
+
void Texturing::attach(unsigned attch, const Texture &tex)
{
set_attachment(attch, &tex);