1 #ifndef MSP_GL_OBJECT_H_
2 #define MSP_GL_OBJECT_H_
6 #include "renderable.h"
7 #include "renderpass.h"
8 #include "resourceobserver.h"
20 Combines a Mesh with a Technique to give it an appearance. The Technique will
21 define which render passes the Object supports.
23 In many cases, it's desirable to include multiple copies of an Object in a
24 Scene, with different model matrices. ObjectInstances can be used to alter the
25 rendering of an object on a per-instance basis.
27 Objects can have multiple levels of detail. The most detailed level has index
28 0, with increasing indices having less detail. When rendering an instance, the
29 instance's get_level_of_detail method is called to determine which LoD to use.
31 class Object: public Renderable, private ResourceObserver
36 class LodLoader: public DataFile::CollectionObjectLoader<Object>
43 LodLoader(Object &, unsigned, Collection *);
46 void mesh(const std::string &);
48 void technique(const std::string &);
49 void technique_inline();
53 class Loader: public LodLoader
57 Loader(Object &, Collection &);
60 virtual void finish();
62 void bounding_sphere_hint(float, float, float, float);
63 void level_of_detail(unsigned);
69 RefPtr<const Mesh> mesh;
70 RefPtr<const Technique> technique;
73 std::vector<LevelOfDetail> lods;
74 Geometry::BoundingSphere<float, 3> bounding_sphere;
77 static Matrix identity_matrix;
81 Object(const Mesh *, const Technique *);
85 LevelOfDetail &get_lod(unsigned, const char *);
88 /** Sets the mesh for the highest level of detail (index 0). */
89 void set_mesh(const Mesh *m) { set_mesh(0, m); }
91 /** Sets the mesh for a given level of detail. Previous LoDs must have been
93 void set_mesh(unsigned, const Mesh *);
96 void update_bounding_sphere();
98 const Mesh *get_mesh(unsigned = 0) const;
100 /** Sets the technique for the highest level of detail (index 0). */
101 void set_technique(const Technique *t) { set_technique(0, t); }
103 /** Sets the technique for a given level of detail. Previous LoDs must have
105 void set_technique(unsigned, const Technique *);
107 const Technique *get_technique(unsigned = 0) const;
108 unsigned get_n_lods() const { return lods.size(); }
110 virtual const Matrix *get_matrix() const { return &identity_matrix; }
111 virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return &bounding_sphere; }
113 virtual void render(Renderer &, const Tag & = Tag()) const;
115 /** Renders an instance of the object. The instance's hook functions are
116 called before and after drawing the mesh. */
117 virtual void render(Renderer &, const ObjectInstance &, const Tag & = Tag()) const;
120 virtual void setup_render(Renderer &, const Tag &) const { }
121 virtual void finish_render(Renderer &, const Tag &) const { }
124 const RenderPass *get_pass(const Tag &, unsigned) const;
126 virtual void resource_loaded(Resource &);
127 virtual void resource_removed(Resource &);