Tulip  4.0.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
OpenGlConfigManager.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_OPENGLCONFIGMANAGER_H
22 #define Tulip_OPENGLCONFIGMANAGER_H
23 
24 #include <cassert>
25 #include <iostream>
26 #include <map>
27 
28 #if defined(_MSC_VER)
29 #include <Windows.h>
30 #endif
31 
32 #if defined(__APPLE__)
33 #include <OpenGL/gl.h>
34 #include <OpenGL/glu.h>
35 #else
36 #include <GL/gl.h>
37 #include <GL/glu.h>
38 # if defined(__WIN32__)
39 # include <GL/glext.h>
40 # endif
41 #endif
42 
43 #ifdef HAVE_CONFIG_H
44 #include <config.h>
45 #endif
46 
47 #include <tulip/tulipconf.h>
48 
49 #define BUFFER_OFFSET(bytes) ((GLubyte*) NULL + (bytes))
50 
51 namespace tlp {
52 
53 class OpenGlErrorViewer;
54 
55 /** \brief Singleton used to manage OpenGl configuration
56  *
57  * Singleton used to manage OpenGl configuration
58  */
59 class TLP_GL_SCOPE OpenGlConfigManager {
60 
61 public:
62 
63  /**
64  * Return the current instance. If instance doesn't exist, create it.
65  */
66  static OpenGlConfigManager &getInst();
67 
68  /**
69  * Change the error viewer and return the old one.
70  */
71  OpenGlErrorViewer *setErrorViewer(OpenGlErrorViewer *errorViewer);
72 
73  /**
74  * Check if system has good graphics card drivers.
75  */
76  void checkDrivers();
77 
78  /**
79  * Returns the OpenGL version number supported by the host system.
80  */
81  double getOpenGLVersion();
82 
83  /**
84  * Return the vendor name of the OpenGL driver installed on the host system.
85  */
86  std::string getOpenGLVendor();
87 
88  /**
89  * Checks if an OpenGL extension is supported by the driver installed on the host system.
90  * \param extensionName the name of the OpenGL extension to check in the form "GL_.*" (for instance "GL_ARB_vertex_buffer_object")
91  */
92  bool isExtensionSupported(const std::string &extensionName);
93 
94  /**
95  * Returns if vertex buffer objects can be used on the host system.
96  */
97  bool hasVertexBufferObject();
98 
99  /**
100  * Enables / disables anti-aliasing rendering.
101  */
102  void setAntiAliasing(const bool antialiasing) {
103  antialiased = antialiasing;
104  }
105 
106  /**
107  * Activates the anti-aliasing of lines and points primitives.
108  * This method has no effect if anti-aliasing has been disabled by a call to setAntiAliasing(false).
109  */
110  void activateLineAndPointAntiAliasing();
111 
112  /**
113  * Desactivates the anti-aliasing of lines and points primitives.
114  * This method has no effect if anti-aliasing has been disabled by a call to setAntiAliasing(false).
115  */
116  void desactivateLineAndPointAntiAliasing();
117 
118  /**
119  * Activates the anti-aliasing of polygons primitives.
120  * This method has no effect if anti-aliasing has been disabled by a call to setAntiAliasing(false).
121  */
122  void activatePolygonAntiAliasing();
123  /**
124  * Desactivates the anti-aliasing of polygons primitives.
125  * This method has no effect if anti-aliasing has been disabled by a call to setAntiAliasing(false).
126  */
127  void desactivatePolygonAntiAliasing();
128 
129  void initGlew();
130 
131 private:
132 
133 
134 
135  /**
136  * Private constructor for singleton
137  */
138  OpenGlConfigManager();
139 
140  static OpenGlConfigManager* inst;
141 
142  OpenGlErrorViewer *errorViewer;
143 
144  bool glewIsInit;
145  bool driversAreChecked;
146  bool antialiased;
147 
148  std::map<std::string, bool> checkedExtensions;
149 
150 };
151 
152 }
153 
154 #endif
155 ///@endcond