Merge pull request #1512 from Lopuska/OpenGL_FullScreen_Clean

[OpenGL - Win32] This fix a bug during resolution change.
This commit is contained in:
Anis 2016-02-18 15:26:21 +01:00
commit d08c0df85d

View file

@ -26,8 +26,10 @@
#include <tchar.h> #include <tchar.h>
#include <winuser.h> #include <winuser.h>
#include "math/mMath.h" #include "math/mMath.h"
#include "gfx/gfxDevice.h"
#include "gfx/gfxStructs.h" #include "gfx/gfxStructs.h"
#include "windowManager/platformWindowMgr.h"
#include "windowManager/win32/win32Window.h" #include "windowManager/win32/win32Window.h"
#include "windowManager/win32/win32WindowMgr.h" #include "windowManager/win32/win32WindowMgr.h"
#include "windowManager/win32/win32CursorController.h" #include "windowManager/win32/win32CursorController.h"
@ -39,11 +41,6 @@
// for winState structure // for winState structure
#include "platformWin32/platformWin32.h" #include "platformWin32/platformWin32.h"
#include <d3d9types.h>
#include "gfx/gfxDevice.h"
#include <zmouse.h>
const UTF16* _MainWindowClassName = L"TorqueJuggernaughtWindow"; const UTF16* _MainWindowClassName = L"TorqueJuggernaughtWindow";
const UTF16* _CurtainWindowClassName = L"TorqueJuggernaughtCurtainWindow"; const UTF16* _CurtainWindowClassName = L"TorqueJuggernaughtCurtainWindow";
@ -148,96 +145,93 @@ const GFXVideoMode & Win32Window::getVideoMode()
void Win32Window::setVideoMode( const GFXVideoMode &mode ) void Win32Window::setVideoMode( const GFXVideoMode &mode )
{ {
bool needCurtain = (mVideoMode.fullScreen != mode.fullScreen); bool needCurtain = ( mVideoMode.fullScreen != mode.fullScreen );
if(needCurtain) if( needCurtain )
{ {
Con::errorf("Win32Window::setVideoMode - invoking curtain"); Con::printf( "Win32Window::setVideoMode - invoking curtain" );
mOwningManager->lowerCurtain(); mOwningManager->lowerCurtain();
} }
mVideoMode = mode; mVideoMode = mode;
mSuppressReset = true; mSuppressReset = true;
// Can't switch to fullscreen while a child of another window // Can't switch to fullscreen while a child of another window
if(mode.fullScreen && !Platform::getWebDeployment() && mOwningManager->getParentWindow()) if( mode.fullScreen && !Platform::getWebDeployment() && mOwningManager->getParentWindow() )
{ {
mOldParent = (HWND)mOwningManager->getParentWindow(); mOldParent = reinterpret_cast<HWND>( mOwningManager->getParentWindow() );
mOwningManager->setParentWindow(NULL); mOwningManager->setParentWindow( NULL );
} }
else if(!mode.fullScreen && mOldParent) else if( !mode.fullScreen && mOldParent )
{ {
mOwningManager->setParentWindow(mOldParent); mOwningManager->setParentWindow( mOldParent );
mOldParent = NULL; mOldParent = NULL;
} }
// Set our window to have the right style based on the mode // Set our window to have the right style based on the mode
if(mode.fullScreen && !Platform::getWebDeployment() && !mOffscreenRender) if( mode.fullScreen && !Platform::getWebDeployment() && !mOffscreenRender )
{ {
WINDOWPLACEMENT wplacement = { sizeof(wplacement) }; WINDOWPLACEMENT wplacement = { sizeof( wplacement ) };
DWORD dwStyle = GetWindowLong(getHWND(), GWL_STYLE); DWORD dwStyle = GetWindowLong( getHWND(), GWL_STYLE );
MONITORINFO mi = { sizeof(mi) }; MONITORINFO mi = { sizeof(mi) };
if (GetWindowPlacement(getHWND(), &wplacement) && GetMonitorInfo(MonitorFromWindow(getHWND(), MONITOR_DEFAULTTOPRIMARY), &mi)) if ( GetWindowPlacement( getHWND(), &wplacement ) && GetMonitorInfo( MonitorFromWindow( getHWND(), MONITOR_DEFAULTTOPRIMARY ), &mi ) )
{
DISPLAY_DEVICE dd = GetPrimaryDevice();
DEVMODE dv;
ZeroMemory(&dv, sizeof(dv));
dv.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dv);
dv.dmPelsWidth = mode.resolution.x;
dv.dmPelsHeight = mode.resolution.y;
dv.dmBitsPerPel = mode.bitDepth;
dv.dmDisplayFrequency = mode.refreshRate;
dv.dmFields = (DM_PELSWIDTH | DM_PELSHEIGHT);
ChangeDisplaySettings(&dv, CDS_FULLSCREEN);
SetWindowLong(getHWND(), GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW);
SetWindowPos(getHWND(), HWND_TOP,
mi.rcMonitor.left,
mi.rcMonitor.top,
mi.rcMonitor.right - mi.rcMonitor.left,
mi.rcMonitor.bottom - mi.rcMonitor.top,
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
}
if(mDisplayWindow)
ShowWindow(getHWND(), SW_SHOWNORMAL);
// Clear the menu bar from the window for full screen
HMENU menu = GetMenu(getHWND());
if(menu)
{ {
SetMenu(getHWND(), NULL); DISPLAY_DEVICE dd = GetPrimaryDevice();
DEVMODE dv;
ZeroMemory( &dv, sizeof( dv ) );
dv.dmSize = sizeof( DEVMODE );
EnumDisplaySettings( dd.DeviceName, ENUM_CURRENT_SETTINGS, &dv );
dv.dmPelsWidth = mode.resolution.x;
dv.dmPelsHeight = mode.resolution.y;
dv.dmBitsPerPel = mode.bitDepth;
dv.dmDisplayFrequency = mode.refreshRate;
dv.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
ChangeDisplaySettings( &dv, CDS_FULLSCREEN );
SetWindowLong( getHWND(), GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW );
SetWindowPos( getHWND(), HWND_TOP, mi.rcMonitor.left,
mi.rcMonitor.top,
mi.rcMonitor.right - mi.rcMonitor.left,
mi.rcMonitor.bottom - mi.rcMonitor.top,
SWP_NOOWNERZORDER | SWP_FRAMECHANGED );
} }
if( mDisplayWindow )
ShowWindow( getHWND(), SW_SHOWNORMAL );
// Clear the menu bar from the window for full screen
if( GetMenu( getHWND() ) )
SetMenu( getHWND(), NULL );
// When switching to Fullscreen, reset device after setting style // When switching to Fullscreen, reset device after setting style
if(mTarget.isValid()) if( mTarget.isValid() )
mTarget->resetMode(); mTarget->resetMode();
mFullscreen = true; mFullscreen = true;
} }
else else
{ {
DISPLAY_DEVICE dd = GetPrimaryDevice(); DISPLAY_DEVICE dd = GetPrimaryDevice();
DEVMODE dv; DEVMODE dv;
ZeroMemory(&dv, sizeof(dv)); ZeroMemory( &dv, sizeof( dv ) );
dv.dmSize = sizeof(DEVMODE); dv.dmSize = sizeof( DEVMODE );
EnumDisplaySettings(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dv); EnumDisplaySettings( dd.DeviceName, ENUM_CURRENT_SETTINGS, &dv );
if ((mode.resolution.x != dv.dmPelsWidth) || (mode.resolution.y != dv.dmPelsHeight)) if ( ( WindowManager->getDesktopResolution() != mode.resolution ||
ChangeDisplaySettings(NULL, 0); ( mode.resolution.x != dv.dmPelsWidth ) || ( mode.resolution.y != dv.dmPelsHeight ) ) )
ChangeDisplaySettings( NULL, 0 );
// Reset device *first*, so that when we call setSize() and let it // Reset device *first*, so that when we call setSize() and let it
// access the monitor settings, it won't end up with our fullscreen // access the monitor settings, it won't end up with our fullscreen
// geometry that is just about to change. // geometry that is just about to change.
if(mTarget.isValid()) if( mTarget.isValid() )
mTarget->resetMode(); mTarget->resetMode();
if (!mOffscreenRender) if ( !mOffscreenRender )
{ {
SetWindowLong( getHWND(), GWL_STYLE, mWindowedWindowStyle); SetWindowLong( getHWND(), GWL_STYLE, mWindowedWindowStyle);
SetWindowPos( getHWND(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); SetWindowPos( getHWND(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
// Put back the menu bar, if any // Put back the menu bar, if any
if(mMenuHandle) if(mMenuHandle)
@ -253,42 +247,37 @@ void Win32Window::setVideoMode( const GFXVideoMode &mode )
} }
else else
{ {
HWND parentWin = (HWND)mOwningManager->getParentWindow(); HWND parentWin = reinterpret_cast<HWND>( mOwningManager->getParentWindow() );
RECT windowRect; RECT windowRect;
GetClientRect(parentWin, &windowRect); GetClientRect( parentWin, &windowRect );
Point2I res(windowRect.right-windowRect.left, windowRect.bottom-windowRect.top); Point2I res( windowRect.right - windowRect.left, windowRect.bottom - windowRect.top );
if (res.x == 0 || res.y == 0)
{ if ( res.x == 0 || res.y == 0 )
// Must be too early in the window set up to obtain the parent's size. setSize( mode.resolution ); // Must be too early in the window set up to obtain the parent's size.
setSize(mode.resolution);
}
else else
{ setSize( res );
setSize(res);
}
} }
if (!mOffscreenRender) if ( !mOffscreenRender )
{ {
// We have to force Win32 to update the window frame and make the window // We have to force Win32 to update the window frame and make the window
// visible and no longer topmost - this code might be possible to simplify. // visible and no longer topmost - this code might be possible to simplify.
SetWindowPos( getHWND(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); SetWindowPos( getHWND(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED );
if(mDisplayWindow) if(mDisplayWindow)
ShowWindow( getHWND(), SW_SHOWNORMAL); ShowWindow( getHWND(), SW_SHOWNORMAL );
} }
mFullscreen = false; mFullscreen = false;
} }
mSuppressReset = false; mSuppressReset = false;
if(needCurtain) if( needCurtain )
mOwningManager->raiseCurtain(); mOwningManager->raiseCurtain();
SetForegroundWindow(getHWND()); SetForegroundWindow( getHWND() );
getScreenResChangeSignal().trigger( this, true );
getScreenResChangeSignal().trigger(this, true);
} }
bool Win32Window::clearFullscreen() bool Win32Window::clearFullscreen()