From 74aa40f2774a8e3f37c7368fed491f4fc40f41bc Mon Sep 17 00:00:00 2001 From: kaetemi Date: Thu, 7 Aug 2014 04:36:51 +0200 Subject: [PATCH] Clean handling of display mode switching in client --- code/nel/include/nel/3d/stereo_debugger.h | 2 +- code/nel/include/nel/3d/stereo_display.h | 4 ++-- code/nel/include/nel/3d/stereo_ovr_04.h | 2 +- .../src/3d/driver/opengl/driver_opengl_window.cpp | 2 +- code/nel/src/3d/stereo_debugger.cpp | 4 ++-- code/nel/src/3d/stereo_ovr_04.cpp | 3 ++- code/ryzom/client/src/connection.cpp | 14 ++++++++------ code/ryzom/client/src/global.cpp | 1 + code/ryzom/client/src/global.h | 1 + code/ryzom/client/src/main_loop_utilities.cpp | 14 ++++++++++++-- 10 files changed, 31 insertions(+), 16 deletions(-) diff --git a/code/nel/include/nel/3d/stereo_debugger.h b/code/nel/include/nel/3d/stereo_debugger.h index 81432d672..6c974f93d 100644 --- a/code/nel/include/nel/3d/stereo_debugger.h +++ b/code/nel/include/nel/3d/stereo_debugger.h @@ -73,7 +73,7 @@ public: void recycleTextures(); /// Attach the driver to the display - virtual void attachToDisplay(); + virtual bool attachToDisplay(); /// Detach the driver from the display virtual void detachFromDisplay(); diff --git a/code/nel/include/nel/3d/stereo_display.h b/code/nel/include/nel/3d/stereo_display.h index 2e37f0663..3b6fdbb21 100644 --- a/code/nel/include/nel/3d/stereo_display.h +++ b/code/nel/include/nel/3d/stereo_display.h @@ -95,8 +95,8 @@ public: /// Sets driver and generates necessary render targets virtual void setDriver(NL3D::UDriver *driver) = 0; - /// Attach the driver to the display - virtual void attachToDisplay() = 0; + /// Attach the driver to the display, return true if attached + virtual bool attachToDisplay() = 0; /// Detach the driver from the display virtual void detachFromDisplay() = 0; diff --git a/code/nel/include/nel/3d/stereo_ovr_04.h b/code/nel/include/nel/3d/stereo_ovr_04.h index f87ba2754..a424eff2e 100644 --- a/code/nel/include/nel/3d/stereo_ovr_04.h +++ b/code/nel/include/nel/3d/stereo_ovr_04.h @@ -91,7 +91,7 @@ public: virtual void setDriver(NL3D::UDriver *driver); /// Attach the driver to the display - virtual void attachToDisplay(); + virtual bool attachToDisplay(); /// Detach the driver from the display virtual void detachFromDisplay(); diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp index 2e9da2431..65f219fc7 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp @@ -2419,7 +2419,7 @@ void CDriverGL::setWindowPos(sint32 x, sint32 y) && GetCursorPos(&cursorPos) && ScreenToClient(_win, &cursorPos); - SetWindowPos(_win, NULL, x, y, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE); + SetWindowPos(_win, NULL, x, y, 0, 0, /*SWP_NOZORDER | SWP_NOACTIVATE |*/ SWP_NOSIZE); if (cursorPosOk) { diff --git a/code/nel/src/3d/stereo_debugger.cpp b/code/nel/src/3d/stereo_debugger.cpp index 940ada508..6650e1c2b 100644 --- a/code/nel/src/3d/stereo_debugger.cpp +++ b/code/nel/src/3d/stereo_debugger.cpp @@ -211,9 +211,9 @@ void CStereoDebugger::setDriver(NL3D::UDriver *driver) } } -void CStereoDebugger::attachToDisplay() +bool CStereoDebugger::attachToDisplay() { - + return false; } void CStereoDebugger::detachFromDisplay() diff --git a/code/nel/src/3d/stereo_ovr_04.cpp b/code/nel/src/3d/stereo_ovr_04.cpp index 3eb666360..fb6b86411 100644 --- a/code/nel/src/3d/stereo_ovr_04.cpp +++ b/code/nel/src/3d/stereo_ovr_04.cpp @@ -444,7 +444,7 @@ bool CStereoOVR::getScreenResolution(uint &width, uint &height) return false; } -void CStereoOVR::attachToDisplay() +bool CStereoOVR::attachToDisplay() { nldebug("OVR: Attach to display '%s'", m_DevicePtr->DisplayDeviceName); @@ -461,6 +461,7 @@ void CStereoOVR::attachToDisplay() mode.Height = m_DevicePtr->Resolution.h; m_Driver->setMode(mode); m_AttachedDisplay = true; + return true; } void CStereoOVR::detachFromDisplay() diff --git a/code/ryzom/client/src/connection.cpp b/code/ryzom/client/src/connection.cpp index 58dbca399..d9051d820 100644 --- a/code/ryzom/client/src/connection.cpp +++ b/code/ryzom/client/src/connection.cpp @@ -206,9 +206,13 @@ void connectionRestaureVideoMode () if (ClientCfg.Width < 800) ClientCfg.Width = 800; if (ClientCfg.Height < 600) ClientCfg.Height = 600; - if ((ClientCfg.Windowed != mode.Windowed) || + if (StereoDisplay) + StereoDisplayAttached = StereoDisplay->attachToDisplay(); + + if (!StereoDisplayAttached && ( + (ClientCfg.Windowed != mode.Windowed) || (ClientCfg.Width != mode.Width) || - (ClientCfg.Height != mode.Height)) + (ClientCfg.Height != mode.Height))) { mode.Windowed = ClientCfg.Windowed; mode.Depth = uint8(ClientCfg.Depth); @@ -218,9 +222,6 @@ void connectionRestaureVideoMode () setVideoMode(mode); } - if (StereoDisplay) - StereoDisplay->attachToDisplay(); - // And setup hardware mouse if we have to InitMouseWithCursor (ClientCfg.HardwareCursor); SetMouseFreeLook (); @@ -257,8 +258,9 @@ void setOutGameFullScreen() // NB: don't setup fullscreen if player wants to play in window if (!ClientCfg.Local && ClientCfg.SelectCharacter == -1) { - if (StereoDisplay) + if (StereoDisplayAttached) StereoDisplay->detachFromDisplay(); + StereoDisplayAttached = false; UDriver::CMode currMode; Driver->getCurrentScreenMode(currMode); diff --git a/code/ryzom/client/src/global.cpp b/code/ryzom/client/src/global.cpp index 83be0e04f..7c298ca58 100644 --- a/code/ryzom/client/src/global.cpp +++ b/code/ryzom/client/src/global.cpp @@ -28,6 +28,7 @@ using namespace NLMISC; NL3D::UDriver *Driver = NULL; // The main 3D Driver NL3D::IStereoDisplay *StereoDisplay = NULL; // Stereo display NL3D::IStereoHMD *StereoHMD = NULL; // Head mount display +bool StereoDisplayAttached = false; // Is stereo display handling the display mode CSoundManager *SoundMngr = NULL; // the sound manager NL3D::UMaterial GenericMat; // Generic Material NL3D::UTextContext *TextContext = NULL; // Context for all the text in the client. diff --git a/code/ryzom/client/src/global.h b/code/ryzom/client/src/global.h index ac47b22cc..de9aa6a73 100644 --- a/code/ryzom/client/src/global.h +++ b/code/ryzom/client/src/global.h @@ -82,6 +82,7 @@ const float ExtraZoneLoadingVision = 100.f; extern NL3D::UDriver *Driver; // The main 3D Driver extern NL3D::IStereoDisplay *StereoDisplay; // Stereo display extern NL3D::IStereoHMD *StereoHMD; // Head mount display +extern bool StereoDisplayAttached; // Is stereo display handling the display mode extern CSoundManager *SoundMngr; // the sound manager extern NL3D::UMaterial GenericMat; // Generic Material extern NL3D::UTextContext *TextContext; // Context for all the text in the client. diff --git a/code/ryzom/client/src/main_loop_utilities.cpp b/code/ryzom/client/src/main_loop_utilities.cpp index 7db7cc0bb..ecf3c7fae 100644 --- a/code/ryzom/client/src/main_loop_utilities.cpp +++ b/code/ryzom/client/src/main_loop_utilities.cpp @@ -59,10 +59,20 @@ void updateFromClientCfg() ))) { nldebug("Apply VR device change"); + // detach display mode + if (StereoDisplay && StereoDisplayAttached) + StereoDisplay->detachFromDisplay(); + StereoDisplayAttached = false; + // re-init releaseStereoDisplayDevice(); initStereoDisplayDevice(); + // try attach display mode if (StereoDisplay) - StereoDisplay->attachToDisplay(); + StereoDisplayAttached = StereoDisplay->attachToDisplay(); + // set latest config display mode if not attached + if (!StereoDisplayAttached) + setVideoMode(UDriver::CMode(ClientCfg.Width, ClientCfg.Height, (uint8)ClientCfg.Depth, + ClientCfg.Windowed, ClientCfg.Frequency)); } // GRAPHICS - GENERAL @@ -73,7 +83,7 @@ void updateFromClientCfg() (ClientCfg.Depth != LastClientCfg.Depth) || (ClientCfg.Frequency != LastClientCfg.Frequency)) { - if (!StereoDisplay) // TODO + if (!StereoDisplayAttached) { setVideoMode(UDriver::CMode(ClientCfg.Width, ClientCfg.Height, (uint8)ClientCfg.Depth, ClientCfg.Windowed, ClientCfg.Frequency));