add("material_slot", &RenderPass::material_slot);
add("back_faces",&RenderPass::back_faces);
add("texunit", &Loader::texunit);
+ add("texunit", &Loader::texunit_auto);
add("texunit", &Loader::texunit_named);
add("uniforms", &Loader::uniforms);
add("uniform_slot", &Loader::uniform_slot);
load_sub_with(ldr);
}
+void RenderPass::Loader::texunit_auto(const string &n)
+{
+ if(!obj.texturing)
+ obj.texturing = new Texturing;
+ int i = obj.texturing->find_free_unit(n);
+ if(i<0)
+ throw runtime_error("no free texunit");
+ texunit_named(i, n);
+}
+
void RenderPass::Loader::texunit_named(unsigned i, const string &n)
{
texunit(i);
private:
void init();
+
void material_inline();
void material(const std::string &);
void texunit(unsigned);
+ void texunit_auto(const std::string &);
void texunit_named(unsigned, const std::string &);
void uniforms();
void uniform_slot(const std::string &);
+#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);
public:
~Texturing();
+ int find_free_unit(const std::string & = std::string()) const;
void attach(unsigned, const Texture &);
void detach(unsigned);
private: