diff --git a/src/GraphicsDeviceManager.cs b/src/GraphicsDeviceManager.cs index 5cce21d..5a415ec 100644 --- a/src/GraphicsDeviceManager.cs +++ b/src/GraphicsDeviceManager.cs @@ -219,56 +219,70 @@ namespace Microsoft.Xna.Framework return; } - // We're about to reset a device, notify the application. - OnDeviceResetting(this, EventArgs.Empty); + // Recreate device information before resetting + GraphicsDeviceInformation gdi = new GraphicsDeviceInformation(); + gdi.Adapter = GraphicsDevice.Adapter; + gdi.GraphicsProfile = GraphicsDevice.GraphicsProfile; + gdi.PresentationParameters = GraphicsDevice.PresentationParameters.Clone(); + OnPreparingDeviceSettings( + this, + new PreparingDeviceSettingsEventArgs(gdi) + ); - // Apply the GraphicsDevice changes internally. - GraphicsDevice.PresentationParameters.BackBufferFormat = + /* Apply the GraphicsDevice changes to the new Parameters. + * FIXME: Do we care about what OnPreparingDeviceSettings says about + * any of the data we're overwriting here? + * -flibit + */ + gdi.PresentationParameters.BackBufferFormat = PreferredBackBufferFormat; - GraphicsDevice.PresentationParameters.BackBufferWidth = + gdi.PresentationParameters.BackBufferWidth = PreferredBackBufferWidth; - GraphicsDevice.PresentationParameters.BackBufferHeight = + gdi.PresentationParameters.BackBufferHeight = PreferredBackBufferHeight; - GraphicsDevice.PresentationParameters.DepthStencilFormat = + gdi.PresentationParameters.DepthStencilFormat = PreferredDepthStencilFormat; - GraphicsDevice.PresentationParameters.IsFullScreen = + gdi.PresentationParameters.IsFullScreen = IsFullScreen; if (!PreferMultiSampling) { - GraphicsDevice.PresentationParameters.MultiSampleCount = 0; + gdi.PresentationParameters.MultiSampleCount = 0; } - else if (GraphicsDevice.PresentationParameters.MultiSampleCount == 0) + else if (gdi.PresentationParameters.MultiSampleCount == 0) { /* XNA4 seems to have an upper limit of 8, but I'm willing to * limit this only in GraphicsDeviceManager's default setting. * If you want even higher values, Reset() with a custom value. * -flibit */ - GraphicsDevice.PresentationParameters.MultiSampleCount = Math.Min( + gdi.PresentationParameters.MultiSampleCount = Math.Min( GraphicsDevice.GLDevice.MaxMultiSampleCount, 8 ); } + // We're about to reset a device, notify the application. + OnDeviceResetting(this, EventArgs.Empty); + // Make the Platform device changes. game.Window.BeginScreenDeviceChange( - GraphicsDevice.PresentationParameters.IsFullScreen + gdi.PresentationParameters.IsFullScreen ); game.Window.EndScreenDeviceChange( - "FNA", - GraphicsDevice.PresentationParameters.BackBufferWidth, - GraphicsDevice.PresentationParameters.BackBufferHeight + gdi.Adapter.Description, // FIXME: Should be Name! -flibit + gdi.PresentationParameters.BackBufferWidth, + gdi.PresentationParameters.BackBufferHeight ); // Apply the PresentInterval. FNAPlatform.SetPresentationInterval( SynchronizeWithVerticalRetrace ? - GraphicsDevice.PresentationParameters.PresentationInterval : + gdi.PresentationParameters.PresentationInterval : PresentInterval.Immediate ); // Reset! - GraphicsDevice.Reset(); + GraphicsDevice.Reset(gdi.PresentationParameters, gdi.Adapter); // We just reset a device, notify the application. OnDeviceReset(this, EventArgs.Empty); diff --git a/src/SDL2/SDL2_GameWindow.cs b/src/SDL2/SDL2_GameWindow.cs index 304a9c5..a8d4e2b 100644 --- a/src/SDL2/SDL2_GameWindow.cs +++ b/src/SDL2/SDL2_GameWindow.cs @@ -137,8 +137,6 @@ namespace Microsoft.Xna.Framework private string INTERNAL_deviceName; - private Point INTERNAL_lastWindowPosition; - #endregion #region Internal Constructor @@ -221,9 +219,11 @@ namespace Microsoft.Xna.Framework ); INTERNAL_SetIcon(title); + INTERNAL_deviceName = SDL.SDL_GetDisplayName( + SDL.SDL_GetWindowDisplayIndex(INTERNAL_sdlWindow) + ); INTERNAL_isFullscreen = false; INTERNAL_wantsFullscreen = false; - INTERNAL_lastWindowPosition = new Point(SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED); } #endregion @@ -240,9 +240,6 @@ namespace Microsoft.Xna.Framework int clientWidth, int clientHeight ) { - // Set screen device name, not that we use it... - INTERNAL_deviceName = screenDeviceName; - // Fullscreen if ( INTERNAL_wantsFullscreen && (SDL.SDL_GetWindowFlags(INTERNAL_sdlWindow) & (uint) SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN) == 0 ) @@ -256,53 +253,47 @@ namespace Microsoft.Xna.Framework */ SDL.SDL_ShowWindow(INTERNAL_sdlWindow); } - SDL.SDL_SetWindowFullscreen( - INTERNAL_sdlWindow, - INTERNAL_wantsFullscreen ? - (uint) SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP : - 0 - ); - /* Because Mac windows resize from the bottom, we have to get the - * position before changing the size so we can keep the window - * centered when resizing in windowed mode. - * -Nick - */ - Rectangle prevBounds = Rectangle.Empty; + // When windowed, set the size before moving if (!INTERNAL_wantsFullscreen) { - prevBounds = ClientBounds; + SDL.SDL_SetWindowFullscreen(INTERNAL_sdlWindow, 0); + SDL.SDL_SetWindowSize(INTERNAL_sdlWindow, clientWidth, clientHeight); } - // Window bounds - SDL.SDL_SetWindowSize(INTERNAL_sdlWindow, clientWidth, clientHeight); - - // Window position - if (INTERNAL_isFullscreen && !INTERNAL_wantsFullscreen) + // Get on the right display! + int displayIndex = 0; + for (int i = 0; i < GraphicsAdapter.Adapters.Count; i += 1) { - // If exiting fullscreen, just center the window on the desktop. - SDL.SDL_SetWindowPosition( - INTERNAL_sdlWindow, - INTERNAL_lastWindowPosition.X, - INTERNAL_lastWindowPosition.Y - ); + // FIXME: Should be checking Name, not Description! -flibit + if (screenDeviceName == GraphicsAdapter.Adapters[i].Description) + { + displayIndex = i; + break; + } } - else if (!INTERNAL_wantsFullscreen) + + // Just to be sure, become a window first before changing displays + if (INTERNAL_deviceName != screenDeviceName) { - // Store the window position before switching to fullscreen - INTERNAL_lastWindowPosition.X = prevBounds.X + ((prevBounds.Width - clientWidth) / 2); - INTERNAL_lastWindowPosition.Y = prevBounds.Y + ((prevBounds.Height - clientHeight) / 2); + SDL.SDL_SetWindowFullscreen(INTERNAL_sdlWindow, 0); + INTERNAL_deviceName = screenDeviceName; + } - SDL.SDL_SetWindowPosition( + // Window always gets centered, per XNA behavior + int pos = SDL.SDL_WINDOWPOS_CENTERED_DISPLAY(displayIndex); + SDL.SDL_SetWindowPosition( + INTERNAL_sdlWindow, + pos, + pos + ); + + // Set fullscreen after we've done all the ugly stuff. + if (INTERNAL_wantsFullscreen) + { + SDL.SDL_SetWindowFullscreen( INTERNAL_sdlWindow, - Math.Max( - INTERNAL_lastWindowPosition.X, - 0 - ), - Math.Max( - INTERNAL_lastWindowPosition.Y, - 0 - ) + (uint) SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP ); }