Tulip  5.1.0
Large graphs analysis and drawing
GlDisplayListManager.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef Tulip_GLDISPLAYLISTMANAGER_H
22 #define Tulip_GLDISPLAYLISTMANAGER_H
23 
24 #include <tulip/OpenGlIncludes.h>
25 
26 #include <map>
27 #include <string>
28 
29 #include <stdint.h>
30 
31 #include <tulip/tulipconf.h>
32 
33 namespace tlp {
34 
35 /** \brief Singleton used to manage OpenGl display list
36  *
37  * Singleton used to manage OpenGl display list.
38  * First createInst must be call.
39  */
40 class TLP_GL_SCOPE GlDisplayListManager {
41 
42  typedef std::map<std::string,GLuint> DisplayListMap;
43  typedef std::map<uintptr_t, DisplayListMap> ContextAndDisplayListMap;
44 
45 public:
46 
47  /**
48  * Return the current instance. If instance doesn't exist, create it.
49  */
50  static GlDisplayListManager &getInst() {
51  if(!inst)
52  inst=new GlDisplayListManager();
53 
54  return *inst;
55  }
56 
57  /**
58  * Change OpenGl context because display list can't be shared in different context
59  */
60  void changeContext(uintptr_t context);
61 
62  /**
63  * remove context
64  */
65  void removeContext(uintptr_t context);
66 
67  /**
68  * Begin to record a new display list with name : name
69  */
70  bool beginNewDisplayList(const std::string& name);
71  /**
72  * End the current record of display list
73  */
74  void endNewDisplayList();
75 
76  /**
77  * Call display list with name : name
78  */
79  bool callDisplayList(const std::string& name);
80 
81 private:
82 
83  /**
84  * Private constructor for singleton
85  */
86  GlDisplayListManager() {}
87 
88  uintptr_t currentContext;
89 
90  static GlDisplayListManager* inst;
91 
92  ContextAndDisplayListMap displayListMap;
93 
94 };
95 
96 }
97 
98 #endif // Tulip_GLDISPLAYLISTMANAGER_H
99 ///@endcond