diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp index 7e3f23f6b0..de318764f4 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp @@ -700,6 +700,14 @@ Component* OpenGLContext::getTargetComponent() const noexcept return attachment != nullptr ? attachment->getComponent() : nullptr; } +OpenGLContext* OpenGLContext::getContextAttachedTo (Component& c) noexcept +{ + if (CachedImage* const ci = CachedImage::get (c)) + return &(ci->context); + + return nullptr; +} + static ThreadLocalValue currentThreadActiveContext; OpenGLContext* OpenGLContext::getCurrentContext() diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.h b/modules/juce_opengl/opengl/juce_OpenGLContext.h index b30d23cb32..4291acccd8 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.h +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.h @@ -87,6 +87,9 @@ public: /** Returns the component to which this context is currently attached, or nullptr. */ Component* getTargetComponent() const noexcept; + /** If the given component has an OpenGLContext attached, then this will return it. */ + static OpenGLContext* getContextAttachedTo (Component& component) noexcept; + //============================================================================== /** Sets the pixel format which you'd like to use for the target GL surface. Note: This must be called BEFORE attaching your context to a target component!