Tulip  4.6.1
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
GlDisplayListManager.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
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 #if defined(_MSC_VER)
25 #include <Windows.h>
26 #endif
27 
28 #if defined(__APPLE__)
29 #include <OpenGL/gl.h>
30 #include <OpenGL/glu.h>
31 #else
32 #include <GL/gl.h>
33 #include <GL/glu.h>
34 #endif
35 
36 #include <map>
37 #include <string>
38 
39 #include <stdint.h>
40 
41 #include <tulip/tulipconf.h>
42 
43 namespace tlp {
44 
45 /** \brief Singleton used to manage OpenGl display list
46  *
47  * Singleton used to manage OpenGl display list.
48  * First createInst must be call.
49  */
50 class TLP_GL_SCOPE GlDisplayListManager {
51 
52  typedef std::map<std::string,GLuint> DisplayListMap;
53  typedef std::map<uintptr_t, DisplayListMap> ContextAndDisplayListMap;
54 
55 public:
56 
57  /**
58  * Return the current instance. If instance doesn't exist, create it.
59  */
60  static GlDisplayListManager &getInst() {
61  if(!inst)
62  inst=new GlDisplayListManager();
63 
64  return *inst;
65  }
66 
67  /**
68  * Change OpenGl context because display list can't be shared in different context
69  */
70  void changeContext(uintptr_t context);
71 
72  /**
73  * remove context
74  */
75  void removeContext(uintptr_t context);
76 
77  /**
78  * Begin to record a new display list with name : name
79  */
80  bool beginNewDisplayList(const std::string& name);
81  /**
82  * End the current record of display list
83  */
84  void endNewDisplayList();
85 
86  /**
87  * Call display list with name : name
88  */
89  bool callDisplayList(const std::string& name);
90 
91 private:
92 
93  /**
94  * Private constructor for singleton
95  */
96  GlDisplayListManager() {}
97 
98  uintptr_t currentContext;
99 
100  static GlDisplayListManager* inst;
101 
102  ContextAndDisplayListMap displayListMap;
103 
104 };
105 
106 }
107 
108 #endif // Tulip_GLDISPLAYLISTMANAGER_H
109 ///@endcond