]> git.tdb.fi Git - libs/gl.git/commitdiff
Inherit Loaders from the ObjectLoader classes
authorMikko Rasa <tdb@tdb.fi>
Thu, 4 Feb 2010 17:59:06 +0000 (17:59 +0000)
committerMikko Rasa <tdb@tdb.fi>
Thu, 4 Feb 2010 17:59:06 +0000 (17:59 +0000)
22 files changed:
source/batch.cpp
source/batch.h
source/font.cpp
source/font.h
source/material.cpp
source/material.h
source/mesh.cpp
source/mesh.h
source/object.cpp
source/object.h
source/objectpass.cpp
source/objectpass.h
source/program.cpp
source/program.h
source/programdata.cpp
source/programdata.h
source/technique.cpp
source/technique.h
source/texture.cpp
source/texture.h
source/texture2d.cpp
source/texture2d.h

index e522491144f1a7f6a06a0329e5c8e1721b241e69..33481a1cdfc8c613692f36de60e667e8413ed698 100644 (file)
@@ -53,14 +53,14 @@ void Batch::draw_with_buffer(unsigned offset) const
 
 
 Batch::Loader::Loader(Batch &b):
-       batch(b)
+       DataFile::ObjectLoader<Batch>(b)
 {
        add("indices", &Loader::indices);
 }
 
 void Batch::Loader::indices(const vector<uint> &ind)
 {
-       batch.append(ind);
+       obj.append(ind);
 }
 
 } // namespace GL
index 6950af894898b93bc576df783a7c9cb857635ac4..bca541392832c3285b78ce97c8ea44cd75342e90 100644 (file)
@@ -9,7 +9,7 @@ Distributed under the LGPL
 #define MSP_GL_BATCH_H_
 
 #include <vector>
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
 #include "primitivetype.h"
 #include "types.h"
 
@@ -19,13 +19,11 @@ namespace GL {
 class Batch
 {
 public:
-       class Loader: public DataFile::Loader
+       class Loader: public DataFile::ObjectLoader<Batch>
        {
        public:
                Loader(Batch &);
        private:
-               Batch &batch;
-
                void indices(const std::vector<uint> &);
        };
 
index f82b45d8ac81fe7bb3ac30b7f70be453b2a720b7..8320374e5070ec5580dc5c6e74ddda3de5f1468c 100644 (file)
@@ -5,6 +5,7 @@ Copyright © 2007  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
+#include <msp/datafile/collection.h>
 #include "gl.h"
 #include "font.h"
 #include "immediate.h"
@@ -125,26 +126,17 @@ float Font::get_glyph_advance(unsigned code) const
 
 
 Font::Loader::Loader(Font &f):
-       font(f),
-       coll(0)
+       DataFile::CollectionObjectLoader<Font>(f, 0)
 {
        init();
 }
 
 Font::Loader::Loader(Font &f, Collection &c):
-       font(f),
-       coll(&c)
+       DataFile::CollectionObjectLoader<Font>(f, &c)
 {
        init();
 }
 
-DataFile::Collection &Font::Loader::get_collection()
-{
-       if(!coll)
-               throw InvalidState("No collection");
-       return *coll;
-}
-
 void Font::Loader::init()
 {
        add("default_size", &Font::default_size);
@@ -160,20 +152,20 @@ void Font::Loader::glyph(unsigned c)
        Glyph gl;
        gl.code=c;
        load_sub(gl);
-       font.glyphs.insert(GlyphMap::value_type(c, gl));
+       obj.glyphs.insert(GlyphMap::value_type(c, gl));
 }
 
 void Font::Loader::texture_inline()
 {
        RefPtr<Texture2D> tex=new Texture2D;
        load_sub(*tex);
-       font.tex=tex.release();
-       font.own_tex=true;
+       obj.tex=tex.release();
+       obj.own_tex=true;
 }
 
 
 Font::Glyph::Loader::Loader(Glyph &g):
-       glyph(g)
+       DataFile::ObjectLoader<Glyph>(g)
 {
        add("texcoords", &Loader::texcoords);
        add("size",      &Glyph::w,     &Glyph::h);
@@ -183,10 +175,10 @@ Font::Glyph::Loader::Loader(Glyph &g):
 
 void Font::Glyph::Loader::texcoords(float x1, float y1, float x2, float y2)
 {
-       glyph.x1=x1;
-       glyph.y1=y1;
-       glyph.x2=x2;
-       glyph.y2=y2;
+       obj.x1=x1;
+       obj.y1=y1;
+       obj.x2=x2;
+       obj.y2=y2;
 }
 
 } // namespace GL
index a2406b9ee043009824dbe1787fd7a05d6b583038..dd40ec0b277f2deb9e835e26b5fda9c1f9ddab96 100644 (file)
@@ -10,7 +10,7 @@ Distributed under the LGPL
 
 #include <map>
 #include <string>
-#include <msp/datafile/collection.h>
+#include <msp/datafile/objectloader.h>
 #include <msp/strings/utf8.h>
 #include "vertexarray.h"
 
@@ -23,19 +23,11 @@ class Texture2D;
 class Font
 {
 public:
-       class Loader: public DataFile::Loader
+       class Loader: public DataFile::CollectionObjectLoader<Font>
        {
-       private:
-               Font &font;
-               DataFile::Collection *coll;
-
        public:
-               typedef DataFile::Collection Collection;
-
                Loader(Font &);
-               Loader(Font &, DataFile::Collection &);
-               Font &get_object() { return font; }
-               DataFile::Collection &get_collection();
+               Loader(Font &, Collection &);
        private:
                void init();
                void glyph(unsigned);
@@ -89,14 +81,11 @@ public:
 private:
        struct Glyph
        {
-               class Loader: public Msp::DataFile::Loader
+               class Loader: public Msp::DataFile::ObjectLoader<Glyph>
                {
                public:
                        Loader(Glyph &);
-                       Glyph &get_object() { return glyph; }
                private:
-                       Glyph &glyph;
-
                        void texcoords(float, float, float, float);
                };
 
index 310834f3554a50619dcc404f066a269ca952d666..b5ec6a5cd913209940acdd68558f1dc072fda8aa 100644 (file)
@@ -66,7 +66,7 @@ const Material *Material::current=0;
 
 
 Material::Loader::Loader(Material &m):
-       mat(m)
+       DataFile::ObjectLoader<Material>(m)
 {
        add("ambient",   &Loader::ambient);
        add("diffuse",   &Loader::diffuse);
@@ -77,22 +77,22 @@ Material::Loader::Loader(Material &m):
 
 void Material::Loader::ambient(float r, float g, float b, float a)
 {
-       mat.ambient=GL::Color(r, g, b, a);
+       obj.ambient=GL::Color(r, g, b, a);
 }
 
 void Material::Loader::diffuse(float r, float g, float b, float a)
 {
-       mat.diffuse=GL::Color(r, g, b, a);
+       obj.diffuse=GL::Color(r, g, b, a);
 }
 
 void Material::Loader::specular(float r, float g, float b, float a)
 {
-       mat.specular=GL::Color(r, g, b, a);
+       obj.specular=GL::Color(r, g, b, a);
 }
 
 void Material::Loader::emission(float r, float g, float b, float a)
 {
-       mat.emission=GL::Color(r, g, b, a);
+       obj.emission=GL::Color(r, g, b, a);
 }
 
 } // namespace GL
index 1da27199aa21ebea2704862527d920de982721c7..6614aeeae12cac4c51b0e9b91c320106b256eea1 100644 (file)
@@ -8,7 +8,7 @@ Distributed under the LGPL
 #ifndef MSP_GL_MATERIAL_H_
 #define MSP_GL_MATERIAL_H_
 
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
 #include "color.h"
 
 namespace Msp {
@@ -21,14 +21,10 @@ objects, application of material is done with several calls to glMaterial.
 class Material
 {
 public:
-       class Loader: public DataFile::Loader
+       class Loader: public DataFile::ObjectLoader<Material>
        {
-       private:
-               Material &mat;
-
        public:
                Loader(Material &);
-               Material &get_object() const { return mat; }
        
        private:
                void ambient(float, float, float, float);
index d43e0d0efdd421b43b209c0e8f4f280d2529c895..2ca040e6feb68e3eb65239a4c05e4eadfd997053 100644 (file)
@@ -99,7 +99,7 @@ void Mesh::update_index_buffer()
 
 
 Mesh::Loader::Loader(Mesh &m):
-       mesh(m)
+       DataFile::ObjectLoader<Mesh>(m)
 {
        add("vertices", &Loader::vertices);
        add("batch",    &Loader::batch);
@@ -107,14 +107,14 @@ Mesh::Loader::Loader(Mesh &m):
 
 void Mesh::Loader::vertices(VertexFormat f)
 {
-       mesh.vertices.reset(f);
-       load_sub(mesh.vertices);
+       obj.vertices.reset(f);
+       load_sub(obj.vertices);
 }
 
 void Mesh::Loader::batch(PrimitiveType p)
 {
-       mesh.batches.push_back(Batch(p));
-       load_sub(mesh.batches.back());
+       obj.batches.push_back(Batch(p));
+       load_sub(obj.batches.back());
 }
 
 } // namespace GL
index 0a4142fea1eebf02f326b9615a4fc5c904ad142b..044e70843d345aa06b960cfdb3697c93a9053584 100644 (file)
@@ -8,7 +8,7 @@ Distributed under the LGPL
 #ifndef MSP_GL_MESH_H_
 #define MSP_GL_MESH_H_
 
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
 #include "batch.h"
 #include "vertexarray.h"
 
@@ -22,13 +22,11 @@ class Mesh
        friend class MeshBuilder;
 
 public:
-       class Loader: public DataFile::Loader
+       class Loader: public DataFile::ObjectLoader<Mesh>
        {
        public:
                Loader(Mesh &);
        private:
-               Mesh &mesh;
-
                void vertices(VertexFormat);
                void batch(PrimitiveType);
        };
index d5d5231bab47dbdd9358a489ea975841298c4a87..f2d1f8bf74a9781c64d829e2f7950513296dbae1 100644 (file)
@@ -5,6 +5,7 @@ Copyright © 2007  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
+#include <msp/datafile/collection.h>
 #include <msp/strings/formatter.h>
 #include "except.h"
 #include "material.h"
@@ -124,8 +125,7 @@ void Object::render_instance(const ObjectInstance &inst, const Tag &tag) const
 
 
 Object::Loader::Loader(Object &o, Collection &c):
-       obj(o),
-       coll(c)
+       DataFile::CollectionObjectLoader<Object>(o, &c)
 {
        add("lod_mesh", &Loader::lod_mesh);
        add("material", &Object::material);
@@ -154,20 +154,20 @@ void Object::Loader::finish()
 void Object::Loader::lod_mesh(unsigned l, const string &n)
 {
        obj.meshes.resize(l+1, 0);
-       obj.meshes[l]=coll.get<Mesh>(n);
+       obj.meshes[l]=coll->get<Mesh>(n);
 }
 
 void Object::Loader::material_inline()
 {
        RefPtr<Material> mat=new Material;
        load_sub(*mat);
-       coll.add(format("_%p", mat.get()), mat.get());
+       coll->add(format("_%p", mat.get()), mat.get());
        obj.material=mat.release();
 }
 
 void Object::Loader::mesh(const string &n)
 {
-       obj.meshes[0]=coll.get<Mesh>(n);
+       obj.meshes[0]=coll->get<Mesh>(n);
 }
 
 void Object::Loader::shader_texture(const string &n)
@@ -179,12 +179,12 @@ void Object::Loader::shader_texture(const string &n)
        if(eqsign==string::npos)
                throw InvalidParameterValue("Must specify texture slot name");
 
-       obj.textures[obj.technique->get_texture_index(n.substr(0, eqsign))]=coll.get<Texture>(n.substr(eqsign+1));
+       obj.textures[obj.technique->get_texture_index(n.substr(0, eqsign))]=coll->get<Texture>(n.substr(eqsign+1));
 }
 
 void Object::Loader::technique(const string &n)
 {
-       obj.technique=coll.get<Technique>(n);
+       obj.technique=coll->get<Technique>(n);
        obj.textures.resize(obj.technique->get_n_textures());
        obj.material=obj.technique->get_material();
 }
@@ -194,7 +194,7 @@ void Object::Loader::texture(const string &n)
        if(obj.main_texture)
                throw Exception("Only one main texture may be specified");
 
-       Texture *tex=coll.get<Texture>(n);
+       Texture *tex=coll->get<Texture>(n);
        if(obj.technique)
                obj.textures[obj.technique->get_texture_index("texture")]=tex;
        obj.main_texture=tex;
index fff1e4cf281d770adf207fada79e156ca016b6e6..bf4a05249436f5453ec678a274431958597a61fb 100644 (file)
@@ -9,7 +9,6 @@ Distributed under the LGPL
 #define MSP_GL_OBJECT_H_
 
 #include <vector>
-#include <msp/datafile/collection.h>
 #include "objectpass.h"
 #include "renderable.h"
 
@@ -41,20 +40,11 @@ private:
        const Material *material;
 
 public:
-       class Loader: public DataFile::Loader
+       class Loader: public DataFile::CollectionObjectLoader<Object>
        {
-       public:
-               typedef DataFile::Collection Collection;
-
-       protected:
-               Object &obj;
-               Collection &coll;
-       
        public:
                Loader(Object &, Collection &);
 
-               Object &get_object() const { return obj; }
-               Collection &get_collection() const { return coll; }
        private:
                virtual void finish();
                void lod_mesh(unsigned, const std::string &);
index afb9f45d96b7209bb9dd63dab6e3b91229e89fdb..01a6c2eb3e21bcae46fe34507f8a0b1027eea35c 100644 (file)
@@ -5,6 +5,7 @@ Copyright © 2007  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
+#include <msp/datafile/collection.h>
 #include "objectpass.h"
 #include "program.h"
 #include "programdata.h"
@@ -26,8 +27,7 @@ ObjectPass::~ObjectPass()
 
 
 ObjectPass::Loader::Loader(ObjectPass &p, Collection &c):
-       pass(p),
-       coll(c)
+       DataFile::CollectionObjectLoader<ObjectPass>(p, &c)
 {
        add("shader", &Loader::shader);
        add("use_textures", &ObjectPass::use_textures);
@@ -35,16 +35,16 @@ ObjectPass::Loader::Loader(ObjectPass &p, Collection &c):
 
 void ObjectPass::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);
 
-               pass.shprog=shprog;
-               if(pass.shdata)
-                       delete pass.shdata;
-               pass.shdata=shdata.release();
+               obj.shprog=shprog;
+               if(obj.shdata)
+                       delete obj.shdata;
+               obj.shdata=shdata.release();
        }
 }
 
index e8190fa7f7c98e4cf13044b08fb446f750ec6d98..e3cac702362191a33759ed3da535ba6e384633a4 100644 (file)
@@ -8,7 +8,7 @@ Distributed under the LGPL
 #ifndef MSP_GL_OBJECTPASS_H_
 #define MSP_GL_OBJECTPASS_H_
 
-#include <msp/datafile/collection.h>
+#include <msp/datafile/objectloader.h>
 
 namespace Msp {
 namespace GL {
@@ -18,19 +18,10 @@ class ProgramData;
 
 struct ObjectPass
 {
-       class Loader: public DataFile::Loader
+       class Loader: public DataFile::CollectionObjectLoader<ObjectPass>
        {
-       public:
-               typedef DataFile::Collection Collection;
-
-       private:
-               ObjectPass &pass;
-               Collection &coll;
-
        public:
                Loader(ObjectPass &, Collection &);
-               ObjectPass &get_object() const { return pass; }
-               Collection &get_collection() const { return coll; }
        private:
                void shader(const std::string &);
        };
index 75f982d7f5dc8fa4c2235af999249cd23cae4146..01644c02400d739b82f737a4e90aee8c886b3189 100644 (file)
@@ -141,9 +141,9 @@ const Program *Program::cur_prog=0;
 
 
 Program::Loader::Loader(Program &p):
-       prog(p)
+       DataFile::ObjectLoader<Program>(p)
 {
-       prog.set_del_shaders(true);
+       obj.set_del_shaders(true);
 
        add("vertex_shader",   &Loader::vertex_shader);
        add("fragment_shader", &Loader::fragment_shader);
@@ -152,22 +152,22 @@ Program::Loader::Loader(Program &p):
 
 void Program::Loader::vertex_shader(const string &src)
 {
-       prog.attach_shader(*new Shader(VERTEX_SHADER, src));
+       obj.attach_shader(*new Shader(VERTEX_SHADER, src));
 }
 
 void Program::Loader::fragment_shader(const string &src)
 {
-       prog.attach_shader(*new Shader(FRAGMENT_SHADER, src));
+       obj.attach_shader(*new Shader(FRAGMENT_SHADER, src));
 }
 
 void Program::Loader::attribute(uint i, const string &n)
 {
-       prog.bind_attribute(i, n);
+       obj.bind_attribute(i, n);
 }
 
 void Program::Loader::finish()
 {
-       prog.link();
+       obj.link();
 }
 
 } // namespace GL
index ad37fb65bfca60d51094e741732faf274da7e1ef..818e72be1174d4a0464bc91b5a691d8f54efd602 100644 (file)
@@ -10,7 +10,7 @@ Distributed under the LGPL
 
 #include <list>
 #include <string>
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
 #include "gl.h"
 #include "types.h"
 
@@ -30,11 +30,8 @@ private:
        static const Program *cur_prog;
 
 public:
-       class Loader: public DataFile::Loader
+       class Loader: public DataFile::ObjectLoader<Program>
        {
-       private:
-               Program &prog;
-
        public:
                Loader(Program &);
 
index a7a9b037ef5b30861b4ce64f6eb66419506fb3e3..9acb93bc4d8701361458e4c20956d88b3e36bb21 100644 (file)
@@ -92,7 +92,7 @@ void ProgramData::apply() const
 
 
 ProgramData::Loader::Loader(ProgramData &pd, Program &pr):
-       pdata(pd),
+       DataFile::ObjectLoader<ProgramData>(pd),
        prog(pr)
 {
        add("uniform1i", &Loader::uniform1i);
@@ -104,27 +104,27 @@ ProgramData::Loader::Loader(ProgramData &pd, Program &pr):
 
 void ProgramData::Loader::uniform1i(const string &n, int v)
 {
-       pdata.uniform(prog.get_uniform_location(n), v);
+       obj.uniform(prog.get_uniform_location(n), v);
 }
 
 void ProgramData::Loader::uniform1f(const string &n, float v)
 {
-       pdata.uniform(prog.get_uniform_location(n), v);
+       obj.uniform(prog.get_uniform_location(n), v);
 }
 
 void ProgramData::Loader::uniform2f(const string &n, float v0, float v1)
 {
-       pdata.uniform(prog.get_uniform_location(n), v0, v1);
+       obj.uniform(prog.get_uniform_location(n), v0, v1);
 }
 
 void ProgramData::Loader::uniform3f(const string &n, float v0, float v1, float v2)
 {
-       pdata.uniform(prog.get_uniform_location(n), v0, v1, v2);
+       obj.uniform(prog.get_uniform_location(n), v0, v1, v2);
 }
 
 void ProgramData::Loader::uniform4f(const string &n, float v0, float v1, float v2, float v3)
 {
-       pdata.uniform(prog.get_uniform_location(n), v0, v1, v2, v3);
+       obj.uniform(prog.get_uniform_location(n), v0, v1, v2, v3);
 }
 
 } // namespace GL
index 4d7938bf1dc7850bd4021f81cf21bdf4df19d1ac..591ffee347f7dfe6bf97a3e1ef9b9772f87c101a 100644 (file)
@@ -9,7 +9,7 @@ Distributed under the LGPL
 #define MSP_GL_PROGRAMDATA_H_
 
 #include <map>
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
 
 namespace Msp {
 namespace GL {
@@ -23,10 +23,9 @@ Stores uniform variables for a shader program.
 class ProgramData
 {
 public:
-       class Loader: public DataFile::Loader
+       class Loader: public DataFile::ObjectLoader<ProgramData>
        {
        private:
-               ProgramData &pdata;
                Program &prog;
 
        public:
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
index 468131f75724cc1a39e6922a0539942991a51db8..3bb347ea4c98b9bb535cf132ec68dbb429383b4c 100644 (file)
@@ -25,20 +25,11 @@ slots which Objects must override.
 class Technique
 {
 public:
-       class Loader: public Msp::DataFile::Loader
+       class Loader: public Msp::DataFile::CollectionObjectLoader<Technique>
        {
-       public:
-               typedef DataFile::Collection Collection;
-
-       protected:
-               Technique &tech;
-               Collection &coll;
-       
        public:
                Loader(Technique &, Collection &);
 
-               Technique &get_object() const { return tech; }
-               Collection &get_collection() const { return coll; }
        private:
                virtual void finish();
                void material_inline();
index 47b6ba37abb300f8fae19a83be1ace593001362f..e897ba92a138ab8282e013ce5bb74938bc74b734 100644 (file)
@@ -111,7 +111,7 @@ void Texture::maybe_bind() const
 
 
 Texture::Loader::Loader(Texture &t):
-       tex(t)
+       DataFile::ObjectLoader<Texture>(t)
 {
        add("min_filter", &Loader::min_filter);
        add("mag_filter", &Loader::mag_filter);
@@ -120,17 +120,17 @@ Texture::Loader::Loader(Texture &t):
 
 void Texture::Loader::min_filter(TextureFilter f)
 {
-       tex.set_min_filter(f);
+       obj.set_min_filter(f);
 }
 
 void Texture::Loader::mag_filter(TextureFilter f)
 {
-       tex.set_mag_filter(f);
+       obj.set_mag_filter(f);
 }
 
 void Texture::Loader::generate_mipmap(bool gm)
 {
-       tex.parameter(GL_GENERATE_MIPMAP_SGIS, gm);
+       obj.parameter(GL_GENERATE_MIPMAP_SGIS, gm);
 }
 
 } // namespace GL
index 48f551f0ae0d5ea591c984aeb49634a0742763b4..21edb81a74ae53ac67d0c18dff005709c048c431 100644 (file)
@@ -9,7 +9,7 @@ Distributed under the LGPL
 #define MSP_GL_TEXTURE_H_
 
 #include <istream>
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
 #include "gl.h"
 #include "types.h"
 
@@ -37,11 +37,8 @@ one of the dimensioned texture classes.
 class Texture
 {
 protected:
-       class Loader: public DataFile::Loader
+       class Loader: public DataFile::ObjectLoader<Texture>
        {
-       protected:
-               Texture &tex;
-
        public:
                Loader(Texture &);
                void min_filter(TextureFilter);
index b8f2f26b7076320f78f5ef792dc69a9acd7e1b82..c1f6e0e9e7bd75f664cc682209b551746d3f4e48 100644 (file)
@@ -89,18 +89,18 @@ void Texture2D::Loader::image_data(const string &data)
        Graphics::Image img;
        img.load_memory(data.data(), data.size());
 
-       static_cast<Texture2D &>(tex).image(img);
+       static_cast<Texture2D &>(obj).image(img);
 }
 
 void Texture2D::Loader::raw_data(const string &data)
 {
-       Texture2D &t2d=static_cast<Texture2D &>(tex);;
+       Texture2D &t2d=static_cast<Texture2D &>(obj);
        t2d.image(0, t2d.ifmt, UNSIGNED_BYTE, data.data());
 }
 
 void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h, unsigned b)
 {
-       static_cast<Texture2D &>(tex).storage(fmt, w, h, b);
+       static_cast<Texture2D &>(obj).storage(fmt, w, h, b);
 }
 
 } // namespace GL
index f1b76783f7e5c5a242c96bb3528d7e7a8929ec40..5784645b03356d5baebc2ecb75c4e17585a34472 100644 (file)
@@ -9,7 +9,6 @@ Distributed under the LGPL
 #define MSP_GL_TEXTURE2D_H_
 
 #include <string>
-#include <msp/datafile/loader.h>
 #include <msp/gbase/image.h>
 #include "pixelformat.h"
 #include "texture.h"