]> git.tdb.fi Git - libs/gl.git/blob - source/object.h
Style update: add spaces around assignment operators
[libs/gl.git] / source / object.h
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007-2008, 2010  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<Mesh *> meshes;
35         Technique *technique;
36         bool own_mesh:1;
37         bool own_technique:1;
38
39 public:
40         class Loader: public DataFile::CollectionObjectLoader<Object>
41         {
42         public:
43                 Loader(Object &);
44                 Loader(Object &, Collection &);
45         private:
46                 void init();
47
48         private:
49                 void lod_mesh(unsigned, const std::string &);
50                 void mesh();
51                 void mesh(const std::string &);
52                 void technique();
53         };
54
55         Object();
56         ~Object();
57
58         const Technique *get_technique() const { return technique; }
59
60         /**
61         Renders the object.  A tag can be provided to render a non-default pass.
62         */
63         virtual void render(const Tag &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(const ObjectInstance &, const Tag &tag = Tag()) const;
71
72         /**
73         Renders multiple instances of the object in one go.  This may improve
74         performance, as the object-specific render setup only has to be done once.
75         Each instance's hook functions will be called before and after drawing the
76         mesh.
77         */
78         template<typename Iter>
79         void render(Iter begin, Iter end, const Tag &tag = Tag()) const
80         {
81                 const RenderPass *pass = get_pass(tag);
82                 if(!pass)
83                         return;
84
85                 Bind bind(*pass);
86                 for(Iter i=begin; i!=end; ++i)
87                         render_instance(**i, tag);
88         }
89 private:
90         const RenderPass *get_pass(const Tag &) const;
91         void render_instance(const ObjectInstance &, const Tag &) const;
92 };
93
94 } // namespace GL
95 } // namespace Msp
96
97 #endif