# Possible vsync bug when drawing with two viewports?

**URL:** <https://discourse.glfw.org/t/possible-vsync-bug-when-drawing-with-two-viewports/131>\
**Category:** support\
**Created:** [April 21, 2015, 9:53pm UTC](https://discourse.glfw.org/t/possible-vsync-bug-when-drawing-with-two-viewports/131 "2015-04-21T21:53:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [April 21, 2015, 9:53pm UTC](https://discourse.glfw.org/t/possible-vsync-bug-when-drawing-with-two-viewports/131/1 "2015-04-21T21:53:04Z")

</div>

**[jasjuang](https://sourceforge.net/u/jasjuang/)** wrote on [Tuesday, April 21, 2015](https://sourceforge.net/p/glfw/discussion/247562/thread/392244b4/#c856):

vsync is switched on and off with glfwSwapInterval(1) or glfwSwapInterval(0)

single viewport is glClear --\> glViewport(0, 0, win\_w,win\_h) --\>  
drawscene() --\> glfwSwapBuffers in the rendering loop

double viewport is glClear --\> glViewport(0, 0, win\_w/2,win\_h) --\>  
drawscene() --\> glViewport(win\_w/2, 0, win\_w/2,win\_h) --\> drawscene()  
–\>glfwSwapBuffers in the rendering loop

My scene single viewport with no vsync --\> 140 fps

My scene double viewport with no vsync --\> 70 fps (as expected since it is  
drawing the same scene twice)

My scene single viewport with vsync --\> 60 fps (as expected because my  
monitor refresh rate is 60Hz)

My scene double viewport with vsync --\> 30 fps (??? I am expecting 60 fps  
here because it is achieving 70 \> 60 fps without vsync, is there any extra  
GLFW function that I have to call?)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [April 22, 2015, 7:27am UTC](https://discourse.glfw.org/t/possible-vsync-bug-when-drawing-with-two-viewports/131/2 "2015-04-22T07:27:22Z")

</div>

**[dougbinks](https://sourceforge.net/u/dougbinks/)** wrote on [Wednesday, April 22, 2015](https://sourceforge.net/p/glfw/discussion/247562/thread/392244b4/#073c):

I doubt this is an issue with glfw, more likely there is a small extra overhead when vsync is on causing you to get frame times of more than 16.6ms (60FPS) from the non vsync’d 14.3ms (70FPS) and so getting the next vsync interval of 33.3ms (30FPS). If you try optimizing your rendering or reducing the load you should be able to achieve 16.6ms.

I see about an extra 2ms of CPU time lost on average due to vsync under some circumstances, so this seems to be a likely explanation.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [April 22, 2015, 7:45am UTC](https://discourse.glfw.org/t/possible-vsync-bug-when-drawing-with-two-viewports/131/3 "2015-04-22T07:45:15Z")

</div>

**[jasjuang](https://sourceforge.net/u/jasjuang/)** wrote on [Wednesday, April 22, 2015](https://sourceforge.net/p/glfw/discussion/247562/thread/392244b4/#073c/6a5d):

Thanks for the excellent explanation!
