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 &, Collection &);
55 virtual void finish();
57 void bounding_sphere_hint(float, float, float, float);
58 void level_of_detail(unsigned);
65 const Technique *technique;
68 std::vector<LevelOfDetail> lods;
69 Geometry::BoundingSphere<float, 3> bounding_sphere;
70 bool lod0_watched = false;
72 static const Matrix identity_matrix;
76 Object(const Mesh *, const Technique *);
80 LevelOfDetail &get_lod(unsigned, const char *);
83 /** Sets the mesh for the highest level of detail (index 0). */
84 void set_mesh(const Mesh *m) { set_mesh(0, m); }
86 /** Sets the mesh for a given level of detail. Previous LoDs must have been
88 void set_mesh(unsigned, const Mesh *);
91 void update_bounding_sphere();
93 const Mesh *get_mesh(unsigned = 0) const;
95 /** Sets the technique for the highest level of detail (index 0). */
96 void set_technique(const Technique *t) { set_technique(0, t); }
98 /** Sets the technique for a given level of detail. Previous LoDs must have
100 void set_technique(unsigned, const Technique *);
102 const Technique *get_technique(unsigned = 0) const;
103 unsigned get_n_lods() const { return lods.size(); }
105 virtual const Matrix *get_matrix() const { return &identity_matrix; }
106 virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return &bounding_sphere; }
108 virtual void render(Renderer &, Tag = Tag()) const;
110 /** Renders an instance of the object. The instance's hook functions are
111 called before and after drawing the mesh. */
112 virtual void render(Renderer &, const ObjectInstance &, Tag = Tag()) const;
115 virtual void setup_render(Renderer &, Tag) const { }
116 virtual void finish_render(Renderer &, Tag) const { }
119 const RenderMethod *get_method(Tag, unsigned) const;
121 virtual void resource_loaded(Resource &);
122 virtual void resource_removed(Resource &);