summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorStenzek <stenzek@gmail.com>2017-07-20 11:38:25 +1000
committerStenzek <stenzek@gmail.com>2017-07-30 12:38:49 +1000
commit3e508fc0a25035c8b20cb173740f70f368b4bc23 (patch)
treebbb5020671c6e198413a8d7dd41d73d12a64d1f7 /Source
parent01ae02482c527f2193dba3e039194e551df59ce1 (diff)
GLInterface: Support shared contexts on AGL
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Common/GL/GLInterface/AGL.h8
-rw-r--r--Source/Core/Common/GL/GLInterface/AGL.mm33
2 files changed, 35 insertions, 6 deletions
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 <AppKit/AppKit.h>
#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<cInterfaceBase> 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<NSOpenGLPixelFormatAttribute>(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<cInterfaceAGL*>(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<cInterfaceBase> cInterfaceAGL::CreateSharedContext()
+{
+ std::unique_ptr<cInterfaceBase> context = std::make_unique<cInterfaceAGL>();
+ 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()