1 #ifndef MSP_GL_OBJECT_H_
2 #define MSP_GL_OBJECT_H_
5 #include "renderable.h"
6 #include "rendermethod.h"
7 #include "resourceobserver.h"
17 Combines a Mesh with a Technique to give it an appearance. The Technique will
18 define which render passes the Object supports.
20 In many cases, it's desirable to include multiple copies of an Object in a
21 Scene, with different model matrices. ObjectInstances can be used to alter the
22 rendering of an object on a per-instance basis.
24 Objects can have multiple levels of detail. The most detailed level has index
25 0, with increasing indices having less detail. When rendering an instance, the
26 instance's get_level_of_detail method is called to determine which LoD to use.
28 class Object: public Renderable, private ResourceObserver
33 class LodLoader: public DataFile::CollectionObjectLoader<Object>
40 LodLoader(Object &, unsigned, Collection *);
43 void mesh(const std::string &);
45 void technique(const std::string &);
46 void technique_inline();
50 class Loader: public LodLoader
53 Loader(Object &o): Loader(o, 0) { }
54 Loader(Object &o, Collection &c): Loader(o, &c) { }
56 Loader(Object &, Collection *);
57 virtual void finish();
59 void bounding_sphere_hint(float, float, float, float);
60 void level_of_detail(unsigned);
67 const Technique *technique;
70 std::vector<LevelOfDetail> lods;
71 Geometry::BoundingSphere<float, 3> bounding_sphere;
74 static const Matrix identity_matrix;
78 Object(const Mesh *, const Technique *);
82 LevelOfDetail &get_lod(unsigned, const char *);
85 /** Sets the mesh for the highest level of detail (index 0). */
86 void set_mesh(const Mesh *m) { set_mesh(0, m); }
88 /** Sets the mesh for a given level of detail. Previous LoDs must have been
90 void set_mesh(unsigned, const Mesh *);
93 void update_bounding_sphere();
95 const Mesh *get_mesh(unsigned = 0) const;
97 /** Sets the technique for the highest level of detail (index 0). */
98 void set_technique(const Technique *t) { set_technique(0, t); }
100 /** Sets the technique for a given level of detail. Previous LoDs must have
102 void set_technique(unsigned, const Technique *);
104 const Technique *get_technique(unsigned = 0) const;
105 unsigned get_n_lods() const { return lods.size(); }
107 virtual const Matrix *get_matrix() const { return &identity_matrix; }
108 virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return &bounding_sphere; }
110 virtual void render(Renderer &, Tag = Tag()) const;
112 /** Renders an instance of the object. The instance's hook functions are
113 called before and after drawing the mesh. */
114 virtual void render(Renderer &, const ObjectInstance &, Tag = Tag()) const;
117 virtual void setup_render(Renderer &, Tag) const { }
118 virtual void finish_render(Renderer &, Tag) const { }
121 const RenderMethod *get_method(Tag, unsigned) const;
123 virtual void resource_loaded(Resource &);
124 virtual void resource_removed(Resource &);