diff --git a/src/Magnum/GL/Context.cpp b/src/Magnum/GL/Context.cpp index 4e1239b05..e1b2cb0ca 100644 --- a/src/Magnum/GL/Context.cpp +++ b/src/Magnum/GL/Context.cpp @@ -703,13 +703,13 @@ Context::Context(NoCreateT, Utility::Arguments& args, Int argc, const char** arg /* Decide how to display initialization log */ if(args.value("log") == "verbose" || args.value("log") == "VERBOSE") - _internalFlags |= InternalFlag::DisplayVerboseInitializationLog; - else if(!(args.value("log") == "quiet" || args.value("log") == "QUIET")) - _internalFlags |= InternalFlag::DisplayInitializationLog; + _configurationFlags |= Configuration::Flag::VerboseLog; + else if(args.value("log") == "quiet" || args.value("log") == "QUIET") + _configurationFlags |= Configuration::Flag::QuietLog; /* Decide whether to enable GPU validation */ if(args.value("gpu-validation") == "on" || args.value("gpu-validation") == "ON") - _internalFlags |= InternalFlag::GpuValidation; + _configurationFlags |= Configuration::Flag::GpuValidation; /* If there are any disabled workarounds, save them until tryCreate() uses them. The disableWorkaround() function saves the internal string view @@ -753,7 +753,7 @@ Context::Context(Context&& other) noexcept: _detectedDrivers{std::move(other._detectedDrivers)}, _driverWorkarounds{std::move(other._driverWorkarounds)}, _disabledExtensions{std::move(other._disabledExtensions)}, - _internalFlags{other._internalFlags} + _configurationFlags{other._configurationFlags} { if(currentContext == &other) currentContext = this; } @@ -776,14 +776,14 @@ bool Context::tryCreate(const Configuration& configuration) { quiet, it'll override the verbose setting from the configuration; if it says verbose, the quiet setting from the configuration will be ignored */ - if((configuration.flags() & Configuration::Flag::VerboseLog) && (_internalFlags & InternalFlag::DisplayInitializationLog)) - _internalFlags |= InternalFlag::DisplayVerboseInitializationLog; - else if((configuration.flags() & Configuration::Flag::QuietLog) && !(_internalFlags >= InternalFlag::DisplayVerboseInitializationLog)) - _internalFlags &= ~InternalFlag::DisplayInitializationLog; + if((configuration.flags() & Configuration::Flag::VerboseLog) && !(_configurationFlags & Configuration::Flag::QuietLog)) + _configurationFlags |= Configuration::Flag::VerboseLog; + else if((configuration.flags() & Configuration::Flag::QuietLog) && !(_configurationFlags & Configuration::Flag::VerboseLog)) + _configurationFlags |= Configuration::Flag::QuietLog; /* GPU validation is enabled if either enables it */ if(configuration.flags() & Configuration::Flag::GpuValidation) - _internalFlags |= InternalFlag::GpuValidation; + _configurationFlags |= Configuration::Flag::GpuValidation; /* Driver workarounds get merged. Not using disableDriverWorkaround() here since the Configuration already contains the internal string views. */ @@ -946,7 +946,7 @@ bool Context::tryCreate(const Configuration& configuration) { currentContext = this; /* Decide whether to print the initialization output or not */ - std::ostream* output = _internalFlags & InternalFlag::DisplayInitializationLog ? Debug::output() : nullptr; + std::ostream* output = _configurationFlags & Configuration::Flag::QuietLog ? nullptr : Debug::output(); /* Print some info and initialize state tracker (which also prints some more info). Mesa's renderer string has a space at the end, trim that. */ @@ -978,7 +978,7 @@ bool Context::tryCreate(const Configuration& configuration) { Renderer::initializeContextBasedFunctionality(); /* Enable GPU validation, if requested */ - if(_internalFlags & InternalFlag::GpuValidation) { + if(_configurationFlags & Configuration::Flag::GpuValidation) { #ifndef MAGNUM_TARGET_WEBGL if(isExtensionSupported()) { Renderer::enable(Renderer::Feature::DebugOutput); @@ -987,7 +987,7 @@ bool Context::tryCreate(const Configuration& configuration) { if((detectedDriver() & DetectedDriver::Amd) && !(flags() & Flag::Debug)) { Warning{} << "GL::Context: GPU validation on AMD drivers requires debug context to work properly"; - } else if(_internalFlags >= InternalFlag::DisplayVerboseInitializationLog) { + } else if(_configurationFlags & Configuration::Flag::VerboseLog) { Debug{} << "GL::Context: enabling GPU validation"; } diff --git a/src/Magnum/GL/Context.h b/src/Magnum/GL/Context.h index e0d9fdb3e..3da9fcdf2 100644 --- a/src/Magnum/GL/Context.h +++ b/src/Magnum/GL/Context.h @@ -65,6 +65,17 @@ namespace Implementation { /** @todo C++17: use &&... instead of all this */ public: enum: bool { value = IsExtension::value && IsExtension::value }; }; + + /* Context::Configuration::Flag, but because we need to use it inside + Context before the Configuration class is defined, it has to be here */ + enum class ContextConfigurationFlag: UnsignedLong { + /* Keeping the 32-bit range reserved for actual GL context flags */ + QuietLog = 1ull << 61, + VerboseLog = 1ull << 62, + GpuValidation = 1ull << 63 + }; + typedef Containers::EnumSet ContextConfigurationFlags; + CORRADE_ENUMSET_OPERATORS(ContextConfigurationFlags) } /** @@ -789,15 +800,6 @@ class MAGNUM_GL_EXPORT Context { #ifdef DOXYGEN_GENERATING_OUTPUT private: #endif - /* Applications want an easy way to know if GPU validation is enabled */ - enum class InternalFlag: UnsignedByte { - DisplayInitializationLog = 1 << 0, - DisplayVerboseInitializationLog = DisplayInitializationLog|(1 << 1), - GpuValidation = 1 << 2 - }; - typedef Containers::EnumSet InternalFlags; - CORRADE_ENUMSET_FRIEND_OPERATORS(InternalFlags) - bool isDriverWorkaroundDisabled(Containers::StringView workaround); Implementation::State& state() { return *_state; } @@ -805,7 +807,7 @@ class MAGNUM_GL_EXPORT Context { state() pointer is not ready yet so we have to pass it directly */ MAGNUM_GL_LOCAL bool isCoreProfileInternal(Implementation::ContextState& state); - InternalFlags internalFlags() const { return _internalFlags; } + Implementation::ContextConfigurationFlags configurationFlags() const { return _configurationFlags; } #ifdef DOXYGEN_GENERATING_OUTPUT private: @@ -855,10 +857,13 @@ class MAGNUM_GL_EXPORT Context { Containers::Optional _detectedDrivers; + /** @todo these are all needed only until the state gets created and + then can be discarded -- what to do? we could avoid including + Array altogether */ /* True means known and disabled, false means known */ Containers::Array> _driverWorkarounds; Containers::Array _disabledExtensions; - InternalFlags _internalFlags; + Implementation::ContextConfigurationFlags _configurationFlags; }; #ifndef MAGNUM_TARGET_WEBGL @@ -903,8 +908,10 @@ class MAGNUM_GL_EXPORT Context::Configuration { * @ref Context::flags(). * @see @ref Flags, @ref setFlags() */ + #ifdef DOXYGEN_GENERATING_OUTPUT enum class Flag: UnsignedLong { - /* Keeping the 32-bit range reserved for actual GL context flags */ + /* Docs only, keep in sync with + Implementation::ContextConfigurationFlag please */ /** * Print only warnings and errors instead of the usual startup log @@ -934,13 +941,20 @@ class MAGNUM_GL_EXPORT Context::Configuration { */ GpuValidation = 1ull << 63 }; + #else + typedef Implementation::ContextConfigurationFlag Flag; + #endif /** * @brief Context setup flags * * @see @ref setFlags(), @ref GL::Context::Flags */ + #ifdef DOXYGEN_GENERATING_OUTPUT typedef Containers::EnumSet Flags; + #else + typedef Implementation::ContextConfigurationFlags Flags; + #endif /*implicit*/ Configuration(); @@ -1079,8 +1093,6 @@ class MAGNUM_GL_EXPORT Context::Configuration { } #endif -CORRADE_ENUMSET_OPERATORS(Context::Configuration::Flags) - /** @hideinitializer @brief Assert that given OpenGL version is supported @param version Version diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index 4dc455378..e435c26aa 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -432,7 +432,7 @@ bool GlfwApplication::tryCreate(const Configuration& configuration, const GLConf /* Request debug context if --magnum-gpu-validation is enabled */ GLConfiguration::Flags glFlags = glConfiguration.flags(); - if(_context->internalFlags() & GL::Context::InternalFlag::GpuValidation) + if(_context->configurationFlags() & GL::Context::Configuration::Flag::GpuValidation) glFlags |= GLConfiguration::Flag::Debug; #ifdef GLFW_CONTEXT_NO_ERROR diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index 0c59ac235..ba985b472 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -467,7 +467,7 @@ bool Sdl2Application::tryCreate(const Configuration& configuration, const GLConf /* Request debug context if --magnum-gpu-validation is enabled */ GLConfiguration::Flags glFlags = glConfiguration.flags(); - if(_context->internalFlags() & GL::Context::InternalFlag::GpuValidation) + if(_context->configurationFlags() & GL::Context::Configuration::Flag::GpuValidation) glFlags |= GLConfiguration::Flag::Debug; /* Set context version, if user-specified */ diff --git a/src/Magnum/Platform/WindowlessEglApplication.cpp b/src/Magnum/Platform/WindowlessEglApplication.cpp index 9fca277c9..bad8f68b6 100644 --- a/src/Magnum/Platform/WindowlessEglApplication.cpp +++ b/src/Magnum/Platform/WindowlessEglApplication.cpp @@ -129,7 +129,7 @@ WindowlessEglContext::WindowlessEglContext(const Configuration& configuration, G --magnum-gpu-validation is enabled because otherwise it's fucking hard to discover what's to blame (lost > 3 hours already). See class docs for more info and a workaround. */ - if(extensionSupported(extensions, "EGL_KHR_debug") && magnumContext && (magnumContext->internalFlags() & GL::Context::InternalFlag::GpuValidation)) { + if(extensionSupported(extensions, "EGL_KHR_debug") && magnumContext && (magnumContext->configurationFlags() & GL::Context::Configuration::Flag::GpuValidation)) { auto eglDebugMessageControl = reinterpret_cast(eglGetProcAddress("eglDebugMessageControlKHR")); const EGLAttrib debugAttribs[] = { EGL_DEBUG_MSG_WARN_KHR, EGL_TRUE, @@ -151,7 +151,7 @@ WindowlessEglContext::WindowlessEglContext(const Configuration& configuration, G if(!count) { Error e; e << "Platform::WindowlessEglApplication::tryCreateContext(): no EGL devices found, likely a driver issue"; - if(!magnumContext || !(magnumContext->internalFlags() & GL::Context::InternalFlag::GpuValidation)) + if(!magnumContext || !(magnumContext->configurationFlags() & GL::Context::Configuration::Flag::GpuValidation)) e << Debug::nospace << "; enable --magnum-gpu-validation to see additional info"; return; } @@ -195,7 +195,7 @@ WindowlessEglContext::WindowlessEglContext(const Configuration& configuration, G if(eglGetError() == EGL_BAD_DEVICE_EXT && !magnumContext->isDriverWorkaroundDisabled("nv-egl-crashy-query-device-attrib"_s)) continue; - if(magnumContext && (magnumContext->internalFlags() >= GL::Context::InternalFlag::DisplayVerboseInitializationLog)) + if(magnumContext && (magnumContext->configurationFlags() >= GL::Context::Configuration::Flag::VerboseLog)) Debug{} << "Platform::WindowlessEglApplication: eglQueryDeviceStringEXT(EGLDevice=" << Debug::nospace << selectedDevice << Debug::nospace << "):" << eglExtensions; EGLAttrib cudaDeviceNumber; @@ -210,7 +210,7 @@ WindowlessEglContext::WindowlessEglContext(const Configuration& configuration, G return; } - if(magnumContext && (magnumContext->internalFlags() >= GL::Context::InternalFlag::DisplayVerboseInitializationLog)) { + if(magnumContext && (magnumContext->configurationFlags() >= GL::Context::Configuration::Flag::VerboseLog)) { Debug{} << "Platform::WindowlessEglApplication: found" << count << "EGL devices, choosing EGL device" << selectedDevice << "for CUDA device" << configuration.cudaDevice(); } @@ -218,7 +218,7 @@ WindowlessEglContext::WindowlessEglContext(const Configuration& configuration, G } else { /* Print the log *before* calling eglQueryDevices() again, as the `count` gets overwritten by it */ - if(magnumContext && (magnumContext->internalFlags() >= GL::Context::InternalFlag::DisplayVerboseInitializationLog)) { + if(magnumContext && (magnumContext->configurationFlags() >= GL::Context::Configuration::Flag::VerboseLog)) { Debug{} << "Platform::WindowlessEglApplication: found" << count << "EGL devices, choosing device" << configuration.device(); } @@ -302,7 +302,7 @@ WindowlessEglContext::WindowlessEglContext(const Configuration& configuration, G #ifndef MAGNUM_TARGET_WEBGL /* Request debug context if --magnum-gpu-validation is enabled */ Configuration::Flags flags = configuration.flags(); - if(magnumContext && magnumContext->internalFlags() & GL::Context::InternalFlag::GpuValidation) + if(magnumContext && magnumContext->configurationFlags() & GL::Context::Configuration::Flag::GpuValidation) flags |= Configuration::Flag::Debug; #endif diff --git a/src/Magnum/Platform/WindowlessGlxApplication.cpp b/src/Magnum/Platform/WindowlessGlxApplication.cpp index d94ea434c..29acee4fe 100644 --- a/src/Magnum/Platform/WindowlessGlxApplication.cpp +++ b/src/Magnum/Platform/WindowlessGlxApplication.cpp @@ -111,7 +111,7 @@ WindowlessGlxContext::WindowlessGlxContext(const WindowlessGlxContext::Configura /* Request debug context if --magnum-gpu-validation is enabled */ Configuration::Flags flags = configuration.flags(); - if(magnumContext && magnumContext->internalFlags() & GL::Context::InternalFlag::GpuValidation) + if(magnumContext && magnumContext->configurationFlags() & GL::Context::Configuration::Flag::GpuValidation) flags |= Configuration::Flag::Debug; /* Optimistically choose core context first */ diff --git a/src/Magnum/Platform/WindowlessWglApplication.cpp b/src/Magnum/Platform/WindowlessWglApplication.cpp index 76985b49b..dffbbc593 100644 --- a/src/Magnum/Platform/WindowlessWglApplication.cpp +++ b/src/Magnum/Platform/WindowlessWglApplication.cpp @@ -124,7 +124,7 @@ WindowlessWglContext::WindowlessWglContext(const Configuration& configuration, G /* Request debug context if --magnum-gpu-validation is enabled */ Configuration::Flags flags = configuration.flags(); - if(magnumContext && magnumContext->internalFlags() & GL::Context::InternalFlag::GpuValidation) + if(magnumContext && magnumContext->configurationFlags() & GL::Context::Configuration::Flag::GpuValidation) flags |= Configuration::Flag::Debug; /* Optimistically choose core context first */ diff --git a/src/Magnum/Platform/WindowlessWindowsEglApplication.cpp b/src/Magnum/Platform/WindowlessWindowsEglApplication.cpp index 5cb872171..b0341f8db 100644 --- a/src/Magnum/Platform/WindowlessWindowsEglApplication.cpp +++ b/src/Magnum/Platform/WindowlessWindowsEglApplication.cpp @@ -115,7 +115,7 @@ WindowlessWindowsEglContext::WindowlessWindowsEglContext(const Configuration& co /* Request debug context if --magnum-gpu-validation is enabled */ Configuration::Flags flags = configuration.flags(); - if(magnumContext && magnumContext->internalFlags() & GL::Context::InternalFlag::GpuValidation) + if(magnumContext && magnumContext->configurationFlags() & GL::Context::Configuration::Flag::GpuValidation) flags |= Configuration::Flag::Debug; const EGLint attributes[] = {