Gl Graph

Gl Graph Source of glversion.cpp


#include "glversion.h"
#include <iostream>
#include <stdio.h>
GlVersion::GlVersion()
{
 
}
 
void GlVersion::init()
{
 
    char* version_str= (char*) glGetString(GL_VERSION);
    STR_GL_VERSION = std::string(version_str);
 
    STR_GL_VENDOR = std::string((char*) glGetString(GL_VENDOR));
    STR_GL_RENDERER = std::string((char*) glGetString(GL_RENDERER));
    STR_GL_EXTENSIONS = std::string((char*) glGetString(GL_EXTENSIONS));
 
    sscanf(version_str, "%d.%d", &glMajorVersion, &glMinorVersion);
    std::cout << "OpenGl :" << glMajorVersion << "." << glMinorVersion << std::endl;
 
    int startpos = 0;
    for (unsigned int endpos = 0; endpos < STR_GL_EXTENSIONS.length(); endpos++)
        if (STR_GL_EXTENSIONS[endpos] == ' ')
        {
            extentions.push_back(STR_GL_EXTENSIONS.substr(startpos, endpos - startpos));
            startpos = endpos + 1;
        }
 
 
    // GLSH Version
    glslMajorVersion = 0;
    glslMinorVersion = 0;
    if(glMajorVersion == 1)
    {
        /* GL 1.X can only provide GLSL v1.00 as an extension */
        if( hasGlEXTENSION("GL_ARB_shading_language_100") )
        {
            glslMajorVersion = 1;
            glslMinorVersion = 0;
        }
 
    }
    else if (glMinorVersion >= 2)
    {
        /* GL 2.0 and greater must parse the version string */
        char* version_str= (char*) glGetString(GL_SHADING_LANGUAGE_VERSION);
        if (version_str!=NULL)
        {
            STR_GLSL_VERSION = std::string(version_str);
            if (sscanf(version_str, "%d.%d", &glslMajorVersion, &glslMinorVersion) != 2)
                std::cout << "Bad GLSL_VERSION Format"  << std::endl;
        }
    }
 
 
 
 
    openGl4=getGlVersionMain() >= 4;
    openGl3_3=getGlVersionMain() >= 4 || (getGlVersionMain() == 3 && getGlMinorVersionMain() >= 3);
    openGl2_1=getGlVersionMain() >= 3 || (getGlVersionMain() == 2 && getGlMinorVersionMain() >= 1);
    openGl2=getGlVersionMain() >= 2;
 
 
 
}
 
bool GlVersion::hasGlEXTENSION(std::string ext) const
{
    for (unsigned int i = 0; i < extentions.size(); i++)
        if (extentions[i].compare(ext)==0)
            return true;
 
    return false;
}
 
 
 
int GlVersion::getGlEXTENSIONSNB() const
{
    return extentions.size();
}
 
std::string GlVersion::getGlEXTENSION(int i) const
{
    return extentions[i];
}
 
void GlVersion::printOpenGlVersion() const
{
    std::cout << "GL_VERSION:" << STR_GL_VERSION << std::endl;
}
 
void GlVersion::printOpenGlVendor() const
{
    std::cout << "GL_VENDOR:" << STR_GL_VENDOR << std::endl;
}
 
void GlVersion::printOpenGlRender() const
{
    std::cout << "GL_RENDERER:" << STR_GL_RENDERER << std::endl;
}
 
void GlVersion::printOpenGlExtention() const
{
    std::cout << "GL_EXTENSIONS:" << STR_GL_EXTENSIONS << std::endl;
}
 
void GlVersion::printOpenGlSLVersion() const
{
    std::cout << "GLSL_VERSION:" << STR_GLSL_VERSION << std::endl;
}
 
std::string GlVersion::getGlEXTENSIONS() const
{
    return STR_GL_EXTENSIONS;
}
 
std::string GlVersion::getGlRENDERER() const
{
    return STR_GL_RENDERER;
}
 
std::string GlVersion::getGlVENDOR() const
{
    return STR_GL_VENDOR;
}
 
std::string GlVersion::getGlVERSION() const
{
    return STR_GL_VERSION;
}
 
std::string GlVersion::getGlSLVERSION() const
{
    return STR_GLSL_VERSION;
}
void GlVersion::printOpenGlInfo() const
{
    printOpenGlVersion();
    printOpenGlVendor();
    printOpenGlRender();
    printOpenGlSLVersion();
    printOpenGlExtention();
}
 
 
int GlVersion::getGlVersionMain() const
{
    return glMajorVersion;
}
 
int GlVersion::getGlMinorVersionMain() const
{
    return glMinorVersion;
}
 
int GlVersion::getGlslMajorVersion() const
{
    return glslMajorVersion;
}
 
int GlVersion::getGlslMinorVersion() const
{
    return glslMinorVersion;
}
 
bool GlVersion::isOpenGl4() const
{
    return openGl4;
}
 
bool GlVersion::isOpenGl3_3() const
{
    return openGl3_3;
}
 
bool GlVersion::isOpenGl2_1() const
{
    return openGl2_1;
}
 
bool GlVersion::isOpenGl2() const
{
    return openGl2;
}