Async delegate: share OpenGL contexts
A render window screen capture is stored in an OpenGL texture. The capture procedure happens on the thread that has the vtk render window and vtk objects, typically the main thread. Encoders, irrespective of software/hardware accelerated ought to obtain pixels from that texture to even begin video encoding. In order to do that, encoders would make the OpenGL context current, bind the texture and read the data.
Async mode: off
When the async mode was disabled, all of the steps were carried out on the main thread and it worked fine.
Async mode: on
The new encoder thread can not directly read that OpenGL texture. It is invalid for another thread to use the main thread's OpenGL context. A temporary workaround was to make a full copy of the texture on the CPU in the main thread before sending the input to the threaded task queue.
This change takes a proper approach to do it right. The async delegate has been modified such that the encoding thread uses a thread-local render window that shares OpenGL context with the main thread's render window.
For now, the initialization happens for the first push and finalization occurs while the task queue is flushed. It's a bit weird because vtkThreadedTaskQueue
cannot execute functions with arbitrary signatures on the same thread.