diff --git a/Source/Core/Common/GL/GLInterface/AGL.h b/Source/Core/Common/GL/GLInterface/AGL.h index 5f9a138282..8d62086954 100644 --- a/Source/Core/Common/GL/GLInterface/AGL.h +++ b/Source/Core/Common/GL/GLInterface/AGL.h @@ -8,6 +8,7 @@ #import #else struct NSOpenGLContext; +struct NSOpenGLPixelFormat; struct NSView; #endif @@ -18,13 +19,16 @@ class cInterfaceAGL : public cInterfaceBase public: void Swap() override; bool Create(void* window_handle, bool stereo, bool core) override; + bool Create(cInterfaceBase* main_context) override; bool MakeCurrent() override; bool ClearCurrent() override; void Shutdown() override; void Update() override; void SwapInterval(int interval) override; + std::unique_ptr CreateSharedContext() override; private: - NSView* m_view; - NSOpenGLContext* m_context; + NSView* m_view = nullptr; + NSOpenGLContext* m_context = nullptr; + NSOpenGLPixelFormat* m_pixel_format = nullptr; }; diff --git a/Source/Core/Common/GL/GLInterface/AGL.mm b/Source/Core/Common/GL/GLInterface/AGL.mm index bdae829cbc..07502475f7 100644 --- a/Source/Core/Common/GL/GLInterface/AGL.mm +++ b/Source/Core/Common/GL/GLInterface/AGL.mm @@ -60,15 +60,14 @@ bool cInterfaceAGL::Create(void* window_handle, bool stereo, bool core) NSOpenGLPFAAccelerated, stereo ? NSOpenGLPFAStereo : static_cast(0), 0}; - NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr]; - if (fmt == nil) + m_pixel_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr]; + if (m_pixel_format == nil) { ERROR_LOG(VIDEO, "failed to create pixel format"); return false; } - m_context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil]; - [fmt release]; + m_context = [[NSOpenGLContext alloc] initWithFormat:m_pixel_format shareContext:nil]; if (m_context == nil) { ERROR_LOG(VIDEO, "failed to create context"); @@ -82,6 +81,30 @@ bool cInterfaceAGL::Create(void* window_handle, bool stereo, bool core) return AttachContextToView(m_context, m_view, &s_backbuffer_width, &s_backbuffer_height); } +bool cInterfaceAGL::Create(cInterfaceBase* main_context) +{ + cInterfaceAGL* agl_context = static_cast(main_context); + NSOpenGLPixelFormat* pixel_format = agl_context->m_pixel_format; + NSOpenGLContext* share_context = agl_context->m_context; + + m_context = [[NSOpenGLContext alloc] initWithFormat:pixel_format shareContext:share_context]; + if (m_context == nil) + { + ERROR_LOG(VIDEO, "failed to create shared context"); + return false; + } + + return true; +} + +std::unique_ptr cInterfaceAGL::CreateSharedContext() +{ + std::unique_ptr context = std::make_unique(); + if (!context->Create(this)) + return nullptr; + return context; +} + bool cInterfaceAGL::MakeCurrent() { [m_context makeCurrentContext]; @@ -100,6 +123,8 @@ void cInterfaceAGL::Shutdown() [m_context clearDrawable]; [m_context release]; m_context = nil; + [m_pixel_format release]; + m_pixel_format = nil; } void cInterfaceAGL::Update()