X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmaterial.cpp;h=b0f62bbc5fbef9f1d07b7bcfd4b688135394c32e;hb=4af69ec90120a0be828a1ae475a38674087110b5;hp=8bd6e54ca51b4bf1a48d5b86c07da3fe075d76c5;hpb=ed7ca8892daceebb963950945fed5e75bd96a8a1;p=libs%2Fgl.git diff --git a/source/material.cpp b/source/material.cpp index 8bd6e54c..b0f62bbc 100644 --- a/source/material.cpp +++ b/source/material.cpp @@ -2,6 +2,7 @@ #include "gl.h" #include "resources.h" #include "texturing.h" +#include "uniform.h" using namespace std; @@ -13,9 +14,17 @@ void Material::attach_texture_to(const Texture *tex, Texturing &texturing, Progr if(!tex) return; - int unit = texturing.find_free_unit(name); + int unit = -1; + + if(const Uniform *uni = tex_shdata.find_uniform(name)) + if(const Uniform1i *uni_int = dynamic_cast(uni)) + unit = uni_int->get(); + + if(unit<0) + unit = texturing.find_free_unit(name); if(unit<0) throw runtime_error("no free texunit"); + texturing.attach(unit, *tex); tex_shdata.uniform(name, unit); }