X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fextension.cpp;h=41b06b217f79c9df88c83498eb595d41cbecaca9;hp=56f96d4ecee2136dcde2d42f5fbdfa7bbf8b421b;hb=73f829d3051f5c6c02ce629991f1757d1586bf74;hpb=ea3487f52f8621f07deb47fa1af22a85b8b23519 diff --git a/source/extension.cpp b/source/extension.cpp index 56f96d4e..41b06b21 100644 --- a/source/extension.cpp +++ b/source/extension.cpp @@ -14,6 +14,31 @@ using namespace std; namespace Msp { namespace GL { +Version::Version() +{ + major = 0; + minor = 0; +} + +Version::Version(unsigned short a, unsigned short i) +{ + major = a; + minor = i; +} + +Version::Version(const string &s) +{ + vector parts = split(s, '.'); + major = lexical_cast(parts[0]); + minor = lexical_cast(parts[1]); +} + +bool Version::operator>=(const Version &other) const +{ + return major>other.major || (major==other.major && minor>=other.minor); +} + + Extension::Extension(const char *n, InitFunc f): name(n), init_func(f), @@ -66,28 +91,21 @@ bool is_supported(const string &ext) return extensions.count(ext); } -const Version &get_gl_version() +inline Version _get_gl_version() { - static Version version; - static bool init_done = false; - - if(!init_done) - { - string gl_ver = reinterpret_cast(glGetString(GL_VERSION)); - vector parts = split(gl_ver.substr(0, gl_ver.find(' ')), '.'); - version.major = lexical_cast(parts[0]); - version.minor = lexical_cast(parts[1]); - - init_done = true; - } + string gl_ver = reinterpret_cast(glGetString(GL_VERSION)); + return Version(gl_ver.substr(0, gl_ver.find(' '))); +} +const Version &get_gl_version() +{ + static Version version = _get_gl_version(); return version; } bool is_version_at_least(unsigned a, unsigned b) { - const Version &ver = get_gl_version(); - return (ver.major>a || (ver.major==a && ver.minor>=b)); + return get_gl_version()>=Version(a, b); } ExtFunc *get_proc_address(const string &name)