diff --git a/src/Magnum/Platform/WindowlessEglApplication.cpp b/src/Magnum/Platform/WindowlessEglApplication.cpp index 27c3f6442..5d1ec933d 100644 --- a/src/Magnum/Platform/WindowlessEglApplication.cpp +++ b/src/Magnum/Platform/WindowlessEglApplication.cpp @@ -84,6 +84,23 @@ bool extensionSupported(const char* const extensions, Containers::ArrayView devices{configuration.device() + 1}; CORRADE_INTERNAL_ASSERT_OUTPUT(eglQueryDevices(configuration.device() + 1, devices, &count)); - if(!(_display = reinterpret_cast(eglGetProcAddress("eglGetPlatformDisplayEXT"))(EGL_PLATFORM_DEVICE_EXT, devices[configuration.device()], nullptr))) { + if(!_sharedContext && !(_display = reinterpret_cast(eglGetProcAddress("eglGetPlatformDisplayEXT"))(EGL_PLATFORM_DEVICE_EXT, devices[configuration.device()], nullptr))) { Error{} << "Platform::WindowlessEglApplication::tryCreateContext(): cannot get platform display for a device:" << Implementation::eglErrorString(eglGetError()); return; } @@ -168,16 +185,19 @@ WindowlessEglContext::WindowlessEglContext(const Configuration& configuration, G } #endif - if(!(_display = eglGetDisplay(EGL_DEFAULT_DISPLAY))) { + if(!_sharedContext && !(_display = eglGetDisplay(EGL_DEFAULT_DISPLAY))) { Error{} << "Platform::WindowlessEglApplication::tryCreateContext(): cannot get default EGL display:" << Implementation::eglErrorString(eglGetError()); return; } } - if(!eglInitialize(_display, nullptr, nullptr)) { - Error() << "Platform::WindowlessEglApplication::tryCreateContext(): cannot initialize EGL:" << Implementation::eglErrorString(eglGetError()); - return; - } + /** + * We must initialize the display if and only if we don't use a shared context + */ + if(!_sharedContext && !eglInitialize(_display, nullptr, nullptr)) { + Error() << "Platform::WindowlessEglApplication::tryCreateContext(): cannot initialize EGL:" << Implementation::eglErrorString(eglGetError()); + return; + } const EGLenum api = #ifndef MAGNUM_TARGET_GLES @@ -274,9 +294,7 @@ WindowlessEglContext::WindowlessEglContext(const Configuration& configuration, G contextFlags = EGL_NONE; } #endif - - if(configuration.sharedContext() != EGL_NO_CONTEXT) _sharedContext = true; - + if(!(_context = eglCreateContext(_display, config, #ifndef MAGNUM_TARGET_WEBGL configuration.sharedContext(), diff --git a/src/Magnum/Platform/WindowlessEglApplication.h b/src/Magnum/Platform/WindowlessEglApplication.h index f7566d452..d7eb217d3 100644 --- a/src/Magnum/Platform/WindowlessEglApplication.h +++ b/src/Magnum/Platform/WindowlessEglApplication.h @@ -276,16 +276,21 @@ class WindowlessEglContext::Configuration { * @m_since_latest * * When set, the created context will share a subset of OpenGL objects - * with @p context, instead of being independent. Many caveats and + * with @p context whose associated display is @p display, instead of being independent. + * Many caveats and * limitations apply to shared OpenGL contexts, please consult the * OpenGL specification for details. Default is `EGL_NO_CONTEXT`, i.e. * no sharing. + * + * @note @p display must be provided to avoid errors on destruction, since + * the display is shared among shared-context on EGL. * @see @ref WindowlessEglContext::glContext(), * @ref WindowlessEglApplication::glContext() * @requires_gles Context sharing is not available in WebGL. */ - Configuration& setSharedContext(EGLContext context) { + Configuration& setSharedContext(EGLContext context, EGLDisplay display) { _sharedContext = context; + _sharedDisplay = display; return *this; } @@ -296,6 +301,14 @@ class WindowlessEglContext::Configuration { * @requires_gles Context sharing is not available in WebGL. */ EGLContext sharedContext() const { return _sharedContext; } + + /** + * @brief Shared display + * @m_since_latest + * + * @requires_gles Context sharing is not available in WebGL. + */ + EGLContext sharedDisplay() const { return _sharedDisplay; } #endif private: @@ -303,6 +316,7 @@ class WindowlessEglContext::Configuration { Flags _flags; UnsignedInt _device; EGLContext _sharedContext = EGL_NO_CONTEXT; + EGLDisplay _sharedDisplay = EGL_NO_DISPLAY; #endif };