rtcGLInfo.cpp
Go to the documentation of this file.
00001 #include <GL/gl.h>
00002 #include <iostream>
00003 #include <sstream>
00004 #include <iomanip>
00005 #include <algorithm>
00006 #include <stdio.h>
00007 #include <string.h>
00008 #include "rtc/rtcGLInfo.h"
00009 
00010 using std::string;
00011 using std::stringstream;
00012 using std::vector;
00013 using std::cout;
00014 using std::endl;
00015 
00016 //== NAMESPACES ===============================================================
00017 namespace rtc {
00018 
00020 // extract openGL info
00021 // This function must be called after GL rendering context opened.
00023 bool GLInfo::getInfo()
00024 {
00025     char* str = 0;
00026     char* tok = 0;
00027 
00028     // get vendor string
00029     str = (char*)glGetString(GL_VENDOR);
00030     if(str) this->vendor = str;                  // check NULL return value
00031     else return false;
00032 
00033     // get renderer string
00034     str = (char*)glGetString(GL_RENDERER);
00035     if(str) this->renderer = str;                // check NULL return value
00036     else return false;
00037 
00038     // get version string
00039     str = (char*)glGetString(GL_VERSION);
00040     if(str) this->version = str;                 // check NULL return value
00041     else return false;
00042 
00043     // get all extensions as a string
00044     str = (char*)glGetString(GL_EXTENSIONS);
00045 
00046     // split extensions
00047     if(str)
00048     {
00049         tok = strtok((char*)str, " ");
00050         while(tok)
00051         {
00052             this->extensions.push_back(tok);    // put a extension into struct
00053             tok = strtok(0, " ");               // next token
00054         }
00055     }
00056     else
00057     {
00058     return false;
00059   }
00060 
00061     // sort extension by alphabetical order
00062     std::sort(this->extensions.begin(), this->extensions.end());
00063 
00064     // get number of color bits
00065     glGetIntegerv(GL_RED_BITS, &this->redBits);
00066     glGetIntegerv(GL_GREEN_BITS, &this->greenBits);
00067     glGetIntegerv(GL_BLUE_BITS, &this->blueBits);
00068     glGetIntegerv(GL_ALPHA_BITS, &this->alphaBits);
00069 
00070     // get depth bits
00071     glGetIntegerv(GL_DEPTH_BITS, &this->depthBits);
00072 
00073     // get stecil bits
00074     glGetIntegerv(GL_STENCIL_BITS, &this->stencilBits);
00075 
00076     // get max number of lights allowed
00077     glGetIntegerv(GL_MAX_LIGHTS, &this->maxLights);
00078 
00079     // get max texture resolution
00080     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &this->maxTextureSize);
00081 
00082     // get max number of clipping planes
00083     glGetIntegerv(GL_MAX_CLIP_PLANES, &this->maxClipPlanes);
00084 
00085     // get max modelview and projection matrix stacks
00086     glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, &this->maxModelViewStacks);
00087     glGetIntegerv(GL_MAX_PROJECTION_STACK_DEPTH, &this->maxProjectionStacks);
00088     glGetIntegerv(GL_MAX_ATTRIB_STACK_DEPTH, &this->maxAttribStacks);
00089 
00090     // get max texture stacks
00091     glGetIntegerv(GL_MAX_TEXTURE_STACK_DEPTH, &this->maxTextureStacks);
00092 
00093     return true;
00094 }
00095 
00096 
00097 
00099 // check if the video card support a certain extension
00101 bool GLInfo::isExtensionSupported(const char* ext)
00102 {
00103     // search corresponding extension
00104     std::vector< string >::const_iterator iter = this->extensions.begin();
00105     std::vector< string >::const_iterator endIter = this->extensions.end();
00106 
00107     while(iter != endIter)
00108     {
00109         if(ext == *iter)
00110             return true;
00111         else
00112             ++iter;
00113     }
00114     return false;
00115 }
00116 
00117 
00118 
00120 // print OpenGL info to screen and save to a file
00122 void GLInfo::printSelf()
00123 {
00124     stringstream ss;
00125 
00126     ss << endl; // blank line
00127     ss << "OpenGL Driver Info" << endl;
00128     ss << "==================" << endl;
00129     ss << "Vendor: " << this->vendor << endl;
00130     ss << "Version: " << this->version << endl;
00131     ss << "Renderer: " << this->renderer << endl;
00132 
00133     ss << endl;
00134     ss << "Color Bits(R,G,B,A): (" << this->redBits << ", " << this->greenBits
00135        << ", " << this->blueBits << ", " << this->alphaBits << ")\n";
00136     ss << "Depth Bits: " << this->depthBits << endl;
00137     ss << "Stencil Bits: " << this->stencilBits << endl;
00138 
00139     ss << endl;
00140     ss << "Max Texture Size: " << this->maxTextureSize << "x" << this->maxTextureSize << endl;
00141     ss << "Max Lights: " << this->maxLights << endl;
00142     ss << "Max Clip Planes: " << this->maxClipPlanes << endl;
00143     ss << "Max Modelview Matrix Stacks: " << this->maxModelViewStacks << endl;
00144     ss << "Max Projection Matrix Stacks: " << this->maxProjectionStacks << endl;
00145     ss << "Max Attribute Stacks: " << this->maxAttribStacks << endl;
00146     ss << "Max Texture Stacks: " << this->maxTextureStacks << endl;
00147 
00148     ss << endl;
00149     ss << "Total Number of Extensions: " << this->extensions.size() << endl;
00150     ss << "==============================" << endl;
00151     for(unsigned int i = 0; i < this->extensions.size(); ++i)
00152         ss << this->extensions.at(i) << endl;
00153 
00154     ss << "======================================================================" << endl;
00155 
00156     cout << ss.str() << endl;
00157 }
00158 
00159 //=============================================================================
00160 } // namespace rtc
00161 //=============================================================================


rtc
Author(s): Benjamin Pitzer
autogenerated on Thu Jan 2 2014 11:04:53