kungfoo's picture

Question about Run()

I stepped right into this framework and wanted to draw a few triangles at first.

Two snips coming up:

// (A)
// (B)

Method (A) gives my Windows task manager (yikes Windows... but #develop just works here) a total load of about 5%.

Method (B) always yields around 55% CPU usage. Is there something I'm missing? (A) just renders as many frames as possible, and updates the world at 60s^-1.
I figured the other method would be using less CPU time. Maybe the overhead results from Thread.Sleeps?

Any ideas on this? Bug or feature?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

This could happen if VSync is on. Here is what is happening:

In the first case, your CPU will sleep e.g. 85 times per second, waiting for the swap to finish. In the second case, it would only sleep 30 times per second, hence the higher CPU usage.

OpenTK itself doesn't sleep at all, because there were some problems with timing. Once I fix these, we'll see reduced CPU usage in all cases.

jdomnitz's picture

Was this ever fixed? There still does not appear to be any sleep function used and CPU usage is out of control. Is there anything that can be done to limit frame-rates without using 100% CPU (or a whole core)?

the Fiddler's picture

You should enable vsync or call System.Threading.Thread.Sleep(n), where n >= 1, right after SwapBuffers().

jdomnitz's picture

I achieved the best results setting n to the exact time until the next render is required to maintain the target fps. Still seeing very high CPU usage though so I was wondering if there were any other tricks (already using adaptive vsync).