diff --git a/src/Magnum/Platform/WindowlessCglApplication.cpp b/src/Magnum/Platform/WindowlessCglApplication.cpp index d6085932e..34eea525b 100644 --- a/src/Magnum/Platform/WindowlessCglApplication.cpp +++ b/src/Magnum/Platform/WindowlessCglApplication.cpp @@ -35,7 +35,7 @@ namespace Magnum { namespace Platform { -WindowlessCglContext::WindowlessCglContext(const Configuration&, GLContext*) { +WindowlessCglContext::WindowlessCglContext(const Configuration & configuration, GLContext*) { int formatCount; CGLPixelFormatAttribute attributes32[] = { kCGLPFAAccelerated, @@ -68,7 +68,7 @@ WindowlessCglContext::WindowlessCglContext(const Configuration&, GLContext*) { } } - if(CGLCreateContext(_pixelFormat, nullptr, &_context) != kCGLNoError) + if(CGLCreateContext(_pixelFormat, configuration.sharedContext(), &_context) != kCGLNoError) Error() << "Platform::WindowlessCglContext: cannot create context"; } diff --git a/src/Magnum/Platform/WindowlessCglApplication.h b/src/Magnum/Platform/WindowlessCglApplication.h index 112d1f347..0e33a9729 100644 --- a/src/Magnum/Platform/WindowlessCglApplication.h +++ b/src/Magnum/Platform/WindowlessCglApplication.h @@ -142,6 +142,28 @@ class WindowlessCglContext { class WindowlessCglContext::Configuration { public: constexpr /*implicit*/ Configuration() {} + + /** + * @brief Creates an OpenGL shared context with @param ctx instead + * of creating a brand new one. + */ + Configuration& setSharedcontext(CGLContextObj ctx) { + _sharedContext = ctx; + return *this; + } + + /** + * @brief Returns the configuration shared context. + * If this has not been specified, (meaning the configuration uses a new opengl context), + * then returns nullptr + */ + CGLContextObj sharedContext() const { + return _sharedContext; + } + +private: + CGLContextObj _context{}; + CGLContextObj _sharedContext{}; }; /** diff --git a/src/Magnum/Platform/WindowlessWglApplication.cpp b/src/Magnum/Platform/WindowlessWglApplication.cpp index 4bab6654b..b3606ca27 100644 --- a/src/Magnum/Platform/WindowlessWglApplication.cpp +++ b/src/Magnum/Platform/WindowlessWglApplication.cpp @@ -145,7 +145,7 @@ WindowlessWglContext::WindowlessWglContext(const Configuration& configuration, G #endif 0 }; - _context = wglCreateContextAttribsARB(_deviceContext, nullptr, contextAttributes); + _context = wglCreateContextAttribsARB(_deviceContext, configuration.sharedContext(), contextAttributes); #ifndef MAGNUM_TARGET_GLES /* Fall back to (forward compatible) GL 2.1 if core context creation fails */ @@ -157,7 +157,7 @@ WindowlessWglContext::WindowlessWglContext(const Configuration& configuration, G WGL_CONTEXT_FLAGS_ARB, GLint(flags & ~Configuration::Flag::ForwardCompatible), 0 }; - _context = wglCreateContextAttribsARB(_deviceContext, nullptr, fallbackContextAttributes); + _context = wglCreateContextAttribsARB(_deviceContext, configuration.sharedContext(), fallbackContextAttributes); /* Fall back to (forward compatible) GL 2.1 if we are on binary NVidia/AMD/Intel drivers on Windows. Instead of creating forward-compatible @@ -196,7 +196,7 @@ WindowlessWglContext::WindowlessWglContext(const Configuration& configuration, G WGL_CONTEXT_FLAGS_ARB, GLint(flags & ~Configuration::Flag::ForwardCompatible), 0 }; - _context = wglCreateContextAttribsARB(_deviceContext, nullptr, fallbackContextAttributes); + _context = wglCreateContextAttribsARB(_deviceContext, configuration.sharedContext(), fallbackContextAttributes); } } #endif diff --git a/src/Magnum/Platform/WindowlessWglApplication.h b/src/Magnum/Platform/WindowlessWglApplication.h index f3c461075..2d726d281 100644 --- a/src/Magnum/Platform/WindowlessWglApplication.h +++ b/src/Magnum/Platform/WindowlessWglApplication.h @@ -232,9 +232,29 @@ class WindowlessWglContext::Configuration { _flags &= ~flags; return *this; } + + /** + * @brief Creates an OpenGL shared context with @param ctx instead + * of creating a brand new one. + */ + Configuration& setSharedcontext(HGLRC ctx) { + _sharedContext = ctx; + return *this; + } + + /** + * @brief Returns the configuration shared context. + * If this has not been specified, (meaning the configuration uses a new opengl context), + * then returns nullptr + */ + HGLRC sharedContext() const { + return _sharedContext; + } private: + HGLRC _sharedContext; Flags _flags; + }; CORRADE_ENUMSET_OPERATORS(WindowlessWglContext::Configuration::Flags)