diff options
author | donbright <hugh.m.bright@gmail.com> | 2013-03-05 23:47:14 (GMT) |
---|---|---|
committer | donbright <hugh.m.bright@gmail.com> | 2013-03-05 23:47:14 (GMT) |
commit | 42f21c3a0850083d245aa3ac346a53e876f0679e (patch) | |
tree | facf41750e0fe27cc4cdaf352c9c8e687011d103 /src/system-gl.cc | |
parent | 422c668dcb538f181683ae51305bf8d3404f48d6 (diff) | |
parent | 4734172c3a16cc06b09e4d2131aa8e380bd0f226 (diff) |
Merge pull request #288 from openscad/issue11_2
Issue11 2
Diffstat (limited to 'src/system-gl.cc')
-rw-r--r-- | src/system-gl.cc | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/system-gl.cc b/src/system-gl.cc new file mode 100644 index 0000000..0c436e5 --- /dev/null +++ b/src/system-gl.cc @@ -0,0 +1,89 @@ + +/* OpenGL helper functions */ + +#include <algorithm> +#include <iostream> +#include <vector> +#include <sstream> +#include <string> +#include "system-gl.h" +#include <boost/algorithm/string.hpp> +#include <boost/format.hpp> + +using namespace std; +using namespace boost; + +double gl_version() +{ + string tmp((const char*)glGetString( GL_VERSION )); + vector<string> strs; + split(strs, tmp, is_any_of(".")); + stringstream out; + if ( strs.size() >= 2) + out << strs[0] << "." << strs[1]; + else + out << "0.0"; + double d; + out >> d; + return d; +} + +string glew_extensions_dump() +{ + std::string tmp; + if ( gl_version() >= 3.0 ) { + GLint numexts = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &numexts); + for ( int i=0;i<numexts;i++ ) { + tmp += (const char *) glGetStringi(GL_EXTENSIONS, i); + tmp += " "; + } + } else { + tmp = (const char *) glGetString(GL_EXTENSIONS); + } + vector<string> extensions; + split( extensions, tmp, is_any_of(" ")); + sort( extensions.begin(), extensions.end() ); + stringstream out; + out << "GL Extensions:"; + for ( int i=0;i<extensions.size();i++ ) out << extensions[i] << "\n"; + return out.str(); +} + +string glew_dump() +{ + GLint rbits, gbits, bbits, abits, dbits, sbits; + glGetIntegerv(GL_RED_BITS, &rbits); + glGetIntegerv(GL_GREEN_BITS, &gbits); + glGetIntegerv(GL_BLUE_BITS, &bbits); + glGetIntegerv(GL_ALPHA_BITS, &abits); + glGetIntegerv(GL_DEPTH_BITS, &dbits); + glGetIntegerv(GL_STENCIL_BITS, &sbits); + + stringstream out; + out << "GLEW version: " << glewGetString(GLEW_VERSION) + << "\nOpenGL Version: " << (const char *)glGetString(GL_VERSION) + << "\nGL Renderer: " << (const char *)glGetString(GL_RENDERER) + << "\nGL Vendor: " << (const char *)glGetString(GL_VENDOR) + << boost::format("\nRGBA(%d%d%d%d), depth(%d), stencil(%d)") % + rbits % gbits % bbits % abits % dbits % sbits; + out << "\nGL_ARB_framebuffer_object: " + << (glewIsSupported("GL_ARB_framebuffer_object") ? "yes" : "no") + << "\nGL_EXT_framebuffer_object: " + << (glewIsSupported("GL_EXT_framebuffer_object") ? "yes" : "no") + << "\nGL_EXT_packed_depth_stencil: " + << (glewIsSupported("GL_EXT_packed_depth_stencil") ? "yes" : "no") + << "\n"; + return out.str(); +}; + +bool report_glerror(const char * function) +{ + GLenum tGLErr = glGetError(); + if (tGLErr != GL_NO_ERROR) { + cerr << "OpenGL error 0x" << hex << tGLErr << ": " << gluErrorString(tGLErr) << " after " << function << endl; + return true; + } + return false; +} + |