3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
12 #include "objectinstance.h"
14 #include "programdata.h"
35 void Object::render(const ObjectInstance *inst) const
45 inst->finish_render();
50 void Object::render(const list<const ObjectInstance *> &insts) const
54 for(list<const ObjectInstance *>::const_iterator i=insts.begin(); i!=insts.end(); ++i)
60 (*i)->finish_render();
66 void Object::setup_render() const
69 throw InvalidState("Trying to render Object without mesh");
75 for(unsigned i=0; i<textures.size(); ++i)
81 else if(!textures.empty())
82 textures.front()->bind();
88 void Object::finish_render() const
92 for(unsigned i=0; i<textures.size(); ++i)
100 Object::Loader::Loader(Object &o, Collection &c):
104 add("material", &Object::material);
105 add("mesh", &Object::mesh);
106 add("shader", &Loader::shader);
107 add("texture", &Loader::texture);
110 Object::Loader::~Loader()
114 for(unsigned i=0; i<textures.size(); ++i)
115 obj.shdata->uniform(obj.shprog->get_uniform_location(textures[i]), static_cast<int>(i));
119 void Object::Loader::shader(const string &n)
121 obj.shprog=&coll.get<Program>(n);
123 obj.shdata=new ProgramData;
126 void Object::Loader::texture(const string &n)
128 unsigned eqsign=n.find('=');
129 if(eqsign!=string::npos)
131 obj.textures.push_back(&coll.get<Texture>(n.substr(eqsign+1)));
132 textures.push_back(n.substr(0, eqsign));
136 obj.textures.push_back(&coll.get<Texture>(n));
137 textures.push_back(n);