]> git.tdb.fi Git - libs/gl.git/commitdiff
Separate main and shader textures in Object
authorMikko Rasa <tdb@tdb.fi>
Thu, 6 Mar 2008 10:59:35 +0000 (10:59 +0000)
committerMikko Rasa <tdb@tdb.fi>
Thu, 6 Mar 2008 10:59:35 +0000 (10:59 +0000)
source/object.cpp
source/object.h

index 19abe36b766c9f650644824c967060847f6a7b38..56b2648203992a8ad10ea55725dbfd1f75788d4d 100644 (file)
@@ -24,6 +24,7 @@ namespace GL {
 
 Object::Object():
        meshes(1, static_cast<Mesh *>(0)),
+       main_texture(0),
        material(0)
 {
        normal_pass=&passes[0];
@@ -78,8 +79,8 @@ void Object::setup_render(const ObjectPass &pass) const
                        textures[i]->bind();
                }
        }
-       else if(!textures.empty())
-               textures.front()->bind();
+       else if(main_texture)
+               main_texture->bind();
 
        if(material)
                material->apply();
@@ -88,12 +89,16 @@ void Object::setup_render(const ObjectPass &pass) const
 void Object::finish_render(const ObjectPass &pass) const
 {
        if(pass.shprog)
-               Program::unbind();
-       for(unsigned i=textures.size(); i--;)
        {
-               TexUnit::activate(i);
-               Texture::unbind();
+               Program::unbind();
+               for(unsigned i=textures.size(); i--;)
+               {
+                       TexUnit::activate(i);
+                       Texture::unbind();
+               }
        }
+       else if(main_texture)
+               Texture::unbind();
 }
 
 void Object::render(const ObjectPass &pass, const ObjectInstance *inst) const
@@ -143,10 +148,11 @@ Object::Loader::Loader(Object &o, Collection &c):
        add("mesh",     &Loader::mesh);
        add("pass",     &Loader::pass);
        add("shader",   &Loader::shader);
+       add("shader_texture", &Loader::shader_texture);
        add("texture",  &Loader::texture);
 }
 
-Object::Loader::~Loader()
+void Object::Loader::finish()
 {
        for(map<unsigned, ObjectPass>::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i)
                if(i->second.shdata)
@@ -200,7 +206,7 @@ void Object::Loader::shader(const string &n)
        }
 }
 
-void Object::Loader::texture(const string &n)
+void Object::Loader::shader_texture(const string &n)
 {
        unsigned eqsign=n.find('=');
        if(eqsign!=string::npos)
@@ -215,5 +221,15 @@ void Object::Loader::texture(const string &n)
        }
 }
 
+void Object::Loader::texture(const string &n)
+{
+       if(obj.main_texture)
+               throw Exception("Only one main texture may be specified");
+
+       obj.main_texture=coll.get<Texture>(n);
+       obj.textures.push_back(obj.main_texture);
+       textures.push_back("texture");
+}
+
 } // namespace GL
 } // namespace Msp
index 0b808983099e08ffba4caf01da9ad943b3966f0f..0039dffd42500f8daadaaff85c1071df279d9564 100644 (file)
@@ -33,10 +33,11 @@ See also class ObjectInstance.
 class Object: public Renderable
 {
 private:
-       std::vector<Mesh *> meshes;
-       std::vector<Texture *> textures;
+       std::vector<const Mesh *> meshes;
+       std::vector<const Texture *> textures;
+       const Texture *main_texture;
        std::map<unsigned, ObjectPass> passes;
-       Material *material;
+       const Material *material;
        ObjectPass *normal_pass;
 
 public:
@@ -53,16 +54,17 @@ public:
        
        public:
                Loader(Object &, Collection &);
-               ~Loader();
 
                Object &get_object() const { return obj; }
                Collection &get_collection() const { return coll; }
        private:
+               virtual void finish();
                void lod_mesh(unsigned, const std::string &);
                void material_inline();
                void mesh(const std::string &);
                void pass(const std::string &);
                void shader(const std::string &);
+               void shader_texture(const std::string &);
                void texture(const std::string &);
        };