VSync=on 的非阻塞 SwapBuffers()
我正在寻找一种便携式方法来制作非阻塞 SwapBuffers(),即使 VSync 已激活。
换句话说,是否有可能收到事件通知或知道下一个 VSync 之前的延迟?
I am looking for a portable way to make a non-blocking SwapBuffers() even if VSync is activated.
In other words, is it possible to to be notified by an event or to know the delay until the next VSync ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IIRC 此扩展有帮助: http://www.opengl.org/registry/specs /SGI/video_sync.txt,但当前驱动程序对它的支持非常差。
IIRC this extension helps: http://www.opengl.org/registry/specs/SGI/video_sync.txt, but it is very poorly supported with current drivers.
首先,为什么不在帧开始时调用 SwapBuffers() 呢?或者以某种方式将管道更改为
当 OpenGL 正在处理您刚刚向其输入的所有命令时,您可以执行所有更新逻辑。
否则有几种方法可以解决这个问题。
我知道 XNA 有一个 ScanLine 属性,它告诉您屏幕当前处于哪条扫描线。我不知道 OpenGL 是否也公开了这一点,但我很确定它一定会公开。 (对吗?)
使用多线程渲染。许多现代引擎将整个线程专门用于渲染。如果阻塞了也没关系,不会干扰主线程。或者,一种更简单的方法是仅在新线程上处理输入等,这可以避免图形上下文的复杂性。
使用三重缓冲。使用三重缓冲意味着您有 2 个后台缓冲区。调用 SwapBuffers 后,屏幕可以继续扫描前缓冲区,新完成的缓冲区等待,第三个缓冲区供您渲染下一帧。当然,如果你已经预渲染了两帧,SwapBuffers()将会阻塞。
Firstly, why don't you just call SwapBuffers() at the start of the frame? Or somehow change the pipeline to
While OpenGL is working away at all of the commands you just threw at it, you can do all of your update logic.
Otherwise there's a few ways to solve this problem.
I know that XNA has a ScanLine Property, which tells you which scanline the screen is currently up to. I don't know if OpenGL exposes this too, but I'm pretty sure it must. (Right?)
Use multithreaded rendering. Many modern engines dedicate a whole thread just for rendering. If it blocks, it's fine, it doesn't disturb the main thread. Alternitavly an easier way is to just handle input etc. on a new thread, this avoids complications with graphics contexts.
Use triple buffering. Using triple buffering means that you have 2 back buffers. Afer you call SwapBuffers, the screen can continue to scan the front buffer, with your newly finished buffer waiting, and the third buffer for you to render the next frame to. Of course, if you have already prerendered two frames, SwapBuffers() will block.