allen-cell-animated / agave

Other
34 stars 6 forks source link

Feature/fix headless gl context #77

Closed toloudis closed 1 year ago

toloudis commented 1 year ago

linux builds were broken - this reinstates linux functionality, making sure that desktop linux builds work as well as server mode on linux.

Background: It's notoriously difficult to render to OpenGL on systems that have gpu and drivers but don't have a monitor attached. Initializing an OpenGL context always requires a platform-specific connection to the OS windowing system. In agave, that context creation has been handled by the Qt library. On linux, headless context creation is enabled with the egl (embedded gl) library which is a special case handled outside of any Qt code.
Another important constraint is that only one OpenGL context can be "current" on any given thread or else very bad (basically unrecoverable) exceptions will be thrown. So if you want to share a context across threads, you have to be cautious when switching from one thread to another so that no calls will accidentally be made.

In this code change, I moved the OpenGL context wrapper down into renderlib where it can hide some implementation details better. It also does a better job of using the correct context wrapper based on the runtime scenario and OS.

Expected (correct) behavior: Running agave normally will never use the "HeadlessContext". Running agave --server will use the HeadlessContext on linux machines only. This should work on server nodes that don't have a display attached. Running agave --server without a display on other operating systems will fail to launch with an error initializing the renderlib. Running agave --server with a display on all three platforms should work fine.