Tulip  5.2.1
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 <cstdint>
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  * Return the current instance. If instance doesn't exist, create it.
48  */
49  static GlDisplayListManager &getInst() {
50  if (!inst)
51  inst = new GlDisplayListManager();
52 
53  return *inst;
54  }
55 
56  /**
57  * Change OpenGl context because display list can't be shared in different context
58  */
59  void changeContext(uintptr_t context);
60 
61  /**
62  * remove context
63  */
64  void removeContext(uintptr_t context);
65 
66  /**
67  * Begin to record a new display list with name : name
68  */
69  bool beginNewDisplayList(const std::string &name);
70  /**
71  * End the current record of display list
72  */
73  void endNewDisplayList();
74 
75  /**
76  * Call display list with name : name
77  */
78  bool callDisplayList(const std::string &name);
79 
80 private:
81  /**
82  * Private constructor for singleton
83  */
84  GlDisplayListManager() {}
85 
86  uintptr_t currentContext;
87 
88  static GlDisplayListManager *inst;
89 
90  ContextAndDisplayListMap displayListMap;
91 };
92 } // namespace tlp
93 
94 #endif // Tulip_GLDISPLAYLISTMANAGER_H
95 ///@endcond