Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Mac OS X 10.9 build issue due to CGLContextObj return type. #33116

Conversation

follower
Copy link
Contributor

Prevents this compilation error on Mac OS X 10.9:

candidate function not viable: cannot convert argument of incomplete type 'void *' to
  'CGLContextObj' (aka '_CGLContextObject *')

The issue occurs because pre-Mac OS X 10.10 the CGLContextObj property had a return type of void * but in 10.10 it changed to a return type of struct _CGLContextObject *.

Also prevents a similar error with CGLPixelFormatObj property.

The issue appeared due to the recent addition of the call to CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext() to work around a macOS 10.14 v-sync issue in b53f2d1.

Note:

  • I've only tested this change by building on Mac OS X 10.9--I don't know if the addition of the static_cast will cause any issues on OS versions that don't require it.
  • An alternative approach would be to use the implementation that appears to come from Apple-supplied examples (e.g. GLEssentials/GLEssentials/Source/Classes/OSX/GLEssentialsGLView.m) which would avoid the cast by explicitly storing the parameters into variables before making the function call:
CGLContextObj cglContext = [[self openGLContext] CGLContextObj];
CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat);

Additional context

Initial CGLContextObj-related build error:

platform/osx/os_osx.mm:1582:2: error: no matching function for call to 'CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext'
        CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, context.CGLContextObj, pixelFormat.CGLPixelFormatObj);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/CoreVideo.framework/Headers/CVDisplayLink.h:100:20: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to
      'CGLContextObj' (aka '_CGLContextObject *')
CV_EXPORT CVReturn CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(CVDisplayLinkRef displayLink, 

Subsequent CGLPixelFormatObj-related build error:

platform/osx/os_osx.mm:1582:2: error: no matching function for call to 'CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext'
        CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, static_cast<CGLContextObj>(context.CGLContextObj), pixelFormat.CGLPixelFormatObj);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/CoreVideo.framework/Headers/CVDisplayLink.h:100:20: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to
      'CGLPixelFormatObj' (aka '_CGLPixelFormatObject *')
CV_EXPORT CVReturn CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(CVDisplayLinkRef displayLink, 
                   ^

Mac OS X 10.9 header with CGLContextObj property in NSOpenGL.h in AppKit framework: AppKit.framework/Versions/C/Headers/NSOpenGL.h

Mac OS X 10.10 header with CGLContextObj property in NSOpenGL.h in AppKit framework: AppKit.framework/Versions/C/Headers/NSOpenGL.h

Current Godot code:

CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, context.CGLContextObj, pixelFormat.CGLPixelFormatObj);

Mac OS X 10.9 header with CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext() function in CVDisplayLink.h in CoreVideo framework: CoreVideo.framework/Versions/A/Headers/CVDisplayLink.h

Equivalent Mac OS X 10.11 (the version the declaration next changed) header with CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext() function in CVDisplayLink.h in CoreVideo framework: CoreVideo.framework/Versions/A/Headers/CVDisplayLink.h

Prevents this compilation error on Mac OS X 10.9:

    candidate function not viable: cannot convert argument of incomplete type 'void *' to
      'CGLContextObj' (aka '_CGLContextObject *')

The issue occurs because pre-Mac OS X 10.10 the `CGLContextObj` property
had a return type of `void *` but in 10.10 it changed to a return
type of `struct _CGLContextObject *`.

Also prevents a similar error with `CGLPixelFormatObj` property.

The issue appeared due to the recent addition of the call to
`CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext()` to work
around a macOS 10.14 v-sync issue.
Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this thing completely seems to be better idea: #33125

CVDisplayLink hack doesn't work properly on macOS 10.15, with it v-sync is stuck in permanently enabled state. CGLCPSwapInterval works as expected.

@follower
Copy link
Contributor Author

follower commented Nov 8, 2019

Even if the DisplayLink hack is going to be removed at some point, FWIW I'd appreciate if this change--assuming it doesn't prevent compilation on later versions--could be merged for now so that I don't have to keep applying it locally.

@akien-mga
Copy link
Member

If removing the CVDisplayLink workaround is the better solution, it would be good to do now for 3.2.
Otherwise I can indeed merge this PR as a stopgap solution until a refactoring. WDYT @bruvzg?

@bruvzg
Copy link
Member

bruvzg commented Nov 21, 2019

WDYT @bruvzg?

Better to remove it doesn't work on 10.15, and useless on previous versions: #33783

@akien-mga
Copy link
Member

Superseded by #33783.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants