Problem switching resolution and mode at the same time

Problems building or running the engine, queries about how to use features etc.
Post Reply
TheWanderer
Halfling
Posts: 44
Joined: Fri Apr 22, 2005 3:58 pm
x 4

Problem switching resolution and mode at the same time

Post by TheWanderer »

Ogre Version: Version 1.12.4 (Rhagorthua)
Operating System: Windows 10
Render System: D3D9

Hey all,

It's been a while. but I've recently gotten back to working on a personal project and I'm having a bit of an issue when switching from full screen to windowed. I had a similar question before, but I've gotten little further along since then (things render now when doing the second switch :D )

Testing Environment:

I have one background texture (material definition included below) which covers the whole window as well as some CEGUI UI elements. My monitor resolution is set to 1920x1200

Steps:

1) Start in Windowed mode (I usually use 1680 x1050 here)
2) Switch to FullScreen at some resolution smaller than 1920x1200 (Everything looks good)
3) Switch to Windowed at 1920x1200

After running through these steps, what I see is the background texture only rendering in what would have fit in the FullScreen resolution, i.e. a small rectangle in the upper left of my screen. I've tried switching to full screen at different resolutions and the area being drawn to after the switch back to windowed always matches the fullscreen resolution.

I've traced the device reset in a debugger to see whether the dimensions in the presentation parameters are correct when the reset occurs, and they are, though I do notice that the visible area for the window immediately after the reset matches the old full screen resolution. I can get the values if you guys think it useful.

I also ran across a function called D3D9RenderWindow::_finishSwitchingFullscreen() which checks whether the application window size matches the desired resolution (which it does; nothing really changes after this call).

I have a loop on a timer printing my window size using GetWindowRect() as well as the viewport size and both have the correct resolution for the new mode.

What else can I check? What other information can I provide to help clarify the situation?

Edit: I just ran another quick test and if I switch back to Windowed mode in the same resolution and the switch again to the higher resolution, it works. So there is something about switching resolution and mode at the same time.

Here are the logs that I have for the switch:

From Windowed to FullScreen

Code: Select all

[18:07:51] Ogre: D3D9 : RenderSystem Option: Video Mode = 640 x 480 @ 32-bit colour
[18:07:52] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_7
[18:07:52] Ogre: Released D3D9 texture: _cegui_ogre_7
[18:07:52] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_17
[18:07:52] Ogre: Released D3D9 texture: _cegui_ogre_17
[18:07:52] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_12
[18:07:52] Ogre: Released D3D9 texture: _cegui_ogre_12
[18:07:52] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_32
[18:07:52] Ogre: Released D3D9 texture: _cegui_ogre_32
[18:07:52] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_22
[18:07:52] Ogre: Released D3D9 texture: _cegui_ogre_22
[18:07:52] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_27
[18:07:52] Ogre: Released D3D9 texture: _cegui_ogre_27
[18:07:52] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_37
[18:07:52] Ogre: Released D3D9 texture: _cegui_ogre_37
[18:07:52] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_52
[18:07:52] Ogre: Released D3D9 texture: _cegui_ogre_52
[18:07:52] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_62
[18:07:52] Ogre: Released D3D9 texture: _cegui_ogre_62
[18:07:52] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_57
[18:07:52] Ogre: Released D3D9 texture: _cegui_ogre_57
[18:07:52] Ogre: D3D9 Device 0x[0A958EE0] entered lost state
[18:07:52] Ogre: !!! Direct3D Device successfully restored.
[18:07:52] Ogre: D3D9 device: 0x[0A958EE0] was reset
[18:08:02] Ogre: D3D9 : RenderSystem Option: Video Mode = 640 x 480 @ 32-bit colour
From FullScreen to Windowed

Code: Select all

[18:37:32] Ogre: D3D9 : RenderSystem Option: Video Mode = 1920 x 1200 @ 32-bit colour
[18:08:13] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_7
[18:08:13] Ogre: Released D3D9 texture: _cegui_ogre_7
[18:08:13] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_17
[18:08:13] Ogre: Released D3D9 texture: _cegui_ogre_17
[18:08:13] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_12
[18:08:13] Ogre: Released D3D9 texture: _cegui_ogre_12
[18:08:13] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_32
[18:08:13] Ogre: Released D3D9 texture: _cegui_ogre_32
[18:08:13] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_22
[18:08:13] Ogre: Released D3D9 texture: _cegui_ogre_22
[18:08:13] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_27
[18:08:13] Ogre: Released D3D9 texture: _cegui_ogre_27
[18:08:13] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_37
[18:08:13] Ogre: Released D3D9 texture: _cegui_ogre_37
[18:08:13] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_52
[18:08:13] Ogre: Released D3D9 texture: _cegui_ogre_52
[18:08:13] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_62
[18:08:13] Ogre: Released D3D9 texture: _cegui_ogre_62
[18:08:13] Ogre: D3D9 device: 0x[0A958EE0] lost. Releasing D3D9 texture: _cegui_ogre_57
[18:08:13] Ogre: Released D3D9 texture: _cegui_ogre_57
[18:08:13] Ogre: D3D9 Device 0x[0A958EE0] entered lost state
[18:08:13] Ogre: Warning: D3D9: disabling VSync in windowed mode can cause timing issues at lower frame rates, turn VSync on if you observe this problem.
[18:08:13] Ogre: !!! Direct3D Device successfully restored.
[18:08:13] Ogre: D3D9 device: 0x[0A958EE0] was reset

Code: Select all

material LoginStateBackground
{
	technique
	{
		pass
		{
			depth_check off
			depth_write off
			lighting off
		
			texture_unit
			{
				texture LoadScreen.png 2d 0
			}
		}
	}
}
Thank you for any help provided!
The Wanderer
User avatar
sercero
Bronze Sponsor
Bronze Sponsor
Posts: 449
Joined: Sun Jan 18, 2015 4:20 pm
Location: Buenos Aires, Argentina
x 155

Re: Problem switching resolution and mode at the same time

Post by sercero »

How do you switch to Fullscreen?

What does the code look like?

I don't think I'll be able to help you, but I am having trouble switching to Fullscreen.

Thanks
TheWanderer
Halfling
Posts: 44
Joined: Fri Apr 22, 2005 3:58 pm
x 4

Re: Problem switching resolution and mode at the same time

Post by TheWanderer »

Hey sercero,

No worries! Happy to share information.

I call OgreRenderWindow::resize() when NOT switching mode and OgreRenderWindow::setFullscreen() if there is a mode switch involved. So something like this (I've removed some extraneous logging code and error checking to make it more readable):

Code: Select all

bool GraphicsSystem::UpdateGraphicsConfig( uint32_t width, uint32_t height, WindowModeType newMode )
{
    if( GetCurrentWindowMode() != newMode )
    {
        m_renderWindow->setFullscreen( newMode == WindowModeType::FullScreenExclusive, width, height );
    }
    else if( GetCurrentResolution() != Resolution( width, height ) ) 
    {
        m_renderWindow->resize( width,  height );
    }
    SetCurrentWindowMode( newMode );
    SetCurrentResolution( width, height );
}
If you're having issues, one question is whether Ogre is creating the window or whether you're providing your own "external" window. If you're using an external window, then you might have some issues if your window has a different style than the one used by Ogre (though you do have some control over it using params, e.g. border). This was my previous issue, and I ended up adding a couple of extra params so that I could set the FullScreen and Windowed styles myself when calling OgreRoot::createRenderWindow().

Another problem with an external window is making sure that the size of the window matches the one you've told Ogre you're using. Note that the values to either Ogre function are of the Window's client area and not the full Application window.

All in all, it's pretty straightforward. Well, except for the issues I'm running into :)
TheWanderer
Halfling
Posts: 44
Joined: Fri Apr 22, 2005 3:58 pm
x 4

Re: Problem switching resolution and mode at the same time

Post by TheWanderer »

Quick, small update:

I ran an experiment in Pix and traced a frame after the second change in window mode (i.e. FullScreen to Windowed). The frame in Pix showed it as drawing the entire background texture, even though I could only see the upper left corner in the application.

As stated above, the application window appears to be the correct size, so not sure why it only draws what would have been visible in the full screen resolution.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1993
Joined: Sun Mar 30, 2014 2:51 pm
x 1073
Contact:

Re: Problem switching resolution and mode at the same time

Post by paroj »

try calling windowMovedOrResized after you do something with the window.
TheWanderer
Halfling
Posts: 44
Joined: Fri Apr 22, 2005 3:58 pm
x 4

Re: Problem switching resolution and mode at the same time

Post by TheWanderer »

Hey paroj,

Thanks for the suggestion! Unfortunately it did not seem to fix the issue. I tested it by tying the call to a shortcut key so I could call it at will, which allowed be to test various cases. I tried just the function, after a small resize, and after a small resize and move. No luck in any of the cases.

Looking at what the function does, it calls updateWindowRect(), which is getting called from both setFullscreen() and from _finishSwitchingFullscreen(), so I would expect not much to change. I'll take another look at the viewports to see if I find anything there.

I'm currently trying out some experiments to see whether the fact that I'm operating at the screen resolution in my second mode switch is the issue. I'll report back with what I find.

I appreciate the info!
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5292
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Problem switching resolution and mode at the same time

Post by dark_sylinc »

A picture says a thousand words. Could you post one please?

Cheers
TheWanderer
Halfling
Posts: 44
Joined: Fri Apr 22, 2005 3:58 pm
x 4

Re: Problem switching resolution and mode at the same time

Post by TheWanderer »

Hey, dark_sylinc.

Here are some images of all three steps.

Two things that I should have mentioned is that 1) I'm using an external hWND and 2) when I go back to windowed, I choose a style without the window header, since I'm trying to implement a Windowed/Fullscreen mode, if you will.

Windowed (1680x1050):
Image

Fullscreen (640x480; which isn't showing much, I guess...):
Image

Back to windowed (1920x1200), which shows only what would have fit in Fullscreen mode (and my Gandalf wallpaper):
Image
TheWanderer
Halfling
Posts: 44
Joined: Fri Apr 22, 2005 3:58 pm
x 4

Re: Problem switching resolution and mode at the same time

Post by TheWanderer »

Victory!!! :shock:

The root of the issue appears to be a call to SetWindowRgn() inside of D3D9RenderWindow::_finishSwitchingFullscreen(), which, when switching to fullscreen (and ONLY to fullscreen), limits the region of the screen to which drawing can be done. Since this never gets reset when switching back to windowed mode, you end up only seeing the area which would have fit inside the fullscreen resolution. Since I'm using an external window, I added a if( mIsExternal ) { return; } at the top of the function to skip it. Any idea why this function is there and why it's not also called when switching to Windowed mode?

Admittedly, I've had to make a couple of more modifications to the DX9 renderer. I feel like the external window handle is not treated as such consistently, so there's a few places where Ogre modifies it when I feel it should not and a few places where it doesn't when I feel it should.

The other change which I had to make (which I've not yet resolved cleanly) occurs in D3D9Device::validateDisplayMonitor() where the resolution change would land my window on my second monitor, causing the to not reset as expected. Actually, now that I think about it, I *might* have resolved that, but I need to test it a bit more. I'll follow up with my findings.

In any case, I'm going to see about submitting a PR to have these changes integrated into the DX9 Renderer. Is there anything special I need to do? ( Didn't seem like it from reading this ). At the very least, it'd be informative to see whether they way that I approached the change makes sense.
User avatar
sercero
Bronze Sponsor
Bronze Sponsor
Posts: 449
Joined: Sun Jan 18, 2015 4:20 pm
Location: Buenos Aires, Argentina
x 155

Re: Problem switching resolution and mode at the same time

Post by sercero »

You might want to create an issue in the github repo to discuss the changes before going into the trouble of creating and submitting the patch, but it is your choice of course.
TheWanderer
Halfling
Posts: 44
Joined: Fri Apr 22, 2005 3:58 pm
x 4

Re: Problem switching resolution and mode at the same time

Post by TheWanderer »

Thanks, sercero! That's exactly what I was looking for (I'm not too familiar with Github).

I'll link the issue here and mark the thread "Resolved" when I do so.
Post Reply