Reputation: 2040
I want to draw OpenGL graphics into multiple windows. All windows 'lead' to the same 'world' so as far as I know there are two options:
Share context between windows. It's pretty straightforward task for GLFW and I have some progress with that, however, the code becomes more and more obscure and I know that OpenGL isn't multithreaded so there is no benefit from rendering into multiple contexts from multiple threads.
I saw an advice to have a single context and use it for the rendering of all windows one by one, i.e. render the first window, swap buffers, render the second one, swap buffers, render the first one again and so on.
However, I cannot determine is it even possible to go with the option two with GLFW. Window and context look tightly tied to each other in the library's concept.
Upvotes: 2
Views: 3520
Reputation: 6771
You can create multiple contexts and "share lists", see the documentation:
When creating a window and its OpenGL or OpenGL ES context with
glfwCreateWindow
, you can specify another window whose context the new one should share its objects (textures, vertex and element buffers, etc.) with.
GLFWwindow* second_window = glfwCreateWindow(640, 480, "Second Window", NULL, first_window);
This will allow you to avoid duplicating all of your assets like textures and buffers for each window.
You assert that OpenGL is not multithreaded. Multiple threads can simultaneously use multiple contexts. Modern GPUs have multiple command queues, so it its parallelism would depend on the display driver and hardware capabilities. In any case, it is likely that utilizing multiple processors will be a net gain, even if overhead is introduced by using multiple threads, assuming your render threads are not too trivial.
Even if you did make one context current on each window one at a time, that introduces overhead as well, being synchronous and sequential. I'll take concurrency + overhead over sequential + overhead anyday.
Upvotes: 6