]> git.tdb.fi Git - libs/gl.git/blob - source/objectinstance.h
Generalize instancing to all Renderables
[libs/gl.git] / source / objectinstance.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_OBJETCINSTANCE_H_
9 #define MSP_GL_OBJETCINSTANCE_H_
10
11 #include <string>
12 #include "renderable.h"
13
14 namespace Msp {
15 namespace GL {
16
17 class Object;
18 class ProgramData;
19
20 /**
21 Represents a single instance of an Object.  An application can derive another
22 class from this and overload the hook functions to specify location and other
23 instance-specific parameters for the rendered objects.
24 */
25 class ObjectInstance: public Renderable
26 {
27 protected:
28         const Object &object;
29
30 public:
31         ObjectInstance(const Object &);
32
33         const Object &get_object() const { return object; }
34         virtual long get_instance_key() const { return reinterpret_cast<long>(&object); }
35
36         virtual void render(const Tag &tag = Tag()) const;
37         virtual void render(Renderer &, const Tag & = Tag()) const;
38
39         /** Hook function, called from Object just before rendering the mesh.
40         Renderer state will have been pushed before this is called. */
41         virtual void setup_render(Renderer &, const Tag &) const { }
42
43         /** Hook function, called from Object right after rendering the mesh.  Since
44         Object takes care of pushing Renderer state, this rarely needs to do
45         anything. */
46         virtual void finish_render(Renderer &, const Tag &) const { }
47
48         virtual unsigned get_level_of_detail() const { return 0; }
49 };
50
51 } // namespace GL
52 } // namespaec Msp
53
54 #endif