X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fobject.cpp;h=1852f91b50222ead401dfa177605c31d9d1ee21b;hp=0469c31a99629187f17ce7d5dde803823636bb2e;hb=HEAD;hpb=85e83ace47e5a9a8ae7263886255dd81afc69278 diff --git a/source/object.cpp b/source/object.cpp deleted file mode 100644 index 0469c31a..00000000 --- a/source/object.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include "except.h" -#include "material.h" -#include "mesh.h" -#include "object.h" -#include "objectinstance.h" -#include "program.h" -#include "programdata.h" -#include "texture.h" -#include "texunit.h" - -using namespace std; - -namespace Msp { -namespace GL { - -Object::Object(): - mesh(0), - shprog(0), - shdata(0), - material(0) -{ } - -Object::~Object() -{ - delete shdata; -} - -void Object::render(const ObjectInstance *inst) const -{ - setup_render(); - - if(inst) - inst->setup_render(); - - mesh->draw(); - - if(inst) - inst->finish_render(); - - finish_render(); -} - -void Object::render(const list &insts) const -{ - setup_render(); - - for(list::const_iterator i=insts.begin(); i!=insts.end(); ++i) - { - (*i)->setup_render(); - - mesh->draw(); - - (*i)->finish_render(); - } - - finish_render(); -} - -void Object::setup_render() const -{ - if(!mesh) - throw InvalidState("Trying to render Object without mesh"); - - if(shprog) - { - shprog->bind(); - shdata->apply(); - for(unsigned i=0; ibind(); - } - } - else if(!textures.empty()) - textures.front()->bind(); - - if(material) - material->apply(); -} - -void Object::finish_render() const -{ - if(shprog) - Program::unbind(); - for(unsigned i=0; iuniform(obj.shprog->get_uniform_location(textures[i]), static_cast(i)); - } -} - -void Object::Loader::shader(const string &n) -{ - obj.shprog=&coll.get(n); - if(!obj.shdata) - obj.shdata=new ProgramData; -} - -void Object::Loader::texture(const string &n) -{ - unsigned eqsign=n.find('='); - if(eqsign!=string::npos) - { - obj.textures.push_back(&coll.get(n.substr(eqsign+1))); - textures.push_back(n.substr(0, eqsign)); - } - else - { - obj.textures.push_back(&coll.get(n)); - textures.push_back(n); - } -} - -} // namespace GL -} // namespace Msp