summaryrefslogtreecommitdiff
path: root/src/system-gl.cc
blob: 098dcb2485048f5f92dc2744f134b5b10b9a907f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

/* 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 ( unsigned 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;
}

contact: Jan Huwald // Impressum