]> git.tdb.fi Git - libs/gl.git/blob - source/instancescene.h
Generalize instancing to all Renderables
[libs/gl.git] / source / instancescene.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_INSTANCESCENE_H_
9 #define MSP_GL_INSTANCESCENE_H_
10
11 #include <map>
12 #include <set>
13 #include "scene.h"
14
15 namespace Msp {
16 namespace GL {
17
18 /**
19 A Scene optimized for rendering instanced Renderables, such as ObjectInstances.
20 All Renderables with the same instance key are rendered consecutively; within
21 the same key rendering order is unspecified.
22 */
23 class InstanceScene: public Scene
24 {
25 private:
26         typedef std::set<const Renderable *> RenderableSet;
27         typedef std::map<long, RenderableSet> InstanceMap;
28
29         InstanceMap renderables;
30
31 public:
32         virtual void add(const Renderable &);
33         virtual void remove(const Renderable &);
34
35         using Scene::render;
36         virtual void render(Renderer &, const Tag &tag = Tag()) const;
37 };
38
39 } // namespace GL
40 } // namespace Msp
41
42 #endif