From 818fdefbd60866d8e1148fbc777760911b749819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 3 Nov 2012 23:34:40 +0100 Subject: [PATCH] Added convenience function Context::supportedVersion(). --- src/Context.cpp | 11 +++++++++++ src/Context.h | 22 +++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Context.cpp b/src/Context.cpp index eab210cba..e86df90df 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -247,4 +247,15 @@ Context::~Context() { _current = nullptr; } +Version Context::supportedVersion(initializer_list versions) const { + for(auto version: versions) + if(isVersionSupported(version)) return version; + + #ifndef MAGNUM_TARGET_GLES + return Version::GL210; + #else + return Version::GLES200; + #endif +} + } diff --git a/src/Context.h b/src/Context.h index 3443cf0dc..f896975f0 100644 --- a/src/Context.h +++ b/src/Context.h @@ -194,11 +194,31 @@ class MAGNUM_EXPORT Context { return _supportedExtensions; } - /** @brief Whether given OpenGL version is supported */ + /** + * @brief Whether given OpenGL version is supported + * + * @see supportedVersion() + */ inline bool isVersionSupported(Version version) const { return _version >= version; } + /** + * @brief Get supported OpenGL version + * + * Returns first supported OpenGL version from passed list. Convenient + * equivalent to subsequent isVersionSupported() calls, e.g.: + * @code + * Version v = isVersionSupported(Version::GL330) ? Version::GL330 : Version::GL210; + * Version v = supportedVersion({Version::GL330, Version::GL210}); + * @endcode + * + * If no version from the list is supported, returns lowest available + * OpenGL version (@ref Version "Version::GL210" for desktop OpenGL, + * @ref Version "Version::GLES200" for OpenGL ES). + */ + Version supportedVersion(std::initializer_list versions) const; + /** * @brief Whether given extension is supported *