PDA

View Full Version : SwapBuffers is waiting for something?



ColacX
06-25-2009, 11:39 AM
Hey there I'm making a multi-threaded application in OpenGL in a Windows enviroment.

So everything is working fine except that i'd like to control my own fps instead of letting windows or opengl do it.

So I identified what is blocking my fps rate and its the SwapBuffers( hDC ) function that seems to be blocking, waiting for next frame or something.

My question: is there a diffrent command that i could use besides SwapBuffers? So that I could increase/control my fps?

or someother command that'll increasy my opengl fps?

Dark Photon
06-25-2009, 11:54 AM
So I identified what is blocking my fps rate and its the SwapBuffers( hDC ) function that seems to be blocking, waiting for next frame or something. ... My question: is there a diffrent command that i could use besides SwapBuffers? So that I could increase/control my fps? ... or someother command that'll increasy my opengl fps?

Normally SwapBuffers synchronizes with the next vertical retrace (monitor frame). Disable sync-to-vblank to disable that behavior. Several ways. On Linux, "setenv __GL_SYNC_TO_VBLANK 0", or in nvidia-settings, uncheck "Sync to VBlank" in OpenGL Settings. But the clean way (on all OSs) is to use the SwapInterval API. Search the archives for some good info there.

That won't make SwapBuffers free (particularly if you have a complicated AA resolve that needs performed or a lot of GL work still in the queue), but it will stop it from busy waiting for the video scan-out. To minimize the amount of queued GL work processed inside of SwapBuffers, it can also be useful (for testing/timing use only!!!!) sometimes to trigger a glFinish before SwapBuffers, to ensure that all the queued GL work is done before you enter SwapBuffers.

Stephen A
06-25-2009, 12:04 PM
Use wglSwapIntervalEXT(0) or glXSwapIntervalSGI(0) to disable vertical synchronization. Note that this will introduce tearing and significantly reduce quality (some people cannot see tearing, others cannot *stand* it). If you must disable vsync, at least make it an option.

Also note that users can force-enable vsync through their drivers, regardless of what you try to do in your application.

ColacX
06-25-2009, 12:35 PM
thanks for the quick replys but i dont get what files i need to download, i downloaded wglext.h but i'm guess i need the cpp files and maybee more?

i ended up in theese pages but theres no links to more downloads.

http://www.opengl.org/wiki/SwapInterval_aka_vsync
http://www.opengl.org/registry/
http://www.opengl.org/registry/specs/EXT/wgl_swap_control.txt
http://www.opengl.org/registry/specs/SGI/swap_control.txt

where to download the extensions? very confusing.
please be be kind and post a small guide on how to get theese. thank you.

Ilian Dinev
06-25-2009, 12:43 PM
wglSwapIntervalEXT = wglGetProcAddress("wglSwapIntervalEXT");

ColacX
06-25-2009, 12:54 PM
it doesn't work. but i guess i dont need it. it works when i change vertical-sync in the nvidia control panel though.

thanks for the help all.

ColacX
06-25-2009, 01:12 PM
oh hey i did make it work. i just did some bad boolean coding. still dont need it though but i was curious :P. thanks all.


#include <gl\wglext.h>

void SetVSync(bool sync)
{
typedef bool (APIENTRY *PFNWGLSWAPINTERVALFARPROC)(int);
PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = 0;
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress("wglSwapIntervalEXT");
wglSwapIntervalEXT(sync);
}