]> git.tdb.fi Git - libs/gl.git/blob - source/object.h
af9d2d26e42656a4fd8ad3c5a7115c4f996f686b
[libs/gl.git] / source / object.h
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007-2008, 2010-2011  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GL_OBJECT_H_
9 #define MSP_GL_OBJECT_H_
10
11 #include <vector>
12 #include "bindable.h"
13 #include "renderable.h"
14 #include "renderpass.h"
15
16 namespace Msp {
17 namespace GL {
18
19 class Material;
20 class Mesh;
21 class ObjectInstance;
22 class Technique;
23 class Texture;
24
25 /**
26 Stores a Mesh together with a Technique to determine its appearance.
27
28 It is possible to use a single Object for rendering multiple identical or
29 similar objects.  See class ObjectInstance.
30 */
31 class Object: public Renderable
32 {
33 private:
34         std::vector<RefPtr<const Mesh> > meshes;
35         RefPtr<const Technique> technique;
36
37 public:
38         class Loader: public DataFile::CollectionObjectLoader<Object>
39         {
40         public:
41                 Loader(Object &);
42                 Loader(Object &, Collection &);
43         private:
44                 void init();
45
46         private:
47                 void mesh_inline();
48                 void mesh_inline_lod(unsigned);
49                 void mesh(const std::string &);
50                 void mesh_lod(unsigned, const std::string &);
51                 void technique_inline();
52                 void technique(const std::string &);
53         };
54
55         Object();
56         ~Object();
57
58         void set_mesh(const Mesh *m) { set_mesh(0, m); }
59         void set_mesh(unsigned, const Mesh *);
60         const Mesh *get_mesh(unsigned = 0) const;
61         void set_technique(const Technique *);
62         const Technique *get_technique() const { return technique.get(); }
63
64         /**
65         Renders the object.  A tag can be provided to render a non-default pass.
66         */
67         virtual void render(const Tag &tag = Tag()) const;
68
69         virtual void render(Renderer &, const Tag & = Tag()) const;
70
71         /**
72         Renders the object with an instance.  The instance's hook functions are
73         called before and after drawing the mesh.  A tag may also be given to render
74         a non-default pass.
75         */
76         virtual void render(Renderer &, const ObjectInstance &, const Tag & = Tag()) const;
77
78 private:
79         const RenderPass *get_pass(const Tag &) const;
80 };
81
82 } // namespace GL
83 } // namespace Msp
84
85 #endif