ogre stops to render

Problems building or running the engine, queries about how to use features etc.
User avatar
Kristian
Hobgoblin
Posts: 542
Joined: Sun Jan 12, 2003 7:35 pm
Location: Copenhagen, Denmark

ogre stops to render

Post by Kristian »

Hi guys
Can someone tell me how I can prevent Ogre from stopping the rendering in a windowed rendering session when i switch to another window ?

- Kristian
User avatar
eugen
OGRE Expert User
OGRE Expert User
Posts: 1422
Joined: Sat May 22, 2004 5:28 am
Location: Bucharest
x 8

Post by eugen »

i dont think it can be done! when switching to another window the render window becomes inactive and thus not something to render in...but i'm not 100% sure about this! why will u need to render on screen if the window is inactive and maybe covered by another window??
if u really need the frames when window inactive, use RenderTarget...this way u can have each rendered frame in a texture (u can do whatever u like with it, even save it on disk) !
nfz
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 1263
Joined: Wed Sep 24, 2003 4:00 pm
Location: Halifax, Nova Scotia, Canada

Post by nfz »

I do it in the material editor I am working on but there are some small changes you have to make to the Ogre renderers (d3d9, gl). I modified the windows message handling routines in OgreWin32Window.cpp (GL renderer) and OgreD3D9RenderWindow.cpp (D3D9 renderer).

This is what I have for both renderers:

Code: Select all

  case WM_ACTIVATE:
  //if( WA_INACTIVE == LOWORD( wParam ) )
  //	win->mActive = false;
  //else
    win->mActive = true;
  break;

The commented out code is the original code.

So the only time win->mActive is set to false is when the window is minimized which is handled lower down in the windows message handling routines by original code. I never understood why drawing to the window was stopped when the window was no longer active. Its only a problem for device context when the window is minimized or no longer visible (moved off screen) and the original code handles this.

I have been using these changes since Ogre 0.13 with no problems in DX9 or OGL and it works with Ogre 1.0 too :).

Maybe I should submit a patch?
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66

Post by sinbad »

If this is a patch, I think this should be added as a RenderWindow option, like

Code: Select all

virtual void setUpdateWhileInactive(bool upd);
It's intentional that we stop rendering when losing the focus - for example in fullscreen mode it will fail anyway but otherwise you probably don't want Ogre hogging the machine whilst you're trying to write an email!
User avatar
PeterNewman
Greenskin
Posts: 128
Joined: Mon Jun 21, 2004 2:34 am
Location: Victoria, Australia

Post by PeterNewman »

I'm not entirely sure, but doesn't it do that anyway (hog even when inactive)? I know when Alt-F4 used to close the window but not exit Ogre, it was still chugging the system even though nothing at all was being rendered.


Myself, I'm using a custom main loop, with a Sleep(0) in it, so Ogre uses 100% if its available, but hands off as soon as anything else wants anything. Not cross-platform though.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66

Post by sinbad »

The ALT-F4 thing is different - that was just not shutting down when the window was closed. If you minimise or otherwise switch tasks Ogre definitely stops hogging.
iq
Greenskin
Posts: 125
Joined: Mon Oct 20, 2003 8:25 pm

Post by iq »

I think that's wrong - it stops rendering, but the programs still loop as fast as possible.

Quick check: running terrain demo windowed and Alt-Tab to explorer window still shows 50% cpu use (HT system, so the thread uses 100% of one virtual core)
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66

Post by sinbad »

It's still light work - I would guess it's so high because nothing else is happening. No, we don't 'sleep' the thread but it's basically in a spin loop, which is not taxing. Start something else up and it will balance more. 100% use of idle time is not hogging.. ;)
qsilver
OGRE Community Helper
OGRE Community Helper
Posts: 198
Joined: Sat Oct 02, 2004 9:11 am
Location: San Francisco, California, USA

Post by qsilver »

But it does throw variable-speed CPUs into high gear! My poor, poor laptop battery... :(

I hacked Ogre's main loop to use WaitMessage() instead of spinning. It's an easy change, but I guess I can submit a patch if you want one.
iq
Greenskin
Posts: 125
Joined: Mon Oct 20, 2003 8:25 pm

Post by iq »

Me personally I don't mind it running through the main loop - writing a game I looked at implementing a custom render loop to keep the network system running until I noticed that only the rendering stops. :o

But still it might do hvy calcs inside the apps - although I firmly believe that a windowed application should do manual rendering and sleeping and not use the ogre main loop.
User avatar
Sarev0k
Halfling
Posts: 86
Joined: Mon Dec 13, 2004 9:47 am
Location: Oregon, United States

Post by Sarev0k »

sinbad wrote:If this is a patch, I think this should be added as a RenderWindow option, like

Code: Select all

virtual void setUpdateWhileInactive(bool upd);
It's intentional that we stop rendering when losing the focus - for example in fullscreen mode it will fail anyway but otherwise you probably don't want Ogre hogging the machine whilst you're trying to write an email!
I was wondering if this ever made it into a build of ogre?

From looking at the source files of the latest release, I don't think it has. Is this a planned feature?

Thanks
Image
An open source 3D real-time strategy game engine (under development)
qsilver
OGRE Community Helper
OGRE Community Helper
Posts: 198
Joined: Sat Oct 02, 2004 9:11 am
Location: San Francisco, California, USA

Post by qsilver »

Some more work needs to be done to redefine what an "active" window is, and how this all works with multiple renderwindows. This will eventually make it in to the 1.1 (Dagon) series but is unlikely to hit the 1.0 branch.

Ogre 1.0 apps that care about this should use their own main loop and call Ogre to render one frame at a time.
rkosh
Gnoblar
Posts: 11
Joined: Thu Jun 30, 2005 12:47 am

Post by rkosh »

@NFZ: My OgreWin32Window.cpp looks like this:

Code: Select all

case WM_ACTIVATE:
			if (win->mIsFullScreen)
			{
				if (LOWORD(wParam) == WA_INACTIVE)
				{
					win->mActive = false;
					ChangeDisplaySettings(NULL, 0);
					ShowWindow(hWnd, SW_SHOWMINNOACTIVE);
				}
				else
				{
					win->mActive = true;
					ShowWindow(hWnd, SW_SHOWNORMAL);

					DEVMODE dm;
					dm.dmSize = sizeof(DEVMODE);
					dm.dmBitsPerPel = win->mColourDepth;
					dm.dmPelsWidth = win->mWidth;
					dm.dmPelsHeight = win->mHeight;
					dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
					if (win->mDisplayFrequency)
					{
						dm.dmDisplayFrequency = win->mDisplayFrequency;
						dm.dmFields |= DM_DISPLAYFREQUENCY;
					}
					ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
				}
			}
			break;
can I do this:

Code: Select all

case WM_ACTIVATE:
			if (win->mIsFullScreen)
			{
				/*if (LOWORD(wParam) == WA_INACTIVE)
				{
					win->mActive = false;
					ChangeDisplaySettings(NULL, 0);
					ShowWindow(hWnd, SW_SHOWMINNOACTIVE);
				}
				else*/
				{
					win->mActive = true;
					ShowWindow(hWnd, SW_SHOWNORMAL);

					DEVMODE dm;
					dm.dmSize = sizeof(DEVMODE);
					dm.dmBitsPerPel = win->mColourDepth;
					dm.dmPelsWidth = win->mWidth;
					dm.dmPelsHeight = win->mHeight;
					dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
					if (win->mDisplayFrequency)
					{
						dm.dmDisplayFrequency = win->mDisplayFrequency;
						dm.dmFields |= DM_DISPLAYFREQUENCY;
					}
					ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
				}
			}
			break;
will this have the same effect that the render window doesnt stop rendering when it looses focus?
Thanks