]> git.tdb.fi Git - libs/gl.git/blob - source/object.h
Add a shortcut constructor to Object
[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 Stores a Mesh together with a Technique to determine its appearance.
20
21 It is possible to use a single Object for rendering multiple identical or
22 similar objects.  See class ObjectInstance.
23 */
24 class Object: public Renderable
25 {
26 private:
27         std::vector<RefPtr<const Mesh> > meshes;
28         RefPtr<const Technique> technique;
29
30 public:
31         class Loader: public DataFile::CollectionObjectLoader<Object>
32         {
33         public:
34                 Loader(Object &);
35                 Loader(Object &, Collection &);
36         private:
37                 void init();
38
39         private:
40                 void mesh_inline();
41                 void mesh_inline_lod(unsigned);
42                 void mesh(const std::string &);
43                 void mesh_lod(unsigned, const std::string &);
44                 void technique_inline();
45                 void technique(const std::string &);
46         };
47
48         Object();
49         Object(const Mesh *, const Technique *);
50         ~Object();
51
52         void set_mesh(const Mesh *m) { set_mesh(0, m); }
53         void set_mesh(unsigned, const Mesh *);
54         const Mesh *get_mesh(unsigned = 0) const;
55         void set_technique(const Technique *);
56         const Technique *get_technique() const { return technique.get(); }
57
58         /**
59         Renders the object.  A tag can be provided to render a non-default pass.
60         */
61         virtual void render(const Tag &tag = Tag()) const;
62
63         virtual void render(Renderer &, const Tag & = Tag()) const;
64
65         /**
66         Renders the object with an instance.  The instance's hook functions are
67         called before and after drawing the mesh.  A tag may also be given to render
68         a non-default pass.
69         */
70         virtual void render(Renderer &, const ObjectInstance &, const Tag & = Tag()) const;
71
72 private:
73         const RenderPass *get_pass(const Tag &) const;
74 };
75
76 } // namespace GL
77 } // namespace Msp
78
79 #endif