From c275640ee0169db95b3f423915e915a196e5ec7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 14 Mar 2014 12:43:06 +0100 Subject: [PATCH] Platform: ability to specify context flags in Sdl2Application. Finally proper support for debug contexts :-) --- src/Magnum/Context.h | 2 +- src/Magnum/Platform/Sdl2Application.cpp | 3 ++ src/Magnum/Platform/Sdl2Application.h | 40 +++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/Magnum/Context.h b/src/Magnum/Context.h index cf44a5e6a..f74fd887e 100644 --- a/src/Magnum/Context.h +++ b/src/Magnum/Context.h @@ -103,7 +103,7 @@ class MAGNUM_EXPORT Context { /** * @brief Context flag * - * @see @ref Flags, @ref flags() + * @see @ref Flags, @ref flags(), @ref Platform::Sdl2Application::Configuration::setFlags() "Platform::*Application::Configuration::setFlags()" */ enum class Flag: GLint { /** diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index 2735cfcbf..0a2c86728 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -109,6 +109,9 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, configuration.sampleCount() > 1 ? 1 : 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, configuration.sampleCount()); + /* Context flags */ + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, int(configuration.flags())); + /* Flags: if not hidden, set as shown */ Uint32 windowFlags(configuration.windowFlags()); if(!(configuration.windowFlags() & Configuration::WindowFlag::Hidden)) windowFlags |= SDL_WINDOW_SHOWN; diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index e4dd18f64..222e0e1f0 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -423,6 +423,30 @@ depth buffer. */ class Sdl2Application::Configuration { public: + /** + * @brief Context flag + * + * @see @ref Flags @ref setFlags() + */ + enum class Flag: int { + Debug = SDL_GL_CONTEXT_DEBUG_FLAG, /**< Create debug context */ + + /** Create context with robust access */ + RobustAccess = SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG + }; + + /** + * @brief Context flags + * + * @see @ref setFlags() + */ + #ifndef DOXYGEN_GENERATING_OUTPUT + typedef Containers::EnumSet Flags; + #else + typedef Containers::EnumSet Flags; + #endif + /** * @brief Window flag * @@ -508,6 +532,20 @@ class Sdl2Application::Configuration { return *this; } + /** @brief Context flags */ + Flags flags() const { return _flags; } + + /** + * @brief Set context flags + * @return Reference to self (for method chaining) + * + * Default is no flag. + */ + Configuration& setFlags(Flags flags) { + _flags = flags; + return *this; + } + #ifndef CORRADE_TARGET_EMSCRIPTEN /** * @brief Context version @@ -561,8 +599,10 @@ class Sdl2Application::Configuration { #ifndef CORRADE_TARGET_EMSCRIPTEN Version _version; #endif + Flags _flags; }; +CORRADE_ENUMSET_OPERATORS(Sdl2Application::Configuration::Flags) CORRADE_ENUMSET_OPERATORS(Sdl2Application::Configuration::WindowFlags) /**