PDA

View Full Version : How to wait for VSYNC ?



09-11-2001, 04:49 AM
How can I wait for VSYNC ?

There are the DirectDraw function :

IDirectDraw2::WaitForVerticalBlank()

What is the corresponding openGL function ?

Peter

Bob
09-11-2001, 09:36 AM
On Windows, you can use WGL_EXT_swap_control, given that your driver support that extension. Or you can look for a way to enable/disable it in some control panel for your graphics board. Other than that, it's not possible.

09-12-2001, 02:24 AM
Can I use the GLUT:

glutPostRedisplay() - to mark the current windows will be redisplayed
glutDisplayFunc() - for callback, if the current windows will be redispayed

to wait for VSYNC ?

Peter

Bob
09-12-2001, 02:38 AM
GLUT does not handle vsync. Either use the extension I mention, or you won't be able to sync your program to the monitor's vertical retrace.

Morglum
09-12-2001, 08:44 AM
That 's not always true ! I've got a geforce and in the config tool there's a list "Vertical Sync". When I choose "On by default" (which is the default option), The code proposed by Peter does work. You simply call glutPostRedisplay at the end of your display func.
Hope that helps !

JoeMac
09-12-2001, 10:38 AM
Here's an old piece of assembly that may (or may not) still work. Check your compiler's method for including assembly
Joe

void vsync()
{
__asm
//wait for vertical sync
{
mov dx, 3dah
WaitNotVerticalSync2:
in al, dx
test al, 08h
jz WaitNotVerticalSync2
WaitVerticalSync2:
in al, dx
test al, 08h
jz WaitVerticalSync2
}
}

Bob
09-12-2001, 11:56 AM
Morglum, I said that in my first post aswell: "Or you can look for a way to enable/disable it in some control panel for your graphics board"

Anyways, this method has nothing to do with OpenGL itself, and there is no way to control this behaviour from the program (apart from manipulating the registry manually, but I doubt that will have an immediate effect). But you are right, his code will work if this option is set to "on by default", but if you think about it, ANY code to display an image in OpenGL will work.

MarsuGL
09-12-2001, 12:17 PM
just a question:
what is the utility to wait for vsync?,
if i'm not wrong, the fps will be limited to the monitor refresh rate wich is at least 60 hz, i think that it's a good refresh rate, maybe not far from the eye limit.
well, usefull, not usefull?

marsu

09-12-2001, 10:06 PM
Hi JoeMac

This piece of code wait activ for VSYNC.
The PC will be blocked.

I am looking for the method to wait passive for VSYNC,
in order to use the processor time for other jobs in another threads.

Peter

Michael Steinberg
09-13-2001, 05:52 AM
Activate the driver capabilities.
When you wait until the next vsync to draw stuff, your geometry comes to late and misses it anyway. You can't know how long it will take to render the frame...

Korval
09-13-2001, 07:34 PM
It's really very simple.

Call SwapBuffers. If vsync is enabled, then it will wait for a vsync, and swap the buffer at the appropriate time.

As for dynamically enabling/disabling vsync, I wouldn't suggest doing it programmatically, unless you do it before initilizing OpenGL.

Morglum
09-14-2001, 12:15 AM
Originally posted by Bob:
Morglum, I said that in my first post aswell: "Or you can look for a way to enable/disable it in some control panel for your graphics board"


Ok excuse me, I hadn't read this thread very carefully.

Michael Steinberg
09-14-2001, 01:25 AM
Korval... that's my point. But you would be rendering useless frames, and I think the problem was to spend the time waiting for a refresh doing other stuff on cpu...