9

In a Windows application, I have multiple OpenGL windows open at the same time. Ideally I would like each of these to draw at 60 fps, synchronized to the screen refresh.

For each render context, I'm calling wglSwapIntervalEXT(1) to turn on vsync. Each window has its own display thread, which draws the frame and then calls SwapBuffers to update.

It turns out that the windows are 'fighting' each other: it looks like the SwapBuffers calls are synchronized and wait for each other, even though they are in separate threads. I'm measuring the frame-to-frame time of each window and with two windows, this drops to 30 fps, with three to 20 fps, etc.

If I turn vsync off with wglSwapIntervalEXT(0), they happily refresh at 60 fps no matter how many windows I open. But with one window open, this is not nearly as smooth as with vsync turned on.

Is there any way to accomplish what I want with OpenGL?

Frederik Slijkerman
  • 6,246
  • 23
  • 38
  • If you think about the problem, you'll realise that they have to sync with each other if you're syncing them all to the refresh rate. There isn't a unique refresh event for each window you see. The only solution I can think of (that's almost certainly a non-starter) is to use one window and make your own window manager inside of it using viewports. – Robinson Apr 07 '12 at 12:01
  • If SwapBuffers would just signal that the buffers need to be swapped, it could return immediately (until the new back buffer is written to, that would need to block). A separate thread owned by the display driver could then wait for the vsync and swap all buffers marked as need-to-swap at the correct moment. However, apparently this is not how things work... – Frederik Slijkerman Apr 10 '12 at 14:13

2 Answers2

1

In Linux a lot of strange behavior occurred to my applications because of calling video functions from various threads.

I solved these problems using one thread only for display since the start of application, create window, create glcontext, etc., and using semaphores and queues for sharing data between this thread and the others.

Weber K.
  • 170
  • 1
  • 10
0

You might be able to obtain the output device and use the WaitForVBlank function in a loop from a thread. That can then post messages or signal events for each window that you're interested in.

Neeraj Singh
  • 519
  • 2
  • 6