GS:GL: Fix GLContextAGL compile

This commit is contained in:
TellowKrinkle 2023-05-10 19:00:22 -05:00 committed by lightningterror
parent 8de0eb3c06
commit a293a9bd4b
2 changed files with 13 additions and 31 deletions

View File

@ -626,7 +626,7 @@ if(USE_OPENGL)
list(APPEND pcsx2GSHeaders GS/Renderers/OpenGL/GLContextWGL.h) list(APPEND pcsx2GSHeaders GS/Renderers/OpenGL/GLContextWGL.h)
target_link_libraries(PCSX2_FLAGS INTERFACE opengl32.lib) target_link_libraries(PCSX2_FLAGS INTERFACE opengl32.lib)
elseif(APPLE) elseif(APPLE)
list(APPEND pcsx2GSSources GS/Renderers/OpenGL/GLContextAGL.cpp) list(APPEND pcsx2GSSources GS/Renderers/OpenGL/GLContextAGL.mm)
list(APPEND pcsx2GSHeaders GS/Renderers/OpenGL/GLContextAGL.h) list(APPEND pcsx2GSHeaders GS/Renderers/OpenGL/GLContextAGL.h)
else() else()
if(X11_API OR WAYLAND_API) if(X11_API OR WAYLAND_API)

View File

@ -24,12 +24,8 @@
#include <dlfcn.h> #include <dlfcn.h>
#if ! __has_feature(objc_arc)
#error "Compile this with -fobjc-arc"
#endif
GLContextAGL::GLContextAGL(const WindowInfo& wi) GLContextAGL::GLContextAGL(const WindowInfo& wi)
: Context(wi) : GLContext(wi)
{ {
m_opengl_module_handle = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_NOW); m_opengl_module_handle = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_NOW);
if (!m_opengl_module_handle) if (!m_opengl_module_handle)
@ -45,9 +41,12 @@ GLContextAGL::~GLContextAGL()
if (m_opengl_module_handle) if (m_opengl_module_handle)
dlclose(m_opengl_module_handle); dlclose(m_opengl_module_handle);
[m_pixel_format release];
[m_context release];
} }
std::unique_ptr<Context> GLContextAGL::Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try) std::unique_ptr<GLContext> GLContextAGL::Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try)
{ {
std::unique_ptr<GLContextAGL> context = std::make_unique<GLContextAGL>(wi); std::unique_ptr<GLContextAGL> context = std::make_unique<GLContextAGL>(wi);
if (!context->Initialize(versions_to_try)) if (!context->Initialize(versions_to_try))
@ -145,7 +144,7 @@ bool GLContextAGL::SetSwapInterval(s32 interval)
return true; return true;
} }
std::unique_ptr<Context> GLContextAGL::CreateSharedContext(const WindowInfo& wi) std::unique_ptr<GLContext> GLContextAGL::CreateSharedContext(const WindowInfo& wi)
{ {
std::unique_ptr<GLContextAGL> context = std::make_unique<GLContextAGL>(wi); std::unique_ptr<GLContextAGL> context = std::make_unique<GLContextAGL>(wi);
@ -164,8 +163,10 @@ std::unique_ptr<Context> GLContextAGL::CreateSharedContext(const WindowInfo& wi)
bool GLContextAGL::CreateContext(NSOpenGLContext* share_context, int profile, bool make_current) bool GLContextAGL::CreateContext(NSOpenGLContext* share_context, int profile, bool make_current)
{ {
if (m_context) [m_context release];
[m_pixel_format release];
m_context = nullptr; m_context = nullptr;
m_pixel_format = nullptr;
const NSOpenGLPixelFormatAttribute attribs[] = { const NSOpenGLPixelFormatAttribute attribs[] = {
NSOpenGLPFADoubleBuffer, NSOpenGLPFADoubleBuffer,
@ -202,17 +203,7 @@ void GLContextAGL::BindContextToView()
return; return;
} }
#ifdef PCSX2_CORE m_view = [static_cast<NSView*>(m_wi.window_handle) retain];
m_view = (__bridge NSView*)m_wi.window_handle;
#else
// Drawing to wx's wxView somehow causes fighting between us and wx, resulting in massive CPU usage on the main thread and no image
// Avoid that by adding our own subview
CleanupView();
NSView* const superview = (__bridge NSView*)m_wi.window_handle;
m_view = [[NSView alloc] initWithFrame:[superview frame]];
[superview addSubview:m_view];
[m_view setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
#endif
[m_view setWantsBestResolutionOpenGLSurface:YES]; [m_view setWantsBestResolutionOpenGLSurface:YES];
UpdateDimensions(); UpdateDimensions();
@ -222,15 +213,6 @@ void GLContextAGL::BindContextToView()
void GLContextAGL::CleanupView() void GLContextAGL::CleanupView()
{ {
#ifndef PCSX2_CORE [m_view release];
if (![NSThread isMainThread])
{
dispatch_sync(dispatch_get_main_queue(), [this]{ CleanupView(); });
return;
}
if (m_view)
[m_view removeFromSuperview];
#endif
m_view = nullptr; m_view = nullptr;
} }