Satchmo Brown
Satchmo Brown

Reputation: 1437

Giving the CPU a rest after rendering scene

I have read that it is a good idea to give a 3D program where rendering is involved a rest between rendering. Is this true? Will this reduce CPU load or is that unrelated?

If so, what method do you recommend? Also, does this have anything to do with framerate cap, i.e. cap at 60 fps and if it is not time to render another frame, rest and wait until we need to render another to meet the 60fps mark.

I am using OpenGL and C++.

Upvotes: 2

Views: 461

Answers (6)

Gold
Gold

Reputation: 136

Game engines should be multithreaded, and each thread working on a different frame buffer object, enabling double/triple buffering method ( it's mandatory ). Calls to glFinish ( ) won't yield a thread but a call to (glX)SwapBuffers () will do when there is no more available buffer for drawing operation, automaticaly decreasing the cpu usage to an optimal point. Nearly every GL implementations are tuned to do that.

Upvotes: 0

noop
noop

Reputation: 308

In systems with shared(unified) GPU memory, such as low-end PCs and most smartphones, CPU and GPU compete with each other for memory bandwidth. Doing additional calculations that involve lots of memory accesses will interfere with texture reads and framebuffer updates resulting in lower framerate.

Upvotes: 0

nmjohn
nmjohn

Reputation: 1432

For simple scenes, this can be a good idea. Otherwise, you're rendering a scene at 2000 fps, and you really won't ever get faster than 120 Hz or 60 Hz to the screen so those scenes are wasted. This lower CPU utilization is good when you have other apps you want to run. If you're running a game that is designed to be the only thing going, then run it at full-bore without such throttling.

Upvotes: 3

André Puel
André Puel

Reputation: 9179

Yes, limiting the framerate reduce the CPU load.

Also, if you have a 2000 fps your monitor won't show every frame, usually only 60fps. http://en.wikipedia.org/wiki/Refresh_rate

I recommend the following method (code using boost date time and thread library):

#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

long desiredFps=60;

void drawLoop() {
    using namespace boost;
    using namespace boost::posix_time;

    ptime lastDraw = microsec_clock::universal_time();
    while( true ) {
        ptime now = microsec_clock::universal_time();
        long diff = (now-lastDraw).total_microseconds();
        long desiredDiff = 1000000/desiredFps;
        if( diff < desiredDiff ) {
            this_thread::sleep(microseconds(desiredDiff-diff));
        }
        draw();
        lastDraw = now;
    }
}

Upvotes: 5

Jonathan Dunlap
Jonathan Dunlap

Reputation: 2631

I haven't heard that waiting for the CPU to rest helps rendering performance. However, the same effect should already be happening. OpenGL should be resting the cpu between frame updates so this shouldn't be a concern in theory. Perhaps the "cpu resting" idea came from frameworks that do not execute the event loop per frame. I'll be looking at this thread if there's different perspective on this.

Upvotes: 1

Steve Wellens
Steve Wellens

Reputation: 20620

I had a Gateway computer that was fine until I started to do graphics rendering. The CPU became toast shortly after.

But that was a flaw in the computer, you shouldn't have to worry about it.

Upvotes: 0

Related Questions