]> git.tdb.fi Git - libs/gl.git/blob - source/objectinstance.h
Merge branch 'animation-rework'
[libs/gl.git] / source / objectinstance.h
1 #ifndef MSP_GL_OBJETCINSTANCE_H_
2 #define MSP_GL_OBJETCINSTANCE_H_
3
4 #include <string>
5 #include "object.h"
6 #include "placeable.h"
7
8 namespace Msp {
9 namespace GL {
10
11 /**
12 Represents a single instance of an Object.  Thanks to being derived from
13 Placeable in can be positioned without additional effort.  Other instance
14 parameters can be set by overriding the hook functions.
15
16 ObjectInstances can benefit from being put in an InstanceScene, which will
17 render all instances of the same object consecutively.
18 */
19 class ObjectInstance: public PlacedRenderable
20 {
21 public:
22         class Loader: public DataFile::ObjectLoader<ObjectInstance>
23         {
24         public:
25                 Loader(ObjectInstance &);
26
27         private:
28                 void transform();
29         };
30
31 protected:
32         const Object &object;
33
34 public:
35         ObjectInstance(const Object &);
36
37         const Object &get_object() const { return object; }
38         virtual long get_instance_key() const { return reinterpret_cast<long>(&object); }
39
40         virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return object.get_bounding_sphere(); }
41
42         virtual void render(const Tag &tag = Tag()) const;
43         virtual void render(Renderer &, const Tag & = Tag()) const;
44
45         /** Hook function, called from Object just before rendering the mesh.
46         Renderer state will have been pushed before this is called. */
47         virtual void setup_render(Renderer &, const Tag &) const;
48
49         /** Hook function, called from Object right after rendering the mesh.  Since
50         Object takes care of pushing Renderer state, this rarely needs to do
51         anything. */
52         virtual void finish_render(Renderer &, const Tag &) const { }
53
54         virtual unsigned get_level_of_detail(const Renderer &) const { return 0; }
55 };
56
57 } // namespace GL
58 } // namespaec Msp
59
60 #endif