Skip to content

Cocoa: Allow sharing OpenGL context data between instances of TOpenGLControl

Adds support for sharing OpenGL context data between multiple instances of TOpenGLControl, in case of Cocoa widgetset.

Similar to !95 (merged) , this time for Cocoa widgetset.

Tested on macOS 12.3.1, Intel-based. Tested with Castle Game Engine editor, that can create multiple contexts (when you open both main design, and some preview) and relies on TOpenGLControl ability to share data between all open contexts. Afer this PR, it works OK.

Note: The code already had some unfinished attempts at this sharing. I just cleaned them up and made working :)

  • TCocoaOpenGLView.nsGL (was only in the comments) does not seem a good approach, you should just use TCocoaOpenGLView.openGLContext that is ready from NSOpenGLView ( https://developer.apple.com/documentation/appkit/nsopenglview/ ). You can get and set TCocoaOpenGLView.openGLContext.

  • Before this PR, aNSOpenGLContext creation was actually useless, nothing was using it. After this PR, aNSOpenGLContext is used by View.setOpenGLContext(aNSOpenGLContext). And it is crucial that it is used, as this seems to be the only way to get context sharing with NSOpenGLView / NSOpenGLContext combination.

  • I also removed unused CGLContext variable. Other comments in the file suggest that CGLContextObj approach was abandoned.

Edited by Michalis Kamburelis

Merge request reports

Loading