Magnum
Public Types | Public Member Functions | Static Public Member Functions | Related Functions | List of all members
Magnum::Context Class Reference

Magnum context. More...

#include <Magnum/Context.h>

Public Types

enum  Flag : GLint { Flag::Debug = GL_CONTEXT_FLAG_DEBUG_BIT, Flag::NoError = GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR, Flag::RobustAccess = GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB }
 Context flag. More...
 
enum  State : UnsignedInt {
  State::Buffers = 1 << 0, State::Framebuffers = 1 << 1, State::Meshes = 1 << 2, State::PixelStorage = 1 << 3,
  State::Renderer = 1 << 4, State::Shaders = 1 << 5, State::Textures = 1 << 6, State::TransformFeedback = 1 << 7
}
 State to reset. More...
 
enum  DetectedDriver : UnsignedShort {
  DetectedDriver::Amd = 1 << 0, DetectedDriver::AMD = UnsignedShort(DetectedDriver::Amd), DetectedDriver::IntelWindows = 1 << 2, DetectedDriver::Mesa = 1 << 3,
  DetectedDriver::NVidia = 1 << 4, DetectedDriver::Svga3D = 1 << 5
}
 Detected driver. More...
 
typedef Containers::EnumSet< FlagFlags
 Context flags. More...
 
typedef Containers::EnumSet< StateStates
 States to reset. More...
 
typedef Containers::EnumSet< DetectedDriverDetectedDrivers
 Detected drivers. More...
 

Public Member Functions

 Context (const Context &)=delete
 Copying is not allowed.
 
 Context (Context &&other)
 Move constructor.
 
Contextoperator= (const Context &)=delete
 Copying is not allowed.
 
Contextoperator= (Context &&)=delete
 Move assignment is not allowed.
 
Version version () const
 OpenGL version. More...
 
std::string vendorString () const
 Vendor string. More...
 
std::string rendererString () const
 Renderer string. More...
 
std::string versionString () const
 Version string. More...
 
std::string shadingLanguageVersionString () const
 Shading language version string. More...
 
std::vector< std::string > shadingLanguageVersionStrings () const
 Shading language version strings. More...
 
std::vector< std::string > extensionStrings () const
 Extension strings. More...
 
Flags flags () const
 Context flags. More...
 
const std::vector< Extension > & supportedExtensions () const
 Supported extensions. More...
 
bool isCoreProfile ()
 Detect if current OpenGL context is a core profile. More...
 
bool isVersionSupported (Version version) const
 Whether given OpenGL version is supported. More...
 
Version supportedVersion (std::initializer_list< Version > versions) const
 Get supported OpenGL version. More...
 
template<class T >
bool isExtensionSupported () const
 Whether given extension is supported. More...
 
template<class T >
bool isExtensionSupported (Version version) const
 Whether given extension is supported in given version. More...
 
bool isExtensionSupported (const Extension &extension) const
 Whether given extension is supported. More...
 
template<class T >
bool isExtensionDisabled () const
 Whether given extension is disabled. More...
 
template<class T >
bool isExtensionDisabled (Version version) const
 Whether given extension is disabled for given version. More...
 
bool isExtensionDisabled (const Extension &extension) const
 Whether given extension is disabled. More...
 
void resetState (States states=~States{})
 Reset internal state tracker. More...
 
DetectedDrivers detectedDriver ()
 Detect driver. More...
 

Static Public Member Functions

static bool hasCurrent ()
 Whether there is any current context. More...
 
static Contextcurrent ()
 Current context. More...
 

Related Functions

(Note that these are not member functions.)

Debugoperator<< (Debug &debug, Context::Flag value)
 Debug output operator. More...
 
Debugoperator<< (Debug &debug, Context::Flags value)
 Debug output operator. More...
 
Debugoperator<< (Debug &debug, Context::DetectedDriver value)
 Debug output operator. More...
 
Debugoperator<< (Debug &debug, Context::DetectedDrivers value)
 Debug output operator. More...
 

Detailed Description

Magnum context.

Provides access to version and extension information. Instance available through Context::current() is automatically created during construction of *Application classes in Platform namespace. You can safely assume that the instance is available during whole lifetime of *Application object. It's also possible to create the context without using any *Application class using Platform::Context subclass, see Platform support documentation for more information.

Command-line options

The context is configurable through command-line options, that are passed either from the Platform::*Application classes or from the Platform::Context class. Usage:

<application> [--magnum-help] [--magnum-disable-workarounds LIST] [--magnum-disable-extensions LIST] ...

Arguments:

Member Typedef Documentation

Context flags.

See also
flags()
Requires OpenGL ES or desktop OpenGL:
Context flags are not available in WebGL.

States to reset.

See also
resetState()

Detected drivers.

See also
detectedDriver()

Member Enumeration Documentation

enum Magnum::Context::Flag : GLint
strong

Context flag.

See also
Flags, flags(), Platform::*Application::Configuration::setFlags()
Requires OpenGL ES or desktop OpenGL:
Context flags are not available in WebGL.
Enumerator
Debug 

Debug context

Requires OpenGL 4.3:
Extension KHR_debug
Requires OpenGL ES extension:
Extension ANDROID_extension_pack_es31a/ KHR_debug
NoError 

Context without error reporting

Requires OpenGL extension:
Extension KHR_no_error
Requires OpenGL ES extension:
Extension KHR_no_error
RobustAccess 

Context with robust access

Requires OpenGL extension:
Extension ARB_robustness
Requires OpenGL ES extension:
Extension EXT_robustness

State to reset.

See also
States, resetState()
Enumerator
Buffers 

Reset tracked buffer-related bindings and state

Framebuffers 

Reset tracked framebuffer-related bindings and state

Meshes 

Reset tracked mesh-related bindings

PixelStorage 

Reset tracked pixel storage-related state

Renderer 

Reset tracked renderer-related state

Shaders 

Reset tracked shader-related bindings

Textures 

Reset tracked texture-related bindings and state

TransformFeedback 

Reset tracked transform feedback-related bindings

Detected driver.

See also
DetectedDriver, detectedDriver()
Enumerator
Amd 

Binary AMD desktop drivers on Windows and Linux

Requires OpenGL ES or desktop OpenGL:
Not detectable on WebGL, as browsers intentionally hide most of the driver information.
AMD 

Binary AMD desktop drivers on Windows and Linux

Requires OpenGL ES or desktop OpenGL:
Not detectable on WebGL, as browsers intentionally hide most of the driver information.
Deprecated:
Use DetectedDriver::Amd instead.
IntelWindows 

Intel desktop drivers on Windows

Requires OpenGL ES or desktop OpenGL:
Not detectable on WebGL, as browsers intentionally hide most of the driver information.
Mesa 

Mesa drivers on Windows and Linux. See also DetectedDriver::Svga3D.

Requires OpenGL ES or desktop OpenGL:
Not detectable on WebGL, as browsers intentionally hide most of the driver information.
NVidia 

Binary NVidia drivers on Windows and Linux

Requires OpenGL ES or desktop OpenGL:
Not detectable on WebGL, as browsers intentionally hide most of the driver information.
Svga3D 

VMware guest GL driver SVGA3D, implemented using Mesa, both Windows and Linux guests. See https://www.mesa3d.org/vmware-guest.html for more information. Detected in combination with DetectedDriver::Mesa.

Requires OpenGL ES or desktop OpenGL:
Not detectable on WebGL, as browsers intentionally hide most of the driver information.

Member Function Documentation

bool Magnum::Context::hasCurrent ( )
static

Whether there is any current context.

If Magnum is built with MAGNUM_BUILD_MULTITHREADED, current context is thread-local instead of global (the default).

See also
current()
Context & Magnum::Context::current ( )
static

Current context.

Expect that there is current context. If Magnum is built with MAGNUM_BUILD_MULTITHREADED, current context is thread-local instead of global (the default).

See also
hasCurrent()
Version Magnum::Context::version ( ) const
inline
std::string Magnum::Context::vendorString ( ) const

Vendor string.

The result is not cached, repeated queries will result in repeated OpenGL calls.

See also
rendererString(), glGetString() with GL_VENDOR
std::string Magnum::Context::rendererString ( ) const

Renderer string.

The result is not cached, repeated queries will result in repeated OpenGL calls.

See also
vendorString(), glGetString() with GL_RENDERER
std::string Magnum::Context::versionString ( ) const

Version string.

The result is not cached, repeated queries will result in repeated OpenGL calls.

See also
shadingLanguageVersionString(), version(), glGetString() with GL_VERSION
std::string Magnum::Context::shadingLanguageVersionString ( ) const

Shading language version string.

The result is not cached, repeated queries will result in repeated OpenGL calls.

See also
versionString(), version(), glGetString() with GL_SHADING_LANGUAGE_VERSION
std::vector< std::string > Magnum::Context::shadingLanguageVersionStrings ( ) const

Shading language version strings.

The result is not cached, repeated queries will result in repeated OpenGL calls.

See also
versionString(), version(), glGet() with GL_NUM_SHADING_LANGUAGE_VERSIONS, glGetString() with GL_SHADING_LANGUAGE_VERSION
std::vector< std::string > Magnum::Context::extensionStrings ( ) const

Extension strings.

The result is not cached, repeated queries will result in repeated OpenGL calls. Note that this function returns list of all extensions reported by the driver (even those not supported by Magnum), see supportedExtensions(), Extension::extensions() or isExtensionSupported() for alternatives.

See also
glGet() with GL_NUM_EXTENSIONS, glGetString() with GL_EXTENSIONS
Flags Magnum::Context::flags ( ) const
inline

Context flags.

Requires OpenGL ES or desktop OpenGL:
Context flags are not available in WebGL.
const std::vector<Extension>& Magnum::Context::supportedExtensions ( ) const
inline

Supported extensions.

The list contains only extensions from OpenGL versions newer than the current.

See also
isExtensionSupported(), Extension::extensions()
bool Magnum::Context::isCoreProfile ( )

Detect if current OpenGL context is a core profile.

The result is cached, repeated queries don't result in repeated OpenGL calls.

See also
glGet() with GL_CORE_PROFILE_MASK
Requires desktop OpenGL:
Not available on OpenGL ES or WebGL.
bool Magnum::Context::isVersionSupported ( Version  version) const

Whether given OpenGL version is supported.

See also
supportedVersion(), MAGNUM_ASSERT_VERSION_SUPPORTED()
Version Magnum::Context::supportedVersion ( std::initializer_list< Version versions) const

Get supported OpenGL version.

Returns first supported OpenGL version from passed list. Convenient equivalent to subsequent isVersionSupported() calls, e.g.:

If no version from the list is supported, returns lowest available OpenGL version (Version::GL210 for desktop OpenGL, Version::GLES200 for OpenGL ES).

See also
isExtensionSupported(Version) const
template<class T >
bool Magnum::Context::isExtensionSupported ( ) const
inline

Whether given extension is supported.

Extensions usable with this function are listed in Extensions namespace in header Extensions.h. Example usage:

if(Context::current().isExtensionSupported<Extensions::GL::ARB::tessellation_shader>()) {
// draw fancy detailed model
} else {
// texture fallback
}
See also
isExtensionSupported(const Extension&) const, MAGNUM_ASSERT_EXTENSION_SUPPORTED(), isExtensionDisabled()
template<class T >
bool Magnum::Context::isExtensionSupported ( Version  version) const
inline

Whether given extension is supported in given version.

Similar to isExtensionSupported(), but checks also that the minimal required version of the extension is larger or equal to version. Useful mainly in shader compilation when the decisions depend on selected GLSL version, for example:

if(Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>(version)) {
// Called only if ARB_explicit_attrib_location is supported
// *and* version is higher than GL 3.1
}
bool Magnum::Context::isExtensionSupported ( const Extension extension) const
inline

Whether given extension is supported.

Can be used e.g. for listing extensions available on current hardware, but for general usage prefer isExtensionSupported() const, as it does most operations in compile time.

See also
supportedExtensions(), Extension::extensions(), MAGNUM_ASSERT_EXTENSION_SUPPORTED()
template<class T >
bool Magnum::Context::isExtensionDisabled ( ) const
inline

Whether given extension is disabled.

Can be used for detecting driver bug workarounds. Disabled extensions return false in isExtensionSupported() even if they are advertised as being supported by the driver.

template<class T >
bool Magnum::Context::isExtensionDisabled ( Version  version) const
inline

Whether given extension is disabled for given version.

Similar to above, but can also check for extensions which are disabled only for particular versions.

bool Magnum::Context::isExtensionDisabled ( const Extension extension) const
inline

Whether given extension is disabled.

Can be used e.g. for listing extensions available on current hardware, but for general usage prefer isExtensionDisabled() const, as it does most operations in compile time.

void Magnum::Context::resetState ( States  states = ~States{})

Reset internal state tracker.

Parameters
statesTracked states to reset. Default is all state.

The engine internally tracks object bindings and other state to avoid redundant OpenGL calls. In some cases (e.g. when non-Magnum code makes GL calls) the internal tracker no longer reflects actual state and needs to be reset to avoid strange issues.

auto Magnum::Context::detectedDriver ( )

Detect driver.

Tries to detect driver using various OpenGL state queries. Once the detection is done, the result is cached, repeated queries don't result in repeated GL calls. Used primarily for enabling driver-specific workarounds.

Friends And Related Function Documentation

Debug & operator<< ( Debug debug,
Context::Flag  value 
)
related

Debug output operator.

Debug output operator:
Allows printing Magnum::Context::Flag with Corrade::Utility::Debug and friends.
Debug & operator<< ( Debug debug,
Context::Flags  value 
)
related

Debug output operator.

Debug output operator:
Allows printing Magnum::Context::Flags with Corrade::Utility::Debug and friends.
Debug & operator<< ( Debug debug,
Context::DetectedDriver  value 
)
related

Debug output operator.

Debug output operator:
Allows printing Magnum::Context::DetectedDriver with Corrade::Utility::Debug and friends.
Debug & operator<< ( Debug debug,
Context::DetectedDrivers  value 
)
related

Debug output operator.

Debug output operator:
Allows printing Magnum::Context::DetectedDrivers with Corrade::Utility::Debug and friends.