namespace GL {
Object::Object():
- meshes(1),
- technique(0),
- own_mesh(false),
- own_technique(false)
+ meshes(1)
{ }
Object::~Object()
{
- if(own_technique)
- delete technique;
- if(own_mesh)
- delete meshes[0];
+}
+
+void Object::set_mesh(unsigned i, const Mesh *m)
+{
+ if(i>meshes.size())
+ throw InvalidParameterValue("LODs must be continuous");
+
+ if(i==meshes.size())
+ meshes.push_back(m);
+ else
+ meshes[i] = m;
+ meshes[i].keep();
+}
+
+void Object::set_technique(const Technique *t)
+{
+ technique = t;
+ technique.keep();
}
void Object::render(const Tag &tag) const
return;
Bind bind(pass);
- meshes[0]->draw();
+ meshes.front()->draw();
}
void Object::render(const ObjectInstance &inst, const Tag &tag) const
Bind bind(pass);
render_instance(inst, tag);
- meshes[0]->draw();
}
const RenderPass *Object::get_pass(const Tag &tag) const
{
allow_pointer_reload = false;
- add("lod_mesh", &Loader::lod_mesh);
add("mesh", static_cast<void (Loader::*)()>(&Loader::mesh));
+ add("mesh", static_cast<void (Loader::*)(unsigned)>(&Loader::mesh));
add("mesh", static_cast<void (Loader::*)(const std::string &)>(&Loader::mesh));
- add("technique", &Loader::technique);
- add("technique", &Object::technique);
+ add("mesh", static_cast<void (Loader::*)(unsigned, const std::string &)>(&Loader::mesh));
+ // Deprecated alias, will be removed
+ add("lod_mesh", static_cast<void (Loader::*)(unsigned, const std::string &)>(&Loader::mesh));
+ add("technique", static_cast<void (Loader::*)()>(&Loader::technique));
+ add("technique", static_cast<void (Loader::*)(const std::string &)>(&Loader::technique));
}
-void Object::Loader::lod_mesh(unsigned l, const string &n)
+void Object::Loader::mesh()
{
- obj.meshes.resize(l+1, 0);
- obj.meshes[l] = get_collection().get<Mesh>(n);
+ RefPtr<Mesh> msh = new Mesh;
+ load_sub(*msh);
+ obj.meshes.front() = msh;
}
-void Object::Loader::mesh()
+void Object::Loader::mesh(unsigned l)
{
- if(obj.meshes[0])
- throw InvalidState("A mesh is already loaded");
+ if(l>obj.meshes.size())
+ throw InvalidParameterValue("LODs must be continuous");
RefPtr<Mesh> msh = new Mesh;
load_sub(*msh);
- obj.meshes[0] = msh.release();
- obj.own_mesh = true;
+ if(l==obj.meshes.size())
+ obj.meshes.push_back(msh);
+ else
+ obj.meshes[l] = msh;
}
void Object::Loader::mesh(const std::string &n)
{
- if(obj.meshes[0])
- throw InvalidState("A mesh is already loaded");
+ obj.set_mesh(get_collection().get<Mesh>(n));
+}
- obj.meshes[0] = get_collection().get<Mesh>(n);
+void Object::Loader::mesh(unsigned l, const string &n)
+{
+ obj.set_mesh(l, get_collection().get<Mesh>(n));
}
void Object::Loader::technique()
load_sub(*tech, get_collection());
else
load_sub(*tech);
- obj.technique = tech.release();
- obj.own_technique = true;
+ obj.technique = tech;
+}
+
+void Object::Loader::technique(const std::string &n)
+{
+ obj.set_technique(get_collection().get<Technique>(n));
}
} // namespace GL
class Object: public Renderable
{
private:
- std::vector<Mesh *> meshes;
- Technique *technique;
- bool own_mesh:1;
- bool own_technique:1;
+ std::vector<RefPtr<const Mesh> > meshes;
+ RefPtr<const Technique> technique;
public:
class Loader: public DataFile::CollectionObjectLoader<Object>
void init();
private:
- void lod_mesh(unsigned, const std::string &);
void mesh();
+ void mesh(unsigned);
void mesh(const std::string &);
+ void mesh(unsigned, const std::string &);
void technique();
+ void technique(const std::string &);
};
Object();
~Object();
- const Technique *get_technique() const { return technique; }
+ void set_mesh(const Mesh *m) { set_mesh(0, m); }
+ void set_mesh(unsigned, const Mesh *);
+ void set_technique(const Technique *);
+ const Technique *get_technique() const { return technique.get(); }
/**
Renders the object. A tag can be provided to render a non-default pass.