OSX: allow setting GL context on any thread (PR #26036)

14 views
Skip to first unread message

Hydra

unread,
Dec 16, 2025, 4:33:57 PM (3 days ago) Dec 16
to wx-...@googlegroups.com, Subscribed

I'm working on an OpenGL renderer for my wxWidgets-based project 3Beans, and I need to maintain a GL context that is potentially used across different threads. The addition of wxGLContext::ClearCurrent() allowed this to work flawlessly on Linux and Windows, but on macOS it was impossible to set the GL context on a non-UI thread. It crashes with the error [NSOpenGLContext setView:] must be called from the main thread. This change allows the context to be set without touching the UI if it's off the main thread, which makes threaded OpenGL work perfectly on macOS as well.


You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/26036

Commit Summary

  • 1725692 OSX: allow setting GL context on any thread

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26036@github.com>

VZ

unread,
Dec 16, 2025, 4:41:08 PM (3 days ago) Dec 16
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#26036)

I am not sure if it's really safe to use wxGLContext from non-UI thread(s), if it is, we need to document what thread-safety guarantees exactly does it provide (but I don't know what they are myself, unfortunately) and add an example of doing this to one of the OpenGL samples.

Of course, adding this check shouldn't do any harm, but I just worry about making promises that we won't be able to keep...


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26036/c3662495941@github.com>

Hydra

unread,
Dec 16, 2025, 4:53:15 PM (3 days ago) Dec 16
to wx-...@googlegroups.com, Subscribed
Hydr8gon left a comment (wxWidgets/wxWidgets#26036)

From what I've gathered online, GL contexts should be thread-safe as long as they're cleared from any other thread before being set on a new one. Of course, that doesn't account for any interactions a wxGLContext might have with a wxGLCanvas. Another solution might be to have a static function for setting the context, like how ClearCurrent() already is.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26036/c3662572138@github.com>

Reply all
Reply to author
Forward
0 new messages