Developer Documentation
gl.cc
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 #include <ACG/GL/acg_glew.hh>
43 #include "gl.hh"
44 
45 #include <cstdlib>
46 #include <sstream>
47 #include <iostream>
48 
49 
50 
51 //=============================================================================
52 namespace ACG {
53 //=============================================================================
54 namespace {
61 inline const char *_getExtensionString() {
62 
63  // glGetString(GL_EXTENSIONS) is deprecated and not available in core profile
64  if(!openGLVersion(3,0))
65  {
66  return (const char*) glGetString(GL_EXTENSIONS);
67  }
68 
69  // enumerate extensions with glGetStringi(GL_EXTENSIONS, id) instead
70 #ifndef __APPLE__
71  if (!glGetStringi)
72  glewInit();
73 #endif
74  static std::string supported_str;
75 
76  if (supported_str.empty()) {
77  GLint extensions = 0;
78  glGetIntegerv(GL_NUM_EXTENSIONS, &extensions);
79 
80  for (int i = 0; i < extensions; ++i) {
81 
82  const char *supported_cstr = reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, i));
83 
84  if (supported_cstr == 0) {
85  std::cerr << "\x1b[1;31mACG::checkExtensionsSupported: "
86  "glGetStringi(GL_EXTENSIONS, "<<i<<") call failed.\x1b[0m\n";
87  return "";
88  }
89 
90  supported_str += supported_cstr;
91  if (i + 1 < extensions)
92  supported_str += " ";
93  }
94  }
95 
96  return supported_str.c_str();
97 }
98 }
99 
100 std::string getExtensionString()
101 {
102  return _getExtensionString();
103 }
104 
107 bool checkExtensionSupported( const std::string& _extension ) {
112  static const std::string supported_str(_getExtensionString());
113 
114  /*
115  * supported_str is a space delimited list. Tokenize it. Simply searching
116  * for _extension within supported_str yields false positives if the
117  * requested extension is a substring of a supported one.
118  */
119  for (std::istringstream supported(supported_str); !supported.eof(); ) {
120  std::string feature;
121  supported >> feature;
122  if (feature == _extension) return true;
123  }
124  return false;
125 }
126 
129 bool openGLVersion( const int _major, const int _minor, bool _verbose ) {
130 
131  // Read OpenGL Version string
132  std::string glVersionString = (const char*)glGetString(GL_VERSION);
133 
134  // Use string stream to parse
135  std::istringstream stream;
136  stream.str(glVersionString);
137 
138  // Buffer for the dot between major and minor
139  char dot;
140 
141  // Read Major version number
142  int major ;
143  stream >> major;
144  stream >> dot;
145 
146  // Read minor version number
147  int minor;
148  stream >> minor;
149 
150  if ( (_major > major) || ( (_major == major) && (_minor > minor)) ) {
151  if(_verbose)
152  {
153  std::cerr << "OpenGL Version check failed. Required : " << _major << "." << _minor << std::endl;
154  std::cerr << "OpenGL Version check failed. Available : " << major << "." << minor << std::endl;
155  }
156  return false;
157  }
158 
159  return true;
160 }
161 
163 static bool compatibilityProfile_ = false;
164 
166 void compatibilityProfile( bool _enableCoreProfile ) {
167  compatibilityProfile_ = _enableCoreProfile;
168 }
169 
172  return compatibilityProfile_;
173 }
174 
175 //=============================================================================
176 } // namespace ACG
177 //=============================================================================
Namespace providing different geometric functions concerning angles.
bool openGLVersion(const int _major, const int _minor, bool _verbose)
Definition: gl.cc:129
bool checkExtensionSupported(const std::string &_extension)
Definition: gl.cc:107
void compatibilityProfile(bool _enableCoreProfile)
Store opengl core profile setting.
Definition: gl.cc:166
std::string getExtensionString()
getExtensionString returns a string containing all supported OpenGL extensions this function uses the...
Definition: gl.cc:100