From bd994b9a1376a021022e5145f30b7566e7923e4d Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 6 Nov 2016 01:37:11 +0200 Subject: [PATCH] Add a function to determine the active GL profile --- source/extension.cpp | 19 +++++++++++++++++++ source/extension.h | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/source/extension.cpp b/source/extension.cpp index 2183a965..78fc7e1c 100644 --- a/source/extension.cpp +++ b/source/extension.cpp @@ -132,6 +132,25 @@ GLApi get_gl_api() #endif } +inline GLProfile _get_gl_profile() +{ + if(get_gl_api()==OPENGL && get_gl_version()>=Version(3, 0)) + { + int mask; + glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); + if(mask==GL_CONTEXT_CORE_PROFILE_BIT) + return CORE_PROFILE; + } + + return COMPATIBILITY_PROFILE; +} + +GLProfile get_gl_profile() +{ + static GLProfile profile = _get_gl_profile(); + return profile; +} + inline Version _get_gl_version() { const char *gl_ver_ptr = reinterpret_cast(glGetString(GL_VERSION)); diff --git a/source/extension.h b/source/extension.h index 671e4af9..85b4fc4a 100644 --- a/source/extension.h +++ b/source/extension.h @@ -12,6 +12,12 @@ enum GLApi OPENGL_ES2 }; +enum GLProfile +{ + CORE_PROFILE, + COMPATIBILITY_PROFILE +}; + struct Version { @@ -66,6 +72,9 @@ bool is_supported(const std::string &); /** Returns the API for which the library was compiled. */ GLApi get_gl_api(); +/** Returns the OpenGL profile for the active context. */ +GLProfile get_gl_profile(); + /** Returns the OpenGL version number, as reported by the implementation. */ const Version &get_gl_version(); -- 2.45.2