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"
16 #include "programdata.h"
17 #include "technique.h"
41 void Object::render(const Tag &tag) const
43 const RenderPass *pass = get_pass(tag);
51 void Object::render(const ObjectInstance &inst, const Tag &tag) const
53 const RenderPass *pass = get_pass(tag);
58 render_instance(inst, tag);
62 const RenderPass *Object::get_pass(const Tag &tag) const
64 if(!technique || !technique->has_pass(tag))
66 return &technique->get_pass(tag);
69 void Object::render_instance(const ObjectInstance &inst, const Tag &tag) const
71 inst.setup_render(tag);
72 unsigned lod = min<unsigned>(inst.get_level_of_detail(), meshes.size()-1);
74 inst.finish_render(tag);
78 Object::Loader::Loader(Object &o):
79 DataFile::CollectionObjectLoader<Object>(o, 0)
84 Object::Loader::Loader(Object &o, Collection &c):
85 DataFile::CollectionObjectLoader<Object>(o, &c)
90 void Object::Loader::init()
92 allow_pointer_reload = false;
94 add("lod_mesh", &Loader::lod_mesh);
95 add("mesh", static_cast<void (Loader::*)()>(&Loader::mesh));
96 add("mesh", static_cast<void (Loader::*)(const std::string &)>(&Loader::mesh));
97 add("technique", &Loader::technique);
98 add("technique", &Object::technique);
101 void Object::Loader::lod_mesh(unsigned l, const string &n)
103 obj.meshes.resize(l+1, 0);
104 obj.meshes[l] = get_collection().get<Mesh>(n);
107 void Object::Loader::mesh()
110 throw InvalidState("A mesh is already loaded");
112 RefPtr<Mesh> msh = new Mesh;
114 obj.meshes[0] = msh.release();
118 void Object::Loader::mesh(const std::string &n)
121 throw InvalidState("A mesh is already loaded");
123 obj.meshes[0] = get_collection().get<Mesh>(n);
126 void Object::Loader::technique()
128 RefPtr<Technique> tech = new Technique;
130 load_sub(*tech, get_collection());
133 obj.technique = tech.release();
134 obj.own_technique = true;