From: Mikko Rasa Date: Sat, 20 Feb 2010 19:06:37 +0000 (+0000) Subject: Correct some #includes X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a93d6abc8a4a3e70fa8f6781d9804583e18ef636;p=libs%2Fgl.git Correct some #includes Allow loaded objects to have an inline mesh --- diff --git a/source/object.cpp b/source/object.cpp index edfe39e5..0a03b7a8 100644 --- a/source/object.cpp +++ b/source/object.cpp @@ -12,7 +12,6 @@ Distributed under the LGPL #include "mesh.h" #include "object.h" #include "objectinstance.h" -#include "objectpass.h" #include "program.h" #include "programdata.h" #include "technique.h" @@ -26,14 +25,17 @@ namespace GL { 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 @@ -73,11 +75,25 @@ void Object::render_instance(const ObjectInstance &inst, const Tag &tag) const } +Object::Loader::Loader(Object &o): + DataFile::CollectionObjectLoader(o, 0) +{ + init(); +} + Object::Loader::Loader(Object &o, Collection &c): DataFile::CollectionObjectLoader(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(&Loader::mesh)); + add("mesh", static_cast(&Loader::mesh)); add("technique", &Loader::technique); add("technique", &Object::technique); } @@ -88,8 +104,22 @@ void Object::Loader::lod_mesh(unsigned l, const string &n) obj.meshes[l]=get_collection().get(n); } -void Object::Loader::mesh(const string &n) +void Object::Loader::mesh() +{ + if(obj.meshes[0]) + throw InvalidState("A mesh is already loaded"); + + RefPtr 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(n); } diff --git a/source/object.h b/source/object.h index d81c4ade..ad856323 100644 --- a/source/object.h +++ b/source/object.h @@ -10,8 +10,8 @@ Distributed under the LGPL #include #include "misc.h" -#include "objectpass.h" #include "renderable.h" +#include "renderpass.h" namespace Msp { namespace GL { @@ -31,18 +31,23 @@ similar objects. See class ObjectInstance. class Object: public Renderable { private: - std::vector meshes; - bool own_technique; - const Technique *technique; + std::vector meshes; + Technique *technique; + bool own_mesh:1; + bool own_technique:1; public: class Loader: public DataFile::CollectionObjectLoader { 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(); }; diff --git a/source/renderpass.cpp b/source/renderpass.cpp index d2fe6688..9e5b71d9 100644 --- a/source/renderpass.cpp +++ b/source/renderpass.cpp @@ -36,19 +36,6 @@ RenderPass::RenderPass(const RenderPass &other): 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; @@ -127,6 +114,8 @@ void RenderPass::unbind() RenderPass::Loader::Loader(RenderPass &p, Collection &c): DataFile::CollectionObjectLoader(p, &c) { + allow_pointer_reload=false; + add("shader", &RenderPass::shprog); add("material", &Loader::material); add("material", &RenderPass::material); @@ -151,7 +140,9 @@ void RenderPass::Loader::finish() void RenderPass::Loader::material() { - // XXX Potential memory management trouble with multiple material statements + if(obj.material) + throw InvalidState("A material is already loaded"); + RefPtr mat=new Material; load_sub(*mat); obj.material=mat.release(); diff --git a/source/technique.h b/source/technique.h index cc81b531..ce12b4f4 100644 --- a/source/technique.h +++ b/source/technique.h @@ -8,7 +8,7 @@ Distributed under the LGPL #ifndef TECHNIQUE_H_ #define TECHNIQUE_H_ -#include "objectpass.h" +#include "renderpass.h" namespace Msp { namespace GL {