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
Stop rendering and save battery power
Re: Stop rendering and save battery power
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.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Stop rendering and save battery power
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)
{
...
}
}
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)
{
...
}
}
Re: Stop rendering and save battery power
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
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