Tulip  5.2.1
Large graphs analysis and drawing
OpenGlConfigManager.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_OPENGLCONFIGMANAGER_H
22 #define Tulip_OPENGLCONFIGMANAGER_H
23 
24 #include <tulip/tulipconf.h>
25 
26 #include <map>
27 #include <string>
28 
29 #define BUFFER_OFFSET(bytes) (static_cast<GLubyte *>(nullptr) + (bytes))
30 
31 namespace tlp {
32 
33 /** \brief Singleton used to manage OpenGl configuration
34  *
35  * Singleton used to manage OpenGl configuration
36  */
37 class TLP_GL_SCOPE OpenGlConfigManager {
38 
39 public:
40  /**
41  * Return the current instance. If instance doesn't exist, create it.
42  *
43  */
44  static OpenGlConfigManager &getInst();
45 
46  /**
47  * Returns the OpenGL version number supported by the host system as a string.
48  *
49  * \since Tulip 5.0
50  */
51  std::string getOpenGLVersionString() const;
52 
53  /**
54  * Returns the OpenGL version number supported by the host system as a number.
55  */
56  double getOpenGLVersion() const;
57 
58  /**
59  * Return the vendor name of the OpenGL driver installed on the host system.
60  */
61  std::string getOpenGLVendor() const;
62 
63  void initExtensions();
64 
65  /**
66  * Checks if an OpenGL extension is supported by the driver installed on the host system.
67  * \param extensionName the name of the OpenGL extension to check in the form "GL_.*" (for
68  * instance "GL_ARB_vertex_buffer_object")
69  */
70  bool isExtensionSupported(const std::string &extensionName);
71 
72  /**
73  * Returns if vertex buffer objects can be used on the host system.
74  */
75  bool hasVertexBufferObject();
76 
77  /**
78  * Enables / disables anti-aliasing rendering.
79  */
80  void setAntiAliasing(const bool antialiasing) {
81  antialiased = antialiasing;
82  }
83 
84  /**
85  * Returns the anti-aliasing state
86  */
87  bool antiAliasing() const {
88  return antialiased;
89  }
90 
91  /**
92  * Activates anti-aliasing
93  * This method has no effect if anti-aliasing has been disabled by a call to
94  * setAntiAliasing(false).
95  */
96  void activateAntiAliasing();
97 
98  /**
99  * Desactivates anti-aliasing
100  * This method has no effect if anti-aliasing has been disabled by a call to
101  * setAntiAliasing(false).
102  */
103  void desactivateAntiAliasing();
104 
105  /**
106  * Returns a maximum number of samples for anti-aliasing based on graphics hardware capability
107  *
108  */
109  int maxNumberOfSamples() const;
110 
111  /**
112  * Activates the anti-aliasing of lines and points primitives.
113  * This method has no effect if anti-aliasing has been disabled by a call to
114  * setAntiAliasing(false).
115  */
116  _DEPRECATED void activateLineAndPointAntiAliasing();
117 
118  /**
119  * Desactivates the anti-aliasing of lines and points primitives.
120  * This method has no effect if anti-aliasing has been disabled by a call to
121  * setAntiAliasing(false).
122  */
123  _DEPRECATED void desactivateLineAndPointAntiAliasing();
124 
125  /**
126  * Activates the anti-aliasing of polygons primitives.
127  * This method has no effect if anti-aliasing has been disabled by a call to
128  * setAntiAliasing(false).
129  */
130  _DEPRECATED void activatePolygonAntiAliasing();
131  /**
132  * Desactivates the anti-aliasing of polygons primitives.
133  * This method has no effect if anti-aliasing has been disabled by a call to
134  * setAntiAliasing(false).
135  */
136  _DEPRECATED void desactivatePolygonAntiAliasing();
137 
138 private:
139  /**
140  * Private constructor for singleton
141  */
142  OpenGlConfigManager();
143 
144  static OpenGlConfigManager *inst;
145 
146  bool glewIsInit;
147  bool antialiased;
148 
149  std::map<std::string, bool> checkedExtensions;
150 };
151 } // namespace tlp
152 
153 #endif
154 ///@endcond