Stop rendering and save battery power

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
ghorwin
Posts: 2
Joined: Mon Nov 25, 2019 7:53 am

Stop rendering and save battery power

Post by ghorwin »

Hi there,

first of all, hi to the community (I'm new to Irrlicht) and a big compliment about this engine! Awesome.

Quick general question: when a scene is not moved by a user and not animated itself, is it possible to prevent render updates so that the graphics card won't have to refresh the view at say, 60 FPS? I'm asking because I want to conserve battery power, when simply viewing an inanimate scene.

Is it possible to put a view into a mode that caches the rendered image on screen and using double-buffering on the painting device. So that the graphics card would only be used, when:

a) resulution of view changes (scaling)
b) scene/camera position is modified by user

but not when another desktop window is moved in front of the scene view? That could save a lot of battery power.

Thanks,
Andreas
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Stop rendering and save battery power

Post by CuteAlien »

You decide when you render, not the engine (you do beginScene(), draw-calls, endScene() somewhere in your main loop). You can render to a texture and then use that texture (set a render target texture, draw to that, then create a screen quad and put your render target texture on that... newest svn trunk version has an example for fullscreen effects with screen quad since a few days, so you might want to check that).
I don't know how much rendering a single texture vs rendering a scene is saving battery (probably depends on the complexity of the scene, but I never experimented... measuring power consumption is tricky).

Some other things you can do:
- Use vsync. Then rendering waits for whatever vsync value you have enabled (like 60 fps).
- Use sleep() (Irrlicht device has sleep function). Even a tiny bit of sleep like just 1ms in your main loop will make a huge difference in cpu consumption. I often increase sleep() time when the application is not the active window.

Handling the case another window is in front of the Irrlicht window is tricky. You can notice when you are not active, but the case of being hidden is harder to find out. 3d applications usually just do awindow redraw. It's not like typical UI applications which just can do nothing until the system sends them a request to redraw some rectangular part of their window. Well... in theory Irrlicht also wouldn't have to redraw until the OS sends such a message, but I don't think that's passed through (as games you usually just don't work like that). Thought it's probably possible to do it somehow like embedding Irrlicht in some other UI system and then react to redraw request in there by rendering again and not rendering otherwise.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
AReichl
Posts: 270
Joined: Wed Jul 13, 2011 2:34 pm

Re: Stop rendering and save battery power

Post by AReichl »

try this:

while(device->run())
{
static bool bTimerRunning = true;
if( ! device->isWindowActive() ) {
if( bTimerRunning ) {
device->getTimer()->stop();
bTimerRunning = false;
}
continue;
} else {
if( ! bTimerRunning ) {
device->getTimer()->start();
bTimerRunning = true;
}
}

driver->beginScene( ...);
smgr->drawAll();
guienv->drawAll();
driver->endScene();

int fps = driver->getFPS();
if(fps != lastFps)
{
...
}
}
ghorwin
Posts: 2
Joined: Mon Nov 25, 2019 7:53 am

Re: Stop rendering and save battery power

Post by ghorwin »

:D Awesome, thanks both of you - actually, the combination of both suggestions does the trick:

a) I detect the unfocusing of the window with isWindowActive() and whenever the window isn't active I use sleep(10)
b) when the mouse focus is elsewhere in the GUI, I also set the scene to sleep(10), and reset the sleep value when focus is back on the device window

CPU consumption goes down a lot... I'll do some benchmarking on some of the bigger scenes and let you know how much longer I can get my battery to last.

Thanks a lot for the help!

-Andreas
Post Reply