Tulip  4.3.0
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 1 and Inria Bordeaux - Sud Ouest
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 <tulip/tulipconf.h>
40 
41 namespace tlp {
42 
43 /** \brief Singleton used to manage OpenGl display list
44  *
45  * Singleton used to manage OpenGl display list.
46  * First createInst must be call.
47  */
48 class TLP_GL_SCOPE GlDisplayListManager {
49 
50  typedef std::map<std::string,GLuint> DisplayListMap;
51  typedef std::map<unsigned long, DisplayListMap> ContextAndDisplayListMap;
52 
53 public:
54 
55  /**
56  * Return the current instance. If instance doesn't exist, create it.
57  */
58  static GlDisplayListManager &getInst() {
59  if(!inst)
60  inst=new GlDisplayListManager();
61 
62  return *inst;
63  }
64 
65  /**
66  * Change OpenGl context because display list can't be shared in different context
67  */
68  void changeContext(unsigned long context);
69 
70  /**
71  * remove context
72  */
73  void removeContext(unsigned long context);
74 
75  /**
76  * Begin to record a new display list with name : name
77  */
78  bool beginNewDisplayList(const std::string& name);
79  /**
80  * End the current record of display list
81  */
82  void endNewDisplayList();
83 
84  /**
85  * Call display list with name : name
86  */
87  bool callDisplayList(const std::string& name);
88 
89 private:
90 
91  /**
92  * Private constructor for singleton
93  */
94  GlDisplayListManager() {}
95 
96  unsigned long currentContext;
97 
98  static GlDisplayListManager* inst;
99 
100  ContextAndDisplayListMap displayListMap;
101 
102 };
103 
104 }
105 
106 #endif // Tulip_GLDISPLAYLISTMANAGER_H
107 ///@endcond