]> git.tdb.fi Git - libs/gl.git/blobdiff - source/object.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / object.cpp
diff --git a/source/object.cpp b/source/object.cpp
deleted file mode 100644 (file)
index 19abe36..0000000
+++ /dev/null
@@ -1,219 +0,0 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
-#include <msp/strings/formatter.h>
-#include "except.h"
-#include "material.h"
-#include "mesh.h"
-#include "object.h"
-#include "objectinstance.h"
-#include "objectpass.h"
-#include "program.h"
-#include "programdata.h"
-#include "texture.h"
-#include "texunit.h"
-
-using namespace std;
-
-namespace Msp {
-namespace GL {
-
-Object::Object():
-       meshes(1, static_cast<Mesh *>(0)),
-       material(0)
-{
-       normal_pass=&passes[0];
-}
-
-Object::~Object()
-{
-       for(map<unsigned, ObjectPass>::iterator i=passes.begin(); i!=passes.end(); ++i)
-               delete i->second.shdata;
-}
-
-bool Object::has_pass(const Tag &tag) const
-{
-       return passes.count(tag.id);
-}
-
-const ObjectPass &Object::get_pass(const Tag &tag) const
-{
-       map<unsigned, ObjectPass>::const_iterator i=passes.find(tag.id);
-       if(i==passes.end())
-               throw KeyError("Unknown pass");
-       return i->second;
-}
-
-void Object::render(const Tag &tag) const
-{
-       render(get_pass(tag), 0);
-}
-
-void Object::render(const ObjectInstance &inst, const Tag &tag) const
-{
-       render(get_pass(tag), &inst);
-}
-
-void Object::render(const list<const ObjectInstance *> &insts, const Tag &tag) const
-{
-       render(get_pass(tag), insts);
-}
-
-void Object::setup_render(const ObjectPass &pass) const
-{
-       if(!meshes[0])
-               throw InvalidState("Trying to render Object without mesh");
-
-       if(pass.shprog)
-       {
-               pass.shprog->bind();
-               pass.shdata->apply();
-               for(unsigned i=0; i<textures.size(); ++i)
-               {
-                       TexUnit::activate(i);
-                       textures[i]->bind();
-               }
-       }
-       else if(!textures.empty())
-               textures.front()->bind();
-
-       if(material)
-               material->apply();
-}
-
-void Object::finish_render(const ObjectPass &pass) const
-{
-       if(pass.shprog)
-               Program::unbind();
-       for(unsigned i=textures.size(); i--;)
-       {
-               TexUnit::activate(i);
-               Texture::unbind();
-       }
-}
-
-void Object::render(const ObjectPass &pass, const ObjectInstance *inst) const
-{
-       setup_render(pass);
-
-       unsigned lod=0;
-       if(inst)
-       {
-               inst->setup_render(pass);
-               lod=min(inst->get_level_of_detail(), meshes.size()-1);
-       }
-
-       meshes[lod]->draw();
-
-       if(inst)
-               inst->finish_render(pass);
-
-       finish_render(pass);
-}
-
-void Object::render(const ObjectPass &pass, const list<const ObjectInstance *> &insts) const
-{
-       setup_render(pass);
-
-       for(list<const ObjectInstance *>::const_iterator i=insts.begin(); i!=insts.end(); ++i)
-       {
-               (*i)->setup_render(pass);
-
-               unsigned lod=min((*i)->get_level_of_detail(), meshes.size()-1);
-               meshes[lod]->draw();
-
-               (*i)->finish_render(pass);
-       }
-
-       finish_render(pass);
-}
-
-
-Object::Loader::Loader(Object &o, Collection &c):
-       obj(o),
-       coll(c)
-{
-       add("lod_mesh", &Loader::lod_mesh);
-       add("material", &Object::material);
-       add("material_inline", &Loader::material_inline);
-       add("mesh",     &Loader::mesh);
-       add("pass",     &Loader::pass);
-       add("shader",   &Loader::shader);
-       add("texture",  &Loader::texture);
-}
-
-Object::Loader::~Loader()
-{
-       for(map<unsigned, ObjectPass>::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i)
-               if(i->second.shdata)
-               {
-                       for(unsigned j=0; j<textures.size(); ++j)
-                               i->second.shdata->uniform(i->second.shprog->get_uniform_location(textures[j]), static_cast<int>(j));
-               }
-}
-
-void Object::Loader::lod_mesh(unsigned l, const string &n)
-{
-       obj.meshes.resize(l+1, 0);
-       obj.meshes[l]=coll.get<Mesh>(n);
-}
-
-void Object::Loader::material_inline()
-{
-       RefPtr<Material> mat=new Material;
-       load_sub(*mat);
-       coll.add(format("%p%p", &obj, mat.get()), mat.get());
-       obj.material=mat.release();
-}
-
-void Object::Loader::mesh(const string &n)
-{
-       obj.meshes[0]=coll.get<Mesh>(n);
-}
-
-void Object::Loader::pass(const string &n)
-{
-       unsigned id=Tag(n).id;
-       if(obj.passes.count(id))
-               throw KeyError("Duplicate pass name");
-       ObjectPass p;
-       load_sub(p, coll);
-       obj.passes[id]=p;
-}
-
-void Object::Loader::shader(const string &n)
-{
-       Program *shprog=coll.get<Program>(n);
-       if(shprog)  // Allow for unsupported shaders
-       {
-               RefPtr<ProgramData> shdata=new ProgramData;
-               load_sub(*shdata, *shprog);
-
-               obj.normal_pass->shprog=shprog;
-               if(obj.normal_pass->shdata)
-                       delete obj.normal_pass->shdata;
-               obj.normal_pass->shdata=shdata.release();
-       }
-}
-
-void Object::Loader::texture(const string &n)
-{
-       unsigned eqsign=n.find('=');
-       if(eqsign!=string::npos)
-       {
-               obj.textures.push_back(coll.get<Texture>(n.substr(eqsign+1)));
-               textures.push_back(n.substr(0, eqsign));
-       }
-       else
-       {
-               obj.textures.push_back(coll.get<Texture>(n));
-               textures.push_back(n);
-       }
-}
-
-} // namespace GL
-} // namespace Msp