Using SwapBuffers() with multiple OpenGL canvases and vertical sync?

怎甘沉沦 提交于 2019-12-08 08:01:44

问题


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()

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

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.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/18747902/using-swapbuffers-with-multiple-opengl-canvases-and-vertical-sync

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