Skip to content

Commit

Permalink
Merge pull request xbmc#24822 from kambala-decapitator/macos-opengl-a…
Browse files Browse the repository at this point in the history
…ttrs

[macOS] fall back to legacy OpenGL profile on NSOpenGLContext creation error
  • Loading branch information
kambala-decapitator authored Mar 8, 2024
2 parents 553e302 + 1fd6362 commit e2c379c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
1 change: 0 additions & 1 deletion xbmc/windowing/osx/CocoaDPMSSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "CocoaDPMSSupport.h"

#include "ServiceBroker.h"
#include "utils/log.h"

#include <CoreFoundation/CFNumber.h>
#include <IOKit/IOKitLib.h>
Expand Down
36 changes: 27 additions & 9 deletions xbmc/windowing/osx/OpenGL/OSXGLView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#import "OSXGLView.h"

#include "ServiceBroker.h"
#include "utils/log.h"
#import "windowing/osx/WinSystemOSX.h"

#include "system_gl.h"

@implementation OSXGLView
{
NSOpenGLContext* m_glcontext;
NSOpenGLPixelFormat* m_pixFmt;
NSTrackingArea* m_trackingArea;
}

Expand All @@ -33,19 +33,37 @@ - (void)SendInputEvent:(NSEvent*)nsEvent

- (id)initWithFrame:(NSRect)frameRect
{
// clang-format off
NSOpenGLPixelFormatAttribute wattrs[] = {
NSOpenGLPFANoRecovery, NSOpenGLPFAAccelerated,
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)32,
NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)8,
NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
NSOpenGLPFADoubleBuffer, (NSOpenGLPixelFormatAttribute)0};
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
NSOpenGLPFAAccelerated,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFAColorSize, 32,
NSOpenGLPFADepthSize, 24,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFANoRecovery,
0
};
// clang-format on
auto createGLContext = [&wattrs]
{
auto pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:wattrs];
return [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
};

self = [super initWithFrame:frameRect];
if (self)
{
m_pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:wattrs];
m_glcontext = [[NSOpenGLContext alloc] initWithFormat:m_pixFmt shareContext:nil];
m_glcontext = createGLContext();
if (!m_glcontext)
{
CLog::Log(LOGERROR,
"failed to create NSOpenGLContext, falling back to legacy OpenGL profile");

wattrs[1] = NSOpenGLProfileVersionLegacy;
m_glcontext = createGLContext();
assert(m_glcontext);
}
}
self.wantsBestResolutionOpenGLSurface = YES;
[self updateTrackingAreas];
Expand Down

0 comments on commit e2c379c

Please sign in to comment.