-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglInfo.cpp
165 lines (133 loc) · 5.61 KB
/
glInfo.cpp
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
///////////////////////////////////////////////////////////////////////////////
// glInfo.cpp
// ==========
// get GL vendor, version, supported extensions and other states using glGet*
// functions and store them glInfo struct variable
//
// To get valid OpenGL infos, OpenGL rendering context (RC) must be opened
// before calling glInfo::getInfo(). Otherwise it returns false.
//
// AUTHOR: Song Ho Ahn ([email protected])
// CREATED: 2005-10-04
// UPDATED: 2009-10-06
//
// Copyright (c) 2005 Song Ho Ahn
///////////////////////////////////////////////////////////////////////////////
#include <GL/gl.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include "glInfo.h"
///////////////////////////////////////////////////////////////////////////////
// extract openGL info
// This function must be called after GL rendering context opened.
///////////////////////////////////////////////////////////////////////////////
bool glInfo::getInfo()
{
char* str = 0;
char* tok = 0;
// get vendor string
str = (char*)glGetString(GL_VENDOR);
if(str) this->vendor = str; // check NULL return value
else return false;
// get renderer string
str = (char*)glGetString(GL_RENDERER);
if(str) this->renderer = str; // check NULL return value
else return false;
// get version string
str = (char*)glGetString(GL_VERSION);
if(str) this->version = str; // check NULL return value
else return false;
// get all extensions as a string
str = (char*)glGetString(GL_EXTENSIONS);
// split extensions
if(str)
{
tok = strtok((char*)str, " ");
while(tok)
{
this->extensions.push_back(tok); // put a extension into struct
tok = strtok(0, " "); // next token
}
}
else
{
return false;
}
// sort extension by alphabetical order
std::sort(this->extensions.begin(), this->extensions.end());
// get number of color bits
glGetIntegerv(GL_RED_BITS, &this->redBits);
glGetIntegerv(GL_GREEN_BITS, &this->greenBits);
glGetIntegerv(GL_BLUE_BITS, &this->blueBits);
glGetIntegerv(GL_ALPHA_BITS, &this->alphaBits);
// get depth bits
glGetIntegerv(GL_DEPTH_BITS, &this->depthBits);
// get stecil bits
glGetIntegerv(GL_STENCIL_BITS, &this->stencilBits);
// get max number of lights allowed
glGetIntegerv(GL_MAX_LIGHTS, &this->maxLights);
// get max texture resolution
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &this->maxTextureSize);
// get max number of clipping planes
glGetIntegerv(GL_MAX_CLIP_PLANES, &this->maxClipPlanes);
// get max modelview and projection matrix stacks
glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, &this->maxModelViewStacks);
glGetIntegerv(GL_MAX_PROJECTION_STACK_DEPTH, &this->maxProjectionStacks);
glGetIntegerv(GL_MAX_ATTRIB_STACK_DEPTH, &this->maxAttribStacks);
// get max texture stacks
glGetIntegerv(GL_MAX_TEXTURE_STACK_DEPTH, &this->maxTextureStacks);
return true;
}
///////////////////////////////////////////////////////////////////////////////
// check if the video card support a certain extension
///////////////////////////////////////////////////////////////////////////////
bool glInfo::isExtensionSupported(const std::string& ext)
{
// search corresponding extension
std::vector<std::string>::const_iterator iter = this->extensions.begin();
std::vector<std::string>::const_iterator endIter = this->extensions.end();
while(iter != endIter)
{
if(ext == *iter)
return true;
else
++iter;
}
return false;
}
///////////////////////////////////////////////////////////////////////////////
// print OpenGL info to screen and save to a file
///////////////////////////////////////////////////////////////////////////////
void glInfo::printSelf()
{
std::stringstream ss;
ss << std::endl; // blank line
ss << "OpenGL Driver Info" << std::endl;
ss << "==================" << std::endl;
ss << "Vendor: " << this->vendor << std::endl;
ss << "Version: " << this->version << std::endl;
ss << "Renderer: " << this->renderer << std::endl;
ss << std::endl;
ss << "Color Bits(R,G,B,A): (" << this->redBits << ", " << this->greenBits
<< ", " << this->blueBits << ", " << this->alphaBits << ")\n";
ss << "Depth Bits: " << this->depthBits << std::endl;
ss << "Stencil Bits: " << this->stencilBits << std::endl;
ss << std::endl;
ss << "Max Texture Size: " << this->maxTextureSize << "x" << this->maxTextureSize << std::endl;
ss << "Max Lights: " << this->maxLights << std::endl;
ss << "Max Clip Planes: " << this->maxClipPlanes << std::endl;
ss << "Max Modelview Matrix Stacks: " << this->maxModelViewStacks << std::endl;
ss << "Max Projection Matrix Stacks: " << this->maxProjectionStacks << std::endl;
ss << "Max Attribute Stacks: " << this->maxAttribStacks << std::endl;
ss << "Max Texture Stacks: " << this->maxTextureStacks << std::endl;
ss << std::endl;
ss << "Total Number of Extensions: " << this->extensions.size() << std::endl;
ss << "==============================" << std::endl;
for(unsigned int i = 0; i < this->extensions.size(); ++i)
ss << this->extensions.at(i) << std::endl;
ss << "======================================================================" << std::endl;
std::cout << ss.str() << std::endl;
}