| @@ -68,6 +68,7 @@ public: | |||||
| bool makeActive() const noexcept { return isInsideGLCallback; } | bool makeActive() const noexcept { return isInsideGLCallback; } | ||||
| bool isActive() const noexcept { return isInsideGLCallback; } | bool isActive() const noexcept { return isInsideGLCallback; } | ||||
| static void deactivateCurrentContext() {} | |||||
| void swapBuffers() const noexcept {} | void swapBuffers() const noexcept {} | ||||
| bool setSwapInterval (const int) { return false; } | bool setSwapInterval (const int) { return false; } | ||||
| @@ -81,7 +81,7 @@ public: | |||||
| // so causes myserious timing-related failures. | // so causes myserious timing-related failures. | ||||
| [EAGLContext setCurrentContext: context]; | [EAGLContext setCurrentContext: context]; | ||||
| createGLBuffers(); | createGLBuffers(); | ||||
| [EAGLContext setCurrentContext: nil]; | |||||
| deactivateCurrentContext(); | |||||
| } | } | ||||
| ~NativeContext() | ~NativeContext() | ||||
| @@ -119,6 +119,11 @@ public: | |||||
| return [EAGLContext currentContext] == context; | return [EAGLContext currentContext] == context; | ||||
| } | } | ||||
| static void deactivateCurrentContext() | |||||
| { | |||||
| [EAGLContext setCurrentContext: nil]; | |||||
| } | |||||
| void swapBuffers() | void swapBuffers() | ||||
| { | { | ||||
| glBindRenderbuffer (GL_RENDERBUFFER, colorBufferHandle); | glBindRenderbuffer (GL_RENDERBUFFER, colorBufferHandle); | ||||
| @@ -114,7 +114,7 @@ public: | |||||
| void shutdownOnRenderThread() | void shutdownOnRenderThread() | ||||
| { | { | ||||
| glXMakeCurrent (display, None, 0); | |||||
| deactivateCurrentContext(); | |||||
| glXDestroyContext (display, renderContext); | glXDestroyContext (display, renderContext); | ||||
| renderContext = nullptr; | renderContext = nullptr; | ||||
| } | } | ||||
| @@ -130,6 +130,11 @@ public: | |||||
| return glXGetCurrentContext() == renderContext && renderContext != 0; | return glXGetCurrentContext() == renderContext && renderContext != 0; | ||||
| } | } | ||||
| static void deactivateCurrentContext() | |||||
| { | |||||
| glXMakeCurrent (display, None, 0); | |||||
| } | |||||
| void swapBuffers() | void swapBuffers() | ||||
| { | { | ||||
| glXSwapBuffers (display, embeddedWindow); | glXSwapBuffers (display, embeddedWindow); | ||||
| @@ -185,6 +185,11 @@ public: | |||||
| return [NSOpenGLContext currentContext] == renderContext; | return [NSOpenGLContext currentContext] == renderContext; | ||||
| } | } | ||||
| static void deactivateCurrentContext() | |||||
| { | |||||
| [NSOpenGLContext clearCurrentContext]; | |||||
| } | |||||
| struct Locker | struct Locker | ||||
| { | { | ||||
| Locker (NativeContext& nc) : cglContext ((CGLContextObj) [nc.renderContext CGLContextObj]) | Locker (NativeContext& nc) : cglContext ((CGLContextObj) [nc.renderContext CGLContextObj]) | ||||
| @@ -50,7 +50,7 @@ public: | |||||
| initialiseGLExtensions(); | initialiseGLExtensions(); | ||||
| const int wglFormat = wglChoosePixelFormatExtension (pixelFormat); | const int wglFormat = wglChoosePixelFormatExtension (pixelFormat); | ||||
| wglMakeCurrent (0, 0); | |||||
| deactivateCurrentContext(); | |||||
| if (wglFormat != pixFormat && wglFormat != 0) | if (wglFormat != pixFormat && wglFormat != 0) | ||||
| { | { | ||||
| @@ -84,6 +84,7 @@ public: | |||||
| void initialiseOnRenderThread() {} | void initialiseOnRenderThread() {} | ||||
| void shutdownOnRenderThread() {} | void shutdownOnRenderThread() {} | ||||
| static void deactivateCurrentContext() { wglMakeCurrent (0, 0); } | |||||
| bool makeActive() const noexcept { return wglMakeCurrent (dc, renderContext) != FALSE; } | bool makeActive() const noexcept { return wglMakeCurrent (dc, renderContext) != FALSE; } | ||||
| bool isActive() const noexcept { return wglGetCurrentContext() == renderContext; } | bool isActive() const noexcept { return wglGetCurrentContext() == renderContext; } | ||||
| void swapBuffers() const noexcept { SwapBuffers (dc); } | void swapBuffers() const noexcept { SwapBuffers (dc); } | ||||
| @@ -545,6 +545,7 @@ OpenGLContext* OpenGLContext::getCurrentContext() | |||||
| bool OpenGLContext::makeActive() const noexcept { return nativeContext != nullptr && nativeContext->makeActive(); } | bool OpenGLContext::makeActive() const noexcept { return nativeContext != nullptr && nativeContext->makeActive(); } | ||||
| bool OpenGLContext::isActive() const noexcept { return nativeContext != nullptr && nativeContext->isActive(); } | bool OpenGLContext::isActive() const noexcept { return nativeContext != nullptr && nativeContext->isActive(); } | ||||
| void OpenGLContext::deactivateCurrentContext() { NativeContext::deactivateCurrentContext(); } | |||||
| void OpenGLContext::triggerRepaint() | void OpenGLContext::triggerRepaint() | ||||
| { | { | ||||
| @@ -176,6 +176,11 @@ public: | |||||
| /** Returns true if this context is currently active for the calling thread. */ | /** Returns true if this context is currently active for the calling thread. */ | ||||
| bool isActive() const noexcept; | bool isActive() const noexcept; | ||||
| /** If any context is active on the current thread, this deactivates it. | |||||
| Note that on some platforms, like Android, this isn't possible. | |||||
| */ | |||||
| static void deactivateCurrentContext(); | |||||
| //============================================================================== | //============================================================================== | ||||
| /** Swaps the buffers (if the context can do this). | /** Swaps the buffers (if the context can do this). | ||||
| There's normally no need to call this directly - the buffers will be swapped | There's normally no need to call this directly - the buffers will be swapped | ||||