VSync=on 的非阻塞 SwapBuffers()

发布于 2024-08-20 20:27:27 字数 93 浏览 17 评论 0原文

我正在寻找一种便携式方法来制作非阻塞 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄居者 2024-08-27 20:27:27

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.

空城缀染半城烟沙 2024-08-27 20:27:27

首先,为什么不在帧开始时调用 SwapBuffers() 呢?或者以某种方式将管道更改为

  Render();
  Update(); //Update before swapping buffers
  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

  Render();
  Update(); //Update before swapping buffers
  SwapBuffers();

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文