mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-03-12 14:46:49 +01:00
GLInterface: Support shared contexts on AGL
This commit is contained in:
parent
01ae02482c
commit
3e508fc0a2
@ -8,6 +8,7 @@
|
|||||||
#import <AppKit/AppKit.h>
|
#import <AppKit/AppKit.h>
|
||||||
#else
|
#else
|
||||||
struct NSOpenGLContext;
|
struct NSOpenGLContext;
|
||||||
|
struct NSOpenGLPixelFormat;
|
||||||
struct NSView;
|
struct NSView;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -18,13 +19,16 @@ class cInterfaceAGL : public cInterfaceBase
|
|||||||
public:
|
public:
|
||||||
void Swap() override;
|
void Swap() override;
|
||||||
bool Create(void* window_handle, bool stereo, bool core) override;
|
bool Create(void* window_handle, bool stereo, bool core) override;
|
||||||
|
bool Create(cInterfaceBase* main_context) override;
|
||||||
bool MakeCurrent() override;
|
bool MakeCurrent() override;
|
||||||
bool ClearCurrent() override;
|
bool ClearCurrent() override;
|
||||||
void Shutdown() override;
|
void Shutdown() override;
|
||||||
void Update() override;
|
void Update() override;
|
||||||
void SwapInterval(int interval) override;
|
void SwapInterval(int interval) override;
|
||||||
|
std::unique_ptr<cInterfaceBase> CreateSharedContext() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NSView* m_view;
|
NSView* m_view = nullptr;
|
||||||
NSOpenGLContext* m_context;
|
NSOpenGLContext* m_context = nullptr;
|
||||||
|
NSOpenGLPixelFormat* m_pixel_format = nullptr;
|
||||||
};
|
};
|
||||||
|
@ -60,15 +60,14 @@ bool cInterfaceAGL::Create(void* window_handle, bool stereo, bool core)
|
|||||||
NSOpenGLPFAAccelerated,
|
NSOpenGLPFAAccelerated,
|
||||||
stereo ? NSOpenGLPFAStereo : static_cast<NSOpenGLPixelFormatAttribute>(0),
|
stereo ? NSOpenGLPFAStereo : static_cast<NSOpenGLPixelFormatAttribute>(0),
|
||||||
0};
|
0};
|
||||||
NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
|
m_pixel_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
|
||||||
if (fmt == nil)
|
if (m_pixel_format == nil)
|
||||||
{
|
{
|
||||||
ERROR_LOG(VIDEO, "failed to create pixel format");
|
ERROR_LOG(VIDEO, "failed to create pixel format");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
|
m_context = [[NSOpenGLContext alloc] initWithFormat:m_pixel_format shareContext:nil];
|
||||||
[fmt release];
|
|
||||||
if (m_context == nil)
|
if (m_context == nil)
|
||||||
{
|
{
|
||||||
ERROR_LOG(VIDEO, "failed to create context");
|
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);
|
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()
|
bool cInterfaceAGL::MakeCurrent()
|
||||||
{
|
{
|
||||||
[m_context makeCurrentContext];
|
[m_context makeCurrentContext];
|
||||||
@ -100,6 +123,8 @@ void cInterfaceAGL::Shutdown()
|
|||||||
[m_context clearDrawable];
|
[m_context clearDrawable];
|
||||||
[m_context release];
|
[m_context release];
|
||||||
m_context = nil;
|
m_context = nil;
|
||||||
|
[m_pixel_format release];
|
||||||
|
m_pixel_format = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cInterfaceAGL::Update()
|
void cInterfaceAGL::Update()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user