1 #ifndef MSP_GL_OBJECT_H_
2 #define MSP_GL_OBJECT_H_
5 #include "renderable.h"
6 #include "renderpass.h"
7 #include "resourceobserver.h"
19 Combines a Mesh with a Technique to give it an appearance. The Technique will
20 define which render passes the Object supports.
22 In many cases, it's desirable to include multiple copies of an Object in a
23 Scene, with different model matrices. ObjectInstances can be used to alter the
24 rendering of an object on a per-instance basis.
26 Objects can have multiple levels of detail. The most detailed level has index
27 0, with increasing indices having less detail. When rendering an instance, the
28 instance's get_level_of_detail method is called to determine which LoD to use.
30 class Object: public Renderable, private ResourceObserver
35 class LodLoader: public DataFile::CollectionObjectLoader<Object>
42 LodLoader(Object &, unsigned, Collection *);
45 void mesh(const std::string &);
47 void technique(const std::string &);
48 void technique_inline();
52 class Loader: public LodLoader
56 Loader(Object &, Collection &);
59 virtual void finish();
61 void bounding_sphere_hint(float, float, float, float);
62 void level_of_detail(unsigned);
69 const Technique *technique;
72 std::vector<LevelOfDetail> lods;
73 Geometry::BoundingSphere<float, 3> bounding_sphere;
76 static Matrix identity_matrix;
80 Object(const Mesh *, const Technique *);
84 LevelOfDetail &get_lod(unsigned, const char *);
87 /** Sets the mesh for the highest level of detail (index 0). */
88 void set_mesh(const Mesh *m) { set_mesh(0, m); }
90 /** Sets the mesh for a given level of detail. Previous LoDs must have been
92 void set_mesh(unsigned, const Mesh *);
95 void update_bounding_sphere();
97 const Mesh *get_mesh(unsigned = 0) const;
99 /** Sets the technique for the highest level of detail (index 0). */
100 void set_technique(const Technique *t) { set_technique(0, t); }
102 /** Sets the technique for a given level of detail. Previous LoDs must have
104 void set_technique(unsigned, const Technique *);
106 const Technique *get_technique(unsigned = 0) const;
107 unsigned get_n_lods() const { return lods.size(); }
109 virtual const Matrix *get_matrix() const { return &identity_matrix; }
110 virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return &bounding_sphere; }
112 virtual void render(Renderer &, Tag = Tag()) const;
114 /** Renders an instance of the object. The instance's hook functions are
115 called before and after drawing the mesh. */
116 virtual void render(Renderer &, const ObjectInstance &, Tag = Tag()) const;
119 virtual void setup_render(Renderer &, Tag) const { }
120 virtual void finish_render(Renderer &, Tag) const { }
123 const RenderPass *get_pass(Tag, unsigned) const;
125 virtual void resource_loaded(Resource &);
126 virtual void resource_removed(Resource &);