2013-01-24 07:11:14 +04:00
|
|
|
|
|
|
|
/* OpenGL helper functions */
|
|
|
|
|
2013-02-21 09:02:44 +04:00
|
|
|
#include <algorithm>
|
2013-01-24 07:11:14 +04:00
|
|
|
#include <iostream>
|
2013-02-21 09:02:44 +04:00
|
|
|
#include <vector>
|
2013-01-24 07:11:14 +04:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include "system-gl.h"
|
|
|
|
#include <boost/algorithm/string.hpp>
|
2013-02-21 09:02:44 +04:00
|
|
|
#include <boost/format.hpp>
|
2013-01-24 07:11:14 +04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace boost;
|
|
|
|
|
2013-02-21 09:02:44 +04:00
|
|
|
double gl_version()
|
2013-01-24 07:11:14 +04:00
|
|
|
{
|
2013-02-21 09:02:44 +04:00
|
|
|
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:";
|
2013-05-26 07:37:26 +04:00
|
|
|
for ( unsigned int i=0;i<extensions.size();i++ )
|
|
|
|
out << extensions[i] << "\n";
|
2013-02-21 09:02:44 +04:00
|
|
|
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);
|
2013-01-24 07:11:14 +04:00
|
|
|
|
2013-02-21 09:02:44 +04:00
|
|
|
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: "
|
2013-01-24 07:11:14 +04:00
|
|
|
<< (glewIsSupported("GL_ARB_framebuffer_object") ? "yes" : "no")
|
2013-02-21 09:02:44 +04:00
|
|
|
<< "\nGL_EXT_framebuffer_object: "
|
2013-01-24 07:11:14 +04:00
|
|
|
<< (glewIsSupported("GL_EXT_framebuffer_object") ? "yes" : "no")
|
2013-02-21 09:02:44 +04:00
|
|
|
<< "\nGL_EXT_packed_depth_stencil: "
|
2013-01-24 07:11:14 +04:00
|
|
|
<< (glewIsSupported("GL_EXT_packed_depth_stencil") ? "yes" : "no")
|
2013-02-21 09:02:44 +04:00
|
|
|
<< "\n";
|
2013-01-24 07:11:14 +04:00
|
|
|
return out.str();
|
|
|
|
};
|
|
|
|
|
|
|
|
bool report_glerror(const char * function)
|
|
|
|
{
|
|
|
|
GLenum tGLErr = glGetError();
|
|
|
|
if (tGLErr != GL_NO_ERROR) {
|
2015-05-15 21:43:23 +03:00
|
|
|
std::ostringstream hexErr;
|
|
|
|
hexErr << hex << tGLErr;
|
|
|
|
cerr << "OpenGL error 0x" << hexErr.str() << ": " << gluErrorString(tGLErr) << " after " << function << endl;
|
2013-01-24 07:11:14 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|