From e3a590b8a914bf64110cfd5c0d194e91aeb17faa Mon Sep 17 00:00:00 2001 From: Max Schwarz Date: Wed, 10 Feb 2021 12:17:27 +0100 Subject: [PATCH 1/3] GL: Context::InternalFlags as parameter in Context constructor --- src/Magnum/GL/Context.cpp | 10 ++++++---- src/Magnum/GL/Context.h | 11 +++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Magnum/GL/Context.cpp b/src/Magnum/GL/Context.cpp index b9fb436769..f8b1ea138c 100644 --- a/src/Magnum/GL/Context.cpp +++ b/src/Magnum/GL/Context.cpp @@ -626,9 +626,9 @@ Context& Context::current() { void Context::makeCurrent(Context* context) { currentContext = context; } -Context::Context(NoCreateT, Int argc, const char** argv, void functionLoader(Context&)): Context{NoCreate, Utility::Arguments{"magnum"}, argc, argv, functionLoader} {} +Context::Context(NoCreateT, Int argc, const char** argv, void functionLoader(Context&), InternalFlags flags): Context{NoCreate, Utility::Arguments{"magnum"}, argc, argv, functionLoader, flags} {} -Context::Context(NoCreateT, Utility::Arguments& args, Int argc, const char** argv, void functionLoader(Context&)): _functionLoader{functionLoader}, _version{Version::None} { +Context::Context(NoCreateT, Utility::Arguments& args, Int argc, const char** argv, void functionLoader(Context&), InternalFlags flags): Context{NoCreate, functionLoader, flags} { /* Parse arguments */ CORRADE_INTERNAL_ASSERT(args.prefix() == "magnum"); args.addOption("disable-workarounds").setHelp("disable-workarounds", "driver workarounds to disable\n (see https://doc.magnum.graphics/magnum/opengl-workarounds.html for detailed info)", "LIST") @@ -644,8 +644,8 @@ 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; + else if(args.value("log") == "quiet" || args.value("log") == "QUIET") + _internalFlags &= ~InternalFlag::DisplayInitializationLog; /* Decide whether to enable GPU validation */ if(args.value("gpu-validation") == "on" || args.value("gpu-validation") == "ON") @@ -660,6 +660,8 @@ Context::Context(NoCreateT, Utility::Arguments& args, Int argc, const char** arg _disabledExtensions.push_back(extension); } +Context::Context(NoCreateT, void functionLoader(Context&), InternalFlags flags): _functionLoader{functionLoader}, _version{Version::None}, _internalFlags{flags} {} + Context::Context(Context&& other) noexcept: _version{other._version}, #ifndef MAGNUM_TARGET_WEBGL _flags{other._flags}, diff --git a/src/Magnum/GL/Context.h b/src/Magnum/GL/Context.h index 655e8168a0..cc05e03717 100644 --- a/src/Magnum/GL/Context.h +++ b/src/Magnum/GL/Context.h @@ -745,7 +745,9 @@ class MAGNUM_GL_EXPORT Context { enum class InternalFlag: UnsignedByte { DisplayInitializationLog = 1 << 0, DisplayVerboseInitializationLog = DisplayInitializationLog|(1 << 1), - GpuValidation = 1 << 2 + GpuValidation = 1 << 2, + + Default = DisplayInitializationLog }; typedef Containers::EnumSet InternalFlags; CORRADE_ENUMSET_FRIEND_OPERATORS(InternalFlags) @@ -766,9 +768,10 @@ class MAGNUM_GL_EXPORT Context { #endif /* Made protected so it's possible to test the NoCreate constructor and also not needed to friend Platform::GLContext. */ - explicit Context(NoCreateT, Int argc, const char** argv, void functionLoader(Context&)); - explicit Context(NoCreateT, Utility::Arguments&& args, Int argc, const char** argv, void functionLoader(Context&)): Context{NoCreate, args, argc, argv, functionLoader} {} - explicit Context(NoCreateT, Utility::Arguments& args, Int argc, const char** argv, void functionLoader(Context&)); + explicit Context(NoCreateT, Int argc, const char** argv, void functionLoader(Context&), InternalFlags flags = InternalFlag::Default); + explicit Context(NoCreateT, Utility::Arguments&& args, Int argc, const char** argv, void functionLoader(Context&), InternalFlags flags = InternalFlag::Default): Context{NoCreate, args, argc, argv, functionLoader, flags} {} + explicit Context(NoCreateT, Utility::Arguments& args, Int argc, const char** argv, void functionLoader(Context&), InternalFlags flags = InternalFlag::Default); + explicit Context(NoCreateT, void functionLoader(Context&), InternalFlags flags = InternalFlag::Default); bool tryCreate(); void create(); From 58afb9c13645e67516de75959e1099bb938a3209 Mon Sep 17 00:00:00 2001 From: Max Schwarz Date: Wed, 10 Feb 2021 12:17:50 +0100 Subject: [PATCH 2/3] Platform: GL::Context::InternalFlags as GLContext() parameter --- src/Magnum/Platform/GLContext.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Magnum/Platform/GLContext.h b/src/Magnum/Platform/GLContext.h index fda6110ac3..41ac0711e1 100644 --- a/src/Magnum/Platform/GLContext.h +++ b/src/Magnum/Platform/GLContext.h @@ -60,13 +60,13 @@ class GLContext: public GL::Context { * Equivalent to calling @ref GLContext(NoCreateT, Int, const char**) * followed by @ref create(). */ - explicit GLContext(Int argc, const char** argv): GLContext{NoCreate, argc, argv} { create(); } + explicit GLContext(Int argc, const char** argv, InternalFlags flags = InternalFlag::Default): GLContext{NoCreate, argc, argv, flags} { create(); } /** @overload */ - explicit GLContext(Int argc, char** argv): GLContext{argc, const_cast(argv)} {} + explicit GLContext(Int argc, char** argv, InternalFlags flags = InternalFlag::Default): GLContext{argc, const_cast(argv), flags} {} /** @overload */ - explicit GLContext(Int argc, std::nullptr_t argv): GLContext{argc, static_cast(argv)} {} + explicit GLContext(Int argc, std::nullptr_t argv, InternalFlags flags = InternalFlag::Default): GLContext{argc, static_cast(argv), flags} {} /** * @brief Default constructor @@ -77,7 +77,7 @@ class GLContext: public GL::Context { * behavior from the environment. See @ref GL-Context-command-line for * more information. */ - explicit GLContext(): GLContext{0, nullptr} {} + explicit GLContext(InternalFlags flags = InternalFlag::Default): GLContext{0, nullptr, flags} {} /** * @brief Construct without creating the context @@ -87,28 +87,28 @@ class GLContext: public GL::Context { * Use @ref create() or @ref tryCreate() to create the context. * @see @ref GLContext(Int, const char**) */ - explicit GLContext(NoCreateT, Int argc, const char** argv): + explicit GLContext(NoCreateT, Int argc, const char** argv, InternalFlags flags = InternalFlag::Default): #ifndef CORRADE_TARGET_EMSCRIPTEN - GL::Context{NoCreate, argc, argv, flextGLInit} {} + GL::Context{NoCreate, argc, argv, flextGLInit, flags} {} #else - GL::Context{NoCreate, argc, argv, nullptr} {} + GL::Context{NoCreate, argc, argv, nullptr, flags} {} #endif /** @overload */ - explicit GLContext(NoCreateT, Int argc, char** argv): GLContext{NoCreate, argc, const_cast(argv)} {} + explicit GLContext(NoCreateT, Int argc, char** argv, InternalFlags flags = InternalFlag::Default): GLContext{NoCreate, argc, const_cast(argv), flags} {} /** @overload */ - explicit GLContext(NoCreateT, Int argc, std::nullptr_t argv): GLContext{NoCreate, argc, static_cast(argv)} {} + explicit GLContext(NoCreateT, Int argc, std::nullptr_t argv, InternalFlags flags = InternalFlag::Default): GLContext{NoCreate, argc, static_cast(argv), flags} {} #ifndef DOXYGEN_GENERATING_OUTPUT /* Used privately to inject additional command-line arguments */ - explicit GLContext(NoCreateT, Utility::Arguments& args, Int argc, char** argv): GLContext{NoCreate, args, argc, const_cast(argv)} {} - explicit GLContext(NoCreateT, Utility::Arguments& args, Int argc, std::nullptr_t argv): GLContext{NoCreate, args, argc, static_cast(argv)} {} - explicit GLContext(NoCreateT, Utility::Arguments& args, Int argc, const char** argv): + explicit GLContext(NoCreateT, Utility::Arguments& args, Int argc, char** argv, InternalFlags flags = InternalFlag::Default): GLContext{NoCreate, args, argc, const_cast(argv), flags} {} + explicit GLContext(NoCreateT, Utility::Arguments& args, Int argc, std::nullptr_t argv, InternalFlags flags = InternalFlag::Default): GLContext{NoCreate, args, argc, static_cast(argv), flags} {} + explicit GLContext(NoCreateT, Utility::Arguments& args, Int argc, const char** argv, InternalFlags flags = InternalFlag::Default): #ifndef CORRADE_TARGET_EMSCRIPTEN - GL::Context{NoCreate, args, argc, argv, flextGLInit} {} + GL::Context{NoCreate, args, argc, argv, flextGLInit, flags} {} #else - GL::Context{NoCreate, args, argc, argv, nullptr} {} + GL::Context{NoCreate, args, argc, argv, nullptr, flags} {} #endif #endif @@ -121,7 +121,7 @@ class GLContext: public GL::Context { * affect the renderer behavior from the environment. See * @ref GL-Context-command-line for more information. */ - explicit GLContext(NoCreateT): GLContext{NoCreate, 0, nullptr} {} + explicit GLContext(NoCreateT, InternalFlags flags = InternalFlag::Default): GLContext{NoCreate, 0, nullptr, flags} {} /** * @brief Create the context From 6cfa9d41e816bfc67f89f149febe0671f9338a32 Mon Sep 17 00:00:00 2001 From: Max Schwarz Date: Wed, 10 Feb 2021 12:19:58 +0100 Subject: [PATCH 3/3] GL: Add Context flag for disabling framebuffer initialization --- src/Magnum/GL/Context.cpp | 4 +++- src/Magnum/GL/Context.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Magnum/GL/Context.cpp b/src/Magnum/GL/Context.cpp index f8b1ea138c..50ed7612b5 100644 --- a/src/Magnum/GL/Context.cpp +++ b/src/Magnum/GL/Context.cpp @@ -912,7 +912,9 @@ bool Context::tryCreate() { /* Initialize functionality based on current OpenGL version and extensions */ /** @todo Get rid of these */ - DefaultFramebuffer::initializeContextBasedFunctionality(*this); + if(!(_internalFlags & InternalFlag::NoFramebuffer)) + DefaultFramebuffer::initializeContextBasedFunctionality(*this); + Renderer::initializeContextBasedFunctionality(); /* Enable GPU validation, if requested */ diff --git a/src/Magnum/GL/Context.h b/src/Magnum/GL/Context.h index cc05e03717..c9e729813e 100644 --- a/src/Magnum/GL/Context.h +++ b/src/Magnum/GL/Context.h @@ -747,6 +747,8 @@ class MAGNUM_GL_EXPORT Context { DisplayVerboseInitializationLog = DisplayInitializationLog|(1 << 1), GpuValidation = 1 << 2, + NoFramebuffer = 1 << 3, + Default = DisplayInitializationLog }; typedef Containers::EnumSet InternalFlags;