]> git.tdb.fi Git - libs/gl.git/blobdiff - source/technique.cpp
Inherit Loaders from the ObjectLoader classes
[libs/gl.git] / source / technique.cpp
index c7bd25ed1a70e51f920a72436255f9070e29aa02..26837b61533167e0ddc268715f2722aee008272e 100644 (file)
@@ -5,6 +5,8 @@ Copyright © 2007  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
+#include <msp/core/refptr.h>
+#include <msp/datafile/collection.h>
 #include <msp/strings/formatter.h>
 #include "material.h"
 #include "program.h"
@@ -62,8 +64,7 @@ const Texture *Technique::get_texture(unsigned i) const
 
 
 Technique::Loader::Loader(Technique &t, Collection &c):
-       tech(t),
-       coll(c)
+       DataFile::CollectionObjectLoader<Technique>(t, &c)
 {
        add("material",        &Technique::material);
        add("material_inline", &Loader::material_inline);
@@ -76,12 +77,12 @@ Technique::Loader::Loader(Technique &t, Collection &c):
 
 void Technique::Loader::finish()
 {
-       for(PassMap::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; j<tech.textures.size(); ++j)
+                       for(unsigned j=0; j<obj.textures.size(); ++j)
                        {
-                               unsigned loc=i->second.shprog->get_uniform_location(tech.textures[j].name);
+                               unsigned loc=i->second.shprog->get_uniform_location(obj.textures[j].name);
                                i->second.shdata->uniform(loc, static_cast<int>(j));
                        }
                }
@@ -91,32 +92,32 @@ void Technique::Loader::material_inline()
 {
        RefPtr<Material> 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)
 {
        Tag tag(n);
-       if(tech.passes.count(tag))
+       if(obj.passes.count(tag))
                throw KeyError("Duplicate pass name", n);
        ObjectPass p;
-       load_sub(p, coll);
-       tech.passes[tag]=p;
+       load_sub(p, *coll);
+       obj.passes[tag]=p;
 }
 
 void Technique::Loader::shader(const string &n)
 {
-       Program *shprog=coll.get<Program>(n);
+       Program *shprog=coll->get<Program>(n);
        if(shprog)  // Allow for unsupported shaders
        {
                RefPtr<ProgramData> 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();
        }
 }
 
@@ -127,37 +128,37 @@ void Technique::Loader::shader_texture(const string &n)
        if(eqsign!=string::npos)
        {
                tex.name=n.substr(0, eqsign);
-               tex.texture=coll.get<Texture>(n.substr(eqsign+1));
+               tex.texture=coll->get<Texture>(n.substr(eqsign+1));
        }
        else
        {
                string::size_type dot=n.rfind('.');
                tex.name=n.substr(0, dot);
-               tex.texture = coll.get<Texture>(n);
+               tex.texture = coll->get<Texture>(n);
        }
        for(string::iterator i=tex.name.begin(); i!=tex.name.end(); ++i)
                if(!isalnum(*i))
                        *i='_';
-       tech.textures.push_back(tex);
+       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<Texture>(n);
+       obj.main_texture=coll->get<Texture>(n);
        TextureSlot tex;
        tex.name="texture";
-       tex.texture=tech.main_texture;
-       tech.textures.push_back(tex);
+       tex.texture=obj.main_texture;
+       obj.textures.push_back(tex);
 }
 
 void Technique::Loader::texture_slot(const string &n)
 {
        TextureSlot tex;
        tex.name=n;
-       tech.textures.push_back(tex);
+       obj.textures.push_back(tex);
 }
 
 } // namespace GL