]> git.tdb.fi Git - libs/gl.git/blob - source/object.h
Add an interface for obtaining bounding spheres from renderables
[libs/gl.git] / source / object.h
1 #ifndef MSP_GL_OBJECT_H_
2 #define MSP_GL_OBJECT_H_
3
4 #include <vector>
5 #include "bindable.h"
6 #include "renderable.h"
7 #include "renderpass.h"
8
9 namespace Msp {
10 namespace GL {
11
12 class Material;
13 class Mesh;
14 class ObjectInstance;
15 class Technique;
16 class Texture;
17
18 /**
19 Combines a Mesh with a Technique to give it an appearance.  The Technique will
20 define which render passes the Object supports.
21
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.
25 */
26 class Object: public Renderable
27 {
28 public:
29         class Loader: public DataFile::CollectionObjectLoader<Object>
30         {
31         public:
32                 Loader(Object &);
33                 Loader(Object &, Collection &);
34         private:
35                 void init();
36                 virtual void finish();
37
38                 void mesh_inline();
39                 void mesh_inline_lod(unsigned);
40                 void mesh(const std::string &);
41                 void mesh_lod(unsigned, const std::string &);
42                 void technique_inline();
43                 void technique(const std::string &);
44         };
45
46 private:
47         std::vector<RefPtr<const Mesh> > meshes;
48         RefPtr<const Technique> technique;
49         Geometry::BoundingSphere<float, 3> bounding_sphere;
50
51 public:
52         Object();
53         Object(const Mesh *, const Technique *);
54         ~Object();
55
56         void set_mesh(const Mesh *m) { set_mesh(0, m); }
57         void set_mesh(unsigned, const Mesh *);
58 private:
59         void update_bounding_sphere();
60 public:
61         const Mesh *get_mesh(unsigned = 0) const;
62         void set_technique(const Technique *);
63         const Technique *get_technique() const { return technique.get(); }
64
65         virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return &bounding_sphere; }
66
67         virtual void render(const Tag &tag = Tag()) const;
68
69         virtual void render(Renderer &, const Tag & = Tag()) const;
70
71         /** Renders an instance of the object.  The instance's hook functions are
72         called before and after drawing the mesh. */
73         virtual void render(Renderer &, const ObjectInstance &, const Tag & = Tag()) const;
74
75 protected:
76         virtual void setup_render(Renderer &, const Tag &) const { }
77         virtual void finish_render(Renderer &, const Tag &) const { }
78
79 private:
80         const RenderPass *get_pass(const Tag &) const;
81 };
82
83 } // namespace GL
84 } // namespace Msp
85
86 #endif