mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-26 09:41:11 +00:00
GLInterface: Support shared contexts on AGL
This commit is contained in:
parent
01ae02482c
commit
3e508fc0a2
@ -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;
|
||||
};
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user