]> git.tdb.fi Git - libs/gl.git/blobdiff - source/materials/technique.cpp
Add inline data items to the collection
[libs/gl.git] / source / materials / technique.cpp
index 22f8f3b63a0752ce547863a35eafa455f2e4f3ee..26a70a018dde6042ce7ddc5f8b21a2e942257ad5 100644 (file)
@@ -1,5 +1,6 @@
 #include <msp/core/refptr.h>
 #include <msp/datafile/collection.h>
+#include <msp/fs/utils.h>
 #include <msp/strings/format.h>
 #include "material.h"
 #include "program.h"
@@ -39,10 +40,10 @@ bool Technique::replace_texture(const string &slot, const Texture &tex)
        bool replaced = false;
        for(PassMap::iterator i=passes.begin(); i!=passes.end(); ++i)
        {
-               int index = i->second.get_texture_index(slot);
-               if(index>=0)
+               Tag tag = i->second.get_texture_tag(slot);
+               if(tag.id)
                {
-                       i->second.set_texture(index, &tex);
+                       i->second.set_texture(tag, &tex);
                        replaced = true;
                }
        }
@@ -69,20 +70,20 @@ bool Technique::replace_material(const string &slot, const Material &mat)
 bool Technique::replace_uniforms(const ProgramData &shdata)
 {
        bool replaced = false;
-       const vector<string> &uniform_names = shdata.get_uniform_names();
+       const vector<Tag> &uniform_tags = shdata.get_uniform_tags();
        for(PassMap::iterator i=passes.begin(); i!=passes.end(); ++i)
        {
                RefPtr<ProgramData> new_shdata;
-               for(vector<string>::const_iterator j=uniform_names.begin(); j!=uniform_names.end(); ++j)
+               for(vector<Tag>::const_iterator j=uniform_tags.begin(); j!=uniform_tags.end(); ++j)
                {
-                       const string &name = i->second.get_slotted_uniform_name(*j);
-                       if(name.empty())
+                       Tag tag = i->second.get_slotted_uniform_tag(*j);
+                       if(!tag.id)
                                continue;
 
                        if(!new_shdata)
                                new_shdata = new ProgramData(*i->second.get_shader_data());
 
-                       new_shdata->uniform(name, shdata.get_uniform(*j));
+                       new_shdata->uniform(tag, shdata.get_uniform(*j));
                        replaced = true;
                }
 
@@ -101,25 +102,42 @@ bool Technique::has_shaders() const
        return false;
 }
 
+void Technique::set_debug_name(const std::string &name)
+{
+#ifdef DEBUG
+       for(map<Tag, RenderPass>::iterator i=passes.begin(); i!=passes.end(); ++i)
+               i->second.set_debug_name(format("%s [pass:%s]", name, i->first.str()));
+#else
+       (void)name;
+#endif
+}
+
+
+DataFile::Loader::ActionMap Technique::Loader::shared_actions;
 
 Technique::Loader::Loader(Technique &t):
        DataFile::CollectionObjectLoader<Technique>(t, 0)
 {
-       init();
+       set_actions(shared_actions);
 }
 
 Technique::Loader::Loader(Technique &t, Collection &c):
        DataFile::CollectionObjectLoader<Technique>(t, &c)
 {
-       init();
+       set_actions(shared_actions);
 }
 
-void Technique::Loader::init()
+void Technique::Loader::init_actions()
 {
        add("inherit", &Loader::inherit);
        add("pass", &Loader::pass);
 }
 
+void Technique::Loader::set_inline_base_name(const string &n)
+{
+       inline_base_name = n;
+}
+
 void Technique::Loader::inherit(const string &n)
 {
        obj.passes = get_collection().get<Technique>(n).get_passes();
@@ -131,7 +149,11 @@ void Technique::Loader::pass(const string &n)
 {
        RenderPass p;
        if(coll)
-               load_sub(p, get_collection());
+       {
+               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);