vsync and cpu usage

Started by korsteve, January 09, 2005, 20:16:34

Previous topic - Next topic

korsteve

Hi,
I'm just wondering if Display.setVSyncEnabled(vsync); and Display.sync(FRAMERATE); are related.  Should they be used together or does one render the other useless?

Also I'm getting 100% cpu usage in both windowed mode and fullscreen, with vsync enabled and disabled.  The program draws a single quad.  Should this happen?

I hope that these questions haven't been asked to death but I couldn't find any definite answers searching.

Thanks,
korsteve

oNyx

>I'm just wondering if Display.setVSyncEnabled(vsync); and
>Display.sync(FRAMERATE); are related.

setVSyncEnabled *tries* to endable/disable vsync. It can work or not (eg if you override it via driver settings). On the opengl side there is no way to tell if vsync is currently enabled or disabled (you can tell with nvidia cards, but that doesn't matter because it doesn't work anywhere else).

So, if you want to use tickbased animation, you need to back it up vsync (which may or may not work) with capping. sync and sync2 are the methods which you can use for that. The former is a simple straighforward implementation and the latter keeps track of time displacement (relative to the perfect moment) and takes that into account for calculating the amount of time which needs to be wasted (sounds more complicated than it is).

I recommand to use sync2 with hz+1 as parameter.

100% CPU usage is perfectly normal for this kind of setup. Most games are like this. But it's not as bad as it looks like. The sync methods spend the time with yield(). So, if any other process/thread needs some time it can grab some cycles.