3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/datafile/collection.h>
9 #include <msp/strings/formatter.h>
14 #include "objectinstance.h"
15 #include "objectpass.h"
17 #include "programdata.h"
18 #include "technique.h"
39 void Object::render(const Tag &tag) const
41 const RenderPass *pass=get_pass(tag);
49 void Object::render(const ObjectInstance &inst, const Tag &tag) const
51 const RenderPass *pass=get_pass(tag);
56 render_instance(inst, tag);
60 const RenderPass *Object::get_pass(const Tag &tag) const
62 if(!technique->has_pass(tag))
64 return &technique->get_pass(tag);
67 void Object::render_instance(const ObjectInstance &inst, const Tag &tag) const
69 inst.setup_render(tag);
70 unsigned lod=min<unsigned>(inst.get_level_of_detail(), meshes.size()-1);
72 inst.finish_render(tag);
76 Object::Loader::Loader(Object &o, Collection &c):
77 DataFile::CollectionObjectLoader<Object>(o, &c)
79 add("lod_mesh", &Loader::lod_mesh);
80 add("mesh", &Loader::mesh);
81 add("technique", &Loader::technique);
82 add("technique", &Object::technique);
85 void Object::Loader::lod_mesh(unsigned l, const string &n)
87 obj.meshes.resize(l+1, 0);
88 obj.meshes[l]=get_collection().get<Mesh>(n);
91 void Object::Loader::mesh(const string &n)
93 obj.meshes[0]=get_collection().get<Mesh>(n);
96 void Object::Loader::technique()
98 RefPtr<Technique> tch=new Technique;
99 load_sub(*tch, get_collection());
100 obj.technique=tch.release();
101 obj.own_technique=true;