#include "gl.h"
#include "resources.h"
#include "texturing.h"
+#include "uniform.h"
using namespace std;
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<const Uniform1i *>(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);
}
return *uniforms[i].value;
}
+const Uniform *ProgramData::find_uniform(const string &name) const
+{
+ int i = find_uniform_index(name);
+ return (i>=0 ? uniforms[i].value : 0);
+}
+
bool ProgramData::uniform_name_compare(const NamedUniform &nu, const string &name)
{
return nu.name<name;
std::vector<std::string> get_uniform_names() const;
const Uniform &get_uniform(const std::string &) const;
+ const Uniform *find_uniform(const std::string &) const;
private:
static bool uniform_name_compare(const NamedUniform &, const std::string &);
public:
UniformScalar(Type v): value(v) { }
+ Type get() const { return value; }
+
virtual void apply(int index) const
{ apply(index, 1, &value); }
UniformVector(const T *vp)
{ std::copy(vp, vp+vecsize, value); }
+ BaseType get(unsigned i) const { return value[i]; }
+
virtual void apply(int index) const
{ apply(index, 1, value); }