X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftechnique.cpp;h=26837b61533167e0ddc268715f2722aee008272e;hb=927a1aa0a3a27e463ec0efc08bd08e7c4e969909;hp=4d2377a350549e50641c0e045cc6e88f7e8c6374;hpb=be74989b0300adecc0062f701ff987cf79d1935a;p=libs%2Fgl.git diff --git a/source/technique.cpp b/source/technique.cpp index 4d2377a3..26837b61 100644 --- a/source/technique.cpp +++ b/source/technique.cpp @@ -5,6 +5,8 @@ Copyright © 2007 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ +#include +#include #include #include "material.h" #include "program.h" @@ -26,18 +28,18 @@ Technique::Technique(): Technique::~Technique() { - for(map::iterator i=passes.begin(); i!=passes.end(); ++i) + for(PassMap::iterator i=passes.begin(); i!=passes.end(); ++i) delete i->second.shdata; } bool Technique::has_pass(const GL::Tag &tag) const { - return passes.count(tag.id); + return passes.count(tag); } const ObjectPass &Technique::get_pass(const GL::Tag &tag) const { - map::const_iterator i=passes.find(tag.id); + PassMap::const_iterator i=passes.find(tag); if(i==passes.end()) throw KeyError("Unknown pass"); return i->second; @@ -45,8 +47,8 @@ const ObjectPass &Technique::get_pass(const GL::Tag &tag) const unsigned Technique::get_texture_index(const std::string &n) const { - for(unsigned i=0; i=textures.size()) throw KeyError("Texture index out of range"); - return textures[i]; + return textures[i].texture; } Technique::Loader::Loader(Technique &t, Collection &c): - tech(t), - coll(c) + DataFile::CollectionObjectLoader(t, &c) { add("material", &Technique::material); add("material_inline", &Loader::material_inline); @@ -76,11 +77,14 @@ Technique::Loader::Loader(Technique &t, Collection &c): void Technique::Loader::finish() { - for(map::iterator i=tech.passes.begin(); i!=tech.passes.end(); ++i) + for(PassMap::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i) if(i->second.shdata) { - for(unsigned j=0; jsecond.shdata->uniform(i->second.shprog->get_uniform_location(tech.tex_names[j]), static_cast(j)); + for(unsigned j=0; jsecond.shprog->get_uniform_location(obj.textures[j].name); + i->second.shdata->uniform(loc, static_cast(j)); + } } } @@ -88,64 +92,73 @@ void Technique::Loader::material_inline() { RefPtr mat=new Material; load_sub(*mat); - coll.add(format("_%p", mat.get()), mat.get()); - tech.material=mat.release(); + coll->add(format("_%p", mat.get()), mat.get()); + obj.material=mat.release(); } void Technique::Loader::pass(const string &n) { - unsigned id=Tag(n).id; - if(tech.passes.count(id)) + Tag tag(n); + if(obj.passes.count(tag)) throw KeyError("Duplicate pass name", n); ObjectPass p; - load_sub(p, coll); - tech.passes[id]=p; + load_sub(p, *coll); + obj.passes[tag]=p; } void Technique::Loader::shader(const string &n) { - Program *shprog=coll.get(n); + Program *shprog=coll->get(n); if(shprog) // Allow for unsupported shaders { RefPtr shdata=new ProgramData; load_sub(*shdata, *shprog); - tech.normal_pass->shprog=shprog; - if(tech.normal_pass->shdata) - delete tech.normal_pass->shdata; - tech.normal_pass->shdata=shdata.release(); + obj.normal_pass->shprog=shprog; + if(obj.normal_pass->shdata) + delete obj.normal_pass->shdata; + obj.normal_pass->shdata=shdata.release(); } } void Technique::Loader::shader_texture(const string &n) { - unsigned eqsign=n.find('='); + string::size_type eqsign=n.find('='); + TextureSlot tex; if(eqsign!=string::npos) { - tech.textures.push_back(coll.get(n.substr(eqsign+1))); - tech.tex_names.push_back(n.substr(0, eqsign)); + tex.name=n.substr(0, eqsign); + tex.texture=coll->get(n.substr(eqsign+1)); } else { - tech.textures.push_back(coll.get(n)); - tech.tex_names.push_back(n); + string::size_type dot=n.rfind('.'); + tex.name=n.substr(0, dot); + tex.texture = coll->get(n); } + for(string::iterator i=tex.name.begin(); i!=tex.name.end(); ++i) + if(!isalnum(*i)) + *i='_'; + obj.textures.push_back(tex); } void Technique::Loader::texture(const string &n) { - if(tech.main_texture) + if(obj.main_texture) throw Exception("Only one main texture may be specified"); - tech.main_texture=coll.get(n); - tech.textures.push_back(tech.main_texture); - tech.tex_names.push_back("texture"); + obj.main_texture=coll->get(n); + TextureSlot tex; + tex.name="texture"; + tex.texture=obj.main_texture; + obj.textures.push_back(tex); } void Technique::Loader::texture_slot(const string &n) { - tech.tex_names.push_back(n); - tech.textures.push_back(0); + TextureSlot tex; + tex.name=n; + obj.textures.push_back(tex); } } // namespace GL