X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fextension.cpp;h=d03616651b39e97c7937c9f9902d7108c11f7b89;hb=f92c10f969a02e707a236cb364332bf079cdf4fc;hp=d4acedaf1213ac55817b6d30715db1b7364c95d1;hpb=269a74980e2db1ee5004b643f23c2607a77ead58;p=libs%2Fgl.git diff --git a/source/extension.cpp b/source/extension.cpp index d4acedaf..d0361665 100644 --- a/source/extension.cpp +++ b/source/extension.cpp @@ -1,5 +1,5 @@ #include -#ifndef WIN32 +#if !defined(WIN32) && !defined(__APPLE__) #define GLX_GLXEXT_PROTOTYPES #include #endif @@ -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,36 +91,44 @@ 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; + string gl_ver = reinterpret_cast(glGetString(GL_VERSION)); + return Version(gl_ver.substr(0, gl_ver.find(' '))); +} - 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]); +const Version &get_gl_version() +{ + static Version version = _get_gl_version(); + return version; +} - init_done = true; - } +inline Version _get_glsl_version() +{ + string glsl_ver = reinterpret_cast(glGetString(GL_SHADING_LANGUAGE_VERSION)); + return Version(glsl_ver.substr(0, glsl_ver.find(' '))); +} +const Version &get_glsl_version() +{ + static Version version = _get_glsl_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) { -#ifndef WIN32 - return glXGetProcAddressARB(reinterpret_cast(name.c_str())); -#else +#if defined(WIN32) return reinterpret_cast(wglGetProcAddress(name.c_str())); +#elif defined(__APPLE__) + (void)name; + return 0; // Not supported +#else + return glXGetProcAddressARB(reinterpret_cast(name.c_str())); #endif }