1

I have four windows on a single display system where each is with its own context and its own drawable (saving that two of them are children to one others). I wish to synchronize the process of swapping the buffer of these windows that it be executed at the same time. A quick search yields me with these possible alternatives.

  • GLX_SGIX_swap_group : Is only available on X11 system.
  • NV_swap_group (WGL_NV_swap_group/GLX_NV_swap_group) : Is available only on Quadro GPUs with framelock support.
  • GLX_OML_sync_control : Offer sync control with counter offered on vsync and swap, but may require more tuning in order to implement one for group swapping. Also is not available NV and fglrx system(?) But does have support for both window and X11 system.

Each seemed to be with their own limitation, especially in terms of hardware support. I have read that Software Swap Synchronization is also feasible, like the swap barrier offered in Equalizer? Is it possible to have a pointer on how one might be implement? Or if there are alternatives I may be redirected to?

null
  • 63
  • 6
  • Is there a reason you don't want to use a single window with four different viewports? – fintelia Sep 17 '13 at 17:38
  • The visual for each window differs, @fintelia. :) – null Sep 17 '13 at 18:02
  • You can actually draw multiple different scenes in the same window if you use separate viewports for each one. – fintelia Sep 17 '13 at 18:34
  • Are each of these windows driven by their own thread? This is trivial to implement in such a case. Otherwise, you can try something I have used successfully in the past, where you use VSYNC for the first buffer swap, it (indirectly) blocks until the VBLANK period is up, you then disable VSYNC and assuming you can finish drawing the other three windows in under ~5.6 ms (@60 Hz) each, you should avoid tearing on the other windows. If you try to VSYNC all of these windows together using a single thread on a 60 Hz display, you'll be limited to 15 FPS and one window will be 3 frame-lengths late :) – Andon M. Coleman Sep 17 '13 at 20:48
  • @AndonM.Coleman Each windows has separate context but are run from the same main thread. :) So the process is to enable vsync on the first buffer swap, swap the buffer, disable the vsync on the first window and then proceed to draw and swap the rest of the windows, correct? – null Sep 24 '13 at 17:31

2 Answers2

0

One possible solutiion would be to turn on Wait for VBlank for all windows (this assumes that all windows are on the same or synchronized displays, though) and manually synchronize the SwapBuffer call. That approach is not 100% waterproof (since the buffer swap command might be issued very close to the actual frame "siwtch", and some threads get it done while some others miss it, but that is very unlikely and only a temporary glitch, as the "late" threads will delay the "early" ones in the last frame and sync is restored).

To Implement this, you can do use some simple barrier. Just don't forget to flush the GL pipeline manually, so that the work is really done and the SwapBuffers is can be executed immediately. All each thread has to do at the end of a frame is glFinish() and wait for the barrier. As soon as all threads reached the barrier, they immediately issue a SwapBuffers().

derhass
  • 43,833
  • 2
  • 57
  • 78
  • Can you help elaborate more on the barrier? :) I only know there is exist SGIX_swap_barrier but the document specified that it needs SGIX_swap_group. – null Sep 24 '13 at 16:42
  • @S.Aymerich: You do not need a specific GL extension for that. I mean the basic concept of a [barrier as synchronization method](http://en.wikipedia.org/wiki/Barrier_%28computer_science%29). There are many ways to implement it, and they are totally unrelated to OpenGL. How to implement this in your case depens on your operation system and/or programming language. – derhass Sep 24 '13 at 20:12
  • Ah! I understand now. I shall take a look at PThreads and its implementation and see how it goes then. Thank you. :) – null Oct 01 '13 at 06:10
0

If having only a single window is acceptable, you can use separate viewports to render each of the views. For instance:

glClear(...);

glViewport(x1, y1, width1, height1); // all coordinates are in pixels
// draw scene 1

glViewport(x2, y2, width2, height2);
// draw scene 2

glViewport(x3, y3, width3, height3);
// draw scene 3

SwapBuffers(...); // actual method depends on your environment
fintelia
  • 1,201
  • 6
  • 17