X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fmaterials%2Ftechnique.cpp;h=163cbec60f0003245631fca2f503a9cdfc0cea5c;hp=ef1764112c4f3de6b98a2310ce67b84267e34e9d;hb=HEAD;hpb=e9a898f315b5d1396f196d785913a283c30940f2 diff --git a/source/materials/technique.cpp b/source/materials/technique.cpp index ef176411..163cbec6 100644 --- a/source/materials/technique.cpp +++ b/source/materials/technique.cpp @@ -3,9 +3,7 @@ #include #include #include "material.h" -#include "program.h" #include "programdata.h" -#include "tag.h" #include "technique.h" #include "texture.h" @@ -14,31 +12,31 @@ using namespace std; namespace Msp { namespace GL { -RenderPass &Technique::add_pass(Tag tag) +RenderMethod &Technique::add_method(Tag tag) { - return insert_unique(passes, tag, RenderPass())->second; + return insert_unique(methods, tag, RenderMethod())->second; } -bool Technique::has_pass(Tag tag) const +bool Technique::has_method(Tag tag) const { - return passes.count(tag); + return methods.count(tag); } -const RenderPass &Technique::get_pass(Tag tag) const +const RenderMethod &Technique::get_method(Tag tag) const { - return get_item(passes, tag); + return get_item(methods, tag); } -const RenderPass *Technique::find_pass(Tag tag) const +const RenderMethod *Technique::find_method(Tag tag) const { - auto i = passes.find(tag); - return (i!=passes.end() ? &i->second : 0); + auto i = methods.find(tag); + return (i!=methods.end() ? &i->second : 0); } bool Technique::replace_texture(const string &slot, const Texture &tex) { bool replaced = false; - for(auto &kvp: passes) + for(auto &kvp: methods) { Tag tag = kvp.second.get_texture_tag(slot); if(tag.id) @@ -54,7 +52,7 @@ bool Technique::replace_texture(const string &slot, const Texture &tex) bool Technique::replace_material(const string &slot, const Material &mat) { bool replaced = false; - for(auto &kvp: passes) + for(auto &kvp: methods) { const string &pass_slot = kvp.second.get_material_slot_name(); if(!pass_slot.empty() && pass_slot==slot) @@ -71,7 +69,7 @@ bool Technique::replace_uniforms(const ProgramData &shdata) { bool replaced = false; const vector &uniform_tags = shdata.get_uniform_tags(); - for(auto &kvp: passes) + for(auto &kvp: methods) { RefPtr new_shdata; for(Tag t: uniform_tags) @@ -81,9 +79,12 @@ bool Technique::replace_uniforms(const ProgramData &shdata) continue; if(!new_shdata) - new_shdata = new ProgramData(*kvp.second.get_shader_data()); + { + new_shdata = new ProgramData; + new_shdata->copy_uniforms(*kvp.second.get_shader_data()); + } - new_shdata->uniform(tag, shdata.get_uniform(t)); + new_shdata->copy_uniform(shdata, tag); replaced = true; } @@ -94,19 +95,11 @@ bool Technique::replace_uniforms(const ProgramData &shdata) return replaced; } -bool Technique::has_shaders() const -{ - for(const auto &kvp: passes) - if(kvp.second.get_shader_program()) - return true; - return false; -} - -void Technique::set_debug_name(const std::string &name) +void Technique::set_debug_name(const string &name) { #ifdef DEBUG - for(auto &kvp: passes) - kvp.second.set_debug_name(format("%s [pass:%s]", name, kvp.first.str())); + for(auto &kvp: methods) + kvp.second.set_debug_name(format("%s [method:%s]", name, kvp.first.str())); #else (void)name; #endif @@ -115,12 +108,6 @@ void Technique::set_debug_name(const std::string &name) DataFile::Loader::ActionMap Technique::Loader::shared_actions; -Technique::Loader::Loader(Technique &t): - DataFile::CollectionObjectLoader(t, 0) -{ - set_actions(shared_actions); -} - Technique::Loader::Loader(Technique &t, Collection &c): DataFile::CollectionObjectLoader(t, &c) { @@ -130,7 +117,7 @@ Technique::Loader::Loader(Technique &t, Collection &c): void Technique::Loader::init_actions() { add("inherit", &Loader::inherit); - add("pass", &Loader::pass); + add("method", &Loader::method); } void Technique::Loader::set_inline_base_name(const string &n) @@ -140,27 +127,22 @@ void Technique::Loader::set_inline_base_name(const string &n) void Technique::Loader::inherit(const string &n) { - obj.passes = get_collection().get(n).get_passes(); + obj.methods = get_collection().get(n).get_methods(); InheritLoader ldr(obj, get_collection()); load_sub_with(ldr); } -void Technique::Loader::pass(const string &n) +void Technique::Loader::method(const string &n) { - RenderPass p; - if(coll) - { - RenderPass::Loader ldr(p, get_collection()); - ldr.set_inline_base_name(format("%s/%s.pass", (inline_base_name.empty() ? FS::basename(get_source()) : inline_base_name), n)); - load_sub_with(ldr); - } - else - load_sub(p); + RenderMethod p; + RenderMethod::Loader ldr(p, get_collection()); + ldr.set_inline_base_name(format("%s/%s.method", (inline_base_name.empty() ? FS::basename(get_source()) : inline_base_name), n)); + load_sub_with(ldr); if(!p.get_shader_program()) - throw logic_error("no shader program in pass"); + throw logic_error("no shader program in method"); - insert_unique(obj.passes, n, p); + insert_unique(obj.methods, n, p); } @@ -179,15 +161,15 @@ void Technique::InheritLoader::material(const string &slot, const string &name) return; // For backwards compatibility - RenderPass &pass = get_item(obj.passes, slot); - if(const Material *base_mat = pass.get_material()) + RenderMethod &method = get_item(obj.methods, slot); + if(const Material *base_mat = method.get_material()) { - for(auto &kvp: obj.passes) + for(auto &kvp: obj.methods) if(kvp.second.get_material()==base_mat) kvp.second.set_material(&mat); } else - pass.set_material(&mat); + method.set_material(&mat); } void Technique::InheritLoader::texture(const string &slot, const string &name)