Browse Source

Added MAGNUM_ASSERT_{VERSION,EXTENSION}_SUPPORTED() macros.

pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
ef1642aea1
  1. 28
      src/Context.cpp
  2. 75
      src/Context.h
  3. 2
      src/Extensions.h

28
src/Context.cpp

@ -35,26 +35,26 @@ namespace Magnum {
Debug operator<<(Debug debug, Version value) {
switch(value) {
#define _c(value) case Version::value: return debug << "Version::" #value;
_c(None)
#define _c(value, string) case Version::value: return debug << string;
_c(None, "None")
#ifndef MAGNUM_TARGET_GLES
_c(GL210)
_c(GL300)
_c(GL310)
_c(GL320)
_c(GL330)
_c(GL400)
_c(GL410)
_c(GL420)
_c(GL430)
_c(GL210, "OpenGL 2.1")
_c(GL300, "OpenGL 3.0")
_c(GL310, "OpenGL 3.1")
_c(GL320, "OpenGL 3.2")
_c(GL330, "OpenGL 3.3")
_c(GL400, "OpenGL 4.0")
_c(GL410, "OpenGL 4.1")
_c(GL420, "OpenGL 4.2")
_c(GL430, "OpenGL 4.3")
#else
_c(GLES200)
_c(GLES300)
_c(GLES200, "OpenGL ES 2.0")
_c(GLES300, "OpenGL ES 3.0")
#endif
#undef _c
}
return debug << "Version::(invalid)";
return debug << "Invalid";
}
const std::vector<Extension>& Extension::extensions(Version version) {

75
src/Context.h

@ -16,7 +16,7 @@
*/
/** @file
* @brief Enum Version, class Magnum::Context, Magnum::Extension
* @brief Enum Version, class Magnum::Context, Magnum::Extension, macro MAGNUM_ASSERT_VERSION_SUPPORTED(), MAGNUM_ASSERT_EXTENSION_SUPPORTED()
*/
#include <bitset>
@ -34,7 +34,11 @@ namespace Implementation {
}
#endif
/** @brief OpenGL version */
/**
@brief OpenGL version
@see Context, MAGNUM_ASSERT_VERSION_SUPPORTED()
*/
enum class Version: GLint {
None = 0xFFFF, /**< @brief Unspecified */
#ifndef MAGNUM_TARGET_GLES
@ -200,7 +204,7 @@ class MAGNUM_EXPORT Context {
/**
* @brief Whether given OpenGL version is supported
*
* @see supportedVersion()
* @see supportedVersion(), MAGNUM_ASSERT_VERSION_SUPPORTED()
*/
inline bool isVersionSupported(Version version) const {
return _version >= version;
@ -235,7 +239,8 @@ class MAGNUM_EXPORT Context {
* }
* @endcode
*
* @see isExtensionSupported(const Extension&) const
* @see isExtensionSupported(const Extension&) const,
* MAGNUM_ASSERT_EXTENSION_SUPPORTED()
*/
template<class T> inline bool isExtensionSupported() const {
return isVersionSupported(T::coreVersion()) || (isVersionSupported(T::requiredVersion()) && extensionStatus[T::Index]);
@ -248,7 +253,8 @@ class MAGNUM_EXPORT Context {
* hardware, but for general usage prefer isExtensionSupported() const,
* as it does most operations in compile time.
*
* @see supportedExtensions(), Extension::extensions()
* @see supportedExtensions(), Extension::extensions(),
* MAGNUM_ASSERT_EXTENSION_SUPPORTED()
*/
inline bool isExtensionSupported(const Extension& extension) const {
return isVersionSupported(extension._coreVersion) || (isVersionSupported(extension._requiredVersion) && extensionStatus[extension._index]);
@ -271,6 +277,65 @@ class MAGNUM_EXPORT Context {
Implementation::State* _state;
};
/** @hideinitializer
@brief Assert that given OpenGL version is supported
@param version Version
Useful for initial checks on availability of required features.
By default, if assertion fails, an message is printed to error output and the
application exits with value `-3`. If `CORRADE_NO_ASSERT` is defined, this
macro does nothing. Example usage:
@code
MAGNUM_ASSERT_VERSION_SUPPORTED(Version::GL330);
@endcode
@see @ref Magnum::Context::isVersionSupported() "Context::isVersionSupported()",
MAGNUM_ASSERT_EXTENSION_SUPPORTED(), CORRADE_ASSERT(),
CORRADE_INTERNAL_ASSERT()
*/
#ifdef CORRADE_NO_ASSERT
#define MAGNUM_ASSERT_VERSION_SUPPORTED(version) do {} while(0)
#else
#define MAGNUM_ASSERT_VERSION_SUPPORTED(version) \
do { \
if(!Context::current()->isVersionSupported(version)) { \
Corrade::Utility::Error() << "Magnum: required version" << version << "is not supported"; \
exit(-3); \
} \
} while(0)
#endif
/** @hideinitializer
@brief Assert that given OpenGL extension is supported
@param extension Extension name (from @ref Magnum::Extensions "Extensions"
namespace)
Useful for initial checks on availability of required features.
By default, if assertion fails, an message is printed to error output and the
application exits with value `-3`. If `CORRADE_NO_ASSERT` is defined, this
macro does nothing. Example usage:
@code
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::geometry_shader4);
@endcode
@see @ref Magnum::Context::isExtensionSupported() "Context::isExtensionSupported()",
MAGNUM_ASSERT_VERSION_SUPPORTED(), CORRADE_ASSERT(),
CORRADE_INTERNAL_ASSERT()
*/
#ifdef CORRADE_NO_ASSERT
#define MAGNUM_ASSERT_EXTENSION_SUPPORTED(extension) do {} while(0)
#else
#define MAGNUM_ASSERT_EXTENSION_SUPPORTED(extension) \
do { \
if(!Context::current()->isExtensionSupported<extension>()) { \
Corrade::Utility::Error() << "Magnum: required extension" << extension::string() << "is not supported"; \
exit(-3); \
} \
} while(0)
#endif
}
#endif

2
src/Extensions.h

@ -33,6 +33,8 @@ and string(), but these structs are better suited for compile-time decisions
rather than Extension instances. See Context::isExtensionSupported() for
example usage.
@see MAGNUM_ASSERT_EXTENSION_SUPPORTED()
@todo Manual indices for extensions, this has gaps
@todo Unhide ES2_compatibility, ES3_compatibility on ES
@todo Add ES and GL 4.3 extensions

Loading…
Cancel
Save