将多个OpenGL窗口同步到vsync [英] Synchronizing multiple OpenGL windows to vsync

查看:228
本文介绍了将多个OpenGL窗口同步到vsync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows应用程序中,我同时打开了多个OpenGL窗口.理想情况下,我希望每一个都以60 fps的速度绘制,并与屏幕刷新同步.

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.

对于每个渲染上下文,我正在调用wglSwapIntervalEXT(1)打开vsync.每个窗口都有其自己的显示线程,该线程绘制框架,然后调用SwapBuffers进行更新.

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.

事实证明,各个窗口彼此打架":看来SwapBuffers调用已同步并彼此等待,即使它们位于单独的线程中也是如此.我正在测量每个窗口和两个窗口的帧间时间,该时间降到30 fps,三到20 fps,等等.

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.

如果我用wglSwapIntervalEXT(0)关闭vsync,则无论我打开多少窗口,它们都会以60 fps的速度愉快地刷新.但是打开一个窗口后,这几乎不如打开vsync时那么流畅.

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.

有什么方法可以用OpenGL完成我想要的吗?

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

推荐答案

在Linux中,由于从各个线程调用视频功能,我的应用程序发生了许多奇怪的行为.

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

我解决了这些问题,从应用程序启动,创建窗口,创建glcontext等以来,仅使用一个线程进行显示,并使用信号量和队列在该线程与其他线程之间共享数据.

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.

这篇关于将多个OpenGL窗口同步到vsync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆