Synchronizing multiple OpenGL windows to vsync

本秂侑毒 提交于 2019-12-05 20:14:21

问题


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?


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/10043745/synchronizing-multiple-opengl-windows-to-vsync

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!