在多个OpenGL画布和垂直同步中使用SwapBuffers()吗? [英] Using SwapBuffers() with multiple OpenGL canvases and vertical sync?

查看:140
本文介绍了在多个OpenGL画布和垂直同步中使用SwapBuffers()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用wxPython编写的GUI,其中包含两个GLCanvas es,一个显示"画布和一个预览"画布,我正在使用PyOpenGL在其上绘制一些非常简单的几何图形. 预览"和显示"画布显示同一帧缓冲区的内容:

I have a GUI written using wxPython that contains two GLCanvases, a 'display' canvas and a 'preview' canvas onto which I am drawing some very simple geometry using PyOpenGL. The 'preview' and 'display' canvases display the contents of the same framebuffer:

我需要以一致的帧速率同步更新这两个画布,而不会撕裂.

I need both of these canvases to be updated synchronously at a consistent framerate with no tearing.

到目前为止,我一直在打电话

So far I have just been calling

self.SetCurrent()
# draw stuff...
self.SwapBuffers()

在我的渲染循环中同时预览和显示画布.如果我在驱动程序设置中禁用了vsync,则此方法相当有效.

for both the preview and display canvases within my rendering loop. This works reasonably well provided that I disable vsync in my driver settings.

但是,如果启用垂直同步,则帧速率会下降到〜30Hz,仅为显示器垂直刷新率的一半.大概是因为渲染循环的执行在每个SwapBuffers()调用等待下一个垂直刷新时停滞了-如果我注释掉两个SwapBuffers()调用之一,我的帧速率会回升到60Hz,但当然只有我的其中一张画布已更新.

However, if I enable vsync my framerate drops to ~30Hz, half the vertical refresh rate of my display. Presumably this is because the execution of the rendering loop stalls at each SwapBuffers() call waiting for the next vertical refresh - if I comment out one of the two SwapBuffers() calls, my framerate goes back up to 60Hz, but then of course only one of my canvases gets updated.

我真正想要的是每个vsync间隔一次同步更新我的两个画布.有什么方法可以使用wx.glcanvas.GLCanvas类实现这一目标?

What I'd really like is for both of my canvases to be updated synchronously, once per vsync interval. Is there any way that I can achieve this using the wx.glcanvas.GLCanvas class?

推荐答案

安东在他的评论中暗示的意思是,您使用{wgl | glX} SwapInterval设置了第一个交换间隔,将SwapBuffers同步为1,然后在同步SwapBuffers返回后,立即将交换间隔设置为0并执行其他SwapBuffers.

What Andon implied in his comment is, that you use {wgl|glX}SwapInterval to set the swap interval for the first, synching SwapBuffers to 1, and then right after the synching SwapBuffers returns set the swap interval to 0 and do the other SwapBuffers.

这篇关于在多个OpenGL画布和垂直同步中使用SwapBuffers()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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