From bd0741f9a9ec143e6cb8688b081143662f85b1c7 Mon Sep 17 00:00:00 2001 From: jules Date: Fri, 4 May 2012 11:23:57 +0100 Subject: [PATCH] Added method OpenGLContext::deactivateCurrentContext(). --- modules/juce_opengl/native/juce_OpenGL_android.h | 1 + modules/juce_opengl/native/juce_OpenGL_ios.h | 7 ++++++- modules/juce_opengl/native/juce_OpenGL_linux.h | 7 ++++++- modules/juce_opengl/native/juce_OpenGL_osx.h | 5 +++++ modules/juce_opengl/native/juce_OpenGL_win32.h | 3 ++- modules/juce_opengl/opengl/juce_OpenGLContext.cpp | 1 + modules/juce_opengl/opengl/juce_OpenGLContext.h | 5 +++++ 7 files changed, 26 insertions(+), 3 deletions(-) diff --git a/modules/juce_opengl/native/juce_OpenGL_android.h b/modules/juce_opengl/native/juce_OpenGL_android.h index 1988fd3aa3..50fca17622 100644 --- a/modules/juce_opengl/native/juce_OpenGL_android.h +++ b/modules/juce_opengl/native/juce_OpenGL_android.h @@ -68,6 +68,7 @@ public: bool makeActive() const noexcept { return isInsideGLCallback; } bool isActive() const noexcept { return isInsideGLCallback; } + static void deactivateCurrentContext() {} void swapBuffers() const noexcept {} bool setSwapInterval (const int) { return false; } diff --git a/modules/juce_opengl/native/juce_OpenGL_ios.h b/modules/juce_opengl/native/juce_OpenGL_ios.h index b5dbcd48b1..e750ff2f7a 100644 --- a/modules/juce_opengl/native/juce_OpenGL_ios.h +++ b/modules/juce_opengl/native/juce_OpenGL_ios.h @@ -81,7 +81,7 @@ public: // so causes myserious timing-related failures. [EAGLContext setCurrentContext: context]; createGLBuffers(); - [EAGLContext setCurrentContext: nil]; + deactivateCurrentContext(); } ~NativeContext() @@ -119,6 +119,11 @@ public: return [EAGLContext currentContext] == context; } + static void deactivateCurrentContext() + { + [EAGLContext setCurrentContext: nil]; + } + void swapBuffers() { glBindRenderbuffer (GL_RENDERBUFFER, colorBufferHandle); diff --git a/modules/juce_opengl/native/juce_OpenGL_linux.h b/modules/juce_opengl/native/juce_OpenGL_linux.h index 3f9cb41b7f..106a3a9cbb 100644 --- a/modules/juce_opengl/native/juce_OpenGL_linux.h +++ b/modules/juce_opengl/native/juce_OpenGL_linux.h @@ -114,7 +114,7 @@ public: void shutdownOnRenderThread() { - glXMakeCurrent (display, None, 0); + deactivateCurrentContext(); glXDestroyContext (display, renderContext); renderContext = nullptr; } @@ -130,6 +130,11 @@ public: return glXGetCurrentContext() == renderContext && renderContext != 0; } + static void deactivateCurrentContext() + { + glXMakeCurrent (display, None, 0); + } + void swapBuffers() { glXSwapBuffers (display, embeddedWindow); diff --git a/modules/juce_opengl/native/juce_OpenGL_osx.h b/modules/juce_opengl/native/juce_OpenGL_osx.h index 77a8a2aec5..cf1fa4c21e 100644 --- a/modules/juce_opengl/native/juce_OpenGL_osx.h +++ b/modules/juce_opengl/native/juce_OpenGL_osx.h @@ -185,6 +185,11 @@ public: return [NSOpenGLContext currentContext] == renderContext; } + static void deactivateCurrentContext() + { + [NSOpenGLContext clearCurrentContext]; + } + struct Locker { Locker (NativeContext& nc) : cglContext ((CGLContextObj) [nc.renderContext CGLContextObj]) diff --git a/modules/juce_opengl/native/juce_OpenGL_win32.h b/modules/juce_opengl/native/juce_OpenGL_win32.h index 6365675db5..bc8fffd7e6 100644 --- a/modules/juce_opengl/native/juce_OpenGL_win32.h +++ b/modules/juce_opengl/native/juce_OpenGL_win32.h @@ -50,7 +50,7 @@ public: initialiseGLExtensions(); const int wglFormat = wglChoosePixelFormatExtension (pixelFormat); - wglMakeCurrent (0, 0); + deactivateCurrentContext(); if (wglFormat != pixFormat && wglFormat != 0) { @@ -84,6 +84,7 @@ public: void initialiseOnRenderThread() {} void shutdownOnRenderThread() {} + static void deactivateCurrentContext() { wglMakeCurrent (0, 0); } bool makeActive() const noexcept { return wglMakeCurrent (dc, renderContext) != FALSE; } bool isActive() const noexcept { return wglGetCurrentContext() == renderContext; } void swapBuffers() const noexcept { SwapBuffers (dc); } diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp index 2bea0e4d16..52512c4455 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp @@ -545,6 +545,7 @@ OpenGLContext* OpenGLContext::getCurrentContext() bool OpenGLContext::makeActive() const noexcept { return nativeContext != nullptr && nativeContext->makeActive(); } bool OpenGLContext::isActive() const noexcept { return nativeContext != nullptr && nativeContext->isActive(); } +void OpenGLContext::deactivateCurrentContext() { NativeContext::deactivateCurrentContext(); } void OpenGLContext::triggerRepaint() { diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.h b/modules/juce_opengl/opengl/juce_OpenGLContext.h index f48228a194..cda9c4dc88 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.h +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.h @@ -176,6 +176,11 @@ public: /** Returns true if this context is currently active for the calling thread. */ 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). There's normally no need to call this directly - the buffers will be swapped