#include "mesh.h"
#include "object.h"
#include "objectinstance.h"
-#include "objectpass.h"
#include "program.h"
#include "programdata.h"
#include "technique.h"
Object::Object():
meshes(1),
- own_technique(false),
- technique(0)
+ technique(0),
+ own_mesh(false),
+ own_technique(false)
{ }
Object::~Object()
{
if(own_technique)
delete technique;
+ if(own_mesh)
+ delete meshes[0];
}
void Object::render(const Tag &tag) const
}
+Object::Loader::Loader(Object &o):
+ DataFile::CollectionObjectLoader<Object>(o, 0)
+{
+ init();
+}
+
Object::Loader::Loader(Object &o, Collection &c):
DataFile::CollectionObjectLoader<Object>(o, &c)
{
+ init();
+}
+
+void Object::Loader::init()
+{
+ allow_pointer_reload=false;
+
add("lod_mesh", &Loader::lod_mesh);
- add("mesh", &Loader::mesh);
+ add("mesh", static_cast<void (Loader::*)()>(&Loader::mesh));
+ add("mesh", static_cast<void (Loader::*)(const std::string &)>(&Loader::mesh));
add("technique", &Loader::technique);
add("technique", &Object::technique);
}
obj.meshes[l]=get_collection().get<Mesh>(n);
}
-void Object::Loader::mesh(const string &n)
+void Object::Loader::mesh()
+{
+ if(obj.meshes[0])
+ throw InvalidState("A mesh is already loaded");
+
+ RefPtr<Mesh> msh=new Mesh;
+ load_sub(*msh);
+ obj.meshes[0]=msh.release();
+ obj.own_mesh=true;
+}
+
+void Object::Loader::mesh(const std::string &n)
{
+ if(obj.meshes[0])
+ throw InvalidState("A mesh is already loaded");
+
obj.meshes[0]=get_collection().get<Mesh>(n);
}
#include <vector>
#include "misc.h"
-#include "objectpass.h"
#include "renderable.h"
+#include "renderpass.h"
namespace Msp {
namespace GL {
class Object: public Renderable
{
private:
- std::vector<const Mesh *> meshes;
- bool own_technique;
- const Technique *technique;
+ std::vector<Mesh *> meshes;
+ Technique *technique;
+ bool own_mesh:1;
+ bool own_technique:1;
public:
class Loader: public DataFile::CollectionObjectLoader<Object>
{
public:
+ Loader(Object &);
Loader(Object &, Collection &);
+ private:
+ void init();
private:
void lod_mesh(unsigned, const std::string &);
+ void mesh();
void mesh(const std::string &);
void technique();
};
textures(other.textures)
{ }
-/*RenderPass &RenderPass::operator=(const RenderPass &other)
-{
- shprog=other.shprog;
- delete shdata;
- shdata=(other.shdata ? new ProgramData(*other.shdata) : 0);
- material=other.material;
- use_material=other.use_material;
- textures=other.textures;
- use_textures=other.use_textures;
-
- return *this;
-}*/
-
RenderPass::~RenderPass()
{
delete shdata;
RenderPass::Loader::Loader(RenderPass &p, Collection &c):
DataFile::CollectionObjectLoader<RenderPass>(p, &c)
{
+ allow_pointer_reload=false;
+
add("shader", &RenderPass::shprog);
add("material", &Loader::material);
add("material", &RenderPass::material);
void RenderPass::Loader::material()
{
- // XXX Potential memory management trouble with multiple material statements
+ if(obj.material)
+ throw InvalidState("A material is already loaded");
+
RefPtr<Material> mat=new Material;
load_sub(*mat);
obj.material=mat.release();
#ifndef TECHNIQUE_H_
#define TECHNIQUE_H_
-#include "objectpass.h"
+#include "renderpass.h"
namespace Msp {
namespace GL {