shprog(other.shprog),
shdata(other.shdata ? new ProgramData(*other.shdata) : 0),
material(other.material),
- texturing(other.texturing ? new Texturing(*other.texturing) : 0)
+ texturing(other.texturing ? new Texturing(*other.texturing) : 0),
+ tex_names(other.tex_names)
{ }
RenderPass::~RenderPass()
texturing->attach(index, *tex);
}
+int RenderPass::get_texture_index(const string &n) const
+{
+ map<string, unsigned>::const_iterator i = tex_names.find(n);
+ if(i==tex_names.end())
+ return -1;
+ return i->second;
+}
+
RenderPass::Loader::Loader(RenderPass &p):
DataFile::CollectionObjectLoader<RenderPass>(p, 0)
add("material", &Loader::material_inline);
add("material", &Loader::material);
add("texunit", &Loader::texunit);
+ add("texunit", &Loader::texunit_named);
add("uniforms", &Loader::uniforms);
}
load_sub_with(ldr);
}
+void RenderPass::Loader::texunit_named(unsigned i, const string &n)
+{
+ texunit(i);
+ obj.tex_names[n] = i;
+}
+
void RenderPass::Loader::uniforms()
{
if(!obj.shprog)
void material_inline();
void material(const std::string &);
void texunit(unsigned);
+ void texunit_named(unsigned, const std::string &);
void uniforms();
};
ProgramData *shdata;
RefPtr<const Material> material;
Texturing *texturing;
+ std::map<std::string, unsigned> tex_names;
RenderPass &operator=(const RenderPass &);
public:
const Material *get_material() const { return material.get(); }
void set_texture(unsigned, const Texture *);
const Texturing *get_texturing() const { return texturing; }
+ int get_texture_index(const std::string &) const;
};
} // namespace GL
/* $Id$
This file is part of libmspgl
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2008-2011 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
add("texture", &InheritLoader::texture);
}
-void Technique::InheritLoader::texture(unsigned index, const string &name)
+void Technique::InheritLoader::texture(const std::string &slot, const string &name)
{
Texture *tex = get_collection().get<Texture>(name);
for(PassMap::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i)
{
- try
- {
- i->second.set_texture(index, tex);
- }
- catch(const KeyError &)
- { }
+ int index = i->second.get_texture_index(slot);
+ if(index<0)
+ continue;
+ i->second.set_texture(index, tex);
}
}
/* $Id$
This file is part of libmspgl
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2008-2011 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
InheritLoader(Technique &, Collection &);
private:
- void texture(unsigned, const std::string &);
+ void texture(const std::string &, const std::string &);
};
typedef std::map<Tag, RenderPass> PassMap;