diff --git a/src/Magnum/Platform/WindowlessIosApplication.h b/src/Magnum/Platform/WindowlessIosApplication.h index 4b1b14243..2e922fc94 100644 --- a/src/Magnum/Platform/WindowlessIosApplication.h +++ b/src/Magnum/Platform/WindowlessIosApplication.h @@ -115,10 +115,23 @@ class WindowlessIosContext { * @brief Make the context current * * Prints error message and returns @cpp false @ce on failure, - * otherwise returns @cpp true @ce. + * otherwise returns @cpp true @ce. If the context is current on + * another thread, you have to @ref release() it there first --- an + * OpenGL context can't be current in multiple threads at the same + * time. */ bool makeCurrent(); + /** + * @brief Release current context + * @m_since_latest + * + * Releases a context previously made current using @ref makeCurrent(). + * Prints error message and returns @cpp false @ce on failure, + * otherwise returns @cpp true @ce. + */ + bool release(); + /** * @brief Underlying OpenGL context * @m_since_latest diff --git a/src/Magnum/Platform/WindowlessIosApplication.mm b/src/Magnum/Platform/WindowlessIosApplication.mm index 15c7cb9ef..83756aeb8 100644 --- a/src/Magnum/Platform/WindowlessIosApplication.mm +++ b/src/Magnum/Platform/WindowlessIosApplication.mm @@ -74,6 +74,14 @@ bool WindowlessIosContext::makeCurrent() { return false; } +bool WindowlessIosContext::release() { + if([EAGLContext setCurrentContext:nil]) + return true; + + Error() << "Platform::WindowlessIosContext::release(): cannot release current context"; + return false; +} + #ifndef DOXYGEN_GENERATING_OUTPUT WindowlessIosApplication::WindowlessIosApplication(const Arguments& arguments): WindowlessIosApplication{arguments, Configuration{}} {} #endif diff --git a/src/Magnum/Platform/WindowlessWglApplication.cpp b/src/Magnum/Platform/WindowlessWglApplication.cpp index d4e647eea..e697fb442 100644 --- a/src/Magnum/Platform/WindowlessWglApplication.cpp +++ b/src/Magnum/Platform/WindowlessWglApplication.cpp @@ -243,6 +243,14 @@ bool WindowlessWglContext::makeCurrent() { return false; } +bool WindowlessWglContext::release() { + if(wglMakeCurrent(_deviceContext, nullptr)) + return true; + + Error() << "Platform::WindowlessWglContext::release(): cannot release current context:" << GetLastError(); + return false; +} + WindowlessWglContext::Configuration::Configuration(): #ifndef MAGNUM_TARGET_GLES _flags{Flag::ForwardCompatible} diff --git a/src/Magnum/Platform/WindowlessWglApplication.h b/src/Magnum/Platform/WindowlessWglApplication.h index 819928a29..5deb05a9c 100644 --- a/src/Magnum/Platform/WindowlessWglApplication.h +++ b/src/Magnum/Platform/WindowlessWglApplication.h @@ -130,10 +130,23 @@ class WindowlessWglContext { * @brief Make the context current * * Prints error message and returns @cpp false @ce on failure, - * otherwise returns @cpp true @ce. + * otherwise returns @cpp true @ce. If the context is current on + * another thread, you have to @ref release() it there first --- an + * OpenGL context can't be current in multiple threads at the same + * time. */ bool makeCurrent(); + /** + * @brief Release current context + * @m_since_latest + * + * Releases a context previously made current using @ref makeCurrent(). + * Prints error message and returns @cpp false @ce on failure, + * otherwise returns @cpp true @ce. + */ + bool release(); + /** * @brief Underlying OpenGL context * @m_since{2020,06} diff --git a/src/Magnum/Platform/WindowlessWindowsEglApplication.cpp b/src/Magnum/Platform/WindowlessWindowsEglApplication.cpp index 7ffbdec5a..685a30892 100644 --- a/src/Magnum/Platform/WindowlessWindowsEglApplication.cpp +++ b/src/Magnum/Platform/WindowlessWindowsEglApplication.cpp @@ -173,6 +173,14 @@ bool WindowlessWindowsEglContext::makeCurrent() { return false; } +bool WindowlessWindowsEglContext::release() { + if(eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) + return true; + + Error() << "Platform::WindowlessWindowsEglApplication::release(): cannot release current context:" << GetLastError(); + return false; +} + #ifndef DOXYGEN_GENERATING_OUTPUT WindowlessWindowsEglApplication::WindowlessWindowsEglApplication(const Arguments& arguments): WindowlessWindowsEglApplication{arguments, Configuration{}} {} #endif diff --git a/src/Magnum/Platform/WindowlessWindowsEglApplication.h b/src/Magnum/Platform/WindowlessWindowsEglApplication.h index c71f1f8d3..589be9571 100644 --- a/src/Magnum/Platform/WindowlessWindowsEglApplication.h +++ b/src/Magnum/Platform/WindowlessWindowsEglApplication.h @@ -115,10 +115,23 @@ class WindowlessWindowsEglContext { * @brief Make the context current * * Prints error message and returns @cpp false @ce on failure, - * otherwise returns @cpp true @ce. + * otherwise returns @cpp true @ce. If the context is current on + * another thread, you have to @ref release() it there first --- an + * OpenGL context can't be current in multiple threads at the same + * time. */ bool makeCurrent(); + /** + * @brief Release current context + * @m_since_latest + * + * Releases a context previously made current using @ref makeCurrent(). + * Prints error message and returns @cpp false @ce on failure, + * otherwise returns @cpp true @ce. + */ + bool release(); + /** * @brief Underlying OpenGL context * @m_since{2020,06}